Re: [PATCH v2] perf trace: avoid garbage when not printing a trace event's arguments

From: Benjamin Peterson
Date: Fri Nov 01 2024 - 17:42:09 EST


On Fri, Nov 1, 2024 at 2:30 PM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
>
> On Fri, Nov 01, 2024 at 02:00:46PM -0700, Howard Chu wrote:
> > Hello Benjamin,

Thanks for testing & reviewing.

> >
> > Before your patch:
> >
> > perf $ ./perf trace -e net:netif_rx_exit
> > 0.000 irq/79-brcmf_p/1694977 net:netif_rx_exit(6n<)
> > 28.153 irq/79-brcmf_p/1694977 net:netif_rx_exit(6n<)
> > 36.429 irq/79-brcmf_p/1694977 net:netif_rx_exit(6n<)
> > 36.461 irq/79-brcmf_p/1694977 net:netif_rx_exit(6n<)
> >
> > After:
> >
> > perf $ ./perf trace -e net:netif_rx_exit
> > 0.000 irq/79-brcmf_p/1694977 net:netif_rx_exit()
> > 7.352 irq/79-brcmf_p/1694977 net:netif_rx_exit()
> > 30.232 irq/79-brcmf_p/1694977 net:netif_rx_exit()
> > 37.529 irq/79-brcmf_p/1694977 net:netif_rx_exit()
> >
> > It works beautifully, but I'm thinking can we simplify it by just doing:
> >
> > + char bf[2048] = { 0 };
> > size_t size = sizeof(bf);
> >

I believe this is slightly suboptimal because it obliges the compiler
to zero out 2kib of the stack every time the function is called.

> >
> > Tested-by: Howard Chu <howardchu95@xxxxxxxxx>
>
> I haven't tested it yet, just in my mind :-)
>
> The patch looks ok and seems to fix a real problem, my only concern, a
> pet peeve, was that it, in addition to fixing a real problem, did an
> unrelated change, the "Remove the return value...", that part looks like
> a distraction, something that shouldn't be there.

In my mind, it was related because both the bug and the odd return
value arise from incorrect counting of the number of written bytes.
Obviously, the fix is what I care about, so feel free to strip out the
return value change on import, or I can resend.