perf_counter tools: Merge common code into perfcounters.h
[pandora-kernel.git] / Documentation / perf_counter / kerneltop.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];