lib/ratelimit: Lockless ratelimiting
Subsystems (6)
PATCH v3 1/1 lib/ratelimit: Lockless ratelimiting
Currently ratelimit_state is protected with spin_lock. If the .lock is taken at the moment of ___ratelimit() call, the message is suppressed to make ratelimiting robust.
That results in the following issue issue:
CPU0 CPU1
------------------ ------------------printk_ratelimit() printk_ratelimit()
| |
try_spin_lock() try_spin_lock()
| |
time_is_before_jiffies() return 0; // suppressSo, concurrent call of ___ratelimit() results in silently suppressing one of the messages, regardless if the limit is reached or not. And rc->missed is not increased in such case so the issue is covered from user.
Convert ratelimiting to use atomic counters and drop spin_lock.
Note: That might be unexpected, but with the first interval of messages storm one can print up to burst*2 messages. So, it doesn't guarantee that in *any* interval amount of messages is lesser than burst. But, that differs lightly from previous behavior where one can start burst=5 interval and print 4 messages on the last milliseconds of interval + new 5 messages from new interval (totally 9 messages in lesser than interval value):
msg0 msg1-msg4 msg0-msg4
| | |
| | |
|--o---------------------o-|-----o--------------------|--> (t) <------->
Lesser than burst
Dropped dev/random patch since v1 version:
lkml.kernel.org/r/<[email protected]>
Dropped `name' in as it's unused in RATELIMIT_STATE_INIT()
--- drivers/char/random.c | 28 ++++++++----------- drivers/gpu/drm/i915/i915_perf.c | 8 ++++-- fs/btrfs/super.c | 16 +++++------ fs/xfs/scrub/scrub.c | 2 +- include/linux/ratelimit.h | 31 ++++++++++++--------- kernel/user.c | 2 +- lib/ratelimit.c | 59 +++++++++++++++++++--------------------- 7 files changed, 73 insertions(+), 73 deletions(-)
drivers/char/random.c +12 -16
@@ -439,10 +439,8 @@ static void _crng_backtrack_protect(struct crng_state *crng,static void process_random_ready_list (void );static void _get_random_bytes (void *buf,int nbytes); -static struct ratelimit_state unseeded_warning = -RATELIMIT_STATE_INIT ("warn_unseeded_randomness" ,HZ ,3 ); -static struct ratelimit_state urandom_warning = -RATELIMIT_STATE_INIT ("warn_urandom_randomness" ,HZ ,3 ); +static struct ratelimit_state unseeded_warning =RATELIMIT_STATE_INIT (HZ ,3 ); +static struct ratelimit_state urandom_warning =RATELIMIT_STATE_INIT (HZ ,3 );static int ratelimit_disable__read_mostly ;
@@ -937,24 +935,22 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r) crng->init_time = jiffies;spin_unlock_irqrestore (&crng->lock, flags);if (crng == &primary_crng && crng_init <2 ) { +unsigned int unseeded_miss, urandom_miss; +invalidate_batched_entropy ();numa_crng_init (); crng_init =2 ;process_random_ready_list ();wake_up_interruptible (&crng_init_wait);pr_notice ("random: crng init done\n" ); -if (unseeded_warning.missed) { -pr_notice ("random: %d get_random_xx warning(s) missed " -"due to ratelimiting\n" , - unseeded_warning.missed); - unseeded_warning.missed =0 ; - } -if (urandom_warning.missed) { -pr_notice ("random: %d urandom warning(s) missed " -"due to ratelimiting\n" , - urandom_warning.missed); - urandom_warning.missed =0 ; - } + unseeded_miss =atomic_xchg (&unseeded_warning.missed,0 ); +if (unseeded_miss) +pr_notice ("random: %u get_random_xx warning(s) missed " +"due to ratelimiting\n" , unseeded_miss); + urandom_miss =atomic_xchg (&urandom_warning.missed,0 ); +if (urandom_miss) +pr_notice ("random: %u urandom warning(s) missed " +"due to ratelimiting\n" , urandom_miss); } }
drivers/gpu/drm/i915/i915_perf.c +5 -3
@@ -1295,6 +1295,7 @@ free_oa_buffer(struct drm_i915_private *i915)static void i915_oa_stream_destroy (struct i915_perf_stream *stream) {struct drm_i915_private *dev_priv = stream->dev_priv; +unsigned int msg_missed;BUG_ON (stream != dev_priv->perf.oa.exclusive_stream);
@@ -1317,9 +1318,10 @@ static void i915_oa_stream_destroy(struct i915_perf_stream *stream)put_oa_config (dev_priv, stream->oa_config); -if (dev_priv->perf.oa.spurious_report_rs.missed) { -DRM_NOTE ("%d spurious OA report notices suppressed due to ratelimiting\n" , - dev_priv->perf.oa.spurious_report_rs.missed); + msg_missed =atomic_read (&dev_priv->perf.oa.spurious_report_rs.missed); +if (msg_missed) { +DRM_NOTE ("%u spurious OA report notices suppressed due to ratelimiting\n" , + msg_missed); } }
fs/btrfs/super.c +8 -8
@@ -177,14 +177,14 @@ static const char * const logtypes[] = {* messages doesn't cause more important ones to be dropped. */ static struct ratelimit_state printk_limits[] = { -RATELIMIT_STATE_INIT (printk_limits[0 ],DEFAULT_RATELIMIT_INTERVAL ,100 ), -RATELIMIT_STATE_INIT (printk_limits[1 ],DEFAULT_RATELIMIT_INTERVAL ,100 ), -RATELIMIT_STATE_INIT (printk_limits[2 ],DEFAULT_RATELIMIT_INTERVAL ,100 ), -RATELIMIT_STATE_INIT (printk_limits[3 ],DEFAULT_RATELIMIT_INTERVAL ,100 ), -RATELIMIT_STATE_INIT (printk_limits[4 ],DEFAULT_RATELIMIT_INTERVAL ,100 ), -RATELIMIT_STATE_INIT (printk_limits[5 ],DEFAULT_RATELIMIT_INTERVAL ,100 ), -RATELIMIT_STATE_INIT (printk_limits[6 ],DEFAULT_RATELIMIT_INTERVAL ,100 ), -RATELIMIT_STATE_INIT (printk_limits[7 ],DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), };void btrfs_printk (const struct btrfs_fs_info *fs_info,const char *fmt, ...)
fs/xfs/scrub/scrub.c +1 -1
@@ -349,7 +349,7 @@ xfs_scrub_experimental_warning( struct xfs_mount *mp) {static struct ratelimit_state scrub_warning =RATELIMIT_STATE_INIT ( -"xfs_scrub_warning" ,86400 *HZ ,1 ); +86400 *HZ ,1 );ratelimit_set_flags (&scrub_warning,RATELIMIT_MSG_ON_RELEASE );if (__ratelimit (&scrub_warning))
include/linux/ratelimit.h +18 -13
@@ -4,7 +4,6 @@#include <linux/param.h> #include <linux/sched.h> -#include <linux/spinlock.h> #define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)#define DEFAULT_RATELIMIT_BURST 10
@@ -13,38 +12,39 @@#define RATELIMIT_MSG_ON_RELEASE BIT(0)struct ratelimit_state { -raw_spinlock_t lock;/* protect the state */ +atomic_t printed; +atomic_t missed;int interval;int burst; -int printed; -int missed;unsigned long begin;unsigned long flags; }; -#define RATELIMIT_STATE_INIT (name, interval_init, burst_init) { \ - .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \ +#define RATELIMIT_STATE_INIT (interval_init, burst_init) { \ .interval = interval_init, \ .burst = burst_init, \ + .printed = ATOMIC_INIT(0), \ + .missed = ATOMIC_INIT(0), \ }#define RATELIMIT_STATE_INIT_DISABLED \ - RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST) + RATELIMIT_STATE_INIT(0, DEFAULT_RATELIMIT_BURST)#define DEFINE_RATELIMIT_STATE (name, interval_init, burst_init) \ \ struct ratelimit_state name = \ - RATELIMIT_STATE_INIT(name, interval_init, burst_init) \ + RATELIMIT_STATE_INIT(interval_init, burst_init)static inline void ratelimit_state_init (struct ratelimit_state *rs,int interval,int burst) {memset (rs,0 ,sizeof (*rs)); -raw_spin_lock_init (&rs->lock); rs->interval = interval; rs->burst = burst; +atomic_set (&rs->printed,0 ); +atomic_set (&rs->missed,0 ); }static inline void ratelimit_default_init (struct ratelimit_state *rs)
@@ -53,16 +53,21 @@ static inline void ratelimit_default_init(struct ratelimit_state *rs) DEFAULT_RATELIMIT_BURST); } +/* +* Keeping It Simple: not reenterable and not safe for concurrent +* ___ratelimit() call as used only by devkmsg_release(). +*/ static inline void ratelimit_state_exit (struct ratelimit_state *rs) { +int missed; +if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE ))return ; -if (rs->missed) { + missed =atomic_xchg (&rs->missed,0 ); +if (missed)pr_warn ("%s: %d output lines suppressed due to ratelimiting\n" , - current->comm, rs->missed); - rs->missed =0 ; - } + current->comm, missed); } static inline void
kernel/user.c +1 -1
@@ -101,7 +101,7 @@ struct user_struct root_user = { .sigpending = ATOMIC_INIT(0), .locked_shm = 0, .uid = GLOBAL_ROOT_UID, - .ratelimit = RATELIMIT_STATE_INIT(root_user.ratelimit, 0, 0), + .ratelimit = RATELIMIT_STATE_INIT(0, 0), };/*
lib/ratelimit.c +28 -31
79 lines not on this page · raw message
Signature · 6 lines
2.13.6 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.BAT: success for lib/ratelimit: Lockless ratelimiting (rev2)
== Series Details ==
== Series Details ==
Series: lib/ratelimit: Lockless ratelimiting (rev2)
URL : https://patchwork.freedesktop.org/series/45416/
State : success
== Summary ==
= CI Bug Log - changes from CI_DRM_4423 -> Patchwork_9516 =
== Summary - SUCCESS ==
No regressions found.
External URL: https://patchwork.freedesktop.org/api/1.0/series/45416/revisions/2/mbox/
== Known issues ==
Here are the changes found in Patchwork_9516 that come from known issues:
=== IGT changes ===
==== Issues hit ====
igt@kms_frontbuffer_tracking@basic:
fi-hsw-peppy: PASS -> DMESG-FAIL (fdo#102614, fdo#106103)
==== Possible fixes ====
igt@gem_exec_suspend@basic-s3:
{fi-cfl-8109u}: INCOMPLETE -> PASS {name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
fdo#102614 https://bugs.freedesktop.org/show_bug.cgi?id=102614
fdo#106103 https://bugs.freedesktop.org/show_bug.cgi?id=106103
== Participating hosts (45 -> 41) ==
Additional (1): fi-bxt-dsi
Missing (5): fi-ctg-p8600 fi-ilk-m540 fi-byt-squawks fi-bsw-cyan fi-hsw-4200u
== Build changes ==
* Linux: CI_DRM_4423 -> Patchwork_9516
CI_DRM_4423: 9b9b45349fe3a36d41586992426d03a238396531 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4533: 199220052af977598033d3810ffb4cc32d377522 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_9516: 74f5587b4c50742d179adb0fab3bae77017b5564 @ git://anongit.freedesktop.org/gfx-ci/linux
== Linux commits ==
74f5587b4c50 lib/ratelimit: Lockless ratelimiting
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_9516/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.IGT: success for lib/ratelimit: Lockless ratelimiting (rev2)
In reply to Dmitry Safonov== Series Details ==
== Series Details ==
Series: lib/ratelimit: Lockless ratelimiting (rev2)
URL : https://patchwork.freedesktop.org/series/45416/
State : success
== Summary ==
= CI Bug Log - changes from CI_DRM_4423_full -> Patchwork_9516_full =
== Summary - WARNING ==
Minor unknown changes coming with Patchwork_9516_full need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in Patchwork_9516_full, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
== Possible new issues ==
Here are the unknown changes that may have been introduced in Patchwork_9516_full:
=== IGT changes ===
==== Warnings ====
igt@gem_exec_schedule@deep-blt:
shard-kbl: SKIP -> PASS +1
igt@gem_exec_schedule@deep-bsd2:
shard-kbl: PASS -> SKIP +1== Known issues ==
Here are the changes found in Patchwork_9516_full that come from known issues:
=== IGT changes ===
==== Issues hit ====
igt@drv_selftest@live_gtt:
shard-apl: PASS -> INCOMPLETE (fdo#103927)
igt@gem_ctx_switch@basic-all-light:
shard-hsw: PASS -> INCOMPLETE (fdo#103540)
igt@kms_flip@flip-vs-expired-vblank:
shard-glk: PASS -> FAIL (fdo#105189)
igt@kms_flip_tiling@flip-to-x-tiled:
shard-glk: PASS -> FAIL (fdo#104724)
igt@kms_setmode@basic:
shard-apl: PASS -> FAIL (fdo#99912)
==== Possible fixes ====
igt@kms_flip@2x-plain-flip-fb-recreate:
shard-glk: FAIL (fdo#100368) -> PASS
igt@kms_vblank@pipe-a-ts-continuation-suspend:
shard-hsw: FAIL (fdo#104894) -> PASS
igt@perf@polling:
shard-hsw: FAIL (fdo#102252) -> PASS
==== Warnings ====
igt@drv_selftest@live_gtt:
shard-glk: INCOMPLETE (fdo#103359, k.org#198133) -> FAIL (fdo#105347) fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#102252 https://bugs.freedesktop.org/show_bug.cgi?id=102252
fdo#103359 https://bugs.freedesktop.org/show_bug.cgi?id=103359
fdo#103540 https://bugs.freedesktop.org/show_bug.cgi?id=103540
fdo#103927 https://bugs.freedesktop.org/show_bug.cgi?id=103927
fdo#104724 https://bugs.freedesktop.org/show_bug.cgi?id=104724
fdo#104894 https://bugs.freedesktop.org/show_bug.cgi?id=104894
fdo#105189 https://bugs.freedesktop.org/show_bug.cgi?id=105189
fdo#105347 https://bugs.freedesktop.org/show_bug.cgi?id=105347
fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912
k.org#198133 https://bugzilla.kernel.org/show_bug.cgi?id=198133
== Participating hosts (5 -> 5) ==
No changes in participating hosts
== Build changes ==
* Linux: CI_DRM_4423 -> Patchwork_9516
CI_DRM_4423: 9b9b45349fe3a36d41586992426d03a238396531 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4533: 199220052af977598033d3810ffb4cc32d377522 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_9516: 74f5587b4c50742d179adb0fab3bae77017b5564 @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_9516/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
I would be glad if someone helps/bothers to review the change :C
Thanks,
Dmitry
Quoted 410 lines · Dmitry Safonov
Currently
ratelimit_stateis protected withspin_lock. If the .lock is
taken at the moment of___ratelimit()call, the message is suppressed to
make ratelimiting robust.That results in the following issue issue:
CPU0 CPU1
------------------ ------------------printk_ratelimit()printk_ratelimit()| | try_spin_lock() try_spin_lock() | | time_is_before_jiffies() return 0; // suppressSo, concurrent call of
___ratelimit()results in silently suppressing one of the messages, regardless if the limit is reached or not. Andrc->missedis not increased in such case so the issue is covered from user.Convert ratelimiting to use atomic counters and drop
spin_lock.Note: That might be unexpected, but with the first interval of messages
storm one can print up to burst*2 messages. So, it doesn't guarantee that in *any* interval amount of messages is lesser than burst. But, that differs lightly from previous behavior where one can start burst=5 interval and print 4 messages on the last milliseconds of interval + new 5 messages from new interval (totally 9 messages in lesser than interval value):msg0 msg1-msg4 msg0-msg4
| | | | | | |--o---------------------o-|-----o--------------------|--> (t)<------->
Lesser than burstDropped dev/random patch since v1 version:
lkml.kernel.org/r/<[email protected]>Dropped `name' in as it's unused in
RATELIMIT_STATE_INIT()Cc Andy Shevchenko <[email protected]>Cc Arnd Bergmann <[email protected]>Cc David Airlie <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Jani Nikula <[email protected]>Cc Joonas Lahtinen <[email protected]>Cc Rodrigo Vivi <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- drivers/char/random.c | 28 ++++++++----------- drivers/gpu/drm/i915/i915_perf.c | 8 ++++-- fs/btrfs/super.c | 16 +++++------ fs/xfs/scrub/scrub.c | 2 +- include/linux/ratelimit.h | 31 ++++++++++++--------- kernel/user.c | 2 +- lib/ratelimit.c | 59 +++++++++++++++++++----------- ---------- 7 files changed, 73 insertions(+), 73 deletions(-)drivers/char/random.c +2
-4@@ -439,10 +439,8 @@ static void _crng_backtrack_protect(structcrng_state *crng, static void process_random_ready_list(void);static void _get_random_bytes (void *buf,int nbytes); -static struct ratelimit_state unseeded_warning = -RATELIMIT_STATE_INIT ("warn_unseeded_randomness" ,HZ ,3 ); -static struct ratelimit_state urandom_warning = -RATELIMIT_STATE_INIT ("warn_urandom_randomness" ,HZ ,3 ); +static struct ratelimit_state unseeded_warning =RATELIMIT_STATE_INIT (HZ ,3 ); +static struct ratelimit_state urandom_warning =RATELIMIT_STATE_INIT (HZ ,3 );static int
ratelimit_disable__read_mostly;drivers/char/random.c +2
-2@@ -937,24 +935,22 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r) crng->init_time = jiffies;spin_unlock_irqrestore (&crng->lock, flags);if (crng == &primary_crng && crng_init <2 ) { +unsigned int unseeded_miss, urandom_miss; +invalidate_batched_entropy ();numa_crng_init (); crng_init =2 ;process_random_ready_list ();wake_up_interruptible (&crng_init_wait);pr_notice ("random: crng init done\n" ); -if (unseeded_warning.missed) { - pr_notice("random: %d get_random_xxwarning(s) missed "
drivers/char/random.c +0
-6-"due to ratelimiting\n" , - unseeded_warning.missed); - unseeded_warning.missed =0 ; - } -if (urandom_warning.missed) { - pr_notice("random: %d urandom warning(s)missed "
drivers/char/random.c +1
-4-"due to ratelimiting\n" , - urandom_warning.missed); - urandom_warning.missed =0 ; - } + unseeded_miss =
atomic_xchg(&unseeded_warning.missed, 0);drivers/char/random.c +2
-0+if (unseeded_miss) + pr_notice("random: %u get_random_xxwarning(s) missed "
drivers/char/random.c +1
-0+ "due to ratelimiting\n",
unseeded_miss);drivers/char/random.c +1
-0+ urandom_miss = atomic_xchg(&urandom_warning.missed,0);
drivers/char/random.c +2
-0+if (urandom_miss) + pr_notice("random: %u urandom warning(s)missed "
drivers/char/random.c +1
-0+ "due to ratelimiting\n",
urandom_miss);drivers/char/random.c +0
-0} }drivers/gpu/drm/i915/i915_perf.c +2
-3@@ -1295,6 +1295,7 @@ free_oa_buffer(struct drm_i915_private *i915)static void i915_oa_stream_destroy (struct i915_perf_stream *stream) {struct drm_i915_private *dev_priv = stream->dev_priv; +unsigned int msg_missed;BUG_ON (stream != dev_priv->perf.oa.exclusive_stream);@@ -1317,9 +1318,10 @@ static void i915_oa_stream_destroy(struct i915_perf_stream *stream) put_oa_config(dev_priv, stream->oa_config); -if (dev_priv->perf.oa.spurious_report_rs.missed) { - DRM_NOTE("%d spurious OA report notices suppressed due to ratelimiting\n", - dev_priv- >perf.oa.spurious_report_rs.missed); + msg_missed = atomic_read(&dev_priv-Quoted 1 line
perf.oa.spurious_report_rs.missed);
drivers/gpu/drm/i915/i915_perf.c +2
-0+if (msg_missed) { + DRM_NOTE("%u spurious OA report notices suppresseddue to ratelimiting\n",
drivers/gpu/drm/i915/i915_perf.c +1
-0+ msg_missed); } }fs/btrfs/super.c +0
-6@@ -177,14 +177,14 @@ static const char * const logtypes[] = {* messages doesn't cause more important ones to be dropped. */ static struct ratelimit_state printk_limits[] = { -RATELIMIT_STATE_INIT (printk_limits[0 ], DEFAULT_RATELIMIT_INTERVAL, 100), -RATELIMIT_STATE_INIT (printk_limits[1 ], DEFAULT_RATELIMIT_INTERVAL, 100), -RATELIMIT_STATE_INIT (printk_limits[2 ], DEFAULT_RATELIMIT_INTERVAL, 100), -RATELIMIT_STATE_INIT (printk_limits[3 ], DEFAULT_RATELIMIT_INTERVAL, 100), -RATELIMIT_STATE_INIT (printk_limits[4 ], DEFAULT_RATELIMIT_INTERVAL, 100), - RATELIMIT_STATE_INIT(printk_limits[5],
DEFAULT_RATELIMIT_INTERVAL, 100),fs/btrfs/super.c +0
-1- RATELIMIT_STATE_INIT(printk_limits[6],
DEFAULT_RATELIMIT_INTERVAL, 100),fs/btrfs/super.c +0
-1- RATELIMIT_STATE_INIT(printk_limits[7],
DEFAULT_RATELIMIT_INTERVAL, 100),fs/btrfs/super.c +8
-0+RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), + RATELIMIT_STATE_INIT(DEFAULT_RATELIMIT_INTERVAL, 100), }; void btrfs_printk(const struct btrfs_fs_info *fs_info, const char*fmt, ...)
fs/xfs/scrub/scrub.c +0
-0@@ -349,7 +349,7 @@ xfs_scrub_experimental_warning( struct xfs_mount *mp) { static struct ratelimit_state scrub_warning =RATELIMIT_STATE_INIT(
fs/xfs/scrub/scrub.c +1
-1- "xfs_scrub_warning", 86400 * HZ, 1); + 86400 * HZ, 1); ratelimit_set_flags(&scrub_warning,
RATELIMIT_MSG_ON_RELEASE);fs/xfs/scrub/scrub.c +0
-0if (__ratelimit (&scrub_warning))include/linux/ratelimit.h +0
-2@@ -4,7 +4,6 @@#include <linux/param.h> #include <linux/sched.h> -#include <linux/spinlock.h> #define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)#define DEFAULT_RATELIMIT_BURST 10@@ -13,38 +12,39 @@#define RATELIMIT_MSG_ON_RELEASE BIT(0)struct ratelimit_state { -raw_spinlock_t lock;/* protect the state */
include/linux/ratelimit.h +2
-3+atomic_t printed; +atomic_t missed;int interval;int burst; -int printed; -int missed;unsigned long begin;unsigned long flags; }; -#define RATELIMIT_STATE_INIT (name, interval_init, burst_init) {\include/linux/ratelimit.h +0
-1- .lock =
__RAW_SPIN_LOCK_UNLOCKED(name.lock), \
+#defineRATELIMIT_STATE_INIT(interval_init, burst_init){ \
.interval =interval_init,
\
.burst =burst_init,\include/linux/ratelimit.h +1
-0+ .printed = ATOMIC_INIT(0),\
include/linux/ratelimit.h +1
-0+ .missed = ATOMIC_INIT(0),\}
#define RATELIMIT_STATE_INIT_DISABLED \include/linux/ratelimit.h +0
-1- RATELIMIT_STATE_INIT(ratelimit_state, 0,
DEFAULT_RATELIMIT_BURST)include/linux/ratelimit.h +1
-0+ RATELIMIT_STATE_INIT(0, DEFAULT_RATELIMIT_BURST)#define DEFINE_RATELIMIT_STATE (name, interval_init, burst_init)\\
structratelimit_statename =\include/linux/ratelimit.h +0
-1- RATELIMIT_STATE_INIT(name, interval_init,
burst_init) \include/linux/ratelimit.h +3
-1+ RATELIMIT_STATE_INIT(interval_init, burst_init)static inline void ratelimit_state_init (struct ratelimit_state *rs,int interval,int burst) {memset (rs,0 ,sizeof (*rs)); -raw_spin_lock_init (&rs->lock); rs->interval = interval; rs->burst = burst; +atomic_set (&rs->printed,0 ); +atomic_set (&rs->missed,0 ); } static inline void ratelimit_default_init(struct ratelimit_state*rs)
include/linux/ratelimit.h +9
-4@@ -53,16 +53,21 @@ static inline void ratelimit_default_init(struct ratelimit_state *rs) DEFAULT_RATELIMIT_BURST); } +/* +* Keeping It Simple: not reenterable and not safe for concurrent +* ___ratelimit() call as used only by devkmsg_release(). +*/ static inline void ratelimit_state_exit (struct ratelimit_state *rs) { +int missed; +if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE ))return ; -if (rs->missed) { + missed =atomic_xchg (&rs->missed,0 ); +if (missed)pr_warn ("%s: %d output lines suppressed due to ratelimiting\n", - current->comm, rs->missed); - rs->missed =0 ; - } + current->comm, missed); }static inline void
kernel/user.c +1
-1@@ -101,7 +101,7 @@ struct user_struct root_user = { .sigpending = ATOMIC_INIT(0), .locked_shm = 0, .uid = GLOBAL_ROOT_UID, - .ratelimit = RATELIMIT_STATE_INIT(root_user.ratelimit, 0, 0), + .ratelimit = RATELIMIT_STATE_INIT(0, 0), };/*
lib/ratelimit.c +12
-0@@ -13,6 +13,18 @@#include <linux/jiffies.h> #include <linux/export.h> +static void ratelimit_end_interval (struct ratelimit_state *rs,const char *func) +{ + rs->begin = jiffies; + +if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE )) { +unsigned int missed =atomic_xchg (&rs->missed,0 ); + +if (missed) +pr_warn ("%s: %u callbacks suppressed\n" , func, missed); + } +} +/* *
__ratelimit- rate limiting
* @rs:ratelimit_statedatalib/ratelimit.c +10
-30@@ -27,45 +39,30 @@*/ int ___ratelimit (struct ratelimit_state *rs,const char *func) { -unsigned long flags; -int ret; -if (!rs->interval)return 1 ; -/* -* If we contend on this state's lock then almost -* by definition we are too busy to print a message, -* in addition to the one that will be printed by -* the entity that is holding the lock already: -*/ -if (!raw_spin_trylock_irqsave (&rs->lock, flags)) +if (unlikely (!rs->burst)) { +atomic_add_unless (&rs->missed,1 ,-1 ); +if (time_is_before_jiffies (rs->begin + rs- >interval)) +ratelimit_end_interval (rs, func); +return 0 ; + } -if (!rs->begin) - rs->begin = jiffies; +if (atomic_add_unless (&rs->printed,1 , rs->burst)) +return 1 ;if (time_is_before_jiffies (rs->begin + rs->interval)) { -if (rs->missed) { -if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE )) { -printk_deferred (KERN_WARNING -"%s: %d callbacks suppressed\n", - func, rs->missed); - rs->missed =0 ; - } - } - rs->begin = jiffies; - rs->printed =0 ; - } -if (rs->burst && rs->burst > rs->printed) { - rs->printed++; - ret =1 ; - }else { - rs->missed++; - ret =0 ; + if (atomic_cmpxchg(&rs->printed, rs->burst, 0)) + ratelimit_end_interval(rs, func); } -raw_spin_unlock_irqrestore (&rs->lock, flags);
lib/ratelimit.c line 68
Quoted 10 lines
lib/ratelimit.c +6
-1-return ret; +if (atomic_add_unless (&rs->printed,1 , rs->burst)) +return 1 ; + +atomic_add_unless (&rs->missed,1 ,-1 ); + +return 0 ; }EXPORT_SYMBOL (___ratelimit);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 2 lines · Dmitry Safonov
I would be glad if someone helps/bothers to review the change :C
Perhaps Petr and / or Steven can help you.
Quoted 424 lines
Thanks,
DmitryQuoted 420 lines · Dmitry Safonov
Currently
ratelimit_stateis protected withspin_lock. If the .lock is
taken at the moment of___ratelimit()call, the message is suppressed to
make ratelimiting robust.That results in the following issue issue:
CPU0 CPU1
------------------ ------------------printk_ratelimit()printk_ratelimit()| | try_spin_lock() try_spin_lock() | | time_is_before_jiffies() return 0; // suppressSo, concurrent call of
___ratelimit()results in silently suppressing one of the messages, regardless if the limit is reached or not. Andrc->missedis not increased in such case so the issue is covered from user.Convert ratelimiting to use atomic counters and drop
spin_lock.Note: That might be unexpected, but with the first interval of messages
storm one can print up to burst*2 messages. So, it doesn't guarantee that in *any* interval amount of messages is lesser than burst. But, that differs lightly from previous behavior where one can start burst=5 interval and print 4 messages on the last milliseconds of interval + new 5 messages from new interval (totally 9 messages in lesser than interval value):msg0 msg1-msg4 msg0-msg4
| | | | | | |--o---------------------o-|-----o--------------------|--> (t)<------->
Lesser than burstDropped dev/random patch since v1 version:
lkml.kernel.org/r/<[email protected]>Dropped `name' in as it's unused in
RATELIMIT_STATE_INIT()Cc Andy Shevchenko <[email protected]>Cc Arnd Bergmann <[email protected]>Cc David Airlie <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Jani Nikula <[email protected]>Cc Joonas Lahtinen <[email protected]>Cc Rodrigo Vivi <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- drivers/char/random.c | 28 ++++++++----------- drivers/gpu/drm/i915/i915_perf.c | 8 ++++-- fs/btrfs/super.c | 16 +++++------ fs/xfs/scrub/scrub.c | 2 +- include/linux/ratelimit.h | 31 ++++++++++++--------- kernel/user.c | 2 +- lib/ratelimit.c | 59 +++++++++++++++++++----------- ---------- 7 files changed, 73 insertions(+), 73 deletions(-)drivers/char/random.c +2
-4@@ -439,10 +439,8 @@ static void _crng_backtrack_protect(structcrng_state *crng, static void process_random_ready_list(void);static void _get_random_bytes (void *buf,int nbytes); -static struct ratelimit_state unseeded_warning = -RATELIMIT_STATE_INIT ("warn_unseeded_randomness" ,HZ ,3 ); -static struct ratelimit_state urandom_warning = -RATELIMIT_STATE_INIT ("warn_urandom_randomness" ,HZ ,3 ); +static struct ratelimit_state unseeded_warning =RATELIMIT_STATE_INIT (HZ ,3 ); +static struct ratelimit_state urandom_warning =RATELIMIT_STATE_INIT (HZ ,3 );static int
ratelimit_disable__read_mostly;drivers/char/random.c +2
-2@@ -937,24 +935,22 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r) crng->init_time = jiffies;spin_unlock_irqrestore (&crng->lock, flags);if (crng == &primary_crng && crng_init <2 ) { +unsigned int unseeded_miss, urandom_miss; +invalidate_batched_entropy ();numa_crng_init (); crng_init =2 ;process_random_ready_list ();wake_up_interruptible (&crng_init_wait);pr_notice ("random: crng init done\n" ); -if (unseeded_warning.missed) { - pr_notice("random: %d get_random_xxwarning(s) missed "
drivers/char/random.c +0
-6-"due to ratelimiting\n" , - unseeded_warning.missed); - unseeded_warning.missed =0 ; - } -if (urandom_warning.missed) { - pr_notice("random: %d urandom warning(s)missed "
drivers/char/random.c +1
-4-"due to ratelimiting\n" , - urandom_warning.missed); - urandom_warning.missed =0 ; - } + unseeded_miss =
atomic_xchg(&unseeded_warning.missed, 0);drivers/char/random.c +2
-0+if (unseeded_miss) + pr_notice("random: %u get_random_xxwarning(s) missed "
+ "due to ratelimiting\n",unseeded_miss);
+urandom_miss= atomic_xchg(&urandom_warning.missed,
0);drivers/char/random.c +2
-0+if (urandom_miss) + pr_notice("random: %u urandom warning(s)missed "
+ "due to ratelimiting\n",urandom_miss); }}
drivers/gpu/drm/i915/i915_perf.c +2
-3@@ -1295,6 +1295,7 @@ free_oa_buffer(struct drm_i915_private *i915)static void i915_oa_stream_destroy (struct i915_perf_stream *stream) {struct drm_i915_private *dev_priv = stream->dev_priv; +unsigned int msg_missed;BUG_ON (stream != dev_priv->perf.oa.exclusive_stream);@@ -1317,9 +1318,10 @@ static void i915_oa_stream_destroy(struct i915_perf_stream *stream) put_oa_config(dev_priv, stream->oa_config); -if (dev_priv->perf.oa.spurious_report_rs.missed) { - DRM_NOTE("%d spurious OA report notices suppressed due to ratelimiting\n", - dev_priv- >perf.oa.spurious_report_rs.missed); + msg_missed = atomic_read(&dev_priv-Quoted 1 line
perf.oa.spurious_report_rs.missed);
drivers/gpu/drm/i915/i915_perf.c +2
-0+if (msg_missed) { + DRM_NOTE("%u spurious OA report notices suppresseddue to ratelimiting\n",
drivers/gpu/drm/i915/i915_perf.c +1
-0+ msg_missed); } }fs/btrfs/super.c +0
-6@@ -177,14 +177,14 @@ static const char * const logtypes[] = {* messages doesn't cause more important ones to be dropped. */ static struct ratelimit_state printk_limits[] = { -RATELIMIT_STATE_INIT (printk_limits[0 ], DEFAULT_RATELIMIT_INTERVAL, 100), -RATELIMIT_STATE_INIT (printk_limits[1 ], DEFAULT_RATELIMIT_INTERVAL, 100), -RATELIMIT_STATE_INIT (printk_limits[2 ], DEFAULT_RATELIMIT_INTERVAL, 100), -RATELIMIT_STATE_INIT (printk_limits[3 ], DEFAULT_RATELIMIT_INTERVAL, 100), -RATELIMIT_STATE_INIT (printk_limits[4 ], DEFAULT_RATELIMIT_INTERVAL, 100), - RATELIMIT_STATE_INIT(printk_limits[5],
DEFAULT_RATELIMIT_INTERVAL, 100),
- RATELIMIT_STATE_INIT(printk_limits[6],DEFAULT_RATELIMIT_INTERVAL, 100),
- RATELIMIT_STATE_INIT(printk_limits[7],DEFAULT_RATELIMIT_INTERVAL, 100),fs/btrfs/super.c +8
-0+RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), +RATELIMIT_STATE_INIT (DEFAULT_RATELIMIT_INTERVAL ,100 ), + RATELIMIT_STATE_INIT(DEFAULT_RATELIMIT_INTERVAL, 100), }; void btrfs_printk(const struct btrfs_fs_info *fs_info, const char*fmt, ...)
fs/xfs/scrub/scrub.c +0
-0@@ -349,7 +349,7 @@ xfs_scrub_experimental_warning( struct xfs_mount *mp) { static struct ratelimit_state scrub_warning =RATELIMIT_STATE_INIT(
fs/xfs/scrub/scrub.c +1
-1- "xfs_scrub_warning", 86400 * HZ, 1); + 86400 * HZ, 1); ratelimit_set_flags(&scrub_warning,
RATELIMIT_MSG_ON_RELEASE);if (
__ratelimit(&scrub_warning))include/linux/ratelimit.h +0
-2@@ -4,7 +4,6 @@#include <linux/param.h> #include <linux/sched.h> -#include <linux/spinlock.h> #define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)#define DEFAULT_RATELIMIT_BURST 10@@ -13,38 +12,39 @@#define RATELIMIT_MSG_ON_RELEASE BIT(0)struct ratelimit_state { -raw_spinlock_t lock;/* protect the state */
include/linux/ratelimit.h +2
-4+atomic_t printed; +atomic_t missed;int interval;int burst; -int printed; -int missed;unsigned long begin;unsigned long flags; }; -#define RATELIMIT_STATE_INIT (name, interval_init, burst_init) { \ - .lock =
__RAW_SPIN_LOCK_UNLOCKED(name.lock), \
+#defineRATELIMIT_STATE_INIT(interval_init, burst_init){ \
.interval =interval_init,
\
.burst =burst_init,
\
+ .printed =ATOMIC_INIT(0),
\include/linux/ratelimit.h +1
-1+ .missed = ATOMIC_INIT(0), \ }#define RATELIMIT_STATE_INIT_DISABLED \ - RATELIMIT_STATE_INIT(ratelimit_state, 0,
DEFAULT_RATELIMIT_BURST)
+RATELIMIT_STATE_INIT(0, DEFAULT_RATELIMIT_BURST)#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \\
structratelimit_statename =
\
- RATELIMIT_STATE_INIT(name,interval_init,burst_init) \include/linux/ratelimit.h +3
-1+ RATELIMIT_STATE_INIT(interval_init, burst_init)static inline void ratelimit_state_init (struct ratelimit_state *rs,int interval,int burst) {memset (rs,0 ,sizeof (*rs)); -raw_spin_lock_init (&rs->lock); rs->interval = interval; rs->burst = burst; +atomic_set (&rs->printed,0 ); +atomic_set (&rs->missed,0 ); } static inline void ratelimit_default_init(struct ratelimit_state*rs)
include/linux/ratelimit.h +9
-4@@ -53,16 +53,21 @@ static inline void ratelimit_default_init(struct ratelimit_state *rs) DEFAULT_RATELIMIT_BURST); } +/* +* Keeping It Simple: not reenterable and not safe for concurrent +* ___ratelimit() call as used only by devkmsg_release(). +*/ static inline void ratelimit_state_exit (struct ratelimit_state *rs) { +int missed; +if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE ))return ; -if (rs->missed) { + missed =atomic_xchg (&rs->missed,0 ); +if (missed)pr_warn ("%s: %d output lines suppressed due to ratelimiting\n", - current->comm, rs->missed); - rs->missed =0 ; - } + current->comm, missed); }static inline void
kernel/user.c +1
-1@@ -101,7 +101,7 @@ struct user_struct root_user = { .sigpending = ATOMIC_INIT(0), .locked_shm = 0, .uid =GLOBAL_ROOT_UID , - .ratelimit =RATELIMIT_STATE_INIT (root_user.ratelimit,0 ,0 ), + .ratelimit = RATELIMIT_STATE_INIT(0, 0), };/*
lib/ratelimit.c +12
-0@@ -13,6 +13,18 @@#include <linux/jiffies.h> #include <linux/export.h> +static void ratelimit_end_interval (struct ratelimit_state *rs,const char *func) +{ + rs->begin = jiffies; + +if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE )) { +unsigned int missed =atomic_xchg (&rs->missed,0 ); + +if (missed) +pr_warn ("%s: %u callbacks suppressed\n" , func, missed); + } +} +/* *
__ratelimit- rate limiting
* @rs:ratelimit_statedatalib/ratelimit.c +16
-31@@ -27,45 +39,30 @@*/ int ___ratelimit (struct ratelimit_state *rs,const char *func) { -unsigned long flags; -int ret; -if (!rs->interval)return 1 ; -/* -* If we contend on this state's lock then almost -* by definition we are too busy to print a message, -* in addition to the one that will be printed by -* the entity that is holding the lock already: -*/ -if (!raw_spin_trylock_irqsave (&rs->lock, flags)) +if (unlikely (!rs->burst)) { +atomic_add_unless (&rs->missed,1 ,-1 ); +if (time_is_before_jiffies (rs->begin + rs- >interval)) +ratelimit_end_interval (rs, func); +return 0 ; + } -if (!rs->begin) - rs->begin = jiffies; +if (atomic_add_unless (&rs->printed,1 , rs->burst)) +return 1 ;if (time_is_before_jiffies (rs->begin + rs->interval)) { -if (rs->missed) { -if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE )) { -printk_deferred (KERN_WARNING -"%s: %d callbacks suppressed\n", - func, rs->missed); - rs->missed =0 ; - } - } - rs->begin = jiffies; - rs->printed =0 ; - } -if (rs->burst && rs->burst > rs->printed) { - rs->printed++; - ret =1 ; - }else { - rs->missed++; - ret =0 ; + if (atomic_cmpxchg(&rs->printed, rs->burst, 0)) + ratelimit_end_interval(rs, func); } -raw_spin_unlock_irqrestore (&rs->lock, flags); -return ret; +if (atomic_add_unless (&rs->printed,1 , rs->burst)) +return 1 ; + +atomic_add_unless (&rs->missed,1 ,-1 ); + +return 0 ; }EXPORT_SYMBOL (___ratelimit);
Signature · 6 lines
With Best Regards, Andy Shevchenko _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 49 lines · Andy Shevchenko
Quoted 2 lines · Dmitry Safonov
I would be glad if someone helps/bothers to review the change :C
Perhaps Petr and / or Steven can help you.
Quoted 42 lines
Thanks,
DmitryQuoted 38 lines · Dmitry Safonov
Currently
ratelimit_stateis protected withspin_lock. If the .lock is
taken at the moment of___ratelimit()call, the message is suppressed to
make ratelimiting robust.That results in the following issue issue:
CPU0 CPU1
------------------ ------------------printk_ratelimit()printk_ratelimit()| | try_spin_lock() try_spin_lock() | | time_is_before_jiffies() return 0; // suppressSo, concurrent call of
___ratelimit()results in silently suppressing one of the messages, regardless if the limit is reached or not. Andrc->missedis not increased in such case so the issue is covered from user.Convert ratelimiting to use atomic counters and drop
spin_lock.Note: That might be unexpected, but with the first interval of messages
storm one can print up to burst*2 messages. So, it doesn't guarantee that in *any* interval amount of messages is lesser than burst. But, that differs lightly from previous behavior where one can start burst=5 interval and print 4 messages on the last milliseconds of interval + new 5 messages from new interval (totally 9 messages in lesser than interval value):msg0 msg1-msg4 msg0-msg4
| | | | | | |--o---------------------o-|-----o--------------------|--> (t)<------->
Lesser than burst
I am a bit confused. Does this patch fix two problems?
+ Lost rc->missed update when try_spin_lock() fails
+ printing up to burst*2 messages in a give interval
It would make the review much easier if you split it into more patches and fix the problems separately.
Otherwise, it looks promissing...
Best Regards,
Petr
PS: I have vacation the following two weeks. Anyway, please, CC me if you send any new version.
Best Regards,
Petr
Quoted 48 lines · Petr Mladek
Quoted 40 lines
Quoted 40 lines · Dmitry Safonov
Quoted 39 lines
Currently
ratelimit_stateis protected withspin_lock. If the .lock
is
taken at the moment of___ratelimit()call, the message is suppressed
to
make ratelimiting robust.That results in the following issue issue:
CPU0 CPU1
------------------ ------------------printk_ratelimit()printk_ratelimit()| | try_spin_lock() try_spin_lock() | | time_is_before_jiffies() return 0; // suppressSo, concurrent call of
___ratelimit()results in silently suppressing
one of the messages, regardless if the limit is reached or not. Andrc->missedis not increased in such case so the issue is covered
from user.Convert ratelimiting to use atomic counters and drop
spin_lock.Note: That might be unexpected, but with the first interval of messages
storm one can print up to burst*2 messages. So, it doesn't guarantee
that in *any* interval amount of messages is lesser than burst. But, that differs lightly from previous behavior where one can start
burst=5 interval and print 4 messages on the last milliseconds of
interval + new 5 messages from new interval (totally 9 messages in
lesser than interval value):Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
msg0 msg1-msg4 msg0-msg4
| | | | | | |--o---------------------o-|-----o--------------------|--> (t)<------->
Lesser than burst
Quoted 4 lines
I am a bit confused. Does this patch fix two problems?
+ Lost
rc->missedupdate whentry_spin_lock()fails
+ printing up to burst*2 messages in a give interval
What I tried to solve here (maybe I could better point it in the commit message): is the situation where ratelimit::burst haven't been hit yet and there are calls for __ratelimit() from different CPUs. So, neither of the messages should be suppressed, but as the spinlock is taken already - one of them is dropped and even without updating missed counter.
Quoted 2 lines
It would make the review much easier if you split it into more patches and fix the problems separately.
Hmm, not really sure: the patch changes spinlock to atomics and I'm not sure it make much sense to add atomics before removing the spinlock..
Quoted 7 lines
Otherwise, it looks promissing...
Best Regards,
PetrPS: I have vacation the following two weeks. Anyway, please, CC me if you send any new version.
Surely, thanks for your attention to the patch (and time).
Signature · 6 lines
Thanks,
Dmitry
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfxQuoted 69 lines · On Fri, 20 Jul 2018 16:33:36 +0100 Dmitry Safonov <[email protected]> wrote:
Quoted 48 lines · Petr Mladek
Quoted 40 lines
Quoted 40 lines · Dmitry Safonov
Quoted 39 lines
Currently
ratelimit_stateis protected withspin_lock. If the .lock
is
taken at the moment of___ratelimit()call, the message is suppressed
to
make ratelimiting robust.That results in the following issue issue:
CPU0 CPU1
------------------ ------------------printk_ratelimit()printk_ratelimit()| | try_spin_lock() try_spin_lock() | | time_is_before_jiffies() return 0; // suppressSo, concurrent call of
___ratelimit()results in silently suppressing
one of the messages, regardless if the limit is reached or not. Andrc->missedis not increased in such case so the issue is covered
from user.Convert ratelimiting to use atomic counters and drop
spin_lock.Note: That might be unexpected, but with the first interval of messages
storm one can print up to burst*2 messages. So, it doesn't guarantee
that in *any* interval amount of messages is lesser than burst. But, that differs lightly from previous behavior where one can start
burst=5 interval and print 4 messages on the last milliseconds of
interval + new 5 messages from new interval (totally 9 messages in
lesser than interval value):Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
msg0 msg1-msg4 msg0-msg4
| | | | | | |--o---------------------o-|-----o--------------------|--> (t)<------->
Lesser than burstQuoted 4 lines
I am a bit confused. Does this patch fix two problems?
+ Lost
rc->missedupdate whentry_spin_lock()fails
+ printing up to burst*2 messages in a give intervalWhat I tried to solve here (maybe I could better point it in the commit message): is the situation where
ratelimit::bursthaven't been hit yet and there are calls for__ratelimit()from different CPUs. So, neither of the messages should be suppressed, but as the spinlock is taken already - one of them is dropped and even without updating missed counter.Quoted 2 lines
It would make the review much easier if you split it into more patches and fix the problems separately.
Hmm, not really sure: the patch changes spinlock to atomics and I'm not sure it make much sense to add atomics before removing the spinlock..
Quoted 2 lines
Otherwise, it looks promissing...
Quoted 8 lines
Quoted 5 lines
Best Regards,
PetrPS: I have vacation the following two weeks. Anyway, please, CC me if you send any new version.
Surely, thanks for your attention to the patch (and time).
I'm just catching up from my vacation. What about making rs->missed into an atomic, and have:
if (!raw_spin_trylock_irqsave(&rs->lock, flags)) {
atomic_inc(&rs->missed);
return 0;
}?
You would also need to do:
if (time_is_before_jiffies(rs->begin + rs->interval)) {
int missed = atomic_xchg(&rs->missed, 0);
if (missed) {So that you don't have a race between checking rs->missed and setting it to zero.
-- Steve
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Steven,
Thanks for your reply,
Quoted 9 lines · Steven Rostedt
I'm just catching up from my vacation. What about making
rs->missedinto an atomic, and have:if (!raw_spin_trylock_irqsave(&rs->lock, flags)) { atomic_inc(&rs->missed); return 0; }?
Uhm. Do you mean as a preparation patch to split this on two patches? Because it will not solve the issue where one CPU has taken rs->lock, and is updating rs->printed, checking burst and whatnot; while the second CPU will loose the message which was even *under* burst limit.
I.e.: there are enough of printk_ratelimit() users in tree and a message from one can be suppressed, while shouldn't.
Quoted 9 lines
You would also need to do:
if (time_is_before_jiffies(rs->begin + rs->interval)) { int missed = atomic_xchg(&rs->missed, 0); if (missed) {So that you don't have a race between checking
rs->missedand setting it
to zero.
Signature · 2 lines
Thanks,
DmitryQuoted 20 lines · Dmitry Safonov
Currently
ratelimit_stateis protected withspin_lock. If the .lock is taken at the moment of___ratelimit()call, the message is suppressed to make ratelimiting robust.That results in the following issue issue:
CPU0 CPU1
------------------ ------------------printk_ratelimit()printk_ratelimit()| | try_spin_lock() try_spin_lock() | | time_is_before_jiffies() return 0; // suppressSo, concurrent call of
___ratelimit()results in silently suppressing one of the messages, regardless if the limit is reached or not. Andrc->missedis not increased in such case so the issue is covered from user.Convert ratelimiting to use atomic counters and drop
spin_lock.
Quoted 7 lines
Note: That might be unexpected, but with the first interval of messages storm one can print up to burst*2 messages. So, it doesn't guarantee that in *any* interval amount of messages is lesser than burst. But, that differs lightly from previous behavior where one can start burst=5 interval and print 4 messages on the last milliseconds of interval + new 5 messages from new interval (totally 9 messages in lesser than interval value):
I am still confused by this paragraph. Does this patch change the behavior? What is the original and what is the new one, please?
Quoted 46 lines
msg0 msg1-msg4 msg0-msg4
| | | | | | |--o---------------------o-|-----o--------------------|--> (t)<------->
Lesser than burstDropped dev/random patch since v1 version:
lkml.kernel.org/r/<[email protected]>Dropped `name' in as it's unused in
RATELIMIT_STATE_INIT()lib/ratelimit.c +12
-4@@ -13,6 +13,18 @@#include <linux/jiffies.h> #include <linux/export.h> +static void ratelimit_end_interval (struct ratelimit_state *rs,const char *func) +{ + rs->begin = jiffies; + +if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE )) { +unsigned int missed =atomic_xchg (&rs->missed,0 ); + +if (missed) +pr_warn ("%s: %u callbacks suppressed\n" , func, missed); + } +} +/* * __ratelimit - rate limiting * @rs: ratelimit_state data @@ -27,45 +39,30 @@*/ int ___ratelimit (struct ratelimit_state *rs,const char *func) { -unsigned long flags; -int ret; -if (!rs->interval)return 1 ; -/*
lib/ratelimit.c line 48
Quoted 10 lines
lib/ratelimit.c +4
-6-* If we contend on this state's lock then almost -* by definition we are too busy to print a message, -* in addition to the one that will be printed by -* the entity that is holding the lock already: -*/ -if (!raw_spin_trylock_irqsave (&rs->lock, flags)) +if (unlikely (!rs->burst)) { +atomic_add_unless (&rs->missed,1 ,-1 ); +if (time_is_before_jiffies (rs->begin + rs->interval)) +ratelimit_end_interval (rs, func);
This is racy. time_is_before_jiffies() might be valid on two CPUs in parallel. They would both call ratelimit_end_interval(). This is not longer atomic context. Therefore one might get scheduled and set rs->begin = jiffies seconds later. I am sure that there might be more crazy scenarios.
Quoted 25 lines
lib/ratelimit.c +4
-17+return 0 ; + } -if (!rs->begin) - rs->begin = jiffies; +if (atomic_add_unless (&rs->printed,1 , rs->burst)) +return 1 ;if (time_is_before_jiffies (rs->begin + rs->interval)) { -if (rs->missed) { -if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE )) { -printk_deferred (KERN_WARNING -"%s: %d callbacks suppressed\n" , - func, rs->missed); - rs->missed =0 ; - } - } - rs->begin = jiffies; - rs->printed =0 ; - } -if (rs->burst && rs->burst > rs->printed) { - rs->printed++; - ret =1 ; - }else {
lib/ratelimit.c line 62
Quoted 10 lines
lib/ratelimit.c +4
-4- rs->missed++; - ret =0 ; +if (atomic_cmpxchg (&rs->printed, rs->burst,0 )) +ratelimit_end_interval (rs, func); } -raw_spin_unlock_irqrestore (&rs->lock, flags); -return ret; +if (atomic_add_unless (&rs->printed,1 , rs->burst)) +return 1 ;
The entire logic is complicated and hard to understand. Especially calling ratelimit_end_interval() and atomic_add_unless(&rs->printed) twice.
lib/ratelimit.c line 67
Quoted 4 lines
lib/ratelimit.c +3
-0+atomic_add_unless (&rs->missed,1 ,-1 ); + +return 0 ; }
I wonder if the following code would do the job (not even compile tested!):
static void ratelimit_end_interval(struct ratelimit_state *rs, const char *func)
{
rs->begin = jiffies;
if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) {
unsigned int missed = atomic_xchg(&rs->missed, 0);
if (missed)
pr_warn("%s: %u callbacks suppressed\n", func, missed);
}
atomic_xchg(&rs->printed, 0);
}/*
* __ratelimit - rate limiting
* @rs: ratelimit_state data
* @func: name of calling function
*
* This enforces a rate limit: not more than @rs->burst callbacks
* in every @rs->interval
*
* RETURNS:
* 0 means callbacks will be suppressed.
* 1 means go ahead and do it.
*/
int ___ratelimit(struct ratelimit_state *rs, const char *func)
{
unsigned long begin, old_begin = rs->begin;
if (!rs->interval)
return 1;
if (time_is_before_jiffies(rs->begin + rs->interval) &&
cmpxchg(&rs->begin, begin, begin + rs->interval) == begin) {
ratelimit_end_interval(rs, func);
}
if (atomic_add_unless(&rs->printed, 1, rs->burst))
return 1;
atomic_add_unless(&rs->missed, 1, -1);
return 0;
}EXPORT_SYMBOL(___ratelimit);
The main logic is the same as in the original code. Only one CPU is able to reset the interval and counters (thanks to cmpxchg). Every caller increases either "printed" or "missed" counter.
Best Regards,
Petr
Hi Petr, thanks for review,
Quoted 36 lines · Petr Mladek
Quoted 24 lines · Dmitry Safonov
Currently
ratelimit_stateis protected withspin_lock. If the .lock is
taken at the moment of___ratelimit()call, the message is suppressed to
make ratelimiting robust.That results in the following issue issue:
CPU0 CPU1
------------------ ------------------printk_ratelimit()printk_ratelimit()| | try_spin_lock() try_spin_lock() | | time_is_before_jiffies() return 0; // suppressSo, concurrent call of
___ratelimit()results in silently suppressing
one of the messages, regardless if the limit is reached or not. Andrc->missedis not increased in such case so the issue is covered
from user.Convert ratelimiting to use atomic counters and drop
spin_lock.Quoted 10 lines
Note: That might be unexpected, but with the first interval of messages
storm one can print up to burst*2 messages. So, it doesn't guarantee
that in *any* interval amount of messages is lesser than burst. But, that differs lightly from previous behavior where one can start
burst=5 interval and print 4 messages on the last milliseconds of interval + new 5 messages from new interval (totally 9 messages in lesser than interval value):
Quoted 2 lines
I am still confused by this paragraph. Does this patch change the behavior? What is the original and what is the new one, please?
Yeah, I could be a bit cleaner about the change.
Originally more than burst messages could be printed if the previous period hasn't ended:
Quoted 7 lines
Quoted 7 lines
msg0 msg1-msg4 msg0-msg4
| | | | | | |--o---------------------o-|-----o--------------------|--> (t)<------->
Lesser than burst
But now, because I check:
+ if (atomic_add_unless(&rs->printed, 1, rs->burst))
+ return 1;
*before* checking the end of interval, the maximum number of messages in the peak will be the same, burst*2 (burst*2 - 1 in original). Why do I check it before the end of interval?
I thought it would be a nice optimization, making atomic_add_unless() the only called function on the fast-path (when we haven't hit the limit yet). If you want, I can move it into a separate patch..
Quoted 51 lines
Quoted 51 lines
Dropped dev/random patch since v1 version:
lkml.kernel.org/r/<[email protected]>Dropped `name' in as it's unused in
RATELIMIT_STATE_INIT()lib/ratelimit.c +12
-0@@ -13,6 +13,18 @@#include <linux/jiffies.h> #include <linux/export.h> +static void ratelimit_end_interval (struct ratelimit_state *rs,const char *func) +{ + rs->begin = jiffies; + +if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE )) { +unsigned int missed =atomic_xchg (&rs->missed,0 ); + +if (missed) +pr_warn ("%s: %u callbacks suppressed\n" , func, missed); + } +} +/* *
__ratelimit- rate limiting
* @rs:ratelimit_statedatalib/ratelimit.c +3
-10@@ -27,45 +39,30 @@*/ int ___ratelimit (struct ratelimit_state *rs,const char *func) { -unsigned long flags; -int ret; -if (!rs->interval)return 1 ; -/* -* If we contend on this state's lock then almost -* by definition we are too busy to print a message, -* in addition to the one that will be printed by -* the entity that is holding the lock already: -*/ -if (!raw_spin_trylock_irqsave (&rs->lock, flags)) +if (unlikely (!rs->burst)) { +atomic_add_unless (&rs->missed,1 ,-1 ); + if (time_is_before_jiffies(rs->begin + rs-
Quoted 8 lines
lib/ratelimit.c line 49
Quoted 2 lines
lib/ratelimit.c +1
-0>interval)) +ratelimit_end_interval (rs ,func );This is racy.
time_is_before_jiffies()might be valid on two CPUs in parallel. They would both callratelimit_end_interval(). This is not longer atomic context. Therefore one might get scheduled and setrs->begin= jiffies seconds later. I am sure that there might be more crazy scenarios.
That's the case with rs->burst == 0.
So, in this situation all the messages will be suppressed. And the only reason to call ratelimit_end_interval() is to update the start time and number of messages not printed.
I didn't want to add any complexion for this case - the worst will be the count of messages suppressed will be imprecise for rs->burst == 0 case. Not a big deal, huh?
Quoted 35 lines
Quoted 35 lines
lib/ratelimit.c +6
-20+return 0 ; + } -if (!rs->begin) - rs->begin = jiffies; +if (atomic_add_unless (&rs->printed,1 , rs->burst)) +return 1 ;if (time_is_before_jiffies (rs->begin + rs->interval)) { -if (rs->missed) { -if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) { -printk_deferred (KERN_WARNING -"%s: %d callbacks suppressed\n", - func, rs->missed); - rs->missed =0 ; - } - } - rs->begin = jiffies; - rs->printed =0 ; - } -if (rs->burst && rs->burst > rs->printed) { - rs->printed++; - ret =1 ; - }else { - rs->missed++; - ret =0 ; + if (atomic_cmpxchg(&rs->printed, rs->burst, 0)) + ratelimit_end_interval(rs, func); } -raw_spin_unlock_irqrestore (&rs->lock, flags);
Quoted 7 lines
lib/ratelimit.c line 62
Quoted 3 lines
lib/ratelimit.c +2
-1-return ret; +if (atomic_add_unless (&rs->printed,1 , rs->burst)) +return 1 ;The entire logic is complicated and hard to understand. Especially calling
ratelimit_end_interval()andatomic_add_unless(&rs->printed)twice.
Probably, I've described the reasons above.. I may add a comment or drop the first atomic_add_unless(), but I would prefer still keep it there, having only one check for fast-path.
Quoted 39 lines
lib/ratelimit.c line 67
Quoted 5 lines
lib/ratelimit.c +3
-0+atomic_add_unless (&rs->missed,1 ,-1 ); + +return 0 ; }I wonder if the following code would do the job (not even compile tested!):
static void
ratelimit_end_interval(struct ratelimit_state *rs, const char *func){ rs->begin = jiffies; if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) { unsigned int missed = atomic_xchg(&rs->missed, 0); if (missed) pr_warn("%s: %u callbacks suppressed\n", func, missed); } atomic_xchg(&rs->printed, 0); }/*
*__ratelimit- rate limiting
* @rs:ratelimit_statedata
* @func: name of calling function
*
* This enforces a rate limit: not more than @rs->burst callbacks
* in every @rs->interval
*
* RETURNS:
* 0 means callbacks will be suppressed.
* 1 means go ahead and do it.
*/
int___ratelimit(struct ratelimit_state *rs, const char *func)
Quoted 8 lines
{
unsigned long begin, old_begin = rs->begin;
if (!rs->interval)
return 1;
if (time_is_before_jiffies(rs->begin + rs->interval) &&
cmpxchg(&rs->begin, begin, begin + rs->interval) == begin) Probably, cmpxchg(&rs->begin, begin, jiffies)? Otherwise hitting it later will be buggy.
Also begin might be uninitialized? (if cmpxchg() fails)
Quoted 10 lines
{
ratelimit_end_interval(rs, func);
}
if (atomic_add_unless(&rs->printed, 1, rs->burst))
return 1;
atomic_add_unless(&rs->missed, 1, -1);
return 0;
}Quoted 6 lines
EXPORT_SYMBOL(___ratelimit);The main logic is the same as in the original code. Only one CPU is able to reset the interval and counters (thanks to cmpxchg). Every caller increases either "printed" or "missed" counter.
Do we care about fast-path argument I did above?
Signature · 6 lines
Thanks,
Dmitry
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfxQuoted 39 lines · Dmitry Safonov
Hi Petr, thanks for review,
Quoted 36 lines · Petr Mladek
Quoted 34 lines · Dmitry Safonov
Currently
ratelimit_stateis protected withspin_lock. If the .lock is
taken at the moment of___ratelimit()call, the message is suppressed to
make ratelimiting robust.That results in the following issue issue:
CPU0 CPU1
------------------ ------------------printk_ratelimit()printk_ratelimit()| | try_spin_lock() try_spin_lock() | | time_is_before_jiffies() return 0; // suppressSo, concurrent call of
___ratelimit()results in silently suppressing
one of the messages, regardless if the limit is reached or not. Andrc->missedis not increased in such case so the issue is covered
from user.Convert ratelimiting to use atomic counters and drop
spin_lock.Note: That might be unexpected, but with the first interval of messages
storm one can print up to burst*2 messages. So, it doesn't guarantee
that in *any* interval amount of messages is lesser than burst. But, that differs lightly from previous behavior where one can start
burst=5 interval and print 4 messages on the last milliseconds of interval + new 5 messages from new interval (totally 9 messages in lesser than interval value):
Quoted 6 lines
Quoted 2 lines
I am still confused by this paragraph. Does this patch change the behavior? What is the original and what is the new one, please?
Yeah, I could be a bit cleaner about the change.
Originally more thanburstmessages could be printed if the previous period hasn't ended:
I am even more confused now. What do you mean by "if the previous period hasn't ended"?
I do not see any way how more than 'burst' messages might be printed between upating rs->begin.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
msg0 msg1-msg4 msg0-msg4
| | | | | | |--o---------------------o-|-----o--------------------|--> (t)<------->
Lesser than burst
s/Lesser than burst/Lesser than rs->period/ ?
Quoted 7 lines
But now, because I check:
(quoted diff) +2
-0+ if (atomic_add_unless(&rs->printed, 1, rs->burst)) + return 1;*before* checking the end of interval, the maximum number of *messages in the peak will be the same, burst*2 (burst*2 - 1 in original).
This paragraph is very confusing as well. It says that the number of messages will be the "same". Then it mentions burst*2 vs. burst*2 - 1. What means the word "same"?
I understand that with the old code you might see "burst*2 -1" messages within rc->period time frame when they are printed close around updating rs->begin.
But I do not see how it might be "burst*2" with the new code. rs->begin must never be updated faster than rs->period. And rs->begin is always updated together with rs->printed. I mean that the first msg0 is always printed at the very beginning of the interval and therefore far from the end. Or do I miss anything?
Quoted 4 lines
Why do I check it before the end of interval?
I thought it would be a nice optimization, makingatomic_add_unless()the only called function on the fast-path (when we haven't hit the limit yet). If you want, I can move it into a separate patch..
ratelimit is basically used together with printk() that is a slow path. Your optimization is not worth the complexity.
And this brings me to the question what is the motivation for this patch, please? Did you have a real life problem with the original behavior?
The main purpose of the function is to reduce the amount of duplicated messages that would mess the log, overload consoles and do not help anything. It is used in situations where it is expected that some messages might get lost.
It might make sense to fix rc->missed counter and also make sure that always the first Nth < burst messages will get printed but only when the code stays readable.
Quoted 59 lines
Quoted 50 lines
Quoted 50 lines
Dropped dev/random patch since v1 version:
lkml.kernel.org/r/<[email protected]>Dropped `name' in as it's unused in
RATELIMIT_STATE_INIT()lib/ratelimit.c +12
-0@@ -13,6 +13,18 @@#include <linux/jiffies.h> #include <linux/export.h> +static void ratelimit_end_interval (struct ratelimit_state *rs,const char *func) +{ + rs->begin = jiffies; + +if (!(rs->flags &RATELIMIT_MSG_ON_RELEASE )) { +unsigned int missed =atomic_xchg (&rs->missed,0 ); + +if (missed) +pr_warn ("%s: %u callbacks suppressed\n" , func, missed); + } +} +/* *
__ratelimit- rate limiting
* @rs:ratelimit_statedatalib/ratelimit.c +3
-10@@ -27,45 +39,30 @@*/ int ___ratelimit (struct ratelimit_state *rs,const char *func) { -unsigned long flags; -int ret; -if (!rs->interval)return 1 ; -/* -* If we contend on this state's lock then almost -* by definition we are too busy to print a message, -* in addition to the one that will be printed by -* the entity that is holding the lock already: -*/ -if (!raw_spin_trylock_irqsave (&rs->lock, flags)) +if (unlikely (!rs->burst)) { +atomic_add_unless (&rs->missed,1 ,-1 ); + if (time_is_before_jiffies(rs->begin + rs-Quoted 8 lines
lib/ratelimit.c line 49
Quoted 2 lines
lib/ratelimit.c +1
-0>interval)) +ratelimit_end_interval (rs ,func );This is racy.
time_is_before_jiffies()might be valid on two CPUs in parallel. They would both callratelimit_end_interval(). This is not longer atomic context. Therefore one might get scheduled and setrs->begin= jiffies seconds later. I am sure that there might be more crazy scenarios.
Quoted 7 lines
That's the case with
rs->burst== 0.
So, in this situation all the messages will be suppressed. And the only reason to callratelimit_end_interval()is to update the start time and number of messages not printed.
I didn't want to add any complexion for this case - the worst will be the count of messages suppressed will be imprecise forrs->burst== 0 case. Not a big deal, huh?
Ah, I see, I have missed the check !rs->burst. Well, it does not make much sense to use this value in the real life. IMHO, it is not worth any optimization and extra code complexity if the rest of the code might handle this situation correctly.
Quoted 38 lines
Quoted 38 lines
I wonder if the following code would do the job (not even compile tested!):
static void
ratelimit_end_interval(struct ratelimit_state *rs, const char *func){ rs->begin = jiffies; if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) { unsigned int missed = atomic_xchg(&rs->missed, 0); if (missed) pr_warn("%s: %u callbacks suppressed\n", func, missed); } atomic_xchg(&rs->printed, 0); }/*
*__ratelimit- rate limiting
* @rs:ratelimit_statedata
* @func: name of calling function
*
* This enforces a rate limit: not more than @rs->burst callbacks
* in every @rs->interval
*
* RETURNS:
* 0 means callbacks will be suppressed.
* 1 means go ahead and do it.
*/
int___ratelimit(struct ratelimit_state *rs, const char *func){ unsigned long begin, old_begin = rs->begin; if (!rs->interval) return 1;
Quoted 6 lines
Quoted 2 lines
if (time_is_before_jiffies(rs->begin + rs->interval) && cmpxchg(&rs->begin, begin, begin + rs->interval) == begin)Probably,
cmpxchg(&rs->begin, begin, jiffies)? Otherwise hitting it later will be buggy.
Alsobeginmight be uninitialized? (ifcmpxchg()fails)
Yup, I messed this a bit. We could remove begin variable and use:
cmpxchg(&rs->begin, old_begin, jiffies)
Best Regards,
Petr