rcu/tree: Add a trace event for RCU CPU stall warnings
authorSangmoon Kim <sangmoon.kim@samsung.com>
Tue, 2 Mar 2021 11:55:15 +0000 (20:55 +0900)
committerPaul E. McKenney <paulmck@kernel.org>
Mon, 15 Mar 2021 20:53:24 +0000 (13:53 -0700)
This commit adds a trace event which allows tracing the beginnings of RCU
CPU stall warnings on systems where sysctl_panic_on_rcu_stall is disabled.

The first parameter is the name of RCU flavor like other trace events.
The second parameter indicates whether this is a stall of an expedited
grace period, a self-detected stall of a normal grace period, or a stall
of a normal grace period detected by some CPU other than the one that
is stalled.

RCU CPU stall warnings are often caused by external-to-RCU issues,
for example, in interrupt handling or task scheduling.  Therefore,
this event uses TRACE_EVENT, not TRACE_EVENT_RCU, to avoid requiring
those interested in tracing RCU CPU stalls to rebuild their kernels
with CONFIG_RCU_TRACE=y.

Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Reviewed-by: Neeraj Upadhyay <neeraju@codeaurora.org>
Signed-off-by: Sangmoon Kim <sangmoon.kim@samsung.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
include/trace/events/rcu.h
kernel/rcu/tree_exp.h
kernel/rcu/tree_stall.h

index 5fc29400e1a2dede2212b503b95ecba533cee654..c7711e9b6900545e9b389caef647dbf32f55cdc7 100644 (file)
@@ -432,6 +432,34 @@ TRACE_EVENT_RCU(rcu_fqs,
                  __entry->cpu, __entry->qsevent)
 );
 
+/*
+ * Tracepoint for RCU stall events. Takes a string identifying the RCU flavor
+ * and a string identifying which function detected the RCU stall as follows:
+ *
+ *     "StallDetected": Scheduler-tick detects other CPU's stalls.
+ *     "SelfDetected": Scheduler-tick detects a current CPU's stall.
+ *     "ExpeditedStall": Expedited grace period detects stalls.
+ */
+TRACE_EVENT(rcu_stall_warning,
+
+       TP_PROTO(const char *rcuname, const char *msg),
+
+       TP_ARGS(rcuname, msg),
+
+       TP_STRUCT__entry(
+               __field(const char *, rcuname)
+               __field(const char *, msg)
+       ),
+
+       TP_fast_assign(
+               __entry->rcuname = rcuname;
+               __entry->msg = msg;
+       ),
+
+       TP_printk("%s %s",
+                 __entry->rcuname, __entry->msg)
+);
+
 #endif /* #if defined(CONFIG_TREE_RCU) */
 
 /*
index 6c6ff06d4ae653586e8114ed1444e99877aaf705..2796084ef85a5d7f77b1ff6da9f198708da114aa 100644 (file)
@@ -521,6 +521,7 @@ static void synchronize_rcu_expedited_wait(void)
                if (rcu_stall_is_suppressed())
                        continue;
                panic_on_rcu_stall();
+               trace_rcu_stall_warning(rcu_state.name, TPS("ExpeditedStall"));
                pr_err("INFO: %s detected expedited stalls on CPUs/tasks: {",
                       rcu_state.name);
                ndetected = 0;
index 475b26171b20fff053842f265fc5b1dc2d7fcd17..59b95cc5cbdf112345519c9bb39a6dd3c64e1ee5 100644 (file)
@@ -536,6 +536,7 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
         * See Documentation/RCU/stallwarn.rst for info on how to debug
         * RCU CPU stall warnings.
         */
+       trace_rcu_stall_warning(rcu_state.name, TPS("StallDetected"));
        pr_err("INFO: %s detected stalls on CPUs/tasks:\n", rcu_state.name);
        rcu_for_each_leaf_node(rnp) {
                raw_spin_lock_irqsave_rcu_node(rnp, flags);
@@ -606,6 +607,7 @@ static void print_cpu_stall(unsigned long gps)
         * See Documentation/RCU/stallwarn.rst for info on how to debug
         * RCU CPU stall warnings.
         */
+       trace_rcu_stall_warning(rcu_state.name, TPS("SelfDetected"));
        pr_err("INFO: %s self-detected stall on CPU\n", rcu_state.name);
        raw_spin_lock_irqsave_rcu_node(rdp->mynode, flags);
        print_cpu_stall_info(smp_processor_id());