From patchwork Wed Oct 25 01:23:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kim Phillips X-Patchwork-Id: 10025557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7F1A760245 for ; Wed, 25 Oct 2017 01:23:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7786926256 for ; Wed, 25 Oct 2017 01:23:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C37C28AC4; Wed, 25 Oct 2017 01:23:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C126B26256 for ; Wed, 25 Oct 2017 01:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Mime-Version:References:In-Reply-To: Message-Id:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Gw6C/wxtOD3F9ne44k9dIu+xKxbxLawZcv7oZJtuInM=; b=eMboB3ebP0qC+H fwrEUEE2uYzNjOCEaKDA9m0elB7cij5q3hB3qnR3fh13S3XwO3QigL6hfm4su8spzlyZ2nnSe3qA9 6OuH39E37qMSyXStEHVugy4b1/1O4d1tD/vvwax36ZDXw6/cK7o5wc4dZV5Z5u4M83htpRIg43hZR n65QRndEonZ+q0uKhLilHnAwx3nKvhT+6NVU349jJ1K+ddmooVJl0EDGjdcVm7jxoj+SE3mLDWkc5 vZtZ9QYmKTyxcpLBc/s7bim0q98geaXnfSov6P2vmw1i4We3jqawWDVuT1N2ko5E6DkcBQWRAI+Xg R9XuBFtBTh1wwqynklgg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e7APl-0007Pr-Tp; Wed, 25 Oct 2017 01:23:25 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e7APj-0007Oo-5y for linux-arm-kernel@lists.infradead.org; Wed, 25 Oct 2017 01:23:24 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8E10080D; Tue, 24 Oct 2017 18:23:02 -0700 (PDT) Received: from dupont (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C5C943F246; Tue, 24 Oct 2017 18:23:01 -0700 (PDT) Date: Tue, 24 Oct 2017 20:23:00 -0500 From: Kim Phillips To: Arnaldo Carvalho de Melo Subject: Re: [RFC 1/3] perf tool: Introduce arch-specific supplemental perf open strerror capability Message-Id: <20171024202300.de189fde683c939966a6646c@arm.com> In-Reply-To: <20171024142744.GE2512@redhat.com> References: <20171024030404.ec366ec2d9c38910ccd84ba5@arm.com> <20171024142744.GE2512@redhat.com> Organization: Arm X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171024_182323_244477_337FE415 X-CRM114-Status: GOOD ( 25.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, robh@kernel.org, mathieu.poirier@linaro.org, pawel.moll@arm.com, suzuki.poulose@arm.com, marc.zyngier@arm.com, Will Deacon , linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com, peterz@infradead.org, mingo@redhat.com, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, 24 Oct 2017 12:27:44 -0200 Arnaldo Carvalho de Melo wrote: > Em Tue, Oct 24, 2017 at 03:04:04AM -0500, Kim Phillips escreveu: > > Introduce new tools/perf/arch/*/util/evsel.c:perf_evsel__suppl_strerror() > > The naming... suppl for what? for the open operation? strerror() methods > are associated with another method, one for which it can use context > like who is the user asking for that operation, procfs/sysfs knobs, > hardware, etc, so we need to have CLASS__METHOD_strerror() > > In this case, CLASS == perf_evsel, METHOD = open, so, if you want to > have something that is _arch_ specific, we could use something like: > > int __weak perf_evsel__open_strerror_arch(struct perf_evsel *evsel __maybe_unused, > struct target *target __maybe_unused, > int err __maybe_unused, > char *msg __maybe_unused, > size_t size __maybe_unused) > { > return 0; > } > > But then you're calling it _before_ the existing switch (err), humm... > I.e. it will add stuff before the string that will be formatted later... > The messages may end up being conflicting, I wonder if the model > wouldn't be better as: ask the arch specific if it wants to override > that specific error with something, if not, fallback to the existing > perf_evsel__open_strerror() code, that could be moved to be > __perf_evsel__open_strerror() and called by the arch specific code. > > Thoughts? Thanks for your good feedback, yes, very good idea, fully agreed and implemented - see below. Thanks, Kim From 6877c8703c0eb186370ed20eee0dfc4ba53980da Mon Sep 17 00:00:00 2001 From: Kim Phillips Date: Tue, 24 Oct 2017 03:04:04 -0500 Subject: [PATCH] perf tool: Introduce arch-specific perf open strerror capability Introduce new tools/perf/arch/*/util/evsel.c:perf_evsel__strerror_arch() so each arch can start to customize usability for its h/w PMU drivers. v2: Addressed ACME's comments: - Renamed perf_evsel__suppl_strerror() perf_evsel__open_strerror_arch() ['suppl' was for supplementary, from D. Howell's prior submission: "[06/27] Provide supplementary error message facility [ver #5]"]. - Changed the logic such that if arch version - called first - doesn't put anything in the string, then call the existing, generic __perf_evsel__open_strerror() (renamed from perf_evsel__open_strerror()). Otherwise, only the string returned from the arch version is emitted. All references to 'supplemental' dropped as a consequence. Also tried addressing Will's comments: - Looked at possibly reducing the number of parameters, but since both evsel and target elements are used to evaluate the condition the error occurred in, and err, msg, and size are required for basic strerror functioning, they all got to stay. Signed-off-by: Kim Phillips --- tools/perf/arch/x86/util/Build | 1 + tools/perf/arch/x86/util/evsel.c | 24 ++++++++++++++++++++++++ tools/perf/util/evsel.c | 32 ++++++++++++++++++++++++-------- tools/perf/util/evsel.h | 2 ++ 4 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 tools/perf/arch/x86/util/evsel.c diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build index f95e6f46ef0d..90ae9358ec21 100644 --- a/tools/perf/arch/x86/util/Build +++ b/tools/perf/arch/x86/util/Build @@ -4,6 +4,7 @@ libperf-y += pmu.o libperf-y += kvm-stat.o libperf-y += perf_regs.o libperf-y += group.o +libperf-y += evsel.o libperf-$(CONFIG_DWARF) += dwarf-regs.o libperf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c new file mode 100644 index 000000000000..20a8ebc83657 --- /dev/null +++ b/tools/perf/arch/x86/util/evsel.c @@ -0,0 +1,24 @@ +#include + +#include +#include + +#include "../../util/evsel.h" + +int perf_evsel__open_strerror_arch(struct perf_evsel *evsel, + struct target *target __maybe_unused, + int err, char *msg, size_t size) +{ + switch (err) { + case EOPNOTSUPP: + if (evsel->attr.type == PERF_TYPE_HARDWARE) + return scnprintf(msg, size, "%s", + "No hardware sampling interrupt available.\n" + "No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it."); + break; + default: + break; + } + + return 0; +} diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 3ec0aed0bdcb..0f53450cfc7b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2686,8 +2686,18 @@ static bool find_process(const char *name) return ret ? false : true; } -int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, - int err, char *msg, size_t size) +int __weak perf_evsel__open_strerror_arch(struct perf_evsel *evsel __maybe_unused, + struct target *target __maybe_unused, + int err __maybe_unused, + char *msg __maybe_unused, + size_t size __maybe_unused) +{ + return 0; +} + +static int __perf_evsel__open_strerror(struct perf_evsel *evsel, + struct target *target, + int err, char *msg, size_t size) { char sbuf[STRERR_BUFSIZE]; int printed = 0; @@ -2745,12 +2755,6 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, if (evsel->attr.precise_ip) return scnprintf(msg, size, "%s", "\'precise\' request may not be supported. Try removing 'p' modifier."); -#if defined(__i386__) || defined(__x86_64__) - if (evsel->attr.type == PERF_TYPE_HARDWARE) - return scnprintf(msg, size, "%s", - "No hardware sampling interrupt available.\n" - "No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it."); -#endif break; case EBUSY: if (find_process("oprofiled")) @@ -2778,6 +2782,18 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, perf_evsel__name(evsel)); } +int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, + int err, char *msg, size_t size) +{ + int printed; + + printed = perf_evsel__open_strerror_arch(evsel, target, err, msg, size); + if (printed) + return printed; + + return __perf_evsel__open_strerror(evsel, target, err, msg, size); +} + char *perf_evsel__env_arch(struct perf_evsel *evsel) { if (evsel && evsel->evlist && evsel->evlist->env) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 77bd310eb0cb..a3822174ac0f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -416,6 +416,8 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err, char *msg, size_t msgsize); int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, int err, char *msg, size_t size); +int perf_evsel__open_strerror_arch(struct perf_evsel *evsel, struct target *target, + int err, char *msg, size_t size); static inline int perf_evsel__group_idx(struct perf_evsel *evsel) {