panic_cpu should be volatile

John Baldwin jhb at freebsd.org
Fri Oct 8 19:08:45 UTC 2010


On Thursday, October 07, 2010 1:40:49 pm Andriy Gapon wrote:
> 
> 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.

Looks fine to me.

-- 
John Baldwin


More information about the freebsd-hackers mailing list