From patchwork Mon Apr 7 15:04:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 27908 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B3B9420490 for ; Mon, 7 Apr 2014 15:08:57 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id wp18sf27872999obc.8 for ; Mon, 07 Apr 2014 08:08:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=rIy2SPFQFfZb0/a7Hy7QvALy5XfTCpQZzI7PjnZa82o=; b=To/P+UYHtvUvI/9w11iPo8rEWp5kB7L/YhXZjOqIrrhSMzctVDcg4HDLeWbdldPVK4 r392VLlReOjuJFd5U3vBNErNT3fcNGsalUG1Fu2CMRljd/ixslMPrxMOrQ6tjRY+QMPa ns2lA43FJhMotAGJACP1j7LXRb2wjgzulRCX1w2tEcAZStP2+fsU9nmrFuW63sGStaOm Yp3D+Xi5vX0DzZ8axfIAsndUrsGLSV3piDEMekUNfkqPMFUR8UW6rUadIzPOViWvGfid 5wvvNQBEiKNvYE3W7DDiwIQIwZd8BNA/vfhkMP1vA3/LjZicm5gRcAI278eLcof9DgMM b97A== X-Gm-Message-State: ALoCoQn75VHfClaKjqar0Z9uVW0OUvuziNbkrOmSOKxILyIznOZrWYAP1qgNx/PHRC0WsAds7HqQ X-Received: by 10.50.70.66 with SMTP id k2mr10499000igu.7.1396883337201; Mon, 07 Apr 2014 08:08:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.30.163 with SMTP id d32ls427271qgd.44.gmail; Mon, 07 Apr 2014 08:08:57 -0700 (PDT) X-Received: by 10.58.105.105 with SMTP id gl9mr20725341veb.3.1396883337107; Mon, 07 Apr 2014 08:08:57 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id rw5si2969378vcb.145.2014.04.07.08.08.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:08:57 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id ik5so5600288vcb.28 for ; Mon, 07 Apr 2014 08:08:57 -0700 (PDT) X-Received: by 10.58.137.169 with SMTP id qj9mr23340veb.46.1396883337009; Mon, 07 Apr 2014 08:08:57 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp169916vcv; Mon, 7 Apr 2014 08:08:56 -0700 (PDT) X-Received: by 10.68.189.33 with SMTP id gf1mr4074351pbc.111.1396883336127; Mon, 07 Apr 2014 08:08:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sh5si8498852pbc.278.2014.04.07.08.08.55; Mon, 07 Apr 2014 08:08:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755649AbaDGPIr (ORCPT + 27 others); Mon, 7 Apr 2014 11:08:47 -0400 Received: from mail-ee0-f46.google.com ([74.125.83.46]:56286 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755322AbaDGPFO (ORCPT ); Mon, 7 Apr 2014 11:05:14 -0400 Received: by mail-ee0-f46.google.com with SMTP id t10so745574eei.19 for ; Mon, 07 Apr 2014 08:05:13 -0700 (PDT) X-Received: by 10.14.203.5 with SMTP id e5mr312153eeo.105.1396883112980; Mon, 07 Apr 2014 08:05:12 -0700 (PDT) Received: from localhost.localdomain (201-179-62-37.mobileinternet.proximus.be. [37.62.179.201]) by mx.google.com with ESMTPSA id o4sm42287649eef.20.2014.04.07.08.05.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:05:11 -0700 (PDT) From: Jean Pihet To: Borislav Petkov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , linux-kernel@vger.kernel.org, Robert Richter Cc: Robert Richter , Namhyung Kim , Jean Pihet Subject: [PATCH 08/16] perf, persistent: Exposing persistent events using sysfs Date: Mon, 7 Apr 2014 17:04:30 +0200 Message-Id: <1396883078-25320-9-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1396883078-25320-1-git-send-email-jean.pihet@linaro.org> References: <1396883078-25320-1-git-send-email-jean.pihet@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: jean.pihet@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org 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 Signed-off-by: Jean Pihet --- .../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..744d53a 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 @@ 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:24' Define the persistent event + flag (bit 24 of the attribute + flags) diff --git a/kernel/events/persistent.c b/kernel/events/persistent.c index 6b039f5..6578acf 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) {