Page MenuHomeFreeBSD

Small optimization for critical_enter()
AbandonedPublic

Authored by jtl on Nov 2 2017, 2:04 PM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 20 2023, 8:43 AM
Unknown Object (File)
Nov 7 2023, 6:16 AM
Unknown Object (File)
Sep 29 2023, 3:01 PM
Unknown Object (File)
Sep 16 2023, 2:57 AM
Unknown Object (File)
Aug 9 2023, 3:12 AM
Unknown Object (File)
Jun 13 2023, 10:30 PM
Unknown Object (File)
May 14 2023, 6:14 AM
Unknown Object (File)
Apr 25 2023, 9:23 AM
Subscribers

Details

Reviewers
gallatin
Summary

By default, the compiler can choose to omit frame pointers for debugged functions. However, we often disable this in kernel builds in order to make debugging functionality easier. (Specifically, if DDB, dtrace, or HWPMC support is enabled, we disable this for amd64.)

On the other hand, there is a class of function that is so trivial that it is highly unlikely it will ever need to be debugged. critical_enter() is such a function: it is a leaf function which simply sets a variable. It also seems like it is worth optimizing, since it is called an extraordinarily large number of times.

(For example, in one recent measurement sample, Intel's VTune product attributed 0.687% of the clockticks in the kernel to critical_enter(). That's a lot of time to spend in a function that functionally just increments a variable.)

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 12392
Build 12668: arc lint + arc unit

Event Timeline

I ended up posting this for review, since I didn't want to lose the diff. However, while thinking about this more, I realized that there is probably a better way to do this.

The whole reason this is a function call instead of an in-line memory operation is to prevent re-ordering, but not require a full memory barrier. clang provides the C11 atomic operations. Those should allow us to do various kinds of fences to prevent re-ordering without a full compiler memory barrier. I would like to explore that more before committing this. Therefore, I'm abandoning this review for now...