All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: "liuqi (BA)" <liuqi115@huawei.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Linuxarm <linuxarm@huawei.com>
Subject: Re: [PATCH v2 1/9] perf: Add EVENT_ATTR_ID to simplify event attributes
Date: Wed, 2 Jun 2021 10:49:22 +0100	[thread overview]
Message-ID: <20210602094922.GA30503@willie-the-truck> (raw)
In-Reply-To: <30abdbec-3174-1f8a-47d4-63a4de3b1e47@huawei.com>

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 <peterz@infradead.org>
> > > Cc: Ingo Molnar <mingo@redhat.com>
> > > Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> > > Cc: Mark Rutland <mark.rutland@arm.com>
> > > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > > Signed-off-by: Qi Liu <liuqi115@huawei.com>
> > > ---
> > >   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

WARNING: multiple messages have this Message-ID (diff)
From: Will Deacon <will@kernel.org>
To: "liuqi (BA)" <liuqi115@huawei.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Linuxarm <linuxarm@huawei.com>
Subject: Re: [PATCH v2 1/9] perf: Add EVENT_ATTR_ID to simplify event attributes
Date: Wed, 2 Jun 2021 10:49:22 +0100	[thread overview]
Message-ID: <20210602094922.GA30503@willie-the-truck> (raw)
In-Reply-To: <30abdbec-3174-1f8a-47d4-63a4de3b1e47@huawei.com>

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 <peterz@infradead.org>
> > > Cc: Ingo Molnar <mingo@redhat.com>
> > > Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> > > Cc: Mark Rutland <mark.rutland@arm.com>
> > > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > > Signed-off-by: Qi Liu <liuqi115@huawei.com>
> > > ---
> > >   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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-06-02  9:49 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-19  9:51 [PATCH v2 0/9] drivers/perf: Use general macro to simplify event attributes Qi Liu
2021-05-19  9:51 ` Qi Liu
2021-05-19  9:51 ` [PATCH v2 1/9] perf: Add EVENT_ATTR_ID " Qi Liu
2021-05-19  9:51   ` Qi Liu
2021-06-01 13:10   ` Will Deacon
2021-06-01 13:10     ` Will Deacon
2021-06-02  8:45     ` liuqi (BA)
2021-06-02  8:45       ` liuqi (BA)
2021-06-02  9:49       ` Will Deacon [this message]
2021-06-02  9:49         ` Will Deacon
2021-06-02 10:49         ` liuqi (BA)
2021-06-02 10:49           ` liuqi (BA)
2021-05-19  9:51 ` [PATCH v2 2/9] drivers/perf: hisi: Remove redundant macro and functions Qi Liu
2021-05-19  9:51   ` Qi Liu
2021-05-19  9:51 ` [PATCH v2 3/9] drivers/perf: Remove redundant macro and functions in SMMU PMU driver Qi Liu
2021-05-19  9:51   ` Qi Liu
2021-05-19  9:51 ` [PATCH v2 4/9] drivers/perf: Remove redundant macro and functions in qcom_l2_pmu.c Qi Liu
2021-05-19  9:51   ` Qi Liu
2021-05-19  9:51 ` [PATCH v2 5/9] drivers/perf: Remove redundant macro and functions in qcom_l3_pmu.c Qi Liu
2021-05-19  9:51   ` Qi Liu
2021-05-19  9:51 ` [PATCH v2 6/9] drivers/perf: Remove redundant macro and functions in xgene_pmu.c Qi Liu
2021-05-19  9:51   ` Qi Liu
2021-05-19  9:51 ` [PATCH v2 7/9] drivers/perf: Remove redundant macro and functions in fsl_imx8_ddr_perf.c Qi Liu
2021-05-19  9:51   ` Qi Liu
2021-05-19 14:36   ` Frank Li
2021-05-19 14:36     ` Frank Li
2021-05-19  9:51 ` [PATCH v2 8/9] drivers/perf: Remove redundant macro and functions in arm_dsu_pmu.c Qi Liu
2021-05-19  9:51   ` Qi Liu
2021-05-19  9:51 ` [PATCH v2 9/9] arm64: perf: Remove redundant macro and functions in perf_event.c Qi Liu
2021-05-19  9:51   ` Qi Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210602094922.GA30503@willie-the-truck \
    --to=will@kernel.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=liuqi115@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.