public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Corey Ashford <cjashfor@linux.vnet.ibm.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org, Paul Mackerras <paulus@samba.org>,
	Mike Galbraith <efault@gmx.de>,
	Arjan van de Ven <arjan@infradead.org>,
	Wu Fengguang <fengguang.wu@intel.com>
Subject: Re: [PATCH 6/6] perf_counter: kerneltop: output event support
Date: Fri, 03 Apr 2009 17:21:47 -0700	[thread overview]
Message-ID: <49D6A81B.8030004@linux.vnet.ibm.com> (raw)
In-Reply-To: <20090325113317.192910290@chello.nl>

As I was stealing code from kerneltop today to use in the PAPI profiling 
implementation, I ran across the code below:

Peter Zijlstra wrote:
> Teach kerneltop about the new output ABI.
> 
> XXX: anybody fancy integrating the PID/TID data into the output?
> 
> Bump the mmap_data pages a little because we bloated the output and
> have to be more careful about overruns with structured data.
> 
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> ---
[snip]

> 
> @@ -1147,28 +1152,75 @@ static void mmap_read(struct mmap_data *
>  	unsigned int head = mmap_read_head(md);
>  	unsigned int old = md->prev;
>  	unsigned char *data = md->base + page_size;
> +	int diff;
> 
>  	gettimeofday(&this_read, NULL);
> 
> -	if (head - old > md->mask) {
> +	/*
> +	 * If we're further behind than half the buffer, there's a chance
> +	 * the writer will bite our tail and screw up the events under us.
> +	 *
> +	 * If we somehow ended up ahead of the head, we got messed up.
> +	 *
> +	 * In either case, truncate and restart at head.
> +	 */
> +	diff = head - old;
> +	if (diff > md->mask / 2 || diff < 0) {
>  		struct timeval iv;
>  		unsigned long msecs;
> 
>  		timersub(&this_read, &last_read, &iv);
>  		msecs = iv.tv_sec*1000 + iv.tv_usec/1000;
> 
> -		fprintf(stderr, "WARNING: failed to keep up with mmap data.  Last read %lu msecs ago.\n", msecs);
> +		fprintf(stderr, "WARNING: failed to keep up with mmap data."
> +				"  Last read %lu msecs ago.\n", msecs);
> 
[snip]

The test for diff < 0 looks incorrect to me.  This shouldn't be an 
error, because it will frequently be the case that the head has wrapped 
around back to the beginning of the mmap'd pages, while old is near the end.

What it needs to find out, I think, is if the modulo distance between 
old and head is greater than 1/2 of the span of the mmap'd pages. 
Here's a suggested change:

-	diff = head - old;
+	diff = (head - old) & md->mask;
-	if (diff > md->mask / 2 || diff < 0) {
+	if (diff > md->mask / 2) {


What do you think?

- Corey


  parent reply	other threads:[~2009-04-04  0:22 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-25 11:30 [PATCH 0/6] perf_counter: new output ABI Peter Zijlstra
2009-03-25 11:30 ` [PATCH 1/6] perf_counter: more elaborate write API Peter Zijlstra
2009-03-25 12:06   ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-25 11:30 ` [PATCH 2/6] perf_counter: output objects Peter Zijlstra
2009-03-25 12:06   ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-25 11:30 ` [PATCH 3/6] perf_counter: sanity check on the output API Peter Zijlstra
2009-03-25 12:06   ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-25 11:30 ` [PATCH 4/6] perf_counter: optionally provide the pid/tid of the sampled task Peter Zijlstra
2009-03-25 12:06   ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-25 11:30 ` [PATCH 5/6] perf_counter: kerneltop: mmap_pages argument Peter Zijlstra
2009-03-25 12:07   ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-25 12:18   ` [PATCH 5/6] " Ingo Molnar
2009-03-25 12:27     ` Peter Zijlstra
2009-03-25 12:35       ` Ingo Molnar
2009-03-25 12:41         ` Peter Zijlstra
2009-03-25 12:54           ` Ingo Molnar
2009-03-25 12:57             ` Peter Zijlstra
2009-03-25 14:52               ` Peter Zijlstra
2009-03-25 17:16                 ` Ingo Molnar
2009-03-25 21:18                   ` Peter Zijlstra
2009-03-26  2:22       ` Paul Mackerras
2009-03-25 11:30 ` [PATCH 6/6] perf_counter: kerneltop: output event support Peter Zijlstra
2009-03-25 12:07   ` [tip:perfcounters/core] " Peter Zijlstra
2009-04-04  0:21   ` Corey Ashford [this message]
2009-04-04 12:17     ` [PATCH 6/6] " Peter Zijlstra
2009-04-04 18:10       ` Corey Ashford
2009-03-25 12:05 ` [PATCH 0/6] perf_counter: new output ABI Ingo Molnar

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=49D6A81B.8030004@linux.vnet.ibm.com \
    --to=cjashfor@linux.vnet.ibm.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=arjan@infradead.org \
    --cc=efault@gmx.de \
    --cc=fengguang.wu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    /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