lockstat updates
Subsystems (4)
PATCH 2/4 lockdep: fixup sk_callback_lock annotation
In reply to Peter Zijlstrathe two init sites resulted in inconsistend names for the lock class.
--- net/core/sock.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
net/core/sock.c +19 -4
@@ -171,6 +171,19 @@ static const char *af_family_slock_key_s"slock-AF_TIPC" ,"slock-AF_BLUETOOTH" ,"slock-AF_IUCV" ,"slock-AF_RXRPC" ,"slock-AF_MAX" }; +static const char *af_family_clock_key_strings[AF_MAX +1 ] = { +"clock-AF_UNSPEC" ,"clock-AF_UNIX" ,"clock-AF_INET" , +"clock-AF_AX25" ,"clock-AF_IPX" ,"clock-AF_APPLETALK" , +"clock-AF_NETROM" ,"clock-AF_BRIDGE" ,"clock-AF_ATMPVC" , +"clock-AF_X25" ,"clock-AF_INET6" ,"clock-AF_ROSE" , +"clock-AF_DECnet" ,"clock-AF_NETBEUI" ,"clock-AF_SECURITY" , +"clock-AF_KEY" ,"clock-AF_NETLINK" ,"clock-AF_PACKET" , +"clock-AF_ASH" ,"clock-AF_ECONET" ,"clock-AF_ATMSVC" , +"clock-21" ,"clock-AF_SNA" ,"clock-AF_IRDA" , +"clock-AF_PPPOX" ,"clock-AF_WANPIPE" ,"clock-AF_LLC" , +"clock-27" ,"clock-28" ,"clock-29" , +"clock-AF_TIPC" ,"clock-AF_BLUETOOTH" ,"clock-AF_MAX" +};#endif /*
@@ -941,8 +954,9 @@ struct sock *sk_clone(const struct sockrwlock_init (&newsk->sk_dst_lock);rwlock_init (&newsk->sk_callback_lock); -lockdep_set_class (&newsk->sk_callback_lock, - af_callback_keys + newsk->sk_family); +lockdep_set_class_and_name (&newsk->sk_callback_lock, + af_callback_keys + newsk->sk_family, + af_family_clock_key_strings[newsk->sk_family]); newsk->sk_dst_cache =NULL ; newsk->sk_wmem_queued =0 ;
@@ -1530,8 +1544,9 @@ void sock_init_data(struct socket *sock,rwlock_init (&sk->sk_dst_lock);rwlock_init (&sk->sk_callback_lock); -lockdep_set_class (&sk->sk_callback_lock, - af_callback_keys + sk->sk_family); +lockdep_set_class_and_name (&sk->sk_callback_lock, + af_callback_keys + sk->sk_family, + af_family_clock_key_strings[sk->sk_family]); sk->sk_state_change = sock_def_wakeup; sk->sk_data_ready = sock_def_readable;
PATCH 1/4 lockdep: variuos fixes
In reply to Peter Zijlstra - update the copyright notices
- use the default hash function
- fix a thinko in a BUILD_BUG_ON
- add a WARN_ON to spot inconsitent naming
- fix a termination issue in /proc/lock_stat
--- include/linux/lockdep.h | 3 ++- kernel/lockdep.c | 20 +++++++++++--------- kernel/lockdep_proc.c | 6 +++++- 3 files changed, 18 insertions(+), 11 deletions(-)
kernel/lockdep.c +11 -9
@@ -5,7 +5,8 @@* * Started by Ingo Molnar: * -* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> * * this code maps all the lock dependencies as they occur in a live kernel * and will warn about the following classes of locking bugs:
@@ -37,6 +38,7 @@#include <linux/debug_locks.h> #include <linux/irqflags.h> #include <linux/utsname.h> +#include <linux/hash.h> #include <asm/sections.h>
@@ -238,8 +240,7 @@ LIST_HEAD(all_lock_classes);*/ #define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)#define CLASSHASH_SIZE (1UL << CLASSHASH_BITS) -#define CLASSHASH_MASK (CLASSHASH_SIZE - 1) -#define __classhashfn (key) ((((unsigned long)key >> CLASSHASH_BITS) + (unsigned long)key) & CLASSHASH_MASK) +#define __classhashfn (key) hash_long((unsigned long)key, CLASSHASH_BITS)#define classhashentry (key) (classhash_table + __classhashfn((key)))static struct list_head classhash_table[CLASSHASH_SIZE ];
@@ -250,9 +251,7 @@ static struct list_head classhash_table[*/ #define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)#define CHAINHASH_SIZE (1UL << CHAINHASH_BITS) -#define CHAINHASH_MASK (CHAINHASH_SIZE - 1) -#define __chainhashfn (chain) \ - (((chain >> CHAINHASH_BITS) + chain) & CHAINHASH_MASK) +#define __chainhashfn (chain) hash_long(chain, CHAINHASH_BITS)#define chainhashentry (chain) (chainhash_table + __chainhashfn((chain)))static struct list_head chainhash_table[CHAINHASH_SIZE ];
@@ -680,7 +679,7 @@ look_up_lock_class(struct lockdep_map *l* (or spin_lock_init()) call - which acts as the key. For static * locks we use the lock object itself as the key. */ -BUILD_BUG_ON (sizeof (struct lock_class_key ) >sizeof (struct lock_class )); +BUILD_BUG_ON (sizeof (struct lock_class_key ) >sizeof (struct lockdep_map )); key = lock->key->subkeys + subclass;
@@ -690,9 +689,12 @@ look_up_lock_class(struct lockdep_map *l* We can walk the hash lockfree, because the hash only * grows, and we are careful when adding entries to the end: */ -list_for_each_entry (class, hash_head, hash_entry) -if (class->key == key) +list_for_each_entry (class, hash_head, hash_entry) { +if (class->key == key) { +WARN_ON_ONCE (class->name != lock->name);return class; + } + }return NULL ; }
include/linux/lockdep.h +2 -1
@@ -1,7 +1,8 @@/* * Runtime locking correctness validator * -* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> * * see Documentation/lockdep-design.txt for more details. */
kernel/lockdep_proc.c +5 -1
@@ -5,7 +5,8 @@* * Started by Ingo Molnar: * -* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> * * Code for /proc/lockdep and /proc/lockdep_stats: *
@@ -498,6 +499,9 @@ static void *ls_start(struct seq_file *mif (data->iter == data->stats)seq_header (m); +if (data->iter == data->iter_end) + data->iter =NULL ; +return data->iter; }
PATCH 3/4 lockstat: measure lock bouncing
In reply to Peter Zijlstra
__acquire
|
lock _____
| \
| __contended
| |
| wait
| _______/
|/
|
__acquired
|
__release
|
unlockWe measure acquisition and contention bouncing.
This is done by recording a cpu stamp in each lock instance.
Contention bouncing requires the cpu stamp to be set on acquisition. Hence we move __acquired into the generic path.
__acquired is then used to measure acquisition bouncing by comparing the current cpu with the old stamp before replacing it.
__contended is used to measure contention bouncing (only useful for preemptable locks)
--- include/linux/lockdep.h | 17 ++++++++++++++++- kernel/lockdep.c | 38 ++++++++++++++++++++++++++------------ kernel/lockdep_proc.c | 18 +++++++++++------- kernel/mutex.c | 2 +- 4 files changed, 54 insertions(+), 21 deletions(-)
include/linux/lockdep.h +16 -1
@@ -130,12 +130,24 @@ struct lock_time {unsigned long nr; }; +enum bounce_type { + bounce_acquired_write, + bounce_acquired_read, + bounce_contended_write, + bounce_contended_read, + nr_bounce_types, + + bounce_acquired = bounce_acquired_write, + bounce_contended = bounce_contended_write, +}; +struct lock_class_stats {unsigned long contention_point[4 ];struct lock_time read_waittime;struct lock_time write_waittime;struct lock_time read_holdtime;struct lock_time write_holdtime; +unsigned long bounces[nr_bounce_types]; };struct lock_class_stats lock_stats (struct lock_class *class);
@@ -150,6 +162,9 @@ struct lockdep_map {struct lock_class_key *key;struct lock_class *class_cache;const char *name; +#ifdef CONFIG_LOCK_STAT +int cpu; +#endif };/*
@@ -321,8 +336,8 @@ do { \if (!try (_lock)) { \lock_contended (&(_lock)->dep_map, _RET_IP_); \lock (_lock); \ -lock_acquired (&(_lock)->dep_map); \ } \ +lock_acquired (&(_lock)->dep_map); \ } while (0) #else /* CONFIG_LOCK_STAT */
kernel/lockdep.c +26 -12
@@ -177,6 +177,9 @@ struct lock_class_stats lock_stats(struclock_time_add (&pcs->read_holdtime, &stats.read_holdtime);lock_time_add (&pcs->write_holdtime, &stats.write_holdtime); + +for (i =0 ; i <ARRAY_SIZE (stats.bounces); i++) + stats.bounces[i] += pcs->bounces[i]; }return stats;
@@ -2328,6 +2331,9 @@ void lockdep_init_map(struct lockdep_map lock->name = name; lock->key = key; lock->class_cache =NULL ; +#ifdef CONFIG_LOCK_STAT + lock->cpu =raw_smp_processor_id (); +#endif if (subclass)register_lock_class (lock, subclass,1 ); }
@@ -2778,6 +2784,8 @@ found_it: stats =get_lock_stats (hlock->class);if (point <ARRAY_SIZE (stats->contention_point)) stats->contention_point[i]++; +if (lock->cpu !=smp_processor_id ()) + stats->bounces[bounce_contended + !!hlock->read]++;put_lock_stats (stats); }
@@ -2789,8 +2797,8 @@ __lock_acquired(struct lockdep_map *lockstruct lock_class_stats *stats;unsigned int depth;u64 now; -s64 waittime; -int i; +s64 waittime =0 ; +int i, cpu; depth = curr->lockdep_depth;if (DEBUG_LOCKS_WARN_ON (!depth))
@@ -2812,19 +2820,25 @@ __lock_acquired(struct lockdep_map *lockreturn ; found_it: -if (!hlock->waittime_stamp) -return ; - - now =sched_clock (); - waittime = now - hlock->waittime_stamp; - hlock->holdtime_stamp = now; + cpu =smp_processor_id (); +if (hlock->waittime_stamp) { + now =sched_clock (); + waittime = now - hlock->waittime_stamp; + hlock->holdtime_stamp = now; + } stats =get_lock_stats (hlock->class); -if (hlock->read) -lock_time_inc (&stats->read_waittime, waittime); -else -lock_time_inc (&stats->write_waittime, waittime); +if (waittime) { +if (hlock->read) +lock_time_inc (&stats->read_waittime, waittime); +else +lock_time_inc (&stats->write_waittime, waittime); + } +if (lock->cpu != cpu) + stats->bounces[bounce_acquired + !!hlock->read]++;put_lock_stats (stats); + + lock->cpu = cpu; }void lock_contended (struct lockdep_map *lock,unsigned long ip)
kernel/lockdep_proc.c +11 -7
@@ -430,16 +430,18 @@ static void seq_stats(struct seq_file *melse seq_printf (m,"%40s:" , name); +seq_printf (m,"%14lu " , stats->bounces[bounce_contended_write]);seq_lock_time (m, &stats->write_waittime); -seq_puts (m," " ); +seq_printf (m," %14lu " , stats->bounces[bounce_acquired_write]);seq_lock_time (m, &stats->write_holdtime);seq_puts (m,"\n" ); }if (stats->read_holdtime.nr) {seq_printf (m,"%38s-R:" , name); +seq_printf (m,"%14lu " , stats->bounces[bounce_contended_read]);seq_lock_time (m, &stats->read_waittime); -seq_puts (m," " ); +seq_printf (m," %14lu " , stats->bounces[bounce_acquired_read]);seq_lock_time (m, &stats->read_holdtime);seq_puts (m,"\n" ); }
@@ -469,26 +471,28 @@ static void seq_stats(struct seq_file *m }if (i) {seq_puts (m,"\n" ); -seq_line (m,'.' ,0 ,40 +1 +8 * (14 +1 )); +seq_line (m,'.' ,0 ,40 +1 +10 * (14 +1 ));seq_puts (m,"\n" ); } }static void seq_header (struct seq_file *m) { -seq_printf (m,"lock_stat version 0.1\n" ); -seq_line (m,'-' ,0 ,40 +1 +8 * (14 +1 )); -seq_printf (m,"%40s %14s %14s %14s %14s %14s %14s %14s %14s\n" , +seq_printf (m,"lock_stat version 0.2\n" ); +seq_line (m,'-' ,0 ,40 +1 +10 * (14 +1 )); +seq_printf (m,"%40s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s\n" ,"class name" , +"con-bounces" ,"contentions" ,"waittime-min" ,"waittime-max" ,"waittime-total" , +"acq-bounces" ,"acquisitions" ,"holdtime-min" ,"holdtime-max" ,"holdtime-total" ); -seq_line (m,'-' ,0 ,40 +1 +8 * (14 +1 )); +seq_line (m,'-' ,0 ,40 +1 +10 * (14 +1 ));seq_printf (m,"\n" ); }
kernel/mutex.c +1 -1
@@ -180,8 +180,8 @@ __mutex_lock_common(struct mutex *lock,spin_lock_mutex (&lock->wait_lock, flags); } -lock_acquired (&lock->dep_map); done: +lock_acquired (&lock->dep_map);/* got the lock - rejoice! */ mutex_remove_waiter (lock, &waiter,task_thread_info (task));debug_mutex_set_owner (lock,task_thread_info (task));
cover lockstat updates
Biggest among these updates is the posibility to measure lock bouncing.
PATCH 4/4 lockstat: better class name representation
optionally add class->name_version and class->subclass to the class name
--- kernel/lockdep_proc.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
kernel/lockdep_proc.c +23 -1
@@ -421,8 +421,30 @@ static void seq_stats(struct seq_file *m class = data->class; stats = &data->stats; -snprintf (name,38 ,"%s" , class->name); + namelen =38 ; +if (class->name_version >1 ) + namelen -=2 ;/* XXX truncates versions > 9 */ +if (class->subclass) + namelen -=2 ; + +if (!class->name) { +char str[KSYM_NAME_LEN ]; +const char *key_name; + + key_name =__get_key_name (class->key, str); +snprintf (name, namelen,"%s" , key_name); + }else { +snprintf (name, namelen,"%s" , class->name); + } namelen =strlen (name); +if (class->name_version >1 ) { +snprintf (name+namelen,3 ,"#%d" , class->name_version); + namelen +=2 ; + } +if (class->subclass) { +snprintf (name+namelen,3 ,"/%d" , class->subclass); + namelen +=2 ; + }if (stats->write_holdtime.nr) {if (stats->read_holdtime.nr)
Re: [patch 1/4] lockdep: variuos fixes
In reply to Peter ZijlstraWhat exactly is being copyright'ed here?
Quoted 128 lines · Peter Zijlstra
- update the copyright notices
- use the default hash function
- fix a thinko in aBUILD_BUG_ON
- add aWARN_ONto spot inconsitent naming
- fix a termination issue in/proc/lock_statSigned-off-by Peter Zijlstra <[email protected]>Acked-by Ingo Molnar <[email protected]>--- include/linux/lockdep.h | 3 ++- kernel/lockdep.c | 20 +++++++++++--------- kernel/lockdep_proc.c | 6 +++++- 3 files changed, 18 insertions(+), 11 deletions(-)Index:
linux-2.6/kernel/lockdep.c
===================================================================kernel/lockdep.c +11
-9@@ -5,7 +5,8 @@* * Started by Ingo Molnar: * -* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> * * this code maps all the lock dependencies as they occur in a live kernel * and will warn about the following classes of locking bugs: @@ -37,6 +38,7 @@#include <linux/debug_locks.h> #include <linux/irqflags.h> #include <linux/utsname.h> +#include <linux/hash.h> #include <asm/sections.h> @@ -238,8 +240,7 @@ LIST_HEAD(all_lock_classes);*/ #define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)#define CLASSHASH_SIZE (1UL << CLASSHASH_BITS) -#define CLASSHASH_MASK (CLASSHASH_SIZE - 1) -#define __classhashfn (key) ((((unsigned long)key >> CLASSHASH_BITS) + (unsigned long)key) & CLASSHASH_MASK) +#define __classhashfn (key) hash_long((unsigned long)key, CLASSHASH_BITS)#define classhashentry (key) (classhash_table + __classhashfn((key)))static struct list_head classhash_table[CLASSHASH_SIZE ];@@ -250,9 +251,7 @@ static struct list_head classhash_table[*/ #define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)#define CHAINHASH_SIZE (1UL << CHAINHASH_BITS) -#define CHAINHASH_MASK (CHAINHASH_SIZE - 1) -#define __chainhashfn (chain) \ - (((chain >> CHAINHASH_BITS) + chain) & CHAINHASH_MASK) +#define __chainhashfn (chain) hash_long(chain, CHAINHASH_BITS)#define chainhashentry (chain) (chainhash_table + __chainhashfn((chain)))static struct list_head chainhash_table[CHAINHASH_SIZE ];@@ -680,7 +679,7 @@ look_up_lock_class(struct lockdep_map *l* (or spin_lock_init()) call - which acts as the key. For static * locks we use the lock object itself as the key. */ -BUILD_BUG_ON (sizeof (struct lock_class_key ) >sizeof (struct lock_class )); +BUILD_BUG_ON (sizeof (struct lock_class_key ) >sizeof (struct lockdep_map )); key = lock->key->subkeys + subclass;@@ -690,9 +689,12 @@ look_up_lock_class(struct lockdep_map *l* We can walk the hash lockfree, because the hash only * grows, and we are careful when adding entries to the end: */ -list_for_each_entry (class, hash_head, hash_entry) -if (class->key == key) +list_for_each_entry (class, hash_head, hash_entry) { +if (class->key == key) { +WARN_ON_ONCE (class->name != lock->name);return class; + } + }return NULL ; }Index:
linux-2.6/include/linux/lockdep.h
===================================================================include/linux/lockdep.h +2
-1@@ -1,7 +1,8 @@/* * Runtime locking correctness validator * -* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> * * see Documentation/lockdep-design.txt for more details. */ Index:
linux-2.6/kernel/lockdep_proc.c
===================================================================kernel/lockdep_proc.c +5
-3@@ -5,7 +5,8 @@* * Started by Ingo Molnar: * -* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> * * Code for /proc/lockdep and /proc/lockdep_stats: * @@ -498,6 +499,9 @@ static void *ls_start(struct seq_file *mif (data->iter == data->stats)seq_header (m); +if (data->iter == data->iter_end) + data->iter =NULL ; +return data->iter; } -- -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [patch 1/4] lockdep: variuos fixes
Quoted 18 lines · debian developer
Quoted 5 lines · Peter Zijlstra
Index:
linux-2.6/kernel/lockdep.c
===================================================================kernel/lockdep.c line 12
Quoted 9 lines
kernel/lockdep.c +2
-1@@ -5,7 +5,8 @@* * Started by Ingo Molnar: * -* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <[email protected]> +* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> * * this code maps all the lock dependencies as they occur in a live kernel * and will warn about the following classes of locking bugs: What exactly is being copyright'ed here?
Thanks for being triply impolite! You score: anonymous, top-posting and dropping CC-lists.
The code in these files, as in most other files in the Linux kernel, is copyrighted. The code is Licensed under GPLv2, but copyright belongs to Red Hat and it's authors are Ingo and myself.
That is, say you want to use this code in a non GPLv2 project (say this GPLv3 thing) then you would need to contact the copyright owner of this code.