Skip to contentSkip to conversation

domain.c idle_loop declaration (take 2)

PATCH In review Mike D. Day 3 participants 4 messages Dec 22, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 domain.c idle_loop declaration (take 2)

The recent change to the declaration of idle_loop in domain.c fixed a compilation problem on gcc 3.4.2. Enclosed patch is another suggestion on how to solve that problem.

Some further analysis, with much help from Jimmy Xenidis of IBM research, shows that the problem was not the declaration of the function as static void, but that the compiler is optimizing the function out of the assembled code.

Compile domain.c to assembly:

[mdday@mdday xen]$ gcc -nostdinc -fno-builtin -fno-common -fno-strict- aliasing -iwithprefix include -Wall -Werror -pipe - I/home/mdday/src/edited/xen-2.0-testing.bk/xen/include -Wno-pointer- arith -Wredundant-decls -O3 -Wunused-function -Wunused -fomit-frame- pointer -msoft-float -m32 -march=i686 -DNDEBUG -S arch/x86/domain.c -
o /tmp/d.S

grep for the label idle_loop in the assembled output:

[mdday@mdday xen]$ grep idle_loop /tmp/d.S .globl
startup_cpu_idle_loop .type startup_cpu_idle_loop, @function
startup_cpu_idle_loop: .size startup_cpu_idle_loop, .-
startup_cpu_idle_loop
movl %eax,%esp; jmp idle_loop

Compile domain.c to assembly without optimization:

[mdday@mdday xen]$ gcc -nostdinc -fno-builtin -fno-common -fno-strict- aliasing -iwithprefix include -Wall -Werror -pipe - I/home/mdday/src/edited/xen-2.0-testing.bk/xen/include -Wno-pointer- arith -Wredundant-decls -O0 -Wunused-function -Wunused -fomit-frame- pointer -msoft-float -m32 -march=i686 -DNDEBUG -S arch/x86/domain.c -
o /tmp/d.S

grep for the label idle_loop in the assembled output:

[mdday@mdday xen]$ grep idle_loop /tmp/d.S .type idle_loop,
@function idle_loop: .size idle_loop, .-idle_loop .globl
startup_cpu_idle_loop
.type startup_cpu_idle_loop, @function
startup_cpu_idle_loop:
call idle_loop
.size startup_cpu_idle_loop, .-startup_cpu_idle_loop
movl %eax,%esp; jmp idle_loop

The compiler is probably correct in optimizing out the function. It is only called through inline assembly, and it is static void. Further experiments with -02 -01 and -0s also cause idle_loop to be optimized out.

It is a good idea to keep idle_loop declared static void. The patch simply includes a declaration using __attribute__ ((used)) that prevents the compiler from optimizing out the function.

Signature · 7 lines
Mike D. Day
Architect, Open Virtualization
IBM Linux Technology Center
3039 Cornwallis Road
Research Triangle Park, NC  27709
Phone: (919) 543-4283
[email protected]
xen-2.0-testing/xen/arch/x86/domain.c +3 -1
@@ -57,7 +57,9 @@
         __sti();
 }
 
-void idle_loop(void)
+static void idle_loop(void) __attribute__ ((used));
+
+static void idle_loop(void)
 {
     int cpu = smp_processor_id();
     for ( ; ; )
#1 lore raw
Quoted 3 lines

The recent change to the declaration of idle_loop in domain.c fixed a compilation problem on gcc 3.4.2. Enclosed patch is another suggestion on how to solve that problem.

Your patch is better. I've applied a variant of it to the testing and unstable trees.

Thanks,
Keir

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/

#2 lore raw
In reply to Mike D. Day
Quoted 6 lines

Some further analysis, with much help from Jimmy Xenidis of IBM research, shows that the problem was not the declaration of the function as static void, but that the compiler is optimizing the function out of the assembled code.

The compiler is probably correct in optimizing out the function. It is only called through inline assembly, and it is static void. Further experiments with -02 -01 and -0s also cause idle_loop to be optimized out.

interesting analysis

Quoted 3 lines

It is a good idea to keep idle_loop declared static void. The patch simply includes a declaration using __attribute__ ((used)) that prevents the compiler from optimizing out the function.

ah, using "__attribute__ used" was able to find it on google. if anyone cares the url is

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#Function-Attributes

Still I wonder how it will interact with plan9 since I think plan9 uses own compile some part of the code.. not totally sure though.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/

#3 lore raw
Quoted 7 lines

ah, using "__attribute__ used" was able to find it on google. if anyone cares the url is

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#Function-Attributes

Still I wonder how it will interact with plan9 since I think plan9 uses own compile some part of the code.. not totally sure though.

We really have no interest in supporting compilers other than GCC for compiling Xen itself. However, if people want to submit patches for other compilers (basically additions to include/xen/compiler.h) then that's fine.

-- Keir

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/