Re: [PATCH] sched/fair: Rate limit calls to update_blocked_averages() for NOHZ

From: Qais Yousef
Date: Mon May 17 2021 - 12:16:59 EST


On 05/13/21 11:45, Tim Chen wrote:
>
>
> On 5/12/21 6:59 AM, Qais Yousef wrote:
> > On 05/11/21 10:25, Tim Chen wrote:
> >>> update_next_balance() is only used in newidle_balance() so we could
> >>> modify it to have:
> >>>
> >>> next = max(jiffies+1, next = sd->last_balance + interval)
> >>
> >> Is the extra assignment "next = sd->last_balance + interval" needed?
> >> This seems more straight forward:
> >>
> >> next = max(jiffies+1, sd->last_balance + interval)
> >
> > I haven't been following the whole conversation closely, but it's always
> > interesting when manipulating time in non time_*() functions.
> >
> > Is this max() safe against wrapping?
>
> Looking at the definition, seems like max doesn't take care of wrapping.
> #define max(a, b) \
> ({ \
> typeof(a) __a = (a); \
> typeof(b) __b = (b); \
> MINMAX_ASSERT_COMPATIBLE(typeof(__a), typeof(__b)); \
> __a > __b ? __a : __b; \
> })
>
>
> Probably need to do
> next = time_after(jiffies+1, sd->last_balance + interval) ? jiffies+1 : sd->last_balance + interval;

Yep, that's what I thought it should look like. There's a small chance jiffies
would have changed between the 2 reads though. I can't see how this would cause
a problem, so we should be fine.

Would it be more useful (and readable) to have time_min()/time_max() wrappers?
This type of usage is rare but it'll help to have a common way to handle this
scenario.

Naming might get controversial though :-); time_earliest()/time_latest() could
be another option.

The wrapper is nice to have for me, so feel free to ignore the suggestion.

Thanks

--
Qais Yousef