From patchwork Thu Aug 22 14:13:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 19414 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E5B9B248E6 for ; Thu, 22 Aug 2013 14:14:50 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id ht10sf1554184vcb.5 for ; Thu, 22 Aug 2013 07:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:delivered-to:sender:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=uxhrKRiPuyg4gKBtuOxjKw86akVfd9ANH6QFdwxiXbg=; b=w+kpzPaSBuyrtNjvgzKHEcm1FL99Ohhq0QPiPUKI0cyFZjG2i5S3Rh3KAwPzE5rYfK ZsGyhOsgxwYV+/fod9/aHwedouT7GqHglLumdvpN9jKzFChRVMk0bHp+EV1gVcOro6/X RClPwKD0BmtVBImRXtNV0lPm1sEoDKtLyU9gaosXUkYLn5dIkIrQay1o4YerrHpoPjwY 3A5HSFFIkq7i3pH7afXI2mbxGQ44R4DeTduzgOjELah8DEb6uO+dh7JJn4hRTWxcYmjM omqY+3JC0eo2bsOQ5yLMc60a1jX3HxIzvJPzawQCjkiYiqdJg7rQwtEmTCCZi1GGu1XY CdYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:sender:from:to:cc :subject:date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=uxhrKRiPuyg4gKBtuOxjKw86akVfd9ANH6QFdwxiXbg=; b=GuQeiW9oadSJJt5yqgEhifufv5Inx4hZjx3+QwUzqGFCxHygpDOTtXlDDOie0tZfnB wWzpqKxOcooYdZm+SluEb1iVkA7QeLJ3sPtJKQzbS/tfZAD2UEJCSIS8HJ6sFgtw98Lb etMaV++uQ+KaA7XWyFK6OXB6VF69N6jufd9bB7OBNHygpa8ZGxxM1OSQ4ndBl1IqCTyF /hTuFOFsqSaVBmJeQxeDwv/+yDSY3BfivIoFqeN+taw6OdLwJMv0YNq+9Fc1BlSG2ZIW 3aq3oOKT9vpTVi1sO5uw8CeVa6UyVyVdMSCmuXB2JrD0YOtpF3HLmchoFD3l56SatnPI 7o+w== X-Received: by 10.224.223.198 with SMTP id il6mr12974537qab.7.1377180890688; Thu, 22 Aug 2013 07:14:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.51.40 with SMTP id h8ls1118073qeo.28.gmail; Thu, 22 Aug 2013 07:14:50 -0700 (PDT) X-Received: by 10.58.19.162 with SMTP id g2mr11816474vee.12.1377180890573; Thu, 22 Aug 2013 07:14:50 -0700 (PDT) Received: from mail-ve0-x233.google.com (mail-ve0-x233.google.com [2607:f8b0:400c:c01::233]) by mx.google.com with ESMTPS id fw17si4012668vec.66.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:50 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::233 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::233; Received: by mail-ve0-f179.google.com with SMTP id c13so1525883vea.38 for ; Thu, 22 Aug 2013 07:14:50 -0700 (PDT) X-Gm-Message-State: ALoCoQnSSqTf1vsQ/uvWoxtO1jEHAcTMGfbe4ae0sxPQuNqbRHfZfg0wHoapauepvWJ/tlcxhL2R X-Received: by 10.221.44.136 with SMTP id ug8mr11764520vcb.13.1377180890470; Thu, 22 Aug 2013 07:14:50 -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.220.174.196 with SMTP id u4csp33215vcz; Thu, 22 Aug 2013 07:14:49 -0700 (PDT) X-Received: by 10.205.14.197 with SMTP id pr5mr7046903bkb.25.1377180889122; Thu, 22 Aug 2013 07:14:49 -0700 (PDT) Received: from mail-bk0-x22b.google.com (mail-bk0-x22b.google.com [2a00:1450:4008:c01::22b]) by mx.google.com with ESMTPS id nu4si2299518bkb.316.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:49 -0700 (PDT) Received-SPF: pass (google.com: domain of rric.net@gmail.com designates 2a00:1450:4008:c01::22b as permitted sender) client-ip=2a00:1450:4008:c01::22b; Received: by mail-bk0-f43.google.com with SMTP id mz13so701245bkb.2 for ; Thu, 22 Aug 2013 07:14:48 -0700 (PDT) X-Received: by 10.204.234.5 with SMTP id ka5mr4947698bkb.5.1377180887805; Thu, 22 Aug 2013 07:14:47 -0700 (PDT) Received: from rric.localhost (g224195237.adsl.alicedsl.de. [92.224.195.237]) by mx.google.com with ESMTPSA id jh13sm3079991bkb.13.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:47 -0700 (PDT) Sender: Robert Richter From: Robert Richter To: Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Borislav Petkov , Jiri Olsa , linux-kernel@vger.kernel.org, Robert Richter , Namhyung Kim , Robert Richter Subject: [PATCH v3 08/12] perf, persistent: Exposing persistent events using sysfs Date: Thu, 22 Aug 2013 16:13:23 +0200 Message-Id: <1377180807-12758-9-git-send-email-rric@kernel.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1377180807-12758-1-git-send-email-rric@kernel.org> References: <1377180807-12758-1-git-send-email-rric@kernel.org> X-Original-Sender: rric.net@gmail.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::233 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/ [ Jiri: Document attr syntax in sysfs ABI ] [ Namhyung: Fix sysfs registration with lockdep enabled ] Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Robert Richter Signed-off-by: Robert Richter --- .../testing/sysfs-bus-event_source-devices-format | 43 ++++++++++++---- kernel/events/persistent.c | 60 ++++++++++++++++++++++ 2 files changed, 92 insertions(+), 11 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..2dbb911 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.xx (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 @@ Contact: Jiri Olsa 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 ede95ab..aca1e98 100644 --- a/kernel/events/persistent.c +++ b/kernel/events/persistent.c @@ -8,6 +8,7 @@ #define CPU_BUFFER_NR_PAGES ((512 * 1024) / PAGE_SIZE) struct pevent { + struct perf_pmu_events_attr sysfs; char *name; int id; }; @@ -119,6 +120,8 @@ static void persistent_event_close(int cpu, struct pevent *pevent) persistent_event_release(event); } +static int pevent_sysfs_register(struct pevent *event); + static int __maybe_unused persistent_open(char *name, struct perf_event_attr *attr, int nr_pages) { @@ -144,12 +147,18 @@ persistent_open(char *name, struct perf_event_attr *attr, int nr_pages) goto fail; } + pevent->sysfs.id = pevent->id; + for_each_possible_cpu(cpu) { ret = persistent_event_open(cpu, pevent, attr, nr_pages); if (ret) goto fail; } + ret = pevent_sysfs_register(pevent); + if (ret) + goto fail; + return 0; fail: for_each_possible_cpu(cpu) @@ -223,10 +232,61 @@ static struct attribute_group persistent_format_group = { .attrs = persistent_format_attrs, }; +#define MAX_EVENTS 16 + +static struct attribute *pevents_attr[MAX_EVENTS + 1] = { }; + +static struct attribute_group pevents_group = { + .name = "events", + .attrs = pevents_attr, +}; + static const struct attribute_group *persistent_attr_groups[] = { &persistent_format_group, + NULL, /* placeholder: &pevents_group */ NULL, }; +#define EVENTS_GROUP_PTR (&persistent_attr_groups[1]) + +static ssize_t pevent_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 pevent_sysfs_register(struct pevent *pevent) +{ + struct perf_pmu_events_attr *sysfs = &pevent->sysfs; + struct attribute *attr = &sysfs->attr.attr; + struct device *dev = persistent_pmu.dev; + const struct attribute_group **group = EVENTS_GROUP_PTR; + int idx; + + sysfs->id = pevent->id; + sysfs->attr = (struct device_attribute) + __ATTR(, 0444, pevent_sysfs_show, NULL); + attr->name = pevent->name; + sysfs_attr_init(attr); + + /* add sysfs attr to events: */ + for (idx = 0; idx < MAX_EVENTS; idx++) { + if (!cmpxchg(pevents_attr + idx, NULL, attr)) + break; + } + + if (idx >= MAX_EVENTS) + return -ENOSPC; + if (!idx) + *group = &pevents_group; + if (!dev) + return 0; /* sysfs not yet initialized */ + if (idx) + return sysfs_add_file_to_group(&dev->kobj, attr, (*group)->name); + return sysfs_create_group(&persistent_pmu.dev->kobj, *group); +} static int persistent_pmu_init(struct perf_event *event) {