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

From: Steven Rostedt
Date: Wed Feb 14 2024 - 18:52:45 EST


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 ;-)

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.

-- Steve