Skip to content

Commit 300df91

Browse files
Paul E. McKenneypaulmck
authored andcommitted
rcu: Event-trace markers for computing RCU CPU utilization
This commit adds the trace_rcu_utilization() marker that is to be used to allow postprocessing scripts compute RCU's CPU utilization, give or take event-trace overhead. Note that we do not include RCU's dyntick-idle interface because event tracing requires RCU protection, which is not available in dyntick-idle mode. Signed-off-by: Paul E. McKenney <paul.mckenney@linaro.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 29c00b4 commit 300df91

2 files changed

Lines changed: 68 additions & 21 deletions

File tree

‎include/trace/events/rcu.h‎

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,58 @@
77
#include <linux/tracepoint.h>
88

99
/*
10-
* Tracepoint for calling rcu_do_batch, performed to start callback invocation:
10+
* Tracepoint for start/end markers used for utilization calculations.
11+
* By convention, the string is of the following forms:
12+
*
13+
* "Start <activity>" -- Mark the start of the specified activity,
14+
* such as "context switch". Nesting is permitted.
15+
* "End <activity>" -- Mark the end of the specified activity.
16+
*/
17+
TRACE_EVENT(rcu_utilization,
18+
19+
TP_PROTO(char *s),
20+
21+
TP_ARGS(s),
22+
23+
TP_STRUCT__entry(
24+
__field(char *, s)
25+
),
26+
27+
TP_fast_assign(
28+
__entry->s = s;
29+
),
30+
31+
TP_printk("%s", __entry->s)
32+
);
33+
34+
/*
35+
* Tracepoint for marking the beginning rcu_do_batch, performed to start
36+
* RCU callback invocation. The first argument is the total number of
37+
* callbacks (including those that are not yet ready to be invoked),
38+
* and the second argument is the current RCU-callback batch limit.
1139
*/
1240
TRACE_EVENT(rcu_batch_start,
1341

14-
TP_PROTO(long callbacks_ready, int blimit),
42+
TP_PROTO(long qlen, int blimit),
1543

16-
TP_ARGS(callbacks_ready, blimit),
44+
TP_ARGS(qlen, blimit),
1745

1846
TP_STRUCT__entry(
19-
__field( long, callbacks_ready )
20-
__field( int, blimit )
47+
__field(long, qlen)
48+
__field(int, blimit)
2149
),
2250

2351
TP_fast_assign(
24-
__entry->callbacks_ready = callbacks_ready;
25-
__entry->blimit = blimit;
52+
__entry->qlen = qlen;
53+
__entry->blimit = blimit;
2654
),
2755

28-
TP_printk("CBs=%ld bl=%d", __entry->callbacks_ready, __entry->blimit)
56+
TP_printk("CBs=%ld bl=%d", __entry->qlen, __entry->blimit)
2957
);
3058

3159
/*
32-
* Tracepoint for the invocation of a single RCU callback
60+
* Tracepoint for the invocation of a single RCU callback function.
61+
* The argument is a pointer to the RCU callback itself.
3362
*/
3463
TRACE_EVENT(rcu_invoke_callback,
3564

@@ -38,20 +67,23 @@ TRACE_EVENT(rcu_invoke_callback,
3867
TP_ARGS(rhp),
3968

4069
TP_STRUCT__entry(
41-
__field( void *, rhp )
42-
__field( void *, func )
70+
__field(void *, rhp)
71+
__field(void *, func)
4372
),
4473

4574
TP_fast_assign(
46-
__entry->rhp = rhp;
47-
__entry->func = rhp->func;
75+
__entry->rhp = rhp;
76+
__entry->func = rhp->func;
4877
),
4978

5079
TP_printk("rhp=%p func=%pf", __entry->rhp, __entry->func)
5180
);
5281

5382
/*
54-
* Tracepoint for the invocation of a single RCU kfree callback
83+
* Tracepoint for the invocation of a single RCU callback of the special
84+
* kfree() form. The first argument is a pointer to the RCU callback
85+
* and the second argument is the offset of the callback within the
86+
* enclosing RCU-protected data structure.
5587
*/
5688
TRACE_EVENT(rcu_invoke_kfree_callback,
5789

@@ -60,20 +92,21 @@ TRACE_EVENT(rcu_invoke_kfree_callback,
6092
TP_ARGS(rhp, offset),
6193

6294
TP_STRUCT__entry(
63-
__field(void *, rhp )
64-
__field(unsigned long, offset )
95+
__field(void *, rhp)
96+
__field(unsigned long, offset)
6597
),
6698

6799
TP_fast_assign(
68-
__entry->rhp = rhp;
100+
__entry->rhp = rhp;
69101
__entry->offset = offset;
70102
),
71103

72104
TP_printk("rhp=%p func=%ld", __entry->rhp, __entry->offset)
73105
);
74106

75107
/*
76-
* Tracepoint for leaving rcu_do_batch, performed after callback invocation:
108+
* Tracepoint for exiting rcu_do_batch after RCU callbacks have been
109+
* invoked. The first argument is the number of callbacks actually invoked.
77110
*/
78111
TRACE_EVENT(rcu_batch_end,
79112

@@ -82,11 +115,11 @@ TRACE_EVENT(rcu_batch_end,
82115
TP_ARGS(callbacks_invoked),
83116

84117
TP_STRUCT__entry(
85-
__field( int, callbacks_invoked )
118+
__field(int, callbacks_invoked)
86119
),
87120

88121
TP_fast_assign(
89-
__entry->callbacks_invoked = callbacks_invoked;
122+
__entry->callbacks_invoked = callbacks_invoked;
90123
),
91124

92125
TP_printk("CBs-invoked=%d", __entry->callbacks_invoked)

‎kernel/rcutree.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ void rcu_bh_qs(int cpu)
184184
*/
185185
void rcu_note_context_switch(int cpu)
186186
{
187+
trace_rcu_utilization("Start context switch");
187188
rcu_sched_qs(cpu);
188189
rcu_preempt_note_context_switch(cpu);
190+
trace_rcu_utilization("End context switch");
189191
}
190192
EXPORT_SYMBOL_GPL(rcu_note_context_switch);
191193

@@ -1275,6 +1277,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
12751277
*/
12761278
void rcu_check_callbacks(int cpu, int user)
12771279
{
1280+
trace_rcu_utilization("Start scheduler-tick");
12781281
if (user ||
12791282
(idle_cpu(cpu) && rcu_scheduler_active &&
12801283
!in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) {
@@ -1308,6 +1311,7 @@ void rcu_check_callbacks(int cpu, int user)
13081311
rcu_preempt_check_callbacks(cpu);
13091312
if (rcu_pending(cpu))
13101313
invoke_rcu_core();
1314+
trace_rcu_utilization("End scheduler-tick");
13111315
}
13121316

13131317
#ifdef CONFIG_SMP
@@ -1369,10 +1373,14 @@ static void force_quiescent_state(struct rcu_state *rsp, int relaxed)
13691373
unsigned long flags;
13701374
struct rcu_node *rnp = rcu_get_root(rsp);
13711375

1372-
if (!rcu_gp_in_progress(rsp))
1376+
trace_rcu_utilization("Start fqs");
1377+
if (!rcu_gp_in_progress(rsp)) {
1378+
trace_rcu_utilization("End fqs");
13731379
return; /* No grace period in progress, nothing to force. */
1380+
}
13741381
if (!raw_spin_trylock_irqsave(&rsp->fqslock, flags)) {
13751382
rsp->n_force_qs_lh++; /* Inexact, can lose counts. Tough! */
1383+
trace_rcu_utilization("End fqs");
13761384
return; /* Someone else is already on the job. */
13771385
}
13781386
if (relaxed && ULONG_CMP_GE(rsp->jiffies_force_qs, jiffies))
@@ -1421,11 +1429,13 @@ static void force_quiescent_state(struct rcu_state *rsp, int relaxed)
14211429
raw_spin_unlock(&rsp->fqslock); /* irqs remain disabled */
14221430
rsp->fqs_need_gp = 0;
14231431
rcu_start_gp(rsp, flags); /* releases rnp->lock */
1432+
trace_rcu_utilization("End fqs");
14241433
return;
14251434
}
14261435
raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
14271436
unlock_fqs_ret:
14281437
raw_spin_unlock_irqrestore(&rsp->fqslock, flags);
1438+
trace_rcu_utilization("End fqs");
14291439
}
14301440

14311441
#else /* #ifdef CONFIG_SMP */
@@ -1481,13 +1491,15 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
14811491
*/
14821492
static void rcu_process_callbacks(struct softirq_action *unused)
14831493
{
1494+
trace_rcu_utilization("Start RCU core");
14841495
__rcu_process_callbacks(&rcu_sched_state,
14851496
&__get_cpu_var(rcu_sched_data));
14861497
__rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data));
14871498
rcu_preempt_process_callbacks();
14881499

14891500
/* If we are last CPU on way to dyntick-idle mode, accelerate it. */
14901501
rcu_needs_cpu_flush();
1502+
trace_rcu_utilization("End RCU core");
14911503
}
14921504

14931505
/*
@@ -1910,6 +1922,7 @@ static int __cpuinit rcu_cpu_notify(struct notifier_block *self,
19101922
struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, cpu);
19111923
struct rcu_node *rnp = rdp->mynode;
19121924

1925+
trace_rcu_utilization("Start CPU hotplug");
19131926
switch (action) {
19141927
case CPU_UP_PREPARE:
19151928
case CPU_UP_PREPARE_FROZEN:
@@ -1945,6 +1958,7 @@ static int __cpuinit rcu_cpu_notify(struct notifier_block *self,
19451958
default:
19461959
break;
19471960
}
1961+
trace_rcu_utilization("End CPU hotplug");
19481962
return NOTIFY_OK;
19491963
}
19501964

0 commit comments

Comments
 (0)