lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Mon, 25 Jul 2011 16:11:15 +0800 From: Lin Ming <ming.m.lin@...el.com> To: Peter Zijlstra <a.p.zijlstra@...llo.nl> Cc: Ingo Molnar <mingo@...e.hu>, Andi Kleen <andi@...stfloor.org>, Stephane Eranian <eranian@...gle.com>, Arnaldo Carvalho de Melo <acme@...stprotocols.net>, linux-kernel <linux-kernel@...r.kernel.org> Subject: Re: [PATCH v2 1/6] perf: Add interface to add general events to sysfs On Mon, 2011-07-18 at 21:34 +0800, Peter Zijlstra wrote: > > Also, I would prefer an interface like: > > int perf_pmu_add_event(struct pmu *pmu, const char *name, u64 config) > { > } > > which would create the events directory if not already present and > allocate and add a pmu_sysfs_event thingy. It's strange that I didn't find a way to check if a directory is present in sysfs. Any hint? So I proceeded with below code. diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 14337a3..6db73d0 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -611,6 +611,7 @@ struct pmu { struct list_head entry; struct device *dev; + struct kobject *events; char *name; int type; diff --git a/kernel/events/core.c b/kernel/events/core.c index 3870c106..080d684 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7081,3 +7081,35 @@ fail: kfree(attr_group); kfree(all_attrs); } + +#define NAME_LEN 64 + +int perf_pmu_add_event(struct pmu *pmu, const char *name, u64 config) +{ + struct kobject *events = pmu->events; + struct pmu_event *event; + struct kobj_attribute *event_attr; + + if (!pmu_bus_running) + return -EINVAL; + + if (!events) { + events = kobject_create_and_add("events", &pmu->dev->kobj); + if (!unlikely(events)) + return -ENOMEM; + } + + event = kzalloc(sizeof(*event), GFP_KERNEL); + if (!event) + return -ENOMEM; + + strncpy(event->name, name, NAME_LEN); + event->config = config; + event_attr = &event->attr; + sysfs_attr_init(&event_attr->attr); + event_attr->attr.name = event->name; + event_attr->attr.mode = 0444; + event_attr->show = pmu_event_show; + + return sysfs_create_file(events, &event_attr->attr); +} -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@...r.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists