lkml.org 
[lkml]   [2010]   [May]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[RFC][PATCH v2 07/11] perf: x86, implements pmu::register_events
From
Date
pmu::register_events register events to sysfs.
The structure as below,

$ tree /sys/devices/system/cpu/event_source/
/sys/devices/system/cpu/event_source/
`-- id

$ tree /sys/devices/system/cpu/events/
/sys/devices/system/cpu/events/
|-- L1-dcache-load-misses
| |-- event_source -> ../../event_source
| `-- id
|-- LLC-load-misses
| |-- event_source -> ../../event_source
| `-- id
|-- branch-misses
| |-- event_source -> ../../event_source
| `-- id
|-- branches
| |-- event_source -> ../../event_source
| `-- id
|-- bus-cycles
| |-- event_source -> ../../event_source
| `-- id
|-- cache-misses
| |-- event_source -> ../../event_source
| `-- id
|-- cache-references
| |-- event_source -> ../../event_source
| `-- id
|-- cycles
| |-- event_source -> ../../event_source
| `-- id
|-- dTLB-load-misses
| |-- event_source -> ../../event_source
| `-- id
|-- dTLB-store-misses
| |-- event_source -> ../../event_source
| `-- id
|-- iTLB-load-misses
| |-- event_source -> ../../event_source
| `-- id
|-- iTLB-load-refs
| |-- event_source -> ../../event_source
| `-- id
`-- instructions
|-- event_source -> ../../event_source
`-- id

Signed-off-by: Lin Ming <ming.m.lin@intel.com>
---
arch/x86/kernel/cpu/perf_event.c | 70 ++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 8a3aea6..148eee6 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1529,6 +1529,75 @@ static int x86_pmu_init_event(struct perf_event *event)
return err;
}

+static int register_event(struct pmu *pmu,
+ struct kobject *parent_kobj, char *name, u64 id)
+{
+ struct perf_event_kobject *event_kobj;
+ struct attribute *attr;
+ int err;
+
+ event_kobj = kzalloc(sizeof(*event_kobj), GFP_KERNEL);
+ if (!event_kobj) {
+ err = -ENOMEM;
+ goto exit;
+ }
+ event_kobj->id = id;
+
+ err = kobject_init_and_add(&event_kobj->kobj,
+ &event_ktype, parent_kobj, name);
+ if (err)
+ goto exit;
+
+ attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+ if (!attr) {
+ err = -ENOMEM;
+ goto exit;
+ }
+ attr->name = "id";
+ attr->mode = 0444;
+
+ err = sysfs_create_file(&event_kobj->kobj, attr);
+ if (err)
+ goto exit;
+
+ err = sysfs_create_link(&event_kobj->kobj, &pmu->kobj, kobject_name(&pmu->kobj));
+
+exit:
+ return err;
+}
+
+static int x86_pmu_register_events(struct pmu *pmu, struct kobject *events_kobj)
+{
+ int type, op, i;
+ int cache_id;
+ int err = 0;
+
+ for (i = PERF_COUNT_HW_CPU_CYCLES; i < PERF_COUNT_HW_MAX; i++) {
+ err = register_event(pmu, events_kobj,
+ perf_hw_event_name(i), x86_pmu.event_map(i));
+ if (err)
+ break;
+ }
+
+ for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
+ for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
+ for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
+
+ cache_id = hw_cache_event_ids[type][op][i];
+ if (cache_id <= 0)
+ continue;
+
+ err = register_event(pmu, events_kobj,
+ perf_hw_cache_event_name(type, op, i), cache_id);
+ if (err)
+ break;
+ }
+ }
+ }
+
+ return err;
+}
+
static struct pmu pmu = {
.id = PMU_TYPE_CPU,
.enable = x86_pmu_enable,
@@ -1541,6 +1610,7 @@ static struct pmu pmu = {
.cancel_txn = x86_pmu_cancel_txn,
.commit_txn = x86_pmu_commit_txn,
.init_event = x86_pmu_init_event,
+ .register_events = x86_pmu_register_events,
};

/*





\
 
 \ /
  Last update: 2010-05-18 19:51    [W:0.048 / U:2.552 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site