Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp506926pxj; Wed, 2 Jun 2021 04:54:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNXJQVuZ85mCufDnk26AvEYlORJ9NxR/l+70tzlRKje+23zcrJ+qjr8n0UlhmZV0mZ2QqW X-Received: by 2002:a05:6e02:1b87:: with SMTP id h7mr11253469ili.271.1622634850476; Wed, 02 Jun 2021 04:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622634850; cv=none; d=google.com; s=arc-20160816; b=wuP1zj9Or0Z0AP/I/YabnJGW1xfchQWroIYg3EY8aeu0HnAIx0NkYYPuJ4m7NUEl8t ack35AB+4Vu9cf1LuJSgPgGz7J9XUI5si6RbGf/xwdpSw/s8eclcoBQPBPSSq7jrlVuA oaP0RDcKyf4FB7UEFKRdGNSlYUQFR490ZHlhNb4OlSNmhB1Gb94btBudorR4m8H1ec5C D5gxrBUCEqDXXxkFetc8UAu8w5VpXxd0wEYzuAnRKpuQ+bsLcT4Y6uHrNy2nvGJ1W1lh s39haugimJIV2PTLvXcTjUjctzYRQs/DBlzO3gs3W1FwwcGmIVVdMkpX1x2U8i3CiH30 SolA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=MYU+/RZ8h7hlCLhJgp5hc/+cEPlHFWvyZICAcy3tIwM=; b=RMk4iAUrB8mjUAFF0r+TtlCQ3gS3qO/5xQ7aaEBNNCQNSHwutXkpjkK4OMzqbpDWRj 8qyaoL6MZrVTvhKUt3OfAgT8EG4kjy1twAHTNNeF6W4udvp41nqXF4oi6mnhwKSdAP39 bbTWVCur/IGvTrk2uWiW1A40OgtEIGfz5VKPDR2EcD3NAAIngAspO/NnrAWlnNTCFHlx yoQVgHupRy3l0kntdTF4NK8F/5+khgZA7p5s/1Z4GQuk6oAFb8WUMHDCSbzV7C+hhQGE OhdxIhj5nCALwHhL+dbrhmrKrRu7/u8yceepyZnvUPu80PwS+P5aEt9sojOJ/et+4d7j sePg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DWYMsfZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i26si20007166ion.51.2021.06.02.04.53.57; Wed, 02 Jun 2021 04:54:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DWYMsfZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229790AbhFBJvL (ORCPT + 99 others); Wed, 2 Jun 2021 05:51:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:52962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229878AbhFBJvK (ORCPT ); Wed, 2 Jun 2021 05:51:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6B90E6101B; Wed, 2 Jun 2021 09:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622627367; bh=CugNKS2a3ZZprq8U1OraauTxEfAA1k4urBEESTDF1Ok=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DWYMsfZJrKTYhD/qmo8nNe/Y9jikdpFvBwhFF9SM0SEeENrtErG7494QRXakockZJ ppZGL/kBXn4do/UVvE2JagUUVGhFa5USn0qtXd4bLfkmwRks/e0NGWmnlF7z8fzH8d LQ1GFAcP19puxWDsJGG6Y7m+2eTdIc3ClW30eBByFUkflUaXqglQXEhp+Dyfy5GOx0 kWwh+bZM+o0Dxjn0jdB+NXYH8ZbCY823XIzFG4fsVnd1ItHxiMHRFH5HZ6L8/wAxUw oFiBxOOLjWYUvtniTkVdOTgDX+gw5QN/zsbZYmfAv4V+luY9aVPPgbK8jpkT5XrPaS ESRK5cCoBXNZg== Date: Wed, 2 Jun 2021 10:49:22 +0100 From: Will Deacon To: "liuqi (BA)" Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Linuxarm Subject: Re: [PATCH v2 1/9] perf: Add EVENT_ATTR_ID to simplify event attributes Message-ID: <20210602094922.GA30503@willie-the-truck> References: <1621417919-6632-1-git-send-email-liuqi115@huawei.com> <1621417919-6632-2-git-send-email-liuqi115@huawei.com> <20210601131020.GD28025@willie-the-truck> <30abdbec-3174-1f8a-47d4-63a4de3b1e47@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <30abdbec-3174-1f8a-47d4-63a4de3b1e47@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 02, 2021 at 04:45:23PM +0800, liuqi (BA) wrote: > > Hi Will, > > Thanks for reviewing this patch. > > On 2021/6/1 21:10, Will Deacon wrote: > > On Wed, May 19, 2021 at 05:51:51PM +0800, Qi Liu wrote: > > > Similar EVENT_ATTR macros are defined in many PMU drivers, > > > like HiSilicon PMU driver, Arm PMU driver, Arm SMMU PMU > > > driver. So Add a generic macro to simplify code. > > > > > > Cc: Peter Zijlstra > > > Cc: Ingo Molnar > > > Cc: Arnaldo Carvalho de Melo > > > Cc: Mark Rutland > > > Cc: Alexander Shishkin > > > Signed-off-by: Qi Liu > > > --- > > > include/linux/perf_event.h | 6 ++++++ > > > kernel/events/core.c | 2 ++ > > > 2 files changed, 8 insertions(+) > > > > > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > > > index f5a6a2f..d0aa74e 100644 > > > --- a/include/linux/perf_event.h > > > +++ b/include/linux/perf_event.h > > > @@ -1576,6 +1576,12 @@ static struct perf_pmu_events_attr _var = { \ > > > .event_str = _str, \ > > > }; > > > +#define PMU_EVENT_ATTR_ID(_name, _id) \ > > > + (&((struct perf_pmu_events_attr[]) { \ > > > + { .attr = __ATTR(_name, 0444, perf_event_sysfs_show, NULL), \ > > > + .id = _id, } \ > > > + })[0].attr.attr) > > > + > > > #define PMU_FORMAT_ATTR(_name, _format) \ > > > static ssize_t \ > > > _name##_show(struct device *dev, \ > > > diff --git a/kernel/events/core.c b/kernel/events/core.c > > > index 0ac818b..330d9cc 100644 > > > --- a/kernel/events/core.c > > > +++ b/kernel/events/core.c > > > @@ -13295,6 +13295,8 @@ ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr, > > > if (pmu_attr->event_str) > > > return sprintf(page, "%s\n", pmu_attr->event_str); > > > + else > > > + return sprintf(page, "config=%#llx\n", pmu_attr->id); > > > > I think it's a really bad idea to hardcode this here. For example, I think > > this patch series breaks user ABI for the SMMU PMU which used to print: > > > > "event=0x%02llx\n" > > > > and by the looks of it many of the other conversions are unsound too. > > > Got it, so I'll use pmu_attr->event_str here, for example, > SMMU_EVENT_ATTR(cycles, "event=0x00") You could, but honestly I don't really see this being any better than the current code. The advantage of using "event=0x%02llx\n" is that things are consistent by construction and therefore userspace can parse the information easily. We lose that if we just hardcode the string and it's error-prone to extend. Will