From: George Dunlap Subject: [PATCH 1 of 3] xentrace: Skip to low cpu when throwing away portions of the circular buffer Date: Tue, 13 Apr 2010 17:52:58 +0100 Message-ID: <16ef34de012960393dd6.1271177578@silas> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: george.dunlap@eu.citrix.com List-Id: xen-devel@lists.xenproject.org Skip to the next "low" cpu when throwing away portions of the circular memory buffer. This makes subsequent analysis easier. Signed-off-by: George Dunlap diff -r 859a372efa66 -r 16ef34de0129 tools/xentrace/xentrace.c --- a/tools/xentrace/xentrace.c Tue Apr 13 13:40:58 2010 +0100 +++ b/tools/xentrace/xentrace.c Tue Apr 13 17:24:07 2010 +0100 @@ -149,6 +149,7 @@ { struct cpu_change_record *rec; long need_to_consume, free, freed; + int last_cpu = -1; if ( membuf.pending_size > 0 ) { @@ -193,11 +194,25 @@ if ( need_to_consume > 0 ) { + last_cpu = rec->data.cpu; MEMBUF_CONS_INCREMENT(freed); need_to_consume -= freed; } } while( need_to_consume > 0 ); + /* For good tsc consistency, we need to start at a low-cpu buffer. Keep + * skipping until the cpu goes down or stays the same. */ + rec = (struct cpu_change_record *)MEMBUF_POINTER(membuf.cons); + while ( rec->data.cpu > last_cpu ) + { + last_cpu = rec->data.cpu; + + freed = sizeof(*rec) + rec->data.window_size; + + MEMBUF_CONS_INCREMENT(freed); + rec = (struct cpu_change_record *)MEMBUF_POINTER(membuf.cons); + } + start_window: /* * Start writing "pending" data. Update prod once all this data is