Prev: [RFC][PATCH v1 09/15] perf: export tracepoint events via sysfs: mce
Next: [RFC][PATCH v1 08/15] perf: export tracepoint events via sysfs: kvm and kvm_mmu
From: Lin Ming on 22 Jul 2010 07:20 Software events are exported under /sys/kernel/events/, for example /sys/kernel/events/ |-- alignment-faults | |-- config | `-- type |-- context-switches | |-- config | `-- type |-- cpu-clock | |-- config | `-- type |-- cpu-migrations | |-- config | `-- type |-- emulation-faults | |-- config | `-- type |-- major-faults | |-- config | `-- type |-- minor-faults | |-- config | `-- type |-- page-faults | |-- config | `-- type ..... --- kernel/perf_event.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 61 insertions(+), 0 deletions(-) diff --git a/kernel/perf_event.c b/kernel/perf_event.c index 1f51ab9..21c359d 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c @@ -4383,6 +4383,22 @@ static int perf_swevent_init(struct perf_event *event) return 0; } +struct kobject *sys_kernel_events_kobj; +static char *perf_sw_event_name(int id); + +static void perf_swevent_export(void) +{ + int i; + + if (!sys_kernel_events_kobj) + return; + + for (i = PERF_COUNT_SW_PAGE_FAULTS; i < PERF_COUNT_SW_MAX; i++) { + perf_sys_add_event(sys_kernel_events_kobj, perf_sw_event_name(i), + i, PERF_TYPE_SOFTWARE); + } +} + static struct pmu perf_swevent = { .event_init = perf_swevent_init, .add = perf_swevent_add, @@ -4390,6 +4406,7 @@ static struct pmu perf_swevent = { .start = perf_swevent_start, .stop = perf_swevent_stop, .read = perf_swevent_read, + .export_events = perf_swevent_export, }; #ifdef CONFIG_EVENT_TRACING @@ -4662,6 +4679,16 @@ static int cpu_clock_event_init(struct perf_event *event) return 0; } +static void cpu_clock_event_export(void) +{ + if (!sys_kernel_events_kobj) + return; + + perf_sys_add_event(sys_kernel_events_kobj, + perf_sw_event_name(PERF_COUNT_SW_CPU_CLOCK), + PERF_COUNT_SW_CPU_CLOCK, PERF_TYPE_SOFTWARE); +} + static struct pmu perf_cpu_clock = { .event_init = cpu_clock_event_init, .add = cpu_clock_event_add, @@ -4669,6 +4696,7 @@ static struct pmu perf_cpu_clock = { .start = cpu_clock_event_start, .stop = cpu_clock_event_stop, .read = cpu_clock_event_read, + .export_events = cpu_clock_event_export, }; /* @@ -4737,6 +4765,16 @@ static int task_clock_event_init(struct perf_event *event) return 0; } +static void task_clock_event_export(void) +{ + if (!sys_kernel_events_kobj) + return; + + perf_sys_add_event(sys_kernel_events_kobj, + perf_sw_event_name(PERF_COUNT_SW_TASK_CLOCK), + PERF_COUNT_SW_TASK_CLOCK, PERF_TYPE_SOFTWARE); +} + static struct pmu perf_task_clock = { .event_init = task_clock_event_init, .add = task_clock_event_add, @@ -4744,6 +4782,7 @@ static struct pmu perf_task_clock = { .start = task_clock_event_start, .stop = task_clock_event_stop, .read = task_clock_event_read, + .export_events = task_clock_event_export, }; static LIST_HEAD(pmus); @@ -5887,6 +5926,8 @@ static int __init perf_event_sysfs_init(void) struct pmu *pmu = NULL; int idx; + sys_kernel_events_kobj = perf_sys_create_events_dir(kernel_kobj); + idx = srcu_read_lock(&pmus_srcu); list_for_each_entry_rcu(pmu, &pmus, entry) { if (pmu->export_events) @@ -6033,6 +6074,18 @@ static char *hw_cache_result[] = { "misses", }; +static char *sw_event_names[] = { + "cpu-clock", + "task-clock", + "page-faults", + "minor-faults", + "major-faults", + "context-switches", + "cpu-migrations", + "alignment-faults", + "emulation-faults", +}; + char *perf_hw_event_name(int id) { if (id >= ARRAY_SIZE(hw_event_names)) @@ -6051,3 +6104,11 @@ char *perf_hw_cache_event_name(u8 cache_type, u8 cache_op, u8 cache_result) return name; } + +static char *perf_sw_event_name(int id) +{ + if (id >= ARRAY_SIZE(sw_event_names)) + return NULL; + + return sw_event_names[id]; +} -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ |