public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Paul Mackerras <paulus@samba.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-arch@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Stephane Eranian <eranian@googlemail.com>,
	Eric Dumazet <dada1@cosmosbay.com>,
	Robert Richter <robert.richter@amd.com>,
	Arjan van de Veen <arjan@infradead.org>,
	Peter Anvin <hpa@zytor.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Steven Rostedt <rostedt@goodmis.org>,
	David Miller <davem@davemloft.net>
Subject: Re: [patch 0/3] [Announcement] Performance Counters for Linux
Date: Fri, 5 Dec 2008 08:03:29 +0100	[thread overview]
Message-ID: <20081205070329.GA30874@elte.hu> (raw)
In-Reply-To: <20081205063131.GB12785@elte.hu>


* Ingo Molnar <mingo@elte.hu> wrote:

> This can be done in a very natural way with our abstraction, and the 
> "hello.c" example happens to do exactly that:

multiple people pointed out that we have not posted hello.c :-/

Here's a simple standalone example (full working code attached below):

int main(void)
{
	unsigned long long count1, count2;
	int fd1, fd2, ret;

	fd1 = perf_counter_open(PERF_COUNT_INSTRUCTIONS, 0, 0, 0, -1);
	assert(fd1 >= 0);
	fd2 = perf_counter_open(PERF_COUNT_CACHE_MISSES, 0, 0, 0, -1);
	assert(fd1 >= 0);

	for (;;) {
		ret = read(fd1, &count1, sizeof(count1));
		assert(ret == 8);
		ret = read(fd2, &count2, sizeof(count2));
		assert(ret == 8);

		printf("counter1 value: %Ld instructions\n", count1);
		printf("counter2 value: %Ld cachemisses\n",  count2);
		sleep(1);
	}
	return 0;
}


which gives this output (one readout per second):

  titan:~/perf-counter-test> ./simple 
  counter1 value: 0 instructions
  counter2 value: 0 cachemisses
  counter1 value: 23 instructions
  counter2 value: 0 cachemisses
  counter1 value: 2853 instructions
  counter2 value: 6 cachemisses
  counter1 value: 5736 instructions
  counter2 value: 7 cachemisses
  counter1 value: 8619 instructions
  counter2 value: 8 cachemisses
  counter1 value: 11502 instructions
  counter2 value: 8 cachemisses
  ^C

You need our patchset but then the code below will work just fine. No 
libraries, no context setup, nothing - just what is more interesting: the 
counter and profiling data.

	Ingo

----------------->
/*
 * Very simple performance counter testcase.
 */
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/uio.h>

#include <linux/unistd.h>

#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>

#ifdef __x86_64__
# define __NR_perf_counter_open	295
#endif

#ifdef __i386__
# define __NR_perf_counter_open 333
#endif

int
perf_counter_open(int		hw_event_type,
                  unsigned int	hw_event_period,
                  unsigned int	record_type,
                  pid_t		pid,
                  int		cpu)
{
	return syscall(__NR_perf_counter_open, hw_event_type, hw_event_period,
			record_type, pid, cpu);
}

enum hw_event_types {
	PERF_COUNT_CYCLES,
	PERF_COUNT_INSTRUCTIONS,
	PERF_COUNT_CACHE_REFERENCES,
	PERF_COUNT_CACHE_MISSES,
	PERF_COUNT_BRANCH_INSTRUCTIONS,
	PERF_COUNT_BRANCH_MISSES,
};

int main(void)
{
	unsigned long long count1, count2;
	int fd1, fd2, ret;

	fd1 = perf_counter_open(PERF_COUNT_INSTRUCTIONS, 0, 0, 0, -1);
	assert(fd1 >= 0);
	fd2 = perf_counter_open(PERF_COUNT_CACHE_MISSES, 0, 0, 0, -1);
	assert(fd1 >= 0);

	for (;;) {
		ret = read(fd1, &count1, sizeof(count1));
		assert(ret == 8);
		ret = read(fd2, &count2, sizeof(count2));
		assert(ret == 8);

		printf("counter1 value: %Ld instructions\n", count1);
		printf("counter2 value: %Ld cachemisses\n",  count2);
		sleep(1);
	}
	return 0;
}

  parent reply	other threads:[~2008-12-05  7:03 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-04 23:44 [patch 0/3] [Announcement] Performance Counters for Linux Thomas Gleixner
2008-12-04 23:44 ` [patch 1/3] performance counters: core code Thomas Gleixner
2008-12-05 10:55   ` Paul Mackerras
2008-12-05 11:20     ` Ingo Molnar
2008-12-04 23:44 ` [patch 2/3] performance counters: documentation Thomas Gleixner
2008-12-05  0:33   ` Paul Mackerras
2008-12-05  0:37     ` David Miller
2008-12-05  2:50       ` Arjan van de Ven
2008-12-05  3:26         ` David Miller
2008-12-05  2:33     ` Andi Kleen
2008-12-04 23:45 ` [patch 3/3] performance counters: x86 support Thomas Gleixner
2008-12-05  0:22 ` [patch 0/3] [Announcement] Performance Counters for Linux Paul Mackerras
2008-12-05  6:31   ` Ingo Molnar
2008-12-05  7:02     ` Arjan van de Ven
2008-12-05  7:52       ` David Miller
2008-12-05  7:03     ` Ingo Molnar [this message]
2008-12-05  7:03       ` Ingo Molnar
2008-12-05  7:16       ` Peter Zijlstra
2008-12-05  7:57         ` Paul Mackerras
2008-12-05  8:03           ` Peter Zijlstra
2008-12-05  8:07             ` David Miller
2008-12-05  8:11               ` Ingo Molnar
2008-12-05  8:17                 ` David Miller
2008-12-05  8:24                   ` Ingo Molnar
2008-12-05  8:27                     ` David Miller
2008-12-05  8:42                       ` Ingo Molnar
2008-12-05  8:49                         ` David Miller
2008-12-05 12:13                           ` Ingo Molnar
2008-12-05 12:13                             ` Ingo Molnar
2008-12-05 12:39                         ` Andi Kleen
2008-12-05 20:08                           ` David Miller
2008-12-10  3:48                             ` Paul Mundt
2008-12-10  4:42                               ` Paul Mackerras
2008-12-10  8:43                               ` Mikael Pettersson
2008-12-10 10:28                               ` Andi Kleen
2008-12-10 10:23                                 ` Paul Mundt
2008-12-10 11:03                                   ` Andi Kleen
2008-12-10 11:03                                     ` Andi Kleen
2008-12-10 10:28                                 ` Andi Kleen
2008-12-05 15:00               ` Arjan van de Ven
2008-12-05  9:16             ` Paul Mackerras
2008-12-05  7:57       ` David Miller
2008-12-05  8:18         ` Ingo Molnar
2008-12-05  8:20           ` David Miller
2008-12-05  7:54     ` Paul Mackerras
2008-12-05  8:08       ` Ingo Molnar
2008-12-05  8:15         ` David Miller
2008-12-05 13:25           ` Ingo Molnar
2008-12-05  9:10         ` Paul Mackerras
2008-12-05 12:07           ` Ingo Molnar
2008-12-06  0:05             ` Paul Mackerras
2008-12-06  1:23               ` Mikael Pettersson
2008-12-06 12:34               ` Peter Zijlstra
2008-12-07  5:15                 ` Paul Mackerras
2008-12-08  7:18                   ` stephane eranian
2008-12-08 11:11                     ` Ingo Molnar
2008-12-08 11:58                       ` David Miller
2008-12-09  0:21                       ` stephane eranian
2008-12-09  0:21                         ` stephane eranian
2008-12-05  0:22 ` H. Peter Anvin
2008-12-05  0:43   ` Paul Mackerras
2008-12-05  1:12 ` David Miller
2008-12-05  6:10   ` Ingo Molnar
2008-12-05  7:50     ` David Miller
2008-12-05  9:34     ` Paul Mackerras
2008-12-05 10:41       ` Ingo Molnar
2008-12-05 10:05     ` Ingo Molnar
2008-12-05  3:30 ` Andrew Morton
2008-12-06  2:36 ` stephane eranian
2008-12-08  2:12   ` [perfmon2] [patch 0/3] [Announcement] Performance Counters forLinux Dan Terpstra
2008-12-10 16:27   ` [patch 0/3] [Announcement] Performance Counters for Linux Rob Fowler
2008-12-10 16:27     ` [perfmon2] " Rob Fowler
2008-12-10 17:11     ` Andi Kleen
2008-12-10 17:11       ` Andi Kleen

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=20081205070329.GA30874@elte.hu \
    --to=mingo@elte.hu \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=dada1@cosmosbay.com \
    --cc=davem@davemloft.net \
    --cc=eranian@googlemail.com \
    --cc=hpa@zytor.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=robert.richter@amd.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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