diff options
author | Kalesh Singh <kaleshsingh@google.com> | 2021-10-30 01:24:10 +0200 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2021-11-02 01:45:11 +0100 |
commit | 8b5d46fd7a3892a2e71c9ba6330f1b46d533d0a0 (patch) | |
tree | b327ba1d4003b14283af9b70d6091e03909519af /include/clocksource | |
parent | tracing/osnoise: Remove PREEMPT_RT ifdefs from inside functions (diff) | |
download | linux-8b5d46fd7a3892a2e71c9ba6330f1b46d533d0a0.tar.xz linux-8b5d46fd7a3892a2e71c9ba6330f1b46d533d0a0.zip |
tracing/histogram: Optimize division by constants
If the divisor is a constant use specific division functions to
avoid extra branches when the trigger is hit.
If the divisor constant but not a power of 2, the division can be
replaced with a multiplication and shift in the following case:
Let X = dividend and Y = divisor.
Choose Z = some power of 2. If Y <= Z, then:
X / Y = (X * (Z / Y)) / Z
(Z / Y) is a constant (mult) which is calculated at parse time, so:
X / Y = (X * mult) / Z
The division by Z can be replaced by a shift since Z is a power of 2:
X / Y = (X * mult) >> shift
As long, as X < Z the results will not be off by more than 1.
Link: https://lkml.kernel.org/r/20211029232410.3494196-1-kaleshsingh@google.com
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Diffstat (limited to 'include/clocksource')
0 files changed, 0 insertions, 0 deletions