Skip to content

Commit 96017bf

Browse files
committed
rcu-tasks: Simplify trc_read_check_handler() atomic operations
Currently, trc_wait_for_one_reader() atomically increments the trc_n_readers_need_end counter before sending the IPI invoking trc_read_check_handler(). All failure paths out of trc_read_check_handler() and also from the smp_call_function_single() within trc_wait_for_one_reader() must carefully atomically decrement this counter. This is more complex than it needs to be. This commit therefore simplifies things and saves a few lines of code by dispensing with the atomic decrements in favor of having trc_read_check_handler() do the atomic increment only in the success case. In theory, this represents no change in functionality. Signed-off-by: Paul E. McKenney <[email protected]>
1 parent cbe0d8d commit 96017bf

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

kernel/rcu/tasks.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -890,32 +890,24 @@ static void trc_read_check_handler(void *t_in)
890890

891891
// If the task is no longer running on this CPU, leave.
892892
if (unlikely(texp != t)) {
893-
if (WARN_ON_ONCE(atomic_dec_and_test(&trc_n_readers_need_end)))
894-
wake_up(&trc_wait);
895893
goto reset_ipi; // Already on holdout list, so will check later.
896894
}
897895

898896
// If the task is not in a read-side critical section, and
899897
// if this is the last reader, awaken the grace-period kthread.
900898
if (likely(!READ_ONCE(t->trc_reader_nesting))) {
901-
if (WARN_ON_ONCE(atomic_dec_and_test(&trc_n_readers_need_end)))
902-
wake_up(&trc_wait);
903-
// Mark as checked after decrement to avoid false
904-
// positives on the above WARN_ON_ONCE().
905899
WRITE_ONCE(t->trc_reader_checked, true);
906900
goto reset_ipi;
907901
}
908902
// If we are racing with an rcu_read_unlock_trace(), try again later.
909-
if (unlikely(READ_ONCE(t->trc_reader_nesting) < 0)) {
910-
if (WARN_ON_ONCE(atomic_dec_and_test(&trc_n_readers_need_end)))
911-
wake_up(&trc_wait);
903+
if (unlikely(READ_ONCE(t->trc_reader_nesting) < 0))
912904
goto reset_ipi;
913-
}
914905
WRITE_ONCE(t->trc_reader_checked, true);
915906

916907
// Get here if the task is in a read-side critical section. Set
917908
// its state so that it will awaken the grace-period kthread upon
918909
// exit from that critical section.
910+
atomic_inc(&trc_n_readers_need_end); // One more to wait on.
919911
WARN_ON_ONCE(READ_ONCE(t->trc_reader_special.b.need_qs));
920912
WRITE_ONCE(t->trc_reader_special.b.need_qs, true);
921913

@@ -1015,21 +1007,15 @@ static void trc_wait_for_one_reader(struct task_struct *t,
10151007
if (per_cpu(trc_ipi_to_cpu, cpu) || t->trc_ipi_to_cpu >= 0)
10161008
return;
10171009

1018-
atomic_inc(&trc_n_readers_need_end);
10191010
per_cpu(trc_ipi_to_cpu, cpu) = true;
10201011
t->trc_ipi_to_cpu = cpu;
10211012
rcu_tasks_trace.n_ipis++;
1022-
if (smp_call_function_single(cpu,
1023-
trc_read_check_handler, t, 0)) {
1013+
if (smp_call_function_single(cpu, trc_read_check_handler, t, 0)) {
10241014
// Just in case there is some other reason for
10251015
// failure than the target CPU being offline.
10261016
rcu_tasks_trace.n_ipis_fails++;
10271017
per_cpu(trc_ipi_to_cpu, cpu) = false;
10281018
t->trc_ipi_to_cpu = cpu;
1029-
if (atomic_dec_and_test(&trc_n_readers_need_end)) {
1030-
WARN_ON_ONCE(1);
1031-
wake_up(&trc_wait);
1032-
}
10331019
}
10341020
}
10351021
}

0 commit comments

Comments
 (0)