perf_counter tools: Merge common code into perfcounters.h
authorWu Fengguang <fengguang.wu@intel.com>
Fri, 20 Mar 2009 02:08:02 +0000 (10:08 +0800)
committerIngo Molnar <mingo@elte.hu>
Mon, 6 Apr 2009 07:30:20 +0000 (09:30 +0200)
kerneltop's MAX_COUNTERS is increased from 8 to 64(the value used by perfstat).

Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Documentation/perf_counter/kerneltop.c
Documentation/perf_counter/perfcounters.h [new file with mode: 0644]
Documentation/perf_counter/perfstat.c

index cf0e30b..fe70a2c 100644 (file)
 
 #include <linux/unistd.h>
 
-#ifdef __x86_64__
-# define __NR_perf_counter_open        295
-#endif
-
-#ifdef __i386__
-# define __NR_perf_counter_open 333
-#endif
-
-/*
- * Pick up some kernel type conventions:
- */
-#define __user
-#define asmlinkage
-
-typedef unsigned int           __u32;
-typedef unsigned long long     __u64;
-typedef long long              __s64;
-
-/*
- * User-space ABI bits:
- */
-
-/*
- * Generalized performance counter event types, used by the hw_event.type
- * parameter of the sys_perf_counter_open() syscall:
- */
-enum hw_event_types {
-       /*
-        * Common hardware events, generalized by the kernel:
-        */
-       PERF_COUNT_CPU_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,
-       PERF_COUNT_BUS_CYCLES           =  6,
-
-       PERF_HW_EVENTS_MAX              =  7,
-
-       /*
-        * 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,
-       PERF_COUNT_PAGE_FAULTS          = -3,
-       PERF_COUNT_CONTEXT_SWITCHES     = -4,
-       PERF_COUNT_CPU_MIGRATIONS       = -5,
-
-       PERF_SW_EVENTS_MIN              = -6,
-};
-
-/*
- * IRQ-notification data record type:
- */
-enum perf_counter_record_type {
-       PERF_RECORD_SIMPLE              =  0,
-       PERF_RECORD_IRQ                 =  1,
-       PERF_RECORD_GROUP               =  2,
-};
-
-/*
- * Hardware event to monitor via a performance monitoring counter:
- */
-struct perf_counter_hw_event {
-       __s64                   type;
-
-       __u64                   irq_period;
-       __u64                   record_type;
-       __u64                   read_format;
-
-       __u64                   disabled       :  1, /* off by default        */
-                               nmi            :  1, /* NMI sampling          */
-                               raw            :  1, /* raw event type        */
-                               inherit        :  1, /* children inherit it   */
-                               pinned         :  1, /* must always be on PMU */
-                               exclusive      :  1, /* only group on PMU     */
-                               exclude_user   :  1, /* don't count user      */
-                               exclude_kernel :  1, /* ditto kernel          */
-                               exclude_hv     :  1, /* ditto hypervisor      */
-                               exclude_idle   :  1, /* don't count when idle */
-
-                               __reserved_1   : 54;
-
-       __u32                   extra_config_len;
-       __u32                   __reserved_4;
-
-       __u64                   __reserved_2;
-       __u64                   __reserved_3;
-};
-
-/*
- * Ioctls that can be done on a perf counter fd:
- */
-#define PERF_COUNTER_IOC_ENABLE                _IO('$', 0)
-#define PERF_COUNTER_IOC_DISABLE       _IO('$', 1)
-
-asmlinkage int sys_perf_counter_open(
-
-       struct perf_counter_hw_event    *hw_event_uptr          __user,
-       pid_t                           pid,
-       int                             cpu,
-       int                             group_fd,
-       unsigned long                   flags)
-{
-       int ret;
-
-       ret = syscall(
-               __NR_perf_counter_open, hw_event_uptr, pid, cpu, group_fd, flags);
-#if defined(__x86_64__) || defined(__i386__)
-       if (ret < 0 && ret > -4096) {
-               errno = -ret;
-               ret = -1;
-       }
-#endif
-       return ret;
-}
+#include "perfcounters.h"
 
 const char *event_types [] = {
        "CPU cycles",
@@ -205,21 +86,10 @@ const unsigned int default_count[] = {
          10000,
 };
 
-/*
- * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
- * counters in the current task.
- */
-#define PR_TASK_PERF_COUNTERS_DISABLE           31
-#define PR_TASK_PERF_COUNTERS_ENABLE            32
-
-#define MAX_COUNTERS           8
-
 static int                     nr_counters                     = -1;
 
 static __u64                   count_filter                   = 100;
 
-#define MAX_NR_CPUS            256
-
 static int                     event_count[MAX_COUNTERS];
 static unsigned long           event_id[MAX_COUNTERS];
 static int                     event_raw[MAX_COUNTERS];
diff --git a/Documentation/perf_counter/perfcounters.h b/Documentation/perf_counter/perfcounters.h
new file mode 100644 (file)
index 0000000..8c1559b
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Ioctls that can be done on a perf counter fd:
+ */
+#define PERF_COUNTER_IOC_ENABLE                _IO('$', 0)
+#define PERF_COUNTER_IOC_DISABLE       _IO('$', 1)
+
+/*
+ * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
+ * counters in the current task.
+ */
+#define PR_TASK_PERF_COUNTERS_DISABLE  31
+#define PR_TASK_PERF_COUNTERS_ENABLE    32
+
+#define MAX_COUNTERS                   64
+#define MAX_NR_CPUS                    256
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+/*
+ * Pick up some kernel type conventions:
+ */
+#define __user
+#define asmlinkage
+
+typedef unsigned int           __u32;
+typedef unsigned long long     __u64;
+typedef long long              __s64;
+
+/*
+ * User-space ABI bits:
+ */
+
+/*
+ * Generalized performance counter event types, used by the hw_event.type
+ * parameter of the sys_perf_counter_open() syscall:
+ */
+enum hw_event_types {
+       /*
+        * Common hardware events, generalized by the kernel:
+        */
+       PERF_COUNT_CPU_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,
+       PERF_COUNT_BUS_CYCLES           =  6,
+
+       PERF_HW_EVENTS_MAX              =  7,
+
+       /*
+        * 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,
+       PERF_COUNT_PAGE_FAULTS          = -3,
+       PERF_COUNT_CONTEXT_SWITCHES     = -4,
+       PERF_COUNT_CPU_MIGRATIONS       = -5,
+
+       PERF_SW_EVENTS_MIN              = -6,
+};
+
+/*
+ * IRQ-notification data record type:
+ */
+enum perf_counter_record_type {
+       PERF_RECORD_SIMPLE              =  0,
+       PERF_RECORD_IRQ                 =  1,
+       PERF_RECORD_GROUP               =  2,
+};
+
+/*
+ * Hardware event to monitor via a performance monitoring counter:
+ */
+struct perf_counter_hw_event {
+       __s64                   type;
+
+       __u64                   irq_period;
+       __u64                   record_type;
+       __u64                   read_format;
+
+       __u64                   disabled       :  1, /* off by default        */
+                               nmi            :  1, /* NMI sampling          */
+                               raw            :  1, /* raw event type        */
+                               inherit        :  1, /* children inherit it   */
+                               pinned         :  1, /* must always be on PMU */
+                               exclusive      :  1, /* only group on PMU     */
+                               exclude_user   :  1, /* don't count user      */
+                               exclude_kernel :  1, /* ditto kernel          */
+                               exclude_hv     :  1, /* ditto hypervisor      */
+                               exclude_idle   :  1, /* don't count when idle */
+
+                               __reserved_1   : 54;
+
+       __u32                   extra_config_len;
+       __u32                   __reserved_4;
+
+       __u64                   __reserved_2;
+       __u64                   __reserved_3;
+};
+
+#ifdef __x86_64__
+# define __NR_perf_counter_open        295
+#endif
+
+#ifdef __i386__
+# define __NR_perf_counter_open 333
+#endif
+
+#ifdef __powerpc__
+#define __NR_perf_counter_open 319
+#endif
+
+asmlinkage int sys_perf_counter_open(
+
+       struct perf_counter_hw_event    *hw_event_uptr          __user,
+       pid_t                           pid,
+       int                             cpu,
+       int                             group_fd,
+       unsigned long                   flags)
+{
+       int ret;
+
+       ret = syscall(
+               __NR_perf_counter_open, hw_event_uptr, pid, cpu, group_fd, flags);
+#if defined(__x86_64__) || defined(__i386__)
+       if (ret < 0 && ret > -4096) {
+               errno = -ret;
+               ret = -1;
+       }
+#endif
+       return ret;
+}
+
index 9a5808f..a3d4a7a 100644 (file)
 
 #include <linux/unistd.h>
 
-#ifdef __x86_64__
-# define __NR_perf_counter_open        295
-#endif
-
-#ifdef __i386__
-# define __NR_perf_counter_open 333
-#endif
-
-#ifdef __powerpc__
-#define __NR_perf_counter_open 319
-#endif
-
-/*
- * Pick up some kernel type conventions:
- */
-#define __user
-#define asmlinkage
-
-typedef unsigned int           __u32;
-typedef unsigned long long     __u64;
-typedef long long              __s64;
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
-/*
- * User-space ABI bits:
- */
-
-/*
- * Generalized performance counter event types, used by the hw_event.type
- * parameter of the sys_perf_counter_open() syscall:
- */
-enum hw_event_types {
-       /*
-        * Common hardware events, generalized by the kernel:
-        */
-       PERF_COUNT_CPU_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,
-       PERF_COUNT_BUS_CYCLES           =  6,
-
-       PERF_HW_EVENTS_MAX              =  7,
-
-       /*
-        * 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,
-       PERF_COUNT_PAGE_FAULTS          = -3,
-       PERF_COUNT_CONTEXT_SWITCHES     = -4,
-       PERF_COUNT_CPU_MIGRATIONS       = -5,
-
-       PERF_SW_EVENTS_MIN              = -6,
-};
-
-/*
- * IRQ-notification data record type:
- */
-enum perf_counter_record_type {
-       PERF_RECORD_SIMPLE              =  0,
-       PERF_RECORD_IRQ                 =  1,
-       PERF_RECORD_GROUP               =  2,
-};
-
-/*
- * Hardware event to monitor via a performance monitoring counter:
- */
-struct perf_counter_hw_event {
-       __s64                   type;
-
-       __u64                   irq_period;
-       __u64                   record_type;
-       __u64                   read_format;
-
-       __u64                   disabled       :  1, /* off by default        */
-                               nmi            :  1, /* NMI sampling          */
-                               raw            :  1, /* raw event type        */
-                               inherit        :  1, /* children inherit it   */
-                               pinned         :  1, /* must always be on PMU */
-                               exclusive      :  1, /* only group on PMU     */
-                               exclude_user   :  1, /* don't count user      */
-                               exclude_kernel :  1, /* ditto kernel          */
-                               exclude_hv     :  1, /* ditto hypervisor      */
-                               exclude_idle   :  1, /* don't count when idle */
-
-                               __reserved_1   : 54;
-
-       __u32                   extra_config_len;
-       __u32                   __reserved_4;
-
-       __u64                   __reserved_2;
-       __u64                   __reserved_3;
-};
-
-/*
- * Ioctls that can be done on a perf counter fd:
- */
-#define PERF_COUNTER_IOC_ENABLE                _IO('$', 0)
-#define PERF_COUNTER_IOC_DISABLE       _IO('$', 1)
-
-asmlinkage int sys_perf_counter_open(
-
-       struct perf_counter_hw_event    *hw_event_uptr          __user,
-       pid_t                           pid,
-       int                             cpu,
-       int                             group_fd,
-       unsigned long                   flags)
-{
-       int ret;
-
-       ret = syscall(
-               __NR_perf_counter_open, hw_event_uptr, pid, cpu, group_fd, flags);
-#if defined(__x86_64__) || defined(__i386__)
-       if (ret < 0 && ret > -4096) {
-               errno = -ret;
-               ret = -1;
-       }
-#endif
-       return ret;
-}
-
+#include "perfcounters.h"
 
 static char *hw_event_names [] = {
        "CPU cycles",
@@ -224,9 +98,6 @@ static struct event_symbol event_symbols [] = {
        {PERF_COUNT_CPU_MIGRATIONS,             "migrations",           },
 };
 
-#define MAX_COUNTERS                                   64
-#define MAX_NR_CPUS                                    256
-
 static int                     nr_counters             = 0;
 static int                     nr_cpus                 = 0;
 
@@ -388,9 +259,6 @@ err:
 
 char fault_here[1000000];
 
-#define PR_TASK_PERF_COUNTERS_DISABLE           31
-#define PR_TASK_PERF_COUNTERS_ENABLE            32
-
 static int fd[MAX_NR_CPUS][MAX_COUNTERS];
 
 static void create_counter(int counter)