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
either:
- 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
  have waited).
- 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.

Bruce
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to