[PATCH RFC 0/9] Reduce ratelimit's false-positive misses

From: Paul E. McKenney
Date: Thu Apr 03 2025 - 17:26:18 EST


Hello!

This RFC series replaces open-coded uses of the ratelimit_state structure
with formal APIs, counts all rate-limit misses, replaces jiffies=0
special case with a flag, provides a ___ratelimit() lockless fastpath
to (almost) eliminate false-positive misses, and adds a simple test.
The lockless fastpath also provides a 10-20% speedup on my x86 laptop,
though your mileage may vary.

The key point of this series is the reduction of false-positive misses.
Patches 4-7 move in this direction within the fully locked confines of
the current design, and patch 8 introduces the lockless fastpath.

The individual patches are as follows:

1. Create functions to handle ratelimit_state internals.

2. random: Avoid open-coded use of ratelimit_state structure's
->missed field.

3. drm/i915: Avoid open-coded use of ratelimit_state structure's
->missed field.

4. drm/amd/pm: Avoid open-coded use of ratelimit_state structure's
internals.

5. Convert the ->missed field to atomic_t.

6. Count misses due to lock contention.

7. Avoid jiffies=0 special case.

8. Reduce ratelimit's false-positive misses.

9. Add trivial kunit test for ratelimit.

Thanx, Paul

------------------------------------------------------------------------

b/drivers/char/random.c | 9 -
b/drivers/gpu/drm/amd/pm/amdgpu_pm.c | 11 --
b/drivers/gpu/drm/i915/i915_perf.c | 8 -
b/include/linux/ratelimit.h | 40 ++++++-
b/include/linux/ratelimit_types.h | 2
b/lib/Kconfig.debug | 11 ++
b/lib/Makefile | 1
b/lib/ratelimit.c | 8 -
b/lib/test_ratelimit.c | 77 ++++++++++++++
include/linux/ratelimit.h | 13 --
include/linux/ratelimit_types.h | 4
lib/ratelimit.c | 186 +++++++++++++++++++++++++++--------
12 files changed, 296 insertions(+), 74 deletions(-)