svn commit: r230201 - head/lib/libc/gen
brde at optusnet.com.au
Thu Jan 19 17:53:34 UTC 2012
On Fri, 20 Jan 2012, Bruce Evans wrote:
> % + v = *p; \
> % + __asm __volatile("lfence" ::: "memory"); \
> Style bug (missing spaces around binary operator `:') which becomes
> a syntax error for C++. Other places in this file use ` : : : '.
> lfence() should be in cpufunc.h if it can be done separately
> like this. However, I think it can't be done separately --
> it needs to be done in the same asm as the load/store, since
> separate C statements may be reordered. This is the same
> problem that forces us to write __asm volatile("sti; hlt");
> instead of sti(); hlt(); in too many places for idling in
> machdep.c. BTW, sti() and hlt() are bogusly not in cpufunc.h
> - I misnamed sti() as disable_intr() since disable_intr() was
> supposed to be MI and I didn't understand that any MI
> interface should not be direct in cpufunc.h.
> - someone misnamed hlt() as halt().
BTW2, there are 1 or 2 direct uses of halt() per arch, and all seem
to be wrong:
- cpu_halt() uses halt() for amd64, i386 and pc98. It neither enables
or disables interrupts. When it is called from ddb, enabling interrupts
would be a bug. Otherwise, it might want to ensure that interrupts
are enabled (to allow i/o to complete), but it is safer to ensure that
they is disabled (the caller, which is normally shutdown_halt(), should
- on arches that support apm (i386 and maybe pc98), apm_cpu_idle() uses
halt(). It neither disables nor enables interrupts. Apparently they
are always enabled already. But that seems to give races. But this
seems to have no effect, since apm_cpu_idle() seems to be never used.
It seems to have been last used in FreeBSD-2, where it is called from
swtch.s. All references to apm were removed from swtch.s in 1997. The
call was replaced by a call through the function pointer _hlt_vector
(aout spelling). This always called a default which just executed the
hlt instruction. _hlt_vector was not connected to apm. This later
turned into cpu_idle() and the function pointer cpu_idle_hook that we
have today. The hook was apparently never connected to apm. It is even
misdescribed in its comment as being the ACPI idle hook. Perhaps ACPI
is the only thing that uses it, but its declaration shouldn't say that.
More information about the svn-src-all