[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20201106015828.GA13572@leoy-ThinkPad-X240s>
Date: Fri, 6 Nov 2020 09:58:28 +0800
From: Leo Yan <leo.yan@...aro.org>
To: André Przywara <andre.przywara@....com>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...hat.com>,
Namhyung Kim <namhyung@...nel.org>,
James Clark <james.clark@....com>,
Dave Martin <Dave.Martin@....com>, Al Grant <Al.Grant@....com>,
Wei Li <liwei391@...wei.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6 06/21] perf arm-spe: Refactor printing string to buffer
Hi Andre, Dave,
On Mon, Nov 02, 2020 at 03:50:01PM +0000, André Przywara wrote:
[...]
> > int arm_spe_pkt_desc(const struct arm_spe_pkt *packet, char *buf,
> > size_t buf_len)
> > {
> > - int ret, ns, el, idx = packet->index;
> > + int ns, el, idx = packet->index;
> > unsigned long long payload = packet->payload;
> > const char *name = arm_spe_pkt_name(packet->type);
> > + size_t blen = buf_len;
> > + int err = 0;
> >
> > switch (packet->type) {
> > case ARM_SPE_BAD:
> > case ARM_SPE_PAD:
> > case ARM_SPE_END:
> > - return snprintf(buf, buf_len, "%s", name);
> > - case ARM_SPE_EVENTS: {
> > - size_t blen = buf_len;
> > -
> > - ret = 0;
> > - ret = snprintf(buf, buf_len, "EV");
> > - buf += ret;
> > - blen -= ret;
> > - if (payload & 0x1) {
> > - ret = snprintf(buf, buf_len, " EXCEPTION-GEN");
> > - buf += ret;
> > - blen -= ret;
> > - }
> > - if (payload & 0x2) {
> > - ret = snprintf(buf, buf_len, " RETIRED");
> > - buf += ret;
> > - blen -= ret;
> > - }
> > - if (payload & 0x4) {
> > - ret = snprintf(buf, buf_len, " L1D-ACCESS");
> > - buf += ret;
> > - blen -= ret;
> > - }
> > - if (payload & 0x8) {
> > - ret = snprintf(buf, buf_len, " L1D-REFILL");
> > - buf += ret;
> > - blen -= ret;
> > - }
> > - if (payload & 0x10) {
> > - ret = snprintf(buf, buf_len, " TLB-ACCESS");
> > - buf += ret;
> > - blen -= ret;
> > - }
> > - if (payload & 0x20) {
> > - ret = snprintf(buf, buf_len, " TLB-REFILL");
> > - buf += ret;
> > - blen -= ret;
> > - }
> > - if (payload & 0x40) {
> > - ret = snprintf(buf, buf_len, " NOT-TAKEN");
> > - buf += ret;
> > - blen -= ret;
> > - }
> > - if (payload & 0x80) {
> > - ret = snprintf(buf, buf_len, " MISPRED");
> > - buf += ret;
> > - blen -= ret;
> > - }
> > + return arm_spe_pkt_snprintf(&err, &buf, &blen, "%s", name);
>
> Nothing critical, but in case you need to respin this series for
> whatever reason, you might want to use NULL for the first argument,
> since you return here and there is little point in setting err. Same for
> other cases where you return directly from an arm_spe_pkt_snprintf() call.
> But it doesn't hurt, so you could leave it as well, and it's more robust
> in case someone extends the code later.
Just remind, in the new patch set v7, I don't change to use NULL for
the first argument and still pass '&err', the main reason is to
consolidate with return value, which is heavily dependent on the 'err'
parameter of arm_spe_pkt_snprintf(); the brief form is as follow:
switch (type) {
...
case ARM_SPE_END:
arm_spe_pkt_snprintf(&err, &buf, &blen, "%s", name);
break;
...
default:
break;
}
handle the 'err';
return err;
Please see the new introduced patch [1] so it can give more idea for
the changes.
Thanks,
Leo
[1] https://lore.kernel.org/patchwork/patch/1333881/
Powered by blists - more mailing lists