Zhiqiang,

On Tue, 25 Jun 2019, Zhiqiang Liu wrote:

> I have a doubt about _msecs_to_jiffies funcs, especially when input m is
> equal to 0.
>
> For different HZ setttings, different _msecs_to_jiffies funcs will be
> chosen for msecs_to_jiffies func. However, the performance of different
> _msecs_to_jiffies is inconsistent with input m is equal to 0.
>
> If HZ satisfies the condition: HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC %
> HZ), the return value of _msecs_to_jiffies func with m=0 is different
> with different HZ setting.

> ------------------------------------
> | HZ |        MSEC_PER_SEC / HZ | return |
> ------------------------------------
> |1000|                1         |   0    |
> |500 |                2         |   1    |
> |200 |                5         |   1    |
> |100 |                10        |   1    |
> ------------------------------------
> 
> Why only the return value of HZ=1000 is equal to 0 with m=0 ?

I don't know how you tested that, but obviously all four HZ values use
this variant:

>     #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
>     static inline unsigned long _msecs_to_jiffies(const unsigned int m)
>     {
>             return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
>     }

and for all four HZ values the result is 0. Why?

For m = 0 the calculation reduces to:

      ((MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ)

i.e.

        (x - 1) / x     where x = [1, 2, 5, 10]

which is guaranteed to be 0 for integer math. If not, you have a compiler
problem.

Thanks,

        tglx

Reply via email to