|
|
Subscribe / Log in / New account

Help educate an old 8-bit assembler mindset

Help educate an old 8-bit assembler mindset

Posted Jun 19, 2021 14:43 UTC (Sat) by corbet (editor, #1)
In reply to: Help educate an old 8-bit assembler mindset by felixfix
Parent article: Protecting control dependencies with volatile_if()

It's all a matter of ordering as seen by others. The write to B may be a "I'm dealing with it" flag; some other process may have changed A and wants to be sure that its change will be observed before B is written.


to post comments

Help educate an old 8-bit assembler mindset

Posted Jun 19, 2021 16:01 UTC (Sat) by felixfix (subscriber, #242) [Link] (3 responses)

But that too is a special case, only applying to threaded code (which I've written enough to be careful around).

"That breaks the control dependency, freeing a sufficiently aggressive CPU to move the write ahead of the read, possibly creating a subtle and unpleasant bug."

So again, other than special cases, including aliased variables, I/O, threaded code, and other unenumerated special cases, what kind of subtle and unpleasant bugs can this create? Or does that sentence only refer to special cases?

Help educate an old 8-bit assembler mindset

Posted Jun 19, 2021 17:47 UTC (Sat) by corbet (editor, #1) [Link] (2 responses)

This is an article about kernel programming, where everything is threaded. Or, as the article says, "The effects of this reordering on single-threaded code are (in the absence of bugs) limited to making it run faster. When there are multiple threads of execution running simultaneously, though, there can be surprises in store. One thread may observe things happening in a different order than others, leading to all sorts of unfortunate confusion."

Help educate an old 8-bit assembler mindset

Posted Jun 20, 2021 7:29 UTC (Sun) by pbonzini (subscriber, #60935) [Link]

To state the obvious, this only applies if there aren't any other ways that the ordering is guaranteed, the most obvious of which would be a spinlock or mutex.

Control dependencies also do not matter in most lockless cases, much less control dependencies where the compiler does have meaningful optimizations that would break. Of course, sometimes they do.

Help educate an old 8-bit assembler mindset

Posted Jun 20, 2021 13:58 UTC (Sun) by felixfix (subscriber, #242) [Link]

I had forgotten that this is about kernels, and thus always threaded. I have written threaded user-space programs, and written ancient 8 bit kernels which were not threaded, and once even modified one line in the linux kernel (some RS-232 control line) for my own use; but never combined those, and lost track of that aspect for this (lwn) thread.

Thanks to all concerned for my education.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds