From: Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP>
Subject: Re: Oberon and Wirthian languages
Date: Tue, 22 Apr 2014 20:46:40 +0000 (UTC)
Date: 2014-04-22T20:46:40+00:00 [thread overview]
Message-ID: <lj6kfg$jhs$1@dont-email.me> (raw)
In-Reply-To: brntbeFnfgcU1@mid.individual.net
On 2014-04-22, Niklas Holsti <niklas.holsti@tidorum.invalid> wrote:
> On 14-04-22 15:25 , Simon Clubley wrote:
>>
>> In general memory mapped I/O you have to do a register read/modify bit
>> field/register write sequence in units of the register size.
>>
>> Consider a atomic record with 3 bit fields called A, B and C.
>>
>> Now consider a Ada record assignment statement which sets the values of
>> the 3 bit fields. The question is how is the assignment to the 3 bit
>> fields turned into code ?
>
> If the record variable Rec has the Atomic aspect, then by the Ada RM any
> assignment Rec := expr must write Rec exactly once, indivisibly, and
> this write should (per implementation advice) be implemented by a single
> store instruction. This applies whatever the right-hand-side expr is.
>
> Note, however, that if the right-hand-side expr includes some references
> to (i.e. reads of) Rec, then there is no guarantee that the read-write
> sequence as a whole is indivisible.
>
>> Is it something like this (which is how it looks in C with masks):
>
> Here one should separate between C 2011 on the one hand and earlier C
> standards on the other. (For C 2011 my reference is the "final" draft
> N1570, which is on the web.)
>
I was recently pointed to this document over in comp.arch.embedded and
it's on my list of things to read but I have not yet done that.
My knowledge of C comes from versions of C prior to C 2011.
> In C 2011, a "compound assignment is a read-modify-write operation with
> memory_order_seq_cst memory order semantics". That is, in C 2011 an
> update like "v &= mask", where v is an _Atomic variable, is an atomic
> *update* with respect to other C threads (but perhaps not with respect
> to other memory bus activity; I admit to an incomplete understanding
> here).
I admit I have not read the C 2011 standard yet, but I don't see how
protecting against other memory bus activity is possible when you have
interrupts active (unless you turn off interrupts during the update
sequence).
Declaring something as "_Atomic" doesn't change the fact it's still a
read/modify/write sequence which is generated for most processors.
> Note that this is rather different from the meaning of the Atomic
> aspect in Ada, which only makes each read indivisible, and each write
> indivisible, but does not guarantee indivisibility of some
> read-modify-write sequence.
>
And I don't see how the C 2011 version does either when the same variable
is referenced in both a interrupt handler and the main program.
> In earlier C standards such as the 1999 standard, the only concept of
> atomicity was the predefined type sig_atomic_t, which corresponds
> closely to the Ada Atomic aspect, that is, the whole variable can be
> read or written with one memory access.
>
>> ldr r2, [r3, #register_offset]
>> -- Load device register contents into r2
>> -- r3 contains device base address
>> orr r2, r2, #1 -- Set bit field A to 1
>> {Additional code here to modify bitfields B and C}
>> str r2, [r3, #register_offset]
>> -- Write all changes to device register at once
>
> Yes, this looks like an Ada assignment of the form
>
> Tmp := Rec;
> Rec := (A => 1, B => expr1, C => expr2, D => Tmp.D, E => Tmp.E, ...);
>
> where Rec has aspect Atomic and assuming that the compiler was able to
> optimize out the "no effect" expressions for the unchanged components D,
> E, .... Note that the following "simpler" assignment
>
> Rec := (A => 1, B => expr1, C => expr2, D => Rec.D, E => Rec.E, ...);
>
> cannot give the code above -- the two (or more) uses of Rec in the
> aggregate force the code to read (load) Rec two (or more) times, because
> an Atomic variable is also Volatile. (That is how I understand it, but
> I'm not entirely sure if each appearance of an object's name in the
> source code as a primary implies the evaluation of the object and
> therefore a "read" of the object.) This assumes a reasonable
> implementation of the Volatile aspect.
>
Ok, now that's interesting. I would not have assumed the compiler would
do the read multiple times in this specific case.
I would have assumed the Volatile attribute would be satisfied in this
specific case by doing the read _once_ at the start of the generated
code and only generating code to modify the A, B and C bitfields
before writing everything back in one step by using a single store
opcode.
>> or is the Ada compiler allowed to do this:
>>
>> ldr r2, [r3, #register_offset]
>> orr r2, r2, #1 -- Set bit field A to 1
>> str r2, [r3, #register_offset] -- Update bit field A only
>>
>> ldr r2, [r3, #register_offset]
>> {Code here to modify bitfield B}
>> str r2, [r3, #register_offset] -- Update bit field B only
>>
>> ldr r2, [r3, #register_offset]
>> {Code here to modify bitfield C}
>> str r2, [r3, #register_offset] -- Update bit field C only
>
> No, three stores to Rec can result only if the source code contains
> three assignments to Rec as a whole, or some assignments to components
> of Rec.
>
Good. That's what I thought/hoped, but I wasn't 100% sure after reading
the Ada 95 RM.
>> Ie: performs a atomic update of each bit field,
>
> In what sense do you call these bit-field updates "atomic"?
>
When the update is done using a single store to update all the changes
to the device register in one non-interruptible opcode.
It's also what I understand the Ada 95 RM to mean as well.
Thank you for having taken the time to write the detailed analysis above;
it was very helpful seeing another person's understanding of these issues.
Thanks,
Simon.
--
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
next prev parent reply other threads:[~2014-04-22 20:46 UTC|newest]
Thread overview: 144+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-11 2:39 Heartbleed Charles H. Sampson
2014-04-11 7:59 ` Heartbleed Maciej Sobczak
2014-04-11 10:50 ` Heartbleed Pascal J. Bourguignon
2014-04-12 1:46 ` Heartbleed Charles H. Sampson
2014-04-11 12:43 ` Heartbleed kalvin.news
2014-04-11 19:33 ` Heartbleed Simon Clubley
2014-04-12 4:58 ` Heartbleed Shark8
2014-04-12 7:15 ` Heartbleed Nasser M. Abbasi
2014-04-12 9:28 ` Heartbleed Georg Bauhaus
2014-04-12 9:33 ` Heartbleed Georg Bauhaus
2014-04-12 11:42 ` Heartbleed Pascal J. Bourguignon
2014-04-12 15:37 ` Heartbleed Nasser M. Abbasi
2014-04-12 18:56 ` Heartbleed Pascal J. Bourguignon
2014-04-12 20:29 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-12 20:34 ` Heartbleed Dmitry A. Kazakov
2014-04-12 20:47 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-12 20:53 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-15 10:02 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-15 12:35 ` Heartbleed Dmitry A. Kazakov
2014-04-12 21:57 ` Heartbleed Niklas Holsti
2014-04-13 13:08 ` Heartbleed Georg Bauhaus
2014-04-13 13:55 ` Heartbleed Pascal J. Bourguignon
2014-04-13 15:13 ` Heartbleed Dennis Lee Bieber
2014-04-13 15:36 ` Heartbleed Nasser M. Abbasi
2014-04-12 18:39 ` Heartbleed Simon Wright
2014-04-12 19:15 ` Heartbleed Pascal J. Bourguignon
2014-04-12 19:18 ` Heartbleed Pascal J. Bourguignon
2014-04-12 20:40 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-12 20:44 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-12 21:31 ` Heartbleed Niklas Holsti
2014-04-12 14:58 ` Heartbleed Dennis Lee Bieber
2014-04-12 18:28 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-12 18:22 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-12 18:38 ` Heartbleed Simon Clubley
2014-04-12 20:24 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-12 21:48 ` Heartbleed Simon Clubley
2014-04-17 6:15 ` Heartbleed Jacob Sparre Andersen
2014-04-17 15:55 ` Heartbleed Shark8
2014-04-17 21:01 ` Heartbleed Simon Clubley
2014-04-17 21:51 ` Heartbleed Shark8
2014-04-17 21:54 ` Heartbleed Alan Jump
2014-04-17 22:02 ` Heartbleed Adam Beneschan
2014-04-17 22:35 ` Heartbleed Simon Clubley
2014-04-17 22:55 ` Heartbleed Jeffrey Carter
2014-04-18 8:48 ` Heartbleed Simon Clubley
2014-04-18 18:02 ` Heartbleed Jeffrey Carter
2014-04-18 20:31 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-18 23:16 ` Heartbleed Pascal J. Bourguignon
2014-04-19 18:29 ` Heartbleed Simon Clubley
2014-04-21 22:50 ` Heartbleed Randy Brukardt
2014-04-18 1:38 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-18 14:59 ` Heartbleed Nasser M. Abbasi
2014-04-18 17:12 ` Heartbleed Alan Browne
2014-04-18 17:30 ` Heartbleed J-P. Rosen
2014-04-18 18:04 ` Heartbleed Jeffrey Carter
2014-04-18 18:34 ` Heartbleed Simon Clubley
2014-04-18 20:45 ` Heartbleed Jeffrey Carter
2014-04-18 21:35 ` Heartbleed Dennis Lee Bieber
2014-04-18 22:20 ` Heartbleed Jeffrey Carter
2014-04-18 22:41 ` Heartbleed Adam Beneschan
2014-04-19 15:53 ` Heartbleed Dennis Lee Bieber
2014-04-18 18:37 ` Heartbleed Alan Browne
2014-04-18 20:45 ` Heartbleed Jeffrey Carter
2014-04-18 21:06 ` Heartbleed Alan Browne
2014-04-18 22:20 ` Heartbleed Jeffrey Carter
2014-04-19 14:04 ` Heartbleed Alan Browne
2014-04-18 20:49 ` Heartbleed Shark8
2014-04-18 21:07 ` Heartbleed Alan Browne
2014-04-18 22:56 ` Heartbleed Nasser M. Abbasi
2014-04-19 4:27 ` Heartbleed tmoran
2014-04-18 21:17 ` Heartbleed Shark8
2014-04-19 18:59 ` Heartbleed Simon Clubley
2014-04-19 19:21 ` Heartbleed Shark8
2014-04-18 1:29 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-18 10:42 ` Heartbleed J-P. Rosen
2014-04-19 11:50 ` Oberon and Wirthian languages (was: Heartbleed) Ludovic Brenta
2014-04-19 12:46 ` Oberon and Wirthian languages Georg Bauhaus
2014-04-19 19:17 ` Simon Clubley
2014-04-19 19:25 ` Shark8
2014-04-19 16:35 ` Oberon and Wirthian languages (was: Heartbleed) Yannick Duchêne (Hibou57)
2014-04-19 19:32 ` Simon Clubley
2014-04-19 22:30 ` Dennis Lee Bieber
2014-04-19 22:35 ` Oberon and Wirthian languages Alan Browne
2014-04-19 16:53 ` Georg Bauhaus
2014-04-19 17:32 ` Simon Wright
2014-04-19 17:35 ` Jeffrey Carter
2014-04-19 18:06 ` Yannick Duchêne (Hibou57)
2014-04-19 18:53 ` Shark8
2014-04-19 20:08 ` Simon Clubley
2014-04-19 22:16 ` Simon Clubley
2014-04-21 13:06 ` Oberon and Wirthian languages (was: Heartbleed) Simon Clubley
2014-04-21 18:13 ` Simon Clubley
2014-04-21 18:45 ` Oberon and Wirthian languages Shark8
2014-04-21 23:26 ` Randy Brukardt
2014-04-22 0:21 ` Simon Clubley
2014-04-22 5:48 ` Shark8
2014-04-21 18:16 ` Jeffrey Carter
2014-04-22 0:34 ` Simon Clubley
2014-04-22 3:01 ` Jeffrey Carter
2014-04-22 23:31 ` Randy Brukardt
2014-04-22 6:41 ` Simon Wright
2014-04-22 12:25 ` Simon Clubley
2014-04-22 19:13 ` Niklas Holsti
2014-04-22 20:46 ` Simon Clubley [this message]
2014-04-22 23:38 ` Randy Brukardt
2014-04-23 12:16 ` Simon Clubley
2014-04-23 20:55 ` Simon Wright
2014-04-24 0:20 ` Simon Clubley
2014-04-24 13:05 ` Niklas Holsti
2014-04-24 18:51 ` Simon Clubley
2014-04-24 20:11 ` Niklas Holsti
2014-04-25 1:37 ` Randy Brukardt
2014-04-25 21:33 ` Simon Clubley
2014-04-25 21:55 ` Randy Brukardt
2014-04-25 23:16 ` Dennis Lee Bieber
2014-04-26 6:31 ` Niklas Holsti
2014-04-26 0:23 ` Nasser M. Abbasi
2014-04-26 2:46 ` Shark8
2014-04-26 2:52 ` Shark8
2014-04-26 6:37 ` Niklas Holsti
2014-04-26 6:19 ` Georg Bauhaus
2014-04-26 6:35 ` Georg Bauhaus
2014-04-26 6:42 ` Niklas Holsti
2014-04-26 17:15 ` Simon Clubley
2014-04-26 6:29 ` Niklas Holsti
2014-04-26 7:36 ` Dmitry A. Kazakov
2014-04-26 7:52 ` Georg Bauhaus
2014-04-26 8:09 ` Dmitry A. Kazakov
2014-04-26 18:32 ` Simon Clubley
2014-05-08 2:36 ` Randy Brukardt
2014-05-08 17:48 ` Niklas Holsti
2014-05-08 19:22 ` Randy Brukardt
2014-04-26 7:23 ` Simon Wright
2014-04-26 9:27 ` Niklas Holsti
2014-04-26 12:34 ` Simon Wright
2014-04-27 10:38 ` Simon Wright
2014-04-27 15:36 ` Simon Clubley
2014-04-27 14:26 ` Brian Drummond
2014-04-22 23:30 ` Randy Brukardt
2014-04-23 12:17 ` Simon Clubley
2014-05-14 9:39 ` Heartbleed gvdschoot
2014-04-12 22:01 ` Heartbleed Yannick Duchêne (Hibou57)
2014-04-18 17:58 ` Heartbleed Alan Browne
2014-04-18 17:24 ` Heartbleed - attacks? Alan Browne
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox