Re: [PATCH 2/3] time: allow gcc to fold constants when using msecs_to_jiffies

From: Nicholas Mc Guire
Date: Sun Apr 12 2015 - 04:37:00 EST


> Your inline version has not worked with any of
> x86-64 gcc 4.4, 4.6, 4.7, or 4.9
>
> I suggest you add some lines to
> lib/test_module.c/test_module_init like:
>
> unsigned int m;
>
> for (m = 10; m < 200; m += 10)
> pr_info("msecs_to_jiffies(%u) is %lu\n",
> m, msecs_to_jiffies(m));
>
> pr_info("msecs_to_jiffies(%u) is %lu\n",
> 10, msecs_to_jiffies(10));
> pr_info("msecs_to_jiffies(%u) is %lu\n",
> 100, msecs_to_jiffies(100));
> pr_info("msecs_to_jiffies(%u) is %lu\n",
> 1000, msecs_to_jiffies(1000));
>
> Then it's pretty easy to look at the assembly/.lst file
>
> Your inline function doesn't allow gcc to precompute
> the msecs_to_jiffies value. The macro one does for all
> those gcc versions.
>
> Try it and look at the generated .lst files with and
> without the patch I sent.
>
I have checked it with the testcase you proposed - and I quite sure
it is working, find the .s file snippets from the test_module.c modified
as you suggested below. HZ is set to 300 so that it is easy to differenciate
the parameter to msecs_to_jiffies and the printed const.

there is no call and no calculation for the constant cases - just load as
it should be.

with the patch applied:
test_module_init:
pushq %rbp #
movq %rsp, %rbp #,
pushq %rbx #
movl $10, %ebx #, m
pushq %rcx #
.L4:
movl %ebx, %edi # m,
call __msecs_to_jiffies #
movl %ebx, %esi # m,
movq %rax, %rdx # D.14515,
movq $.LC1, %rdi #,
xorl %eax, %eax #
addl $10, %ebx #, m
call printk #
cmpl $200, %ebx #, m
jne .L4 #, <---end of for loop
movl $3, %edx #, <---msecs_to_jiffies(10)
movl $10, %esi #,
movq $.LC1, %rdi #,
xorl %eax, %eax #
call printk #
movl $30, %edx #, <---msecs_to_jiffies(100)
movl $100, %esi #,
movq $.LC1, %rdi #,
xorl %eax, %eax #
call printk #
movl $300, %edx #, <---msecs_to_jiffies(1000)
movl $1000, %esi #,
movq $.LC1, %rdi #,
xorl %eax, %eax #
call printk #

without the patch applied:

pushq %rbp #
movq %rsp, %rbp #,
pushq %rbx #
movl $10, %ebx #, m
pushq %rcx #
.L2:
movl %ebx, %edi # m,
call msecs_to_jiffies #
movl %ebx, %esi # m,
movq %rax, %rdx # D.14503,
movq $.LC0, %rdi #,
xorl %eax, %eax #
addl $10, %ebx #, m
call printk #
cmpl $200, %ebx #, m
jne .L2 #,
movl $10, %edi #,
call msecs_to_jiffies #
movl $10, %esi #,
movq %rax, %rdx # D.14504,
movq $.LC0, %rdi #,
xorl %eax, %eax #
call printk #
movl $100, %edi #,
call msecs_to_jiffies #
movl $100, %esi #,
movq %rax, %rdx # D.14505,
movq $.LC0, %rdi #,
xorl %eax, %eax #
call printk #
movl $1000, %edi #,

could you check the .s file for you test module ?
I'm a bit lost on why you are not seeing this - also
checked with cross-build (multi_v7_defconfig) and it
looks like thats working as well.

thx!
hofrat
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/