From: Xu, A. <anh...@in...> - 2012-02-09 15:08:29
|
Resend it with signed-off header :) commit 173054bd6fe8438979c79eaf50059e5f36a26504 Author: Xu,Anhua <anh...@in...> Date: Wed Feb 8 17:03:36 2012 +0800 performance_counter02: update syscall and perf data structures Performance counters currently named performance events. The original data structures are deprecated. Update syscall and associated data structure Signed-off-by: Anhua Xu <anh...@in...> diff --git a/testcases/kernel/performance_counters/performance_counter02.c b/testcases/kernel/performance_counters/performance_counter02.c index cc8773e..d0ea9c2 100644 --- a/testcases/kernel/performance_counters/performance_counter02.c +++ b/testcases/kernel/performance_counters/performance_counter02.c @@ -65,6 +65,7 @@ it print out the values of each counter. #include <sys/prctl.h> #include <sys/types.h> #include <linux/types.h> +#include <linux/perf_event.h> /* Harness Specific Include Files. */ #include "test.h" @@ -82,46 +83,14 @@ typedef unsigned int u32; typedef unsigned long long u64; typedef long long s64; -struct perf_counter_hw_event { - s64 type; - u64 irq_period; - u32 record_type; - - u32 disabled : 1, /* off by default */ - nmi : 1, /* NMI sampling */ - raw : 1, /* raw event type */ - __reserved_1 : 29; - u64 __reserved_2; -}; - -enum hw_event_types { - PERF_COUNT_CYCLES = 0, - PERF_COUNT_INSTRUCTIONS = 1, - PERF_COUNT_CACHE_REFERENCES = 2, - PERF_COUNT_CACHE_MISSES = 3, - PERF_COUNT_BRANCH_INSTRUCTIONS = 4, - PERF_COUNT_BRANCH_MISSES = 5, - - /* - * Special "software" counters provided by the kernel, even if - * the hardware does not support performance counters. These - * counters measure various physical and sw events of the - * kernel (and allow the profiling of them as well): - */ - PERF_COUNT_CPU_CLOCK = -1, - PERF_COUNT_TASK_CLOCK = -2, - /* - * Future software events: - */ - /* PERF_COUNT_PAGE_FAULTS = -3, - PERF_COUNT_CONTEXT_SWITCHES = -4, */ -}; - -int sys_perf_counter_open(struct perf_counter_hw_event *hw_event, - pid_t pid, int cpu, int group_fd, unsigned long flags) +static inline int +sys_perf_event_open(struct perf_event_attr *attr, + pid_t pid, int cpu, int group_fd, + unsigned long flags) { - return syscall(__NR_perf_event_open, hw_event, pid, cpu, group_fd, - flags); + attr->size = sizeof(*attr); + return syscall(__NR_perf_event_open, attr, pid, cpu, + group_fd, flags); } #define MAX_CTRS 50 @@ -142,8 +111,8 @@ main(int ac, char **av) { int tsk0; int hwfd[MAX_CTRS], tskfd[MAX_CTRS]; - struct perf_counter_hw_event tsk_event; - struct perf_counter_hw_event hw_event; + struct perf_event_attr tsk_event; + struct perf_event_attr hw_event; unsigned long long vt0, vt[MAX_CTRS], vh[MAX_CTRS], vtsum, vhsum; int i, n, nhw; int verbose = 0; @@ -173,23 +142,25 @@ main(int ac, char **av) n = nhw + 4; memset(&tsk_event, 0, sizeof(tsk_event)); - tsk_event.type = PERF_COUNT_TASK_CLOCK; + tsk_event.type = PERF_TYPE_SOFTWARE; + tsk_event.config = PERF_COUNT_SW_TASK_CLOCK; tsk_event.disabled = 1; memset(&hw_event, 0, sizeof(hw_event)); hw_event.disabled = 1; - hw_event.type = PERF_COUNT_INSTRUCTIONS; + hw_event.type = PERF_TYPE_HARDWARE; + hw_event.config = PERF_COUNT_HW_INSTRUCTIONS; - tsk0 = sys_perf_counter_open(&tsk_event, 0, -1, -1, 0); + tsk0 = sys_perf_event_open(&tsk_event, 0, -1, -1, 0); if (tsk0 == -1) { tst_brkm(TBROK | TERRNO, cleanup, "perf_counter_open failed (1)"); } else { tsk_event.disabled = 0; for (i = 0; i < n; ++i) { - hwfd[i] = sys_perf_counter_open(&hw_event, 0, -1, + hwfd[i] = sys_perf_event_open(&hw_event, 0, -1, -1, 0); - tskfd[i] = sys_perf_counter_open(&tsk_event, 0, -1, + tskfd[i] = sys_perf_event_open(&tsk_event, 0, -1, hwfd[i], 0); if (tskfd[i] == -1 || hwfd[i] == -1) { tst_brkm(TBROK | TERRNO, cleanup, |