Page MenuHomeFreeBSD

x86 atomics: use lock prefix unconditionally
ClosedPublic

Authored by kib on Feb 3 2022, 9:59 AM.
Tags
None
Referenced Files
F102413114: D34153.diff
Mon, Nov 11, 10:42 PM
Unknown Object (File)
Thu, Nov 7, 10:45 AM
Unknown Object (File)
Sat, Nov 2, 9:35 AM
Unknown Object (File)
Mon, Oct 28, 7:37 PM
Unknown Object (File)
Mon, Oct 28, 4:23 AM
Unknown Object (File)
Oct 7 2024, 1:09 AM
Unknown Object (File)
Sep 24 2024, 4:45 AM
Unknown Object (File)
Sep 24 2024, 4:18 AM
Subscribers

Details

Summary
Atomics have significant other use besides providing in-system
primitives for safe memory updates.  They are used for implementing
communication with out of system software or hardware following some
protocols.

For instance, even UP kernel might require a protocol using atomics to
communicate with the software-emulated device on SMP hypervisor.  Or
real hardware might need atomic accesses as part of the proper
management protocol.

Another point is that UP configurations on x86 are extinct, so slight
performance hit by unconditionally use proper atomics is not important.
It is compensated by less code clutter, which in fact improves the
UP/i386 lifetime expectations.

Requested by:   Elliott Mitchell <ehem+freebsd@m5p.com>

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Feb 3 2022, 9:59 AM

s/read hardware/real hardware/ in the commit message I think.

This revision is now accepted and ready to land.Feb 3 2022, 10:21 AM

One less special case for klds. Yea!

The two comments also need to be removed or adjusted, but that can be done during commit. Yet another generation of hardware/software passes on.

sys/amd64/include/atomic.h
105–112

This makes the second sentence of the first paragraph no longer true. The second paragraph became untrue at f4b3640475cec9299517289b7e8731ae26997cfc. I would tend to simply purge the comment, though it could also be adjusted.

sys/i386/include/atomic.h
99–106

Same situation with the identical comment here.

kib marked 2 inline comments as done.

Remove obsoleted comment.

This revision now requires review to proceed.Feb 3 2022, 5:48 PM
This revision is now accepted and ready to land.Feb 3 2022, 5:56 PM
jhb added inline comments.
sys/amd64/include/atomic.h
164

Maybe keep the space after the ; so that if anyone looks at the generated assembly it is 'lock; and' vs 'lock;and'? (In examples below you use a space in, e.g. 'lock; cmpxchg'.) Hmm, looks like you did keep the space in i386?

kib marked an inline comment as done.

Keep space after lock; on amd64

This revision now requires review to proceed.Feb 3 2022, 8:30 PM

I was also a bit worried about the losing the space after the "lock;", just I thought removing it could be justified (didn't realize it was still there for i386). Hopefully all the end of line backslashes still line up. I'm assuming that is Phabricator not rendering things correctly.

This revision is now accepted and ready to land.Feb 3 2022, 10:02 PM