|
|
Subscribe / Log in / New account

Who's afraid of a big bad optimizing compiler?

Who's afraid of a big bad optimizing compiler?

Posted May 10, 2020 16:39 UTC (Sun) by rep_movsd (guest, #100040)
Parent article: Who's afraid of a big bad optimizing compiler?

Forgive me for being so dense, but why is there an ACCESS_ONCE macro rather than declaring objects that are accessed by multiple threads as volatile?


to post comments

Who's afraid of a big bad optimizing compiler?

Posted May 10, 2020 21:16 UTC (Sun) by farnz (subscriber, #17727) [Link]

Couple of reasons:

  1. volatile is not necessarily defined clearly enough on all architectures to be what you want. In the event that it's not sufficient on a given architecture, you can make ACCESS_ONCE do the right thing. I don't believe this applies to the kernel, but it's something to be aware of.
  2. Even on architectures where volatile does do the right thing, it causes pessimisation of all accesses to that object, not just those that need ACCESS_ONCE semantics. '

A different coding style wouldn't need to worry about the second case, as it would cast away volatile instead of using ACCESS_ONCE for cases that don't need ACCESS_ONCE semantics, but for better or worse, the Linux coding style doesn't work that way.


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