From patchwork Tue Jun 11 16:42:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 17900 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f199.google.com (mail-vc0-f199.google.com [209.85.220.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2249325DF1 for ; Thu, 13 Jun 2013 10:57:31 +0000 (UTC) Received: by mail-vc0-f199.google.com with SMTP id gf11sf3001200vcb.6 for ; Thu, 13 Jun 2013 03:57:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:resent-from:resent-date:resent-message-id:resent-to :sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-google-group-id:list-post :list-help:list-archive:list-unsubscribe; bh=D2K/zY8fUjscZuTomcmCif8r8h1zS0nxO/wey/SAqi8=; b=qSBg6rbFpryyxwZlJeJ6iX1xtCBp6x745ukD0+0D2Zl9fcpKJ2k2D/1YOCpVGlpsDr W9uBsoU+AyNnf7RRyDnEMzDR8C4Z4SUSQ0y2/z6uHmLJ8agONQ9UAuKvjpjOI6/fILMN 5hj7p3I/mwo4oybkEjtK1HiqlwwcVBe4QLL3DtB2pGMqZ7vAFBxf2L20gYI2QsA+eY/J L2rRj4CBes6j7D63czR54HJlWHnMoeWzyvmMjxd3IQHFUET5jg0kgPA/FyAt7URfFXMt lpse/pz8DvxRVwuHHdofj64gwIPaWSGZkjtH4/Ch7MiVCbjN1GXdbKrm9XsNYTMlKuWm bpng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:resent-from:resent-date:resent-message-id:resent-to :sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=D2K/zY8fUjscZuTomcmCif8r8h1zS0nxO/wey/SAqi8=; b=ljP8ZZsfZMweYFnubeWdKvRhgXmoQtP0iKoa27pwCfG/gxDoxGpK8UgBXaHrG6JznO mtdVtPJc2bg9j3PdZyB6irC1RE4pNc3VTmiQ+nIPBUrYjcBp/lmZRnKcSSmTstKvfvFP FHA2FU0z8RMNkxoyGGy2LOdS7m0TAs2GpMHIcudywp0jxfZLoJu0QBEVPTYYf/PozmC6 PXiKzpMKoiZjucRzyj03Y7EJXBFkNwO5eYdJY1eo8Gk2OI+BVu0HynEGZfKWXuKkDVC7 xJzoQoAAmP3qQsJWysfhJ5UzNxwZAzmUXEPsTh023JBAlCpBaRCs9cObWaZ6Y5VID8Zk hKLQ== X-Received: by 10.224.215.68 with SMTP id hd4mr1300987qab.5.1371121050925; Thu, 13 Jun 2013 03:57:30 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.58.233 with SMTP id u9ls1516226qeq.53.gmail; Thu, 13 Jun 2013 03:57:30 -0700 (PDT) X-Received: by 10.52.228.103 with SMTP id sh7mr93886vdc.48.1371121050794; Thu, 13 Jun 2013 03:57:30 -0700 (PDT) Received: from mail-ve0-x22f.google.com (mail-ve0-x22f.google.com [2607:f8b0:400c:c01::22f]) by mx.google.com with ESMTPS id to9si10174738vdc.136.2013.06.13.03.57.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Jun 2013 03:57:30 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22f is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22f; Received: by mail-ve0-f175.google.com with SMTP id da11so7498805veb.20 for ; Thu, 13 Jun 2013 03:57:30 -0700 (PDT) X-Received: by 10.52.170.148 with SMTP id am20mr80362vdc.75.1371121050632; Thu, 13 Jun 2013 03:57:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.191.99 with SMTP id gx3csp16622vec; Thu, 13 Jun 2013 03:57:29 -0700 (PDT) X-Received: by 10.205.103.67 with SMTP id dh3mr74626bkc.19.1371121049027; Thu, 13 Jun 2013 03:57:29 -0700 (PDT) Received: from mail-bk0-x236.google.com (mail-bk0-x236.google.com [2a00:1450:4008:c01::236]) by mx.google.com with ESMTPS id pa1si66495bkb.270.2013.06.13.03.57.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Jun 2013 03:57:29 -0700 (PDT) Received-SPF: pass (google.com: domain of rric.net@gmail.com designates 2a00:1450:4008:c01::236 as permitted sender) client-ip=2a00:1450:4008:c01::236; Received: by mail-bk0-f54.google.com with SMTP id it16so3062660bkc.41 for ; Thu, 13 Jun 2013 03:57:28 -0700 (PDT) X-Received: by 10.204.191.132 with SMTP id dm4mr64574bkb.66.1371121048061; Thu, 13 Jun 2013 03:57:28 -0700 (PDT) Received: from rric.localhost (g224198135.adsl.alicedsl.de. [92.224.198.135]) by mx.google.com with ESMTPSA id so13sm9185809bkb.15.2013.06.13.03.57.26 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 13 Jun 2013 03:57:27 -0700 (PDT) Resent-From: Robert Richter Resent-Date: Thu, 13 Jun 2013 12:57:24 +0200 Resent-Message-ID: <20130613105724.GN12218@rric.localhost> Resent-To: linaro-kernel@lists.linaro.org, patches@linaro.org Received: from rric.localhost (f053086247.adsl.alicedsl.de. [78.53.86.247]) by mx.google.com with ESMTPSA id b12sm6160884bkz.0.2013.06.11.09.43.09 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Jun 2013 09:43:10 -0700 (PDT) Sender: Robert Richter 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 13/14] perf, persistent: Exposing persistent events using sysfs Date: Tue, 11 Jun 2013 18:42:39 +0200 Message-Id: <1370968960-22527-14-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> X-Gm-Message-State: ALoCoQlRIVvih/czI3Lt55SLij3mNp/RS4fYH58r5NdEwxaFTaIorUjpNr1jvYTQ+HaBQ2D/mm9/ X-Original-Sender: rric.net@gmail.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22f is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gmail.com Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Robert Richter Expose persistent events in the system to userland using sysfs. Perf tools are able to read existing pmu events from sysfs. Now we use a persistent pmu as an event container containing all registered persistent events of the system. This patch adds dynamically registration of persistent events to sysfs. E.g. something like this: /sys/bus/event_source/devices/persistent/events/mce_record:persistent,config=106 /sys/bus/event_source/devices/persistent/format/persistent:attr5:23 Perf tools need to support the attr syntax that is added in a separate patch set. With it we are able to run perf tool commands to read persistent events, e.g.: # perf record -e persistent/mce_record/ sleep 10 # perf top -e persistent/mce_record/ [ Document attr syntax in sysfs ABI ] Reported-by: Jiri Olsa Signed-off-by: Robert Richter Signed-off-by: Robert Richter --- .../testing/sysfs-bus-event_source-devices-format | 43 ++++++++++++----- kernel/events/persistent.c | 55 +++++++++++++++++++++- 2 files changed, 86 insertions(+), 12 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-format b/Documentation/ABI/testing/sysfs-bus-event_source-devices-format index 77f47ff..47b7353 100644 --- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-format +++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-format @@ -1,13 +1,14 @@ -Where: /sys/bus/event_source/devices//format +Where: /sys/bus/event_source/devices//format/ Date: January 2012 -Kernel Version: 3.3 +Kernel Version: 3.3 + 3.12 (added attr:) Contact: Jiri Olsa -Description: - Attribute group to describe the magic bits that go into - perf_event_attr::config[012] for a particular pmu. - Each attribute of this group defines the 'hardware' bitmask - we want to export, so that userspace can deal with sane - name/value pairs. + +Description: Define formats for bit ranges in perf_event_attr + + Attribute group to describe the magic bits that go + into struct perf_event_attr for a particular pmu. Bit + range may be any bit mask of an u64 (bits 0 to 63). Userspace must be prepared for the possibility that attributes define overlapping bit ranges. For example: @@ -15,6 +16,26 @@ Description: attr2 = 'config:0-7' attr3 = 'config:12-35' - Example: 'config1:1,6-10,44' - Defines contents of attribute that occupies bits 1,6-10,44 of - perf_event_attr::config1. + Syntax Description + + config[012]*: Each attribute of this group + defines the 'hardware' bitmask + we want to export, so that + userspace can deal with sane + name/value pairs. + + attr: Set any field of the event + attribute. The index is a + decimal number that specifies + the u64 value to be set within + struct perf_event_attr. + + Examples: + + 'config1:1,6-10,44' Defines contents of attribute + that occupies bits 1,6-10,44 + of perf_event_attr::config1. + + 'attr5:23' Define the persistent event + flag (bit 23 of the attribute + flags) diff --git a/kernel/events/persistent.c b/kernel/events/persistent.c index 96201c1..8be7c05 100644 --- a/kernel/events/persistent.c +++ b/kernel/events/persistent.c @@ -17,8 +17,10 @@ struct pers_event_desc { struct pers_event { char *name; struct perf_event_attr attr; + struct perf_pmu_events_attr sysfs; }; +static struct pmu persistent_pmu; static DEFINE_PER_CPU(struct list_head, pers_events); static DEFINE_PER_CPU(struct mutex, pers_events_lock); @@ -137,6 +139,8 @@ unwind: return PTR_ERR(event); } +static int pers_event_sysfs_register(struct pers_event *event); + int perf_add_persistent_event_by_id(char* name, int id) { struct pers_event *event; @@ -150,6 +154,8 @@ int perf_add_persistent_event_by_id(char* name, int id) if (!event->name) goto fail; + event->sysfs.id = id; + attr = &event->attr; attr->sample_period = 1; attr->wakeup_events = 1; @@ -163,6 +169,8 @@ int perf_add_persistent_event_by_id(char* name, int id) if (ret) goto fail; + pers_event_sysfs_register(event); + return 0; fail: kfree(event->name); @@ -207,12 +215,57 @@ static struct attribute_group persistent_format_group = { .attrs = persistent_format_attrs, }; +#define MAX_EVENTS 16 + +static struct attribute *persistent_events_attr[MAX_EVENTS + 1] = { }; + +static struct attribute_group persistent_events_group = { + .name = "events", + .attrs = persistent_events_attr, +}; + static const struct attribute_group *persistent_attr_groups[] = { &persistent_format_group, + NULL, /* placeholder: &persistent_events_group */ NULL, }; +#define EVENTS_GROUP (persistent_attr_groups[1]) -static struct pmu persistent_pmu; +static ssize_t pers_event_sysfs_show(struct device *dev, + struct device_attribute *__attr, char *page) +{ + struct perf_pmu_events_attr *attr = + container_of(__attr, struct perf_pmu_events_attr, attr); + return sprintf(page, "persistent,config=%lld", + (unsigned long long)attr->id); +} + +static int pers_event_sysfs_register(struct pers_event *event) +{ + struct device_attribute *attr = &event->sysfs.attr; + int idx; + + *attr = (struct device_attribute)__ATTR(, 0444, pers_event_sysfs_show, + NULL); + attr->attr.name = event->name; + + /* add sysfs attr to events: */ + for (idx = 0; idx < MAX_EVENTS; idx++) { + if (!cmpxchg(persistent_events_attr + idx, NULL, &attr->attr)) + break; + } + + if (idx >= MAX_EVENTS) + return -ENOSPC; + if (!idx) + EVENTS_GROUP = &persistent_events_group; + if (!persistent_pmu.dev) + return 0; /* sysfs not yet initialized */ + if (idx) + return sysfs_update_group(&persistent_pmu.dev->kobj, + EVENTS_GROUP); + return sysfs_create_group(&persistent_pmu.dev->kobj, EVENTS_GROUP); +} static int persistent_pmu_init(struct perf_event *event) {