Re: [PATCH v7 19/36] function_graph: Implement fgraph_reserve_data() and fgraph_retrieve_data()

From: Google
Date: Fri Feb 16 2024 - 02:40:22 EST


On Wed, 14 Feb 2024 18:54:07 -0500
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> On Thu, 15 Feb 2024 08:45:52 +0900
> Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx> wrote:
>
> > > Hmm, the above is a fast path. I wonder if we should add a patch to make that into:
> > >
> > > if (unlikely(size_bytes & (sizeof(long) - 1)))
> > > data_size = DIV_ROUND_UP(size_bytes, sizeof(long));
> > > else
> > > data_size = size_bytes >> (sizeof(long) == 4 ? 2 : 3);
> > >
> > > to keep from doing the division.
> >
> > OK, I thought DIV_ROUND_UP was not much cost. Since sizeof(long) is
> > fixed 4 or 8, so
> >
> > data_size = (size_bytes + sizeof(long) - 1) >> BITS_PER_LONG;
> >
> > will this work?
>
> No, because BITS_PER_LONG is 32 or 64 ;-)

Oops indeed.

>
> But this should;
>
> data_size = (size_bytes + sizeof(long) - 1) >> (sizeof(long) == 4 ? 2 : 3);
>
> As sizeof(long) is a constant, that conditional expression will be hard
> coded into either 2 or 3 by the compiler.

Yeah. OK, let me update it.

Thank you,

>
> -- Steve


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>