public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: William Cohen <wcohen@redhat.com>
To: "Frank Ch. Eigler" <fche@redhat.com>
Cc: systemtap@sources.redhat.com
Subject: Re: Proposed systemtap access to perfmon hardware
Date: Fri, 17 Mar 2006 16:20:00 -0000	[thread overview]
Message-ID: <441AE1DE.2040207@redhat.com> (raw)
In-Reply-To: <y0mmzfr9w2a.fsf@ton.toronto.redhat.com>

To try to get a feel on how the performance monitoring hardware support 
would work in SystemTap I wrote some simple examples. Below are examples 
for computing IPC, average cycle count, and sampling within a function. 
The IPC and average cycle count function need a bit of rework to work 
for a SMP machines.

Let me know if there are comments or questions on the examples.

-Will

COMPUTING IPC

global cycles_h
global instr_retired_h
probe perfmon.event("cycles") {cycles_h = $handle;}
probe perfmon.event("intr_retired") {instr_retired_h = $handle;}

probe begin {print ("start probe");}
probe end
{
	factor=100;
	ipc = (factor*perfmon_get_counter(intr_retired_h))/
	    perfmon_get_counter(cycles_h);
	print ("ipc is %d.%d \n", ipc/factor, ipc % factor);
}




DETERMINING AVERAGE CYCLE COUNT FOR FUNCTION (AND CHILDREN)

global cycles_h

probe perfmon.event("cycles") {
       cycles_h = $handle;
       perfmon_stop_counter(cycles_h);
}

global count

probe kernel.function("blah"){
       ++count;
       perfmon_start_counter(cycles_h);
}

probe kernel.function.return("blah"){
       perfmon_stop_counter(cycles_h);
}

probe begin {print ("start probe");}
probe end
{
	total_cycles=perfmon_stop_counter(cycles_h);
	print ("average count in blah %d\n", total_cycles/count);
}


SAMPLING WITHIN A FUNCTION (AND CHILDREN)

global cycles_h
global where_am_i

probe perfmon.event("cycles").sample(100000) {
       cycles_h = $handle;
       # record where sample occured
       where_am_i[instruction_pointer()]++;
}

global count

probe kernel.function("blah"){
       ++count;
       perfmon_start_counter(cycles_h);
}

probe kernel.function("blah").return{
       perfmon_stop_counter(cycles_h);
}

probe begin
{
       # turn off the sampling
       perfmon_stop_counter(cycles_h);
       print("start probe");
}

probe end
{
	#write out the where_am_i entries
	print("address\tcount\n");
	foreach ([+ip] in where_am_i) {
		print("0x%x\t%d\n", ip, where_am_i[ip]);
	}
}

  reply	other threads:[~2006-03-17 16:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-15 16:24 William Cohen
2006-03-15 22:34 ` Frank Ch. Eigler
2006-03-17 16:20   ` William Cohen [this message]
2006-03-17 17:10     ` Bill Rugolsky Jr.
2006-03-17 17:34     ` Frank Ch. Eigler
2006-03-17 20:26       ` William Cohen
2006-03-20 17:27         ` Frank Ch. Eigler
2006-03-22  3:34 ` Maynard Johnson
2006-03-22 18:02   ` William Cohen
2006-03-22 22:16     ` Maynard Johnson
2006-03-22 18:30   ` Frank Ch. Eigler
2006-03-22 19:09 Stone, Joshua I
2006-03-22 20:04 ` Frank Ch. Eigler
2006-03-22 23:23 Stone, Joshua I
2006-03-22 23:46 Stone, Joshua I
2006-03-23 12:54 ` Maynard Johnson
2006-03-23 14:46   ` William Cohen
2006-03-23 17:09 Stone, Joshua I

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=441AE1DE.2040207@redhat.com \
    --to=wcohen@redhat.com \
    --cc=fche@redhat.com \
    --cc=systemtap@sources.redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).