public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Yang Xi <yangxilkm@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	linux-kernel@vger.kernel.org, chyyuu <chyyuu@gmail.com>
Subject: Re: [PATCH 2.6.28-rc4]lock_stat: Add "con-hungry" to show that how many person-time fight for the ticket spinlock
Date: Fri, 26 Dec 2008 09:34:31 +0100	[thread overview]
Message-ID: <20081226083431.GA755@elte.hu> (raw)
In-Reply-To: <d36bb30d0812252324n512f4653of62f8b42684217d4@mail.gmail.com>


* Yang Xi <yangxilkm@gmail.com> wrote:

> Because the lock-stat and lock-dep is so heavy, this statistic result is 
> not very accurate :(

hm, lockdep indeed has to do some non-trivial work - but is that really 
true of pure lockstat too? If you have a workload where you can see that 
it's heavy, you could do an NMI profile on x86 by running kerneltop on 
tip/master:

     http://redhat.com/~mingo/perfcounters/kerneltop.c

You should get a top-alike list of the highest-cost functions. If lockstat 
is heavy, its activities should show up there.

> @@ -34,6 +34,7 @@ config X86
>  	select HAVE_ARCH_TRACEHOOK
>  	select HAVE_GENERIC_DMA_COHERENT if X86_32
>  	select HAVE_EFFICIENT_UNALIGNED_ACCESS
> +	select HAVE_TICKET_SPINLOCK

no fundamental objections against your patch, but i think it needs a 
couple of cleanups first.

For example, this HAVE_TICKET_SPINLOCK distinction is unnecessarily 
exposed to the core kernel, why not just allow architectures to define 
spin_nr_contended():

> +#ifdef CONFIG_HAVE_TICKET_SPINLOCK
> +#define spin_nr_contended(lock) __ticket_spin_nr_contended(&(lock)->raw_lock)
> +#else
> +#define spin_nr_contended(lock) (spin_is_contended(lock) ? 1 : 0)
> +#endif

and do something like this in spinlock.h to give a default definition:

#ifndef spin_nr_contended
# define spin_nr_contended(lock) (spin_is_contended(lock) ? 1 : 0)
#endif

> @@ -2588,7 +2594,6 @@ static int __lock_acquire(struct lockdep_map
> *lock, unsigned int subclass,
> 
>  	if (check == 2 && !mark_irqflags(curr, hlock))
>  		return 0;
> -
>  	/* mark it as used: */
>  	if (!mark_lock(curr, hlock, LOCK_USED))
>  		return 0;
> @@ -2623,7 +2628,6 @@ static int __lock_acquire(struct lockdep_map
> *lock, unsigned int subclass,
> 
>  	if (!validate_chain(curr, lock, hlock, chain_head, chain_key))
>  		return 0;
> -
>  	curr->curr_chain_key = chain_key;
>  	curr->lockdep_depth++;
>  	check_chain_key(curr);
> @@ -3000,6 +3004,13 @@ __lock_contended(struct lockdep_map *lock,

those newlines you removed were there for a reason - they delimit blocks 
of code from each other and make return statements more visible.


> unsigned long ip)
>  	struct lock_class_stats *stats;
>  	unsigned int depth;
>  	int i, point;
> +	spinlock_t *lock_ptr;
> +	unsigned long hungry = 0;

please keep the local variable definitions in their original style, i.e. a 
reverse christmas tree:

>  	struct lock_class_stats *stats;
> +	unsigned long hungry = 0;
> +	spinlock_t *lock_ptr;
>  	unsigned int depth;
>  	int i, point;

> +
> +	if (lock->isticketspinlock) {
> +		lock_ptr = container_of(lock, spinlock_t, dep_map);
> +		hungry = spin_nr_contended(lock_ptr);
> +	}

do we need the ->isticketspinlock distinction? Cannot we call 
spin_nr_contended() for all spinlocks? (it's just that for ticket 
spinlocks we get a real value out of it - for normal spinlocks we only get 
0/1 out of it. But that is not a problem really.)

also, please rename 'hungry' to something more descriptive: for example 
'nr_contended' fits pretty well?

> @@ -3030,9 +3041,16 @@ found_it:
>  		stats->contention_point[point]++;
>  	if (lock->cpu != smp_processor_id())
>  		stats->bounces[bounce_contended + !!hlock->read]++;
> +	stats->bounces[bounce_hungry] += hungry;
> +	if (lock->isticketspinlock) {
> +		if (stats->bounces[bounce_max_hungry] < hungry)
> +			stats->bounces[bounce_max_hungry] = hungry;
> +	}
> +
>  	put_lock_stats(stats);
>  }
> 
> +
>  static void

spurious newline.

	Ingo

  reply	other threads:[~2008-12-26  8:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-18 11:00 [PATCH 2.6.28-rc4]lock_stat: Add "con-hungry" to show that how many person-time fight for the ticket spinlock Yang Xi
2008-11-18 16:20 ` Peter Zijlstra
2008-11-19  5:18   ` Yang Xi
2008-11-19 16:39     ` Peter Zijlstra
2008-11-20  8:09       ` Yang Xi
2008-11-23  1:40         ` Peter Zijlstra
2008-11-23  8:23           ` Yang Xi
2008-12-26  7:24           ` Yang Xi
2008-12-26  8:34             ` Ingo Molnar [this message]
2008-12-26 13:13               ` Yang Xi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081226083431.GA755@elte.hu \
    --to=mingo@elte.hu \
    --cc=a.p.zijlstra@chello.nl \
    --cc=chyyuu@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yangxilkm@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox