Fork us on GitHub Follow us on Facebook Follow us on Twitter

Ignore:
Timestamp:
2009-08-21T14:08:20Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
a71c158
Parents:
af8e565
Message:

extend the spinlock interface (static spinlocks, statically declared spinlocks with user-defined name)
ignore deadlock detection on all spinlocks whose name begins with "*" (this is more generic than a hardwired list of spinlocks to ignore)
printf_lock is not required to be public anymore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/synch/spinlock.h

    raf8e565 r90c8b8d  
    4343
    4444#ifdef CONFIG_SMP
     45
    4546typedef struct {
     47        atomic_t val;
     48       
    4649#ifdef CONFIG_DEBUG_SPINLOCK
    4750        char *name;
    4851#endif
    49         atomic_t val;
    5052} spinlock_t;
    5153
     
    5456 * where the lock gets initialized in run time.
    5557 */
    56 #define SPINLOCK_DECLARE(slname)        spinlock_t slname
    57 #define SPINLOCK_EXTERN(slname)         extern spinlock_t slname
     58#define SPINLOCK_DECLARE(lock_name)  spinlock_t lock_name
     59#define SPINLOCK_EXTERN(lock_name)   extern spinlock_t lock_name
    5860
    5961/*
     
    6264 */
    6365#ifdef CONFIG_DEBUG_SPINLOCK
    64 #define SPINLOCK_INITIALIZE(slname)     \
    65         spinlock_t slname = {           \
    66                 .name = #slname,        \
    67                 .val = { 0 }            \
     66
     67#define SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \
     68        spinlock_t lock_name = { \
     69                .name = desc_name, \
     70                .val = { 0 } \
    6871        }
     72
     73#define SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) \
     74        static spinlock_t lock_name = { \
     75                .name = desc_name, \
     76                .val = { 0 } \
     77        }
     78
     79#define spinlock_lock(lock)  spinlock_lock_debug(lock)
     80
    6981#else
    70 #define SPINLOCK_INITIALIZE(slname)     \
    71         spinlock_t slname = {           \
    72                 .val = { 0 }            \
     82
     83#define SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \
     84        spinlock_t lock_name = { \
     85                .val = { 0 } \
    7386        }
     87
     88#define SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) \
     89        static spinlock_t lock_name = { \
     90                .val = { 0 } \
     91        }
     92
     93#define spinlock_lock(lock)  atomic_lock_arch(&(lock)->val)
     94
    7495#endif
    7596
    76 extern void spinlock_initialize(spinlock_t *sl, char *name);
    77 extern int spinlock_trylock(spinlock_t *sl);
    78 extern void spinlock_lock_debug(spinlock_t *sl);
     97#define SPINLOCK_INITIALIZE(lock_name) \
     98        SPINLOCK_INITIALIZE_NAME(lock_name, #lock_name)
    7999
    80 #ifdef CONFIG_DEBUG_SPINLOCK
    81 #  define spinlock_lock(x) spinlock_lock_debug(x)
    82 #else
    83 #  define spinlock_lock(x) atomic_lock_arch(&(x)->val)
    84 #endif
     100#define SPINLOCK_STATIC_INITIALIZE(lock_name) \
     101        SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, #lock_name)
     102
     103extern void spinlock_initialize(spinlock_t *lock, char *name);
     104extern int spinlock_trylock(spinlock_t *lock);
     105extern void spinlock_lock_debug(spinlock_t *lock);
    85106
    86107/** Unlock spinlock
     
    90111 * @param sl Pointer to spinlock_t structure.
    91112 */
    92 static inline void spinlock_unlock(spinlock_t *sl)
     113static inline void spinlock_unlock(spinlock_t *lock)
    93114{
    94         ASSERT(atomic_get(&sl->val) != 0);
    95 
     115        ASSERT(atomic_get(&lock->val) != 0);
     116       
    96117        /*
    97118         * Prevent critical section code from bleeding out this way down.
     
    99120        CS_LEAVE_BARRIER();
    100121       
    101         atomic_set(&sl->val, 0);
     122        atomic_set(&lock->val, 0);
    102123        preemption_enable();
    103124}
     
    105126#ifdef CONFIG_DEBUG_SPINLOCK
    106127
    107 extern int printf(const char *, ...);
     128#include <print.h>
    108129
    109 #define DEADLOCK_THRESHOLD              100000000
    110 #define DEADLOCK_PROBE_INIT(pname)      size_t pname = 0
    111 #define DEADLOCK_PROBE(pname, value)                                    \
    112         if ((pname)++ > (value)) {                                      \
    113                 (pname) = 0;                                            \
    114                 printf("Deadlock probe %s: exceeded threshold %u\n",    \
    115                     "cpu%u: function=%s, line=%u\n",                    \
    116                     #pname, (value), CPU->id, __func__, __LINE__);      \
     130#define DEADLOCK_THRESHOLD  100000000
     131
     132#define DEADLOCK_PROBE_INIT(pname)  size_t pname = 0
     133
     134#define DEADLOCK_PROBE(pname, value) \
     135        if ((pname)++ > (value)) { \
     136                (pname) = 0; \
     137                printf("Deadlock probe %s: exceeded threshold %u\n", \
     138                    "cpu%u: function=%s, line=%u\n", \
     139                    #pname, (value), CPU->id, __func__, __LINE__); \
    117140        }
    118 #else
    119 #define DEADLOCK_PROBE_INIT(pname)
    120 #define DEADLOCK_PROBE(pname, value)
    121 #endif
    122141
    123142#else
    124143
     144#define DEADLOCK_PROBE_INIT(pname)
     145#define DEADLOCK_PROBE(pname, value)
     146
     147#endif
     148
     149#else /* CONFIG_SMP */
     150
    125151/* On UP systems, spinlocks are effectively left out. */
     152
    126153#define SPINLOCK_DECLARE(name)
    127154#define SPINLOCK_EXTERN(name)
     155
    128156#define SPINLOCK_INITIALIZE(name)
     157#define SPINLOCK_STATIC_INITIALIZE(name)
    129158
    130 #define spinlock_initialize(x, name)
    131 #define spinlock_lock(x)                preemption_disable()
    132 #define spinlock_trylock(x)             (preemption_disable(), 1)
    133 #define spinlock_unlock(x)              preemption_enable()
     159#define SPINLOCK_INITIALIZE_NAME(name, desc_name)
     160#define SPINLOCK_STATIC_INITIALIZE_NAME(name, desc_name)
     161
     162#define spinlock_initialize(lock, name)
     163
     164#define spinlock_lock(lock)     preemption_disable()
     165#define spinlock_trylock(lock)  (preemption_disable(), 1)
     166#define spinlock_unlock(lock)   preemption_enable()
    134167
    135168#define DEADLOCK_PROBE_INIT(pname)
Note: See TracChangeset for help on using the changeset viewer.