Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755471Ab3FKQob (ORCPT ); Tue, 11 Jun 2013 12:44:31 -0400 Received: from mail-bk0-f50.google.com ([209.85.214.50]:45839 "EHLO mail-bk0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755404Ab3FKQnK (ORCPT ); Tue, 11 Jun 2013 12:43:10 -0400 From: Robert Richter To: Borislav Petkov Cc: Ingo Molnar , Peter Zijlstra , Arnaldo Carvalho de Melo , Jiri Olsa , linux-kernel@vger.kernel.org, Robert Richter , Robert Richter Subject: [PATCH v2 12/14] perf, persistent: Name each persistent event Date: Tue, 11 Jun 2013 18:42:38 +0200 Message-Id: <1370968960-22527-13-git-send-email-rric@kernel.org> X-Mailer: git-send-email 1.8.1.1 In-Reply-To: <1370968960-22527-1-git-send-email-rric@kernel.org> References: <1370968960-22527-1-git-send-email-rric@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3905 Lines: 116 From: Robert Richter For later adding persistent events to sysfs we need a name for each event. Adding a name to each persistent event. Signed-off-by: Robert Richter Signed-off-by: Robert Richter --- arch/x86/kernel/cpu/mcheck/mce.c | 3 ++- include/linux/perf_event.h | 4 ++-- kernel/events/persistent.c | 30 +++++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c index d421937..833eb7a 100644 --- a/arch/x86/kernel/cpu/mcheck/mce.c +++ b/arch/x86/kernel/cpu/mcheck/mce.c @@ -1991,7 +1991,8 @@ int __init mcheck_init(void) int __init mcheck_init_tp(void) { - if (perf_add_persistent_event_by_id(event_mce_record.event.type)) { + if (perf_add_persistent_event_by_id(event_mce_record.name, + event_mce_record.event.type)) { pr_err("Error adding MCE persistent event.\n"); return -EINVAL; } diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index dc72c93..06b4357b 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -751,7 +751,7 @@ extern void perf_event_disable(struct perf_event *event); extern int __perf_event_disable(void *info); extern void perf_event_task_tick(void); extern int perf_add_persistent_event(struct perf_event_attr *, unsigned); -extern int perf_add_persistent_event_by_id(int id); +extern int perf_add_persistent_event_by_id(char *name, int id); #else /* !CONFIG_PERF_EVENTS */ static inline void perf_event_task_sched_in(struct task_struct *prev, @@ -794,7 +794,7 @@ static inline int __perf_event_disable(void *info) { return -1; } static inline void perf_event_task_tick(void) { } static inline int perf_add_persistent_event(struct perf_event_attr *attr, unsigned nr_pages) { return -EINVAL; } -static inline int perf_add_persistent_event_by_id(int id) { return -EINVAL; } +static inline int perf_add_persistent_event_by_id(char *name, int id) { return -EINVAL; } #endif /* !CONFIG_PERF_EVENTS */ #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_NO_HZ_FULL) diff --git a/kernel/events/persistent.c b/kernel/events/persistent.c index 97c57c9..96201c1 100644 --- a/kernel/events/persistent.c +++ b/kernel/events/persistent.c @@ -14,6 +14,11 @@ struct pers_event_desc { int fd; }; +struct pers_event { + char *name; + struct perf_event_attr attr; +}; + static DEFINE_PER_CPU(struct list_head, pers_events); static DEFINE_PER_CPU(struct mutex, pers_events_lock); @@ -132,14 +137,20 @@ unwind: return PTR_ERR(event); } -int perf_add_persistent_event_by_id(int id) +int perf_add_persistent_event_by_id(char* name, int id) { - struct perf_event_attr *attr; + struct pers_event *event; + struct perf_event_attr *attr; + int ret = -ENOMEM; - attr = kzalloc(sizeof(*attr), GFP_KERNEL); - if (!attr) + event = kzalloc(sizeof(*event), GFP_KERNEL); + if (!event) return -ENOMEM; + event->name = kstrdup(name, GFP_KERNEL); + if (!event->name) + goto fail; + attr = &event->attr; attr->sample_period = 1; attr->wakeup_events = 1; attr->sample_type = PERF_SAMPLE_RAW; @@ -148,7 +159,16 @@ int perf_add_persistent_event_by_id(int id) attr->type = PERF_TYPE_TRACEPOINT; attr->size = sizeof(*attr); - return perf_add_persistent_event(attr, CPU_BUFFER_NR_PAGES); + ret = perf_add_persistent_event(attr, CPU_BUFFER_NR_PAGES); + if (ret) + goto fail; + + return 0; +fail: + kfree(event->name); + kfree(event); + + return ret; } int perf_get_persistent_event_fd(unsigned cpu, struct perf_event_attr *attr) -- 1.8.1.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/