Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2339132imu; Fri, 23 Nov 2018 07:49:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/X3IB/aybqqC872HPcvs068eHDNz2gSDYt8NQBaZwfM8EDf1MrCMYevfiwmadp8QLS/bFGS X-Received: by 2002:a17:902:6bc4:: with SMTP id m4mr1327533plt.93.1542988176221; Fri, 23 Nov 2018 07:49:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542988176; cv=none; d=google.com; s=arc-20160816; b=uUKQSrl5bFx86uwRZ5rYLpVdSkLu9l2+XNkmqoxl1bh1eWvTqdQOgDGwpms7SlOip4 UMVViHWcZHKA4YaGg7hHbzMIYMbVDbKPUSXaypRAPMuePFUyUWaToO1YJWWqra9K+R/z uX1pVX2/KUIOg4YvylxKLMOCZw0u6cdDS/MtsWE7LkhFtmV7QWxoog5os/uN1WjH3xvi b3BnJTCSVeaKWpYdrR+IdDjNGKtJmhlsj39IUJIRa2FmCcgf6BhMOjKll9ftAFX/yjFt 7wPSeR/iu5xG+LhygjQFBi09q20fmrriCeG85IK+epL8xZs8AnGJ/QmJk9EAuZHdWitK htuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=IHHJSoG5SXiqAWg3UdPx2Nl2+m+aIFdCRG37AhSlVCk=; b=LIa+Cac3v7lXwYtSrh8bOoCXv9+U3ovGQ48WBtnTq8Vq3KolAudKgCD7pQWcDvwINg +Osbe0nE6DnyxbnsAavZKICwoB+G0Yvp1lzn5QCXViSHz1Yi6p2LvbF//93Kxlq5vIAi Bcphe/kV/IHpOI+x+Bys7B0H/D1iS4fr3qIrOgqO+VEWMi/x4GkDkDV2yJbL2l/Chet7 AvSqAMtWzqj4XvHtJg3gJRLSAMflUFDPPUdq7o5LZOGzFh8HAtEO4DYIC8mpToMdIZEw cQlju8C7rbStqABEtrnvJioehCC4Ocq1la4SvBfSEPQy+8XB/uxXKM177Cs+sfaBYwJN MaIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12si23434156pgn.145.2018.11.23.07.49.17; Fri, 23 Nov 2018 07:49:36 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391042AbeKVXAz (ORCPT + 99 others); Thu, 22 Nov 2018 18:00:55 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:47114 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731683AbeKVXAy (ORCPT ); Thu, 22 Nov 2018 18:00:54 -0500 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 5A6D93804; Thu, 22 Nov 2018 04:21:45 -0800 (PST) Received: from localhost (unknown [10.37.6.11]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E4B8D3F5A0; Thu, 22 Nov 2018 04:21:44 -0800 (PST) Date: Thu, 22 Nov 2018 12:21:43 +0000 From: Andrew Murray To: Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Shawn Guo , Sascha Hauer , Will Deacon , Mark Rutland , Benjamin Herrenschmidt , Thomas Gleixner , Borislav Petkov , x86@kernel.org, linux-alpha@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 00/10] perf/core: Generalise event exclusion checking Message-ID: <20181122122142.GI42987@e119886-lin.cambridge.arm.com> References: <1542363853-13849-1-git-send-email-andrew.murray@arm.com> <20181119130800.GE9761@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181119130800.GE9761@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1+81 (426a6c1) (2018-08-26) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 19, 2018 at 02:08:00PM +0100, Peter Zijlstra wrote: > On Fri, Nov 16, 2018 at 10:24:03AM +0000, Andrew Murray wrote: > > Many PMU drivers do not have the capability to exclude counting events > > that occur in specific contexts such as idle, kernel, guest, etc. These > > drivers indicate this by returning an error in their event_init upon > > testing the events attribute flags. > > > > However this approach requires that each time a new event modifier is > > added to perf, all the perf drivers need to be modified to indicate that > > they don't support the attribute. This results in additional boiler-plate > > code common to many drivers that needs to be maintained. An example of > > this is the addition of exclude_host and exclude_guest in 2011 yet many > > PMU drivers do not support this or indicate an error on events that make > > use of it. > > > > This patch generalises the test for exclusion and updates PMU drivers to > > use it. This is a functional change as some PMU drivers will now correctly > > report that they don't support certain events whereas they previously did. > > Right, I like that idea, and yes, there's a lot of fail around there :/ > > > A longer term approach may instead be for PMU's to advertise their > > capabilities on registration. > > This I think is the better approach. We already have the > PERF_PMU_CAP_flags that can be used to advertise various PMU > capabilities. OK I'll respin my series to take this approach. > > Something along these lines I suppose; then every PMU that actually > checks the flags, needs to set the flag, otherwise it'll fail. > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > index 53c500f0ca79..de15723ea52a 100644 > --- a/include/linux/perf_event.h > +++ b/include/linux/perf_event.h > @@ -244,6 +244,7 @@ struct perf_event; > #define PERF_PMU_CAP_EXCLUSIVE 0x10 > #define PERF_PMU_CAP_ITRACE 0x20 > #define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x40 > +#define PERF_PMU_CAP_EXCLUDE 0x80 > > /** > * struct pmu - generic performance monitoring unit > diff --git a/kernel/events/core.c b/kernel/events/core.c > index 84530ab358c3..d76b724177b9 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -9772,6 +9772,14 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event) > if (ctx) > perf_event_ctx_unlock(event->group_leader, ctx); > > + if (!ret) { > + if ((pmu->capabilities & PERF_PMU_CAP_EXCLUDE) || > + event_has_exclude_flags(event)) { > + event->destroy(event); > + ret = -EINVAL; > + } > + } > + I don't quite follow this logic. Should that not have been: if (!(pmu->capabilities & PERF_PMU_CAP_EXCLUDE) && event_has_exclude_flags(event)) { Meaning that if an event has any exclude flags but the pmu doesn't have the capability to handle them then error. If you're happy with my proposed logic, then would it also make sense to move this before the call to the pmu->event_init ? Thanks, Andrew Murray > if (ret) > module_put(pmu->module); > >