Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Jan 2012 04:53:30 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, davidxu@FreeBSD.org, John Baldwin <jhb@FreeBSD.org>
Subject:   Re: svn commit: r230201 - head/lib/libc/gen
Message-ID:  <20120120041332.V1706@besplex.bde.org>
In-Reply-To: <20120120030456.O1411@besplex.bde.org>
References:  <201201160615.q0G6FE9r019542@svn.freebsd.org> <4F178CDC.3030807@gmail.com> <4F17B0DE.3060008@gmail.com> <201201191023.28426.jhb@freebsd.org> <20120120030456.O1411@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120120041332.V1706>