panic_cpu should be volatile

From: Andriy Gapon <avg_at_freebsd.org>
Date: Thu, 07 Oct 2010 20:40:49 +0300
panic_cpu variable in kern_shutdown.c should be volatile otherwise it's cached in
a register in the innermost while-loop in this code (observed on amd64 with base
gcc and -O2):
if (panic_cpu != PCPU_GET(cpuid))
        while (atomic_cmpset_int(&panic_cpu, NOCPU,
            PCPU_GET(cpuid)) == 0)
                while (panic_cpu != NOCPU)
                        ; /* nothing */

The patch is here:
http://people.freebsd.org/~avg/panic_cpu.diff

I also took a liberty to move the variable into the scope of panic() functions as
it doesn't seem to be useful outside of it.  But this is not necessary, of course.

Big thanks to mdf_at_ for the hint and to kib_at_ and kan_at_ for memory model expertise.

P.S.
The assembly:
        .loc 1 544 0
        movl    panic_cpu(%rip), %eax
.LVL134:
        .p2align 4,,7
.L210:
        cmpl    $255, %eax
        jne     .L210
        jmp     .L225
-- 
Andriy Gapon
Received on Thu Oct 07 2010 - 15:40:52 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:08 UTC