Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1342161

Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec
Date 2016-02-24 17:10 +0100
Message-ID <r5KaL-6ZF-37@gated-at.bofh.it> (permalink)
References (3 earlier) <r5nnP-7qp-13@gated-at.bofh.it> <r5oae-7Zs-19@gated-at.bofh.it> <r5pfX-fN-13@gated-at.bofh.it> <r5GgP-3YX-41@gated-at.bofh.it> <r5IiE-5Ha-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Feb 24, 2016 at 03:02:39PM +0100, Peter Zijlstra wrote:
> FWIW, it would be nice to have a similar test for:
> 
> 	attr = {
> 		.disabled = true;
> 	}
> 
> 	sys_perf_event_open(&attr, .pid = self);
> 
> 	if (attr.disabled)
> 		ioctl(ENABLE);
> 
> 	/* generate N events */
> 
> 	ioctl(DISABLE);
> 
> 	read();
> 
> 	/* print event cnt and scale factors */
> 
> and one that has .disabled = false.


root@ivb-ep:~/perf# ./main 
1000000903 218851613 218851613
root@ivb-ep:~/perf# ./main 1
1000000235 218981231 218981231


Appears to work...

---

#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include "perf.h"

static struct perf_event_attr perf_attr = {
	.type = PERF_TYPE_HARDWARE,
	.config = PERF_COUNT_HW_INSTRUCTIONS,
	.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
		       PERF_FORMAT_TOTAL_TIME_RUNNING,
	.exclude_kernel = 1,
	.pinned = 1,
};

void die(const char *err, ...)
{
	va_list params;

	va_start(params, err);
	vfprintf(stderr, err, params);
	va_end(params);

	exit(-1);
}

int main (int argc, char **argv)
{
	u64 val[3];
	int i, fd;

	perf_attr.disabled = argc > 1;

	fd = sys_perf_event_open(&perf_attr, 0, -1, -1, 0);
	if (fd < 0)
		die("failed to create perf_event");

	if (perf_attr.disabled)
		ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);

	for (i = 0; i < 100000000; i++) {
		asm volatile ("nop\n\r"
			      "nop\n\r"
			      "nop\n\r"
			      "nop\n\r"
			      "nop\n\r"
			      "nop\n\r"
			      "nop\n\r");
	}

	ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);

	read(fd, &val, sizeof(val));

	printf("%Lu %Lu %Lu\n", val[0], val[1], val[2]);

	return 0;
}

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Peter Zijlstra <peterz@infradead.org> - 2016-02-23 16:30 +0100
  Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Jiri Olsa <jolsa@redhat.com> - 2016-02-23 16:50 +0100
    Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Pratyush Anand <panand@redhat.com> - 2016-02-23 17:40 +0100
      Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Peter Zijlstra <peterz@infradead.org> - 2016-02-23 18:50 +0100
        Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Peter Zijlstra <peterz@infradead.org> - 2016-02-24 13:00 +0100
          Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Peter Zijlstra <peterz@infradead.org> - 2016-02-24 15:10 +0100
            Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Peter Zijlstra <peterz@infradead.org> - 2016-02-24 17:10 +0100
              Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Pratyush Anand <panand@redhat.com> - 2016-02-25 05:10 +0100
    Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Jiri Olsa <jolsa@redhat.com> - 2016-02-23 22:50 +0100
      Re: [RFC][PATCH 4/7] perf: Fix scaling vs enable_on_exec Oleg Nesterov <oleg@redhat.com> - 2016-02-26 03:30 +0100

csiph-web