lkml.org 
[lkml]   [2020]   [Nov]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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/

\
 
 \ /
  Last update: 2020-11-06 02:59    [W:0.147 / U:3.576 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site