Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible need of "volatile" with dsb/isb instructions #634

Open
ssilverman opened this issue Jan 19, 2022 · 12 comments
Open

Possible need of "volatile" with dsb/isb instructions #634

ssilverman opened this issue Jan 19, 2022 · 12 comments

Comments

@ssilverman
Copy link
Contributor

I was reading this: https://forum.pjrc.com/threads/69288-Strange-IRQ_CMP0-behaviour-of-Teensy-3-2-help-needed-to-track-down-issue?p=298177&viewfull=1#post298177
and remembered I've seen asm("dsb") instructions without the volatile.

The following places in this repo use this instruction without volatile:

  1. asm("dsb" ::: "memory");
  2. asm("dsb" ::: "memory");
  3. asm("dsb");
    (there are two "dsb" and two "isb" here)
  4. asm("DSB");
@FrankBoesing
Copy link
Contributor

As these things work, there is no need to change them.

@FrankBoesing
Copy link
Contributor

FrankBoesing commented Jan 19, 2022

On the contrary - I'd think about removing the DSB  (for example for audiostream), after a test. 
A unneeded dsb is esp. with volatile a real performance killer.

"voaltile" by nature kills performance :)

@ssilverman
Copy link
Contributor Author

Is there no chance of reordering, then, even with future compilers? Or maybe even the lines with :::“memory” can’t be reordered?

@FrankBoesing
Copy link
Contributor

don't know.

@tsandmann
Copy link
Contributor

There's no difference in using volatile here, because no output operands are used:

asm statements that have no output operands and asm goto statements, are implicitly volatile.

See gcc docs.

Reordering is a completely different story (that's independent of volatile).

@ssilverman
Copy link
Contributor Author

ssilverman commented Feb 2, 2022

Thanks, @tsandmann. That makes it a little more clear. Is there even a way to disable reordering for these statements?

Update: or maybe the compiler considers the “dsb” instruction non-reorderable?

@FrankBoesing
Copy link
Contributor

There is no difference, yes, so it does not hurt to just leave it there :)

@FrankBoesing
Copy link
Contributor

...and was it for GCC 5.4 the same?

@tsandmann
Copy link
Contributor

Thanks, @tsandmann. That makes it a little more clear. Is there even a way to disable reordering for these statements?

Did you see any issue because of reordering there? I don't think there's an easy way to guarantee that, but if it's an actual issue here, sth. like the example in the linked docs should work.

Update: or maybe the compiler considers the “dsb” instruction non-reorderable?

I don't think so, but adding ::: "memory" prevents reordering any read/write instruction around it.

@tsandmann
Copy link
Contributor

...and was it for GCC 5.4 the same?

According to gcc-5.4.0/gcc/Extended-Asm.html, yes.

@FrankBoesing
Copy link
Contributor

thanks!

@ssilverman
Copy link
Contributor Author

ssilverman commented Feb 2, 2022

@tsandmann no issue with reordering that I know of. I thought that the comments in that forum post suggested that one must add volatile to prevent reordering. There’s some finer details which you pointed out. I’m just trying to learn more. Thanks for the info. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants