History

rcu/tree: Make rcu_do_batch count how many callbacks were executed

The rcu_do_batch() function extracts the ready-to-invoke callbacks from the rcu_segcblist located in the ->cblist field of the current CPU's rcu_data structure. These callbacks are first moved to a local (unsegmented) rcu_cblist. The rcu_do_batch() function then uses this rcu_cblist's ->len field to count how many CBs it has invoked, but it does so by counting that field down from zero. Finally, this function negates the value in this ->len field (resulting in a positive number) and subtracts the result from the ->len field of the current CPU's ->cblist field. Except that it is sometimes necessary for rcu_do_batch() to stop invoking callbacks mid-stream, despite there being more ready to invoke, for example, if a high-priority task wakes up. In this case the remaining not-yet-invoked callbacks are requeued back onto the CPU's ->cblist, but remain in the ready-to-invoke segment of that list. As above, the negative of the local rcu_cblist's ->len field is still subtracted from the ->len field of the current CPU's ->cblist field. The design of counting down from 0 is confusing and error-prone, plus use of a positive count will make it easier to provide a uniform and consistent API to deal with the per-segment counts that are added later in this series. For example, rcu_segcblist_extract_done_cbs() can unconditionally populate the resulting unsegmented list's ->len field during extraction. This commit therefore explicitly counts how many callbacks were executed in rcu_do_batch() itself, counting up from zero, and then uses that to update the per-CPU segcb list's ->len field, without relying on the downcounting of rcl->len from zero.

Joel Fernandes (Google) committed 6 years ago

Commit 6bc33581 parent 5c8fe583 files · +7 −7Browse files

Unified · Split

3 files
  1. kernel/rcu/rcu_segcblist.c +1 −1
  2. kernel/rcu/rcu_segcblist.h +1 −0
  3. kernel/rcu/tree.c +5 −6
kernel/rcu/rcu_segcblist.c+1−1
@@ -95,7 +95,7 @@ static void rcu_segcblist_set_len(struct rcu_segcblist *rsclp, long v) · 94 unmodified lines
9595 * This increase is fully ordered with respect to the callers accesses
9696 * both before and after.
9797 */
98−static void rcu_segcblist_add_len(struct rcu_segcblist *rsclp, long v)
98+void rcu_segcblist_add_len(struct rcu_segcblist *rsclp, long v)
9999 {
100100 #ifdef CONFIG_RCU_NOCB_CPU
101101 smp_mb__before_atomic(); /* Up to the caller! */
kernel/rcu/rcu_segcblist.h+1−0
@@ -76,6 +76,7 @@ static inline bool rcu_segcblist_restempty(struct rcu_segcblist *rsclp, int seg) · 75 unmodified lines
7676 }
7777
7878 void rcu_segcblist_inc_len(struct rcu_segcblist *rsclp);
79+void rcu_segcblist_add_len(struct rcu_segcblist *rsclp, long v);
7980 void rcu_segcblist_init(struct rcu_segcblist *rsclp);
8081 void rcu_segcblist_disable(struct rcu_segcblist *rsclp);
8182 void rcu_segcblist_offload(struct rcu_segcblist *rsclp);
kernel/rcu/tree.c+5−6
@@ -2434,7 +2434,7 @@ static void rcu_do_batch(struct rcu_data *rdp) · 2433 unmodified lines
24342434 const bool offloaded = rcu_segcblist_is_offloaded(&rdp->cblist);
24352435 struct rcu_head *rhp;
24362436 struct rcu_cblist rcl = RCU_CBLIST_INITIALIZER(rcl);
2437− long bl, count;
2437+ long bl, count = 0;
24382438 long pending, tlimit = 0;
24392439
24402440 /* If no callbacks are ready, just return. */
@@ -2479,6 +2479,7 @@ static void rcu_do_batch(struct rcu_data *rdp) · 38 unmodified lines
24792479 for (; rhp; rhp = rcu_cblist_dequeue(&rcl)) {
24802480 rcu_callback_t f;
24812481
2482+ count++;
24822483 debug_rcu_head_unqueue(rhp);
24832484
24842485 rcu_lock_acquire(&rcu_callback_map);
@@ -2492,15 +2493,14 @@ static void rcu_do_batch(struct rcu_data *rdp) · 7 unmodified lines
24922493
24932494 /*
24942495 * Stop only if limit reached and CPU has something to do.
2495− * Note: The rcl structure counts down from zero.
24962496 */
2497− if (-rcl.len >= bl && !offloaded &&
2497+ if (count >= bl && !offloaded &&
24982498 (need_resched() ||
24992499 (!is_idle_task(current) && !rcu_is_callbacks_kthread())))
25002500 break;
25012501 if (unlikely(tlimit)) {
25022502 /* only call local_clock() every 32 callbacks */
2503− if (likely((-rcl.len & 31) || local_clock() < tlimit))
2503+ if (likely((count & 31) || local_clock() < tlimit))
25042504 continue;
25052505 /* Exceeded the time limit, so leave. */
25062506 break;
@@ -2517,7 +2517,6 @@ static void rcu_do_batch(struct rcu_data *rdp) · 10 unmodified lines
25172517
25182518 local_irq_save(flags);
25192519 rcu_nocb_lock(rdp);
2520− count = -rcl.len;
25212520 rdp->n_cbs_invoked += count;
25222521 trace_rcu_batch_end(rcu_state.name, count, !!rcl.head, need_resched(),
25232522 is_idle_task(current), rcu_is_callbacks_kthread());
@@ -2525,7 +2524,7 @@ static void rcu_do_batch(struct rcu_data *rdp) · 1 unmodified line
25252524 /* Update counts and requeue any remaining callbacks. */
25262525 rcu_segcblist_insert_done_cbs(&rdp->cblist, &rcl);
25272526 smp_mb(); /* List handling before counting for rcu_barrier(). */
2528− rcu_segcblist_insert_count(&rdp->cblist, &rcl);
2527+ rcu_segcblist_add_len(&rdp->cblist, -count);
25292528
25302529 /* Reinstate batch limit if we have worked down the excess. */
25312530 count = rcu_segcblist_n_cbs(&rdp->cblist);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t