Changeset e3f41b6 in mainline


Ignore:
Timestamp:
2005-06-06T20:01:57Z (20 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b0bf501
Parents:
d47f0e1
Message:

Code cleanup in scheduler.c thread.c - removed unnecessary spinlock.
atomic_inc, atomic_dec moved to arch/atomic.h instead of arch/smp/atomic.h,
advisable to use even in non-smp mode.
Fixed atomic_inc, atomic_dec in mips architecture.

Files:
17 edited
3 moved

Legend:

Unmodified
Added
Removed
  • arch/ia32/Makefile.inc

    rd47f0e1 re3f41b6  
    3131        arch/smp/mps.c \
    3232        arch/smp/smp.c \
    33         arch/smp/atomic.S \
     33        arch/atomic.S \
    3434        arch/smp/ipi.c \
    3535        arch/ia32.c \
  • arch/ia32/include/atomic.h

    rd47f0e1 re3f41b6  
    3232#include <arch/types.h>
    3333
    34 extern void atomic_inc(int *val);
    35 extern void atomic_dec(int *val);
     34extern void atomic_inc(volatile int *val);
     35extern void atomic_dec(volatile int *val);
    3636
    3737extern int test_and_set(int *val);
  • arch/ia32/src/atomic.S

    rd47f0e1 re3f41b6  
    3333        pushl %ebx
    3434        movl 8(%esp),%ebx
     35#ifdef __SMP__ 
    3536        lock incl (%ebx)
     37#else
     38        incl (%ebx)
     39#endif         
    3640        popl %ebx
    3741        ret
     
    4145        pushl %ebx
    4246        movl 8(%esp),%ebx
     47#ifdef __SMP__ 
    4348        lock decl (%ebx)
     49#else
     50        decl (%ebx)
     51#endif
    4452        popl %ebx
    4553        ret
  • arch/mips/_link.ld

    rd47f0e1 re3f41b6  
    88
    99OUTPUT_FORMAT(binary)
    10 ENTRY(kernel_image_start)
     10ENTRY(kernel_image_start) 
    1111
    1212SECTIONS {
  • arch/mips/include/atomic.h

    rd47f0e1 re3f41b6  
    3030#define __MIPS_ATOMIC_H__
    3131
    32 #define atomic_inc(x)   ((*x)++)
    33 #define atomic_dec(x)   ((*x)--)
     32#define atomic_inc(x)   (a_add(x,1))
     33#define atomic_dec(x)   (a_sub(x,1))
     34
     35/*
     36 * Atomic addition
     37 *
     38 * This case is harder, and we have to use the special LL and SC operations
     39 * to achieve atomicity. The instructions are similar to LW (load) and SW
     40 * (store), except that the LL (load-linked) instruction loads the address
     41 * of the variable to a special register and if another process writes to
     42 * the same location, the SC (store-conditional) instruction fails.
     43 */
     44static inline int a_add( volatile int *val, int i)
     45{
     46        int tmp, tmp2;
     47
     48        asm volatile (
     49                "       .set    push\n"
     50                "       .set    noreorder\n"
     51                "       nop\n"
     52                "1:\n"
     53                "       ll      %0, %1\n"
     54                "       addu    %0, %0, %2\n"
     55                "       move    %3, %0\n"
     56                "       sc      %0, %1\n"
     57                "       beq     %0, 0x0, 1b\n"
     58                "       move    %0, %3\n"
     59                "       .set    pop\n"
     60                : "=&r" (tmp), "=o" (*val)
     61                : "r" (i), "r" (tmp2)
     62                );
     63        return tmp;
     64}
     65
     66
     67/*
     68 * Atomic subtraction
     69 *
     70 * Implemented in the same manner as a_add, except we substract the value.
     71 */
     72static inline int a_sub( volatile int *val, int i)
     73
     74{
     75        int tmp, tmp2;
     76
     77        asm volatile (
     78                "       .set    push\n"
     79                "       .set    noreorder\n"
     80                "       nop\n"
     81                "1:\n"
     82                "       ll      %0, %1\n"
     83                "       subu    %0, %0, %2\n"
     84                "       move    %3, %0\n"
     85                "       sc      %0, %1\n"
     86                "       beq     %0, 0x0, 1b\n"
     87                "       move    %0, %3\n"
     88                "       .set    pop\n"
     89                : "=&r" (tmp), "=o" (*val)
     90                : "r" (i), "r" (tmp2)
     91                );
     92        return tmp;
     93}
     94
    3495
    3596#endif
  • include/proc/scheduler.h

    rd47f0e1 re3f41b6  
    4444};
    4545
    46 extern spinlock_t nrdylock;
    4746extern volatile int nrdy;
    4847
  • src/Makefile

    rd47f0e1 re3f41b6  
    7171
    7272kernel.bin: $(arch_objects) $(objects) $(test_objects)
    73         $(LD) $(LFLAGS) $(arch_objects) $(objects) $(test_objects) -o $@ >kernel.map
     73        $(LD) $(LFLAGS) $(arch_objects) $(objects) $(test_objects) -o $@ -Map kernel.map
    7474
    7575%.s: %.S
  • src/mm/tlb.c

    rd47f0e1 re3f41b6  
    3131#include <synch/spinlock.h>
    3232#include <typedefs.h>
    33 #include <arch/smp/atomic.h>
     33#include <arch/atomic.h>
    3434#include <arch/interrupt.h>
    3535#include <config.h>
  • src/proc/scheduler.c

    rd47f0e1 re3f41b6  
    4343#include <synch/spinlock.h>
    4444#include <arch/faddr.h>
    45 
    46 #ifdef __SMP__
    47 #include <arch/smp/atomic.h>
    48 #endif /* __SMP__ */
     45#include <arch/atomic.h>
    4946
    5047/*
     
    5451 */
    5552
    56 spinlock_t nrdylock;
    5753volatile int nrdy;
    5854
     
    7874void scheduler_init(void)
    7975{
    80         spinlock_initialize(&nrdylock);
    8176}
    8277
     
    141136                }
    142137       
    143                 spinlock_lock(&nrdylock);
    144                 nrdy--;
    145                 spinlock_unlock(&nrdylock);             
     138                atomic_dec(&nrdy);
    146139
    147140                spinlock_lock(&CPU->lock);
     
    499492                                        spinlock_unlock(&cpu->lock);
    500493
    501                                         spinlock_lock(&nrdylock);
    502                                         nrdy--;
    503                                         spinlock_unlock(&nrdylock);                                     
     494                                        atomic_dec(&nrdy);
    504495
    505496                                        r->n--;
  • src/proc/thread.c

    rd47f0e1 re3f41b6  
    5050#include <smp/ipi.h>
    5151#include <arch/faddr.h>
     52#include <arch/atomic.h>
    5253
    5354char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */
     
    135136        spinlock_unlock(&r->lock);
    136137
    137         spinlock_lock(&nrdylock);
    138         avg = ++nrdy / config.cpu_active;
    139         spinlock_unlock(&nrdylock);
     138        atomic_inc(&nrdy);
     139        avg = nrdy / config.cpu_active;
    140140
    141141        spinlock_lock(&cpu->lock);
  • src/synch/spinlock.c

    rd47f0e1 re3f41b6  
    2929#include <arch.h>
    3030
    31 #ifdef __SMP__
    32 #include <arch/smp/atomic.h>
    33 #endif
    34 
     31#include <arch/atomic.h>
    3532#include <synch/spinlock.h>
    3633
  • src/time/clock.c

    rd47f0e1 re3f41b6  
    3939#include <arch.h>
    4040#include <list.h>
    41 
    42 #ifdef __SMP__
    43 #include <arch/smp/atomic.h>
    44 #endif
     41#include <arch/atomic.h>
    4542
    4643/** Clock routine
  • test/fpu/fpu1/test.c

    rd47f0e1 re3f41b6  
    3333
    3434#include <test.h>
    35 #include <arch/smp/atomic.h>
     35#include <arch/atomic.h>
    3636#include <proc/thread.h>
    3737
  • test/synch/rwlock1/test.c

    rd47f0e1 re3f41b6  
    2929#include <test.h>
    3030#include <arch.h>
    31 #include <arch/smp/atomic.h>
     31#include <arch/atomic.h>
    3232#include <print.h>
    3333#include <proc/thread.h>
  • test/synch/rwlock2/test.c

    rd47f0e1 re3f41b6  
    2929#include <test.h>
    3030#include <arch.h>
    31 #include <arch/smp/atomic.h>
     31#include <arch/atomic.h>
    3232#include <print.h>
    3333#include <proc/thread.h>
  • test/synch/rwlock3/test.c

    rd47f0e1 re3f41b6  
    2929#include <test.h>
    3030#include <arch.h>
    31 #include <arch/smp/atomic.h>
     31#include <arch/atomic.h>
    3232#include <print.h>
    3333#include <proc/thread.h>
  • test/synch/rwlock4/test.c

    rd47f0e1 re3f41b6  
    2929#include <test.h>
    3030#include <arch.h>
    31 #include <arch/smp/atomic.h>
     31#include <arch/atomic.h>
    3232#include <print.h>
    3333#include <proc/thread.h>
  • test/synch/rwlock5/test.c

    rd47f0e1 re3f41b6  
    2929#include <test.h>
    3030#include <arch.h>
    31 #include <arch/smp/atomic.h>
     31#include <arch/atomic.h>
    3232#include <print.h>
    3333#include <proc/thread.h>
  • test/synch/semaphore1/test.c

    rd47f0e1 re3f41b6  
    2929#include <test.h>
    3030#include <arch.h>
    31 #include <arch/smp/atomic.h>
     31#include <arch/atomic.h>
    3232#include <print.h>
    3333#include <proc/thread.h>
  • test/synch/semaphore2/test.c

    rd47f0e1 re3f41b6  
    2929#include <test.h>
    3030#include <arch.h>
    31 #include <arch/smp/atomic.h>
     31#include <arch/atomic.h>
    3232#include <print.h>
    3333#include <proc/thread.h>
Note: See TracChangeset for help on using the changeset viewer.