Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Mar 2000 23:30:00 -0600 (CST)
From:      Jonathan Lemon <jlemon@flugsvamp.com>
To:        bright@wintelcom.net, current@freebsd.org
Subject:   Re: Using packed structs to gain cheap SMP primatives
Message-ID:  <200003300530.XAA40214@prism.flugsvamp.com>
In-Reply-To: <local.mail.freebsd-current/20000329214422.X21029@fw.wintelcom.net>
References:  <local.mail.freebsd-current/20000329192526.U21029@fw.wintelcom.net> <local.mail.freebsd-current/NBBBJNDFEKPEHPFCLNLHMEIJGHAA.pulsifer@mediaone.net>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <local.mail.freebsd-current/20000329214422.X21029@fw.wintelcom.net> you write:
>* Allen Pulsifer <pulsifer@mediaone.net> [000329 21:05] wrote:
>> Here's another alternative for reading structures like time
>> that always change monotonically: read the values in
>> "MSB" to "LSB" order, then go back and check in reverse
>> order that nothing has changed.  For example, to read a
>> structure containing hours, minutes, seconds:
>> 
>> for (;;)
>> {	h = timep->hour;
>> 	m = timep->minute;
>> 	s = timep->second;
>> 	if (m != timep->minute) continue;
>> 	if (h != timep->hour) continue;
>> 	break;
>> }
>> 
>> The assumption is that from the instant you first read
>> timep->hour until the instant you double check its value,
>> it could not have wrapped all the way back around to its
>> previous value.  Or to put it another way, if it has
>> succeeding in wrapping all the way around, having a
>> correct snapshot of the structure is the least of your
>> problems and the value you use is arbitary.
>> 
>> This same method can be used to read the MSW and LSW of
>> any counter-like structure that is updated by an interrupt.
>> 
>> Note this method will not work for a structure that can
>> both increment and decrement--it has to be only one or
>> the other.
>
>I'm aware of this, the problem is that tz may move in either
>direction.  Hence my question about using sizes that are machine
>atomic for read/write.  :)
>
>I've got several books on various systems here and I don't remeber
>any of them mentioning a problem with 32bit aligned updates being
>atomic.

Each architecture will define what is atomic or not.  Most modern
architectures will provide atomic access to their native word size,
provided it is aligned on a natural word boundary.

On the PPro and upwards, 64 bit reads/writes to quadword aligned
structures are atomic.  it's just too bad that there is no direct
64-bit read insn (excluding FP).
--
Jonathan


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




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