lkml.org 
[lkml]   [2015]   [Apr]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH RFC] allow constant folding in msecs_to_jiffies where possible for gcc
From
Date
On Thu, 2015-04-02 at 08:37 +0200, Nicholas Mc Guire wrote:
> A number of cleanup patches where switching var * HZ / 1000
> constructs to msecs_to_jiffies(var) to ensure that all corener
> cases are handled properly. The downside of this though is that
> it now uses a function call and also was not performing
> constant folding where it was originally possible.
>
> msecs_to_jiffies() will calculate jiffies even if constants are
> passed in that could be handled by constant folding at compile time
> using __builtin_constant_p() gcc can optimize the constant case
> again.

OK, but how could this actually work?

This code isn't visible in a module at compile time, so how
could the compiler actually optimize the function call away?

Look at the disassembly for any object that uses
msecs_to_jiffies(<constant>).

For instance: drivers/bluetooth/hci_vhci.o

schedule_delayed_work(&data->open_timeout, msecs_to_jiffies(1000));
60d: bf e8 03 00 00 mov $0x3e8,%edi
612: e8 00 00 00 00 callq 617 <vhci_open+0xc7>
613: R_X86_64_PC32 msecs_to_jiffies-0x4

You need to make this code either a macro or static inline
in jiffies.h, and for that the kernel/timeconst.h file needs
to be available.





\
 
 \ /
  Last update: 2015-04-02 15:21    [W:0.040 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site