Add defer_rcu_ratelimit()
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Fri, 23 Oct 2009 12:17:29 +0000 (08:17 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Fri, 23 Oct 2009 12:17:29 +0000 (08:17 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
README
urcu-defer.c
urcu-defer.h

diff --git a/README b/README
index ecdda633e20fe3f6fa772a90644b99b2f302ea3b..e1ce893737acd0d4d79260462f6383ff45a05c42 100644 (file)
--- a/README
+++ b/README
@@ -104,6 +104,9 @@ Usage of liburcu-defer
          callbacks are executed in batch periodically after a grace period.
          Do _not_ use defer_rcu() within a read-side critical section, because
          it may call synchronize_rcu() if the thread queue is full.
+       * Provides defer_rcu_ratelimit() primitive, which acts just like
+         defer_rcu(), but takes an additional rate limiter callback forcing
+         synchronized callback execution of the limiter returns non-zero.
 
 Being careful with signals
 
index dd570713ee8234a82fa80208f612565c5028c112..3cc1a0c0b32b9132673b47a361ea116f9a8bf338 100644 (file)
@@ -232,9 +232,15 @@ end:
 /*
  * _defer_rcu - Queue a RCU callback.
  */
-void _defer_rcu(void (*fct)(void *p), void *p)
+void _defer_rcu_ratelimit(void (*fct)(void *p), void *p, int (*rl)(void *p))
 {
        unsigned long head, tail;
+       int sync;
+
+       /*
+        * Verify if we reached the rate limiter threshold.
+        */
+       sync = rl ? rl(p) : 0;
 
        /*
         * Head is only modified by ourself. Tail can be modified by reclamation
@@ -244,10 +250,10 @@ void _defer_rcu(void (*fct)(void *p), void *p)
        tail = LOAD_SHARED(defer_queue.tail);
 
        /*
-        * If queue is full, empty it ourself.
+        * If queue is full, or reached threshold. Empty queue ourself.
         * Worse-case: must allow 2 supplementary entries for fct pointer.
         */
-       if (unlikely(head - tail >= DEFER_QUEUE_SIZE - 2)) {
+       if (unlikely(sync || (head - tail >= DEFER_QUEUE_SIZE - 2))) {
                assert(head - tail <= DEFER_QUEUE_SIZE);
                rcu_defer_barrier_thread();
                assert(head - LOAD_SHARED(defer_queue.tail) == 0);
@@ -315,9 +321,9 @@ void *thr_defer(void *args)
  * library wrappers to be used by non-LGPL compatible source code.
  */
 
-void defer_rcu(void (*fct)(void *p), void *p)
+void defer_rcu_ratelimit(void (*fct)(void *p), void *p, int (*rl)(void *p))
 {
-       _defer_rcu(fct, p);
+       _defer_rcu_ratelimit(fct, p, rl);
 }
 
 static void start_defer_thread(void)
index 9fdaf1863b038e44ac6637e133dfbd4c5284f957..75b600568bc7a2df852cb246e1a300732c6989b8 100644 (file)
  * primitive need to call synchronize_rcu() if the thread queue is full.
  */
 
-#define rcu_reclaim_queue(p)   defer_rcu(free, p)
+#define defer_rcu(fct, p)      defer_rcu_ratelimit(fct, p, NULL)
 
-extern void defer_rcu(void (*fct)(void *p), void *p);
+extern void defer_rcu_ratelimit(void (*fct)(void *p), void *p,
+                               int (*rl)(void *p));
 
 /*
  * Thread registration for reclamation.
This page took 0.026725 seconds and 4 git commands to generate.