Re: Follow-up on Linux-kernel code accessibility

From: Dr. David Alan Gilbert
Date: Sun Dec 28 2025 - 07:54:44 EST


* Paul E. McKenney (paulmck@xxxxxxxxxx) wrote:

<snip>

> > > >
> > > > j = (j + 2) / 3;
> > >
> > > "Divide by three rounding up."
> >
> > That's not *that* obvious, but ok, but then why 3?
> >
> > Then later there is:
> > WRITE_ONCE(rcu_state.jiffies_kick_kthreads,
> > jiffies + (j ? 3 * j : 2));
> >
> > Which I assume is related - but then why the 2?
>
> Would the two of you (Julia and Dave) like to join in with Steve and
> myself walking through this function and its caller?

Not sure what you mean join in; not really set up for a call etc at the
moment, but happy to continue a mail chain.

But, if we're talking about the understandability of these few lines,
it looks like this could be something like:


// We have 3 ..... for the case when ...
const unsigned long something = 3;
....
j = DIV_ROUND_UP(j, something);

which would seem to make it more readable with very little effort.

(Hmm, since j is unsigned long why do we have a test of:
if (j <= 0)
j = 1
)

Dave

> > Curiosly my local tame Qwen3 LLM explained the rounding up:
> >
> > > I see some code doing 'j = (j + 2) / 3' - what's it trying to do?
> > The expression `j = (j + 2) / 3` is a clever way to **round up an
> > integer division by 3** — that is, it computes the ceiling of `j / 3`
> > for non-negative integers.
>
> Good to see!
>
> Thanx, Paul
>
> > Dave
> >
> > >
> > > Thanx, Paul
> > >
> > > > > > julia
> > > > > >
> > > > > >
> > > > > >
> > > > > > >
> > > > > > > Thanx, Paul
> > > > > > >
> > > > > > > [1] https://docs.google.com/document/d/1GCdQC8SDbb54W1shjEXqGZ0Rq8a6kIeYutdSIajfpLA/edit?pli=1&tab=t.0#heading=h.ytgz5i5df43s
> > > > > > >
> > > > > > > [2] https://www.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html
> > > > > > >
> > > > >
> > >
> > --
> > -----Open up your eyes, open up your mind, open up your code -------
> > / Dr. David Alan Gilbert | Running GNU/Linux | Happy \
> > \ dave @ treblig.org | | In Hex /
> > \ _________________________|_____ http://www.treblig.org |_______/
--
-----Open up your eyes, open up your mind, open up your code -------
/ Dr. David Alan Gilbert | Running GNU/Linux | Happy \
\ dave @ treblig.org | | In Hex /
\ _________________________|_____ http://www.treblig.org |_______/