Skip to content

Commit adcc3bf

Browse files
glemcorostedt
authored andcommitted
sched: Adapt sched tracepoints for RV task model
Add the following tracepoint: * sched_set_need_resched(tsk, cpu, tif) Called when a task is set the need resched [lazy] flag Remove the unused ip parameter from sched_entry and sched_exit and alter sched_entry to have a value of preempt consistent with the one used in sched_switch. Also adapt all monitors using sched_{entry,exit} to avoid breaking build. These tracepoints are useful to describe the Linux task model and are adapted from the patches by Daniel Bristot de Oliveira (https://bristot.me/linux-task-model/). Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Nam Cao <[email protected]> Cc: Tomas Glozar <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Clark Williams <[email protected]> Cc: John Kacur <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Gabriele Monaco <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 9d475d8 commit adcc3bf

File tree

8 files changed

+34
-18
lines changed

8 files changed

+34
-18
lines changed

include/linux/sched.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,11 @@ extern void io_schedule_finish(int token);
339339
extern long io_schedule_timeout(long timeout);
340340
extern void io_schedule(void);
341341

342-
/* wrapper function to trace from this header file */
342+
/* wrapper functions to trace from this header file */
343343
DECLARE_TRACEPOINT(sched_set_state_tp);
344344
extern void __trace_set_current_state(int state_value);
345+
DECLARE_TRACEPOINT(sched_set_need_resched_tp);
346+
extern void __trace_set_need_resched(struct task_struct *curr, int tif);
345347

346348
/**
347349
* struct prev_cputime - snapshot of system and user cputime
@@ -2063,6 +2065,9 @@ static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
20632065

20642066
static inline void set_tsk_need_resched(struct task_struct *tsk)
20652067
{
2068+
if (tracepoint_enabled(sched_set_need_resched_tp) &&
2069+
!test_tsk_thread_flag(tsk, TIF_NEED_RESCHED))
2070+
__trace_set_need_resched(tsk, TIF_NEED_RESCHED);
20662071
set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
20672072
}
20682073

include/trace/events/sched.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -882,18 +882,22 @@ DECLARE_TRACE(sched_compute_energy,
882882
TP_ARGS(p, dst_cpu, energy, max_util, busy_time));
883883

884884
DECLARE_TRACE(sched_entry,
885-
TP_PROTO(bool preempt, unsigned long ip),
886-
TP_ARGS(preempt, ip));
885+
TP_PROTO(bool preempt),
886+
TP_ARGS(preempt));
887887

888888
DECLARE_TRACE(sched_exit,
889-
TP_PROTO(bool is_switch, unsigned long ip),
890-
TP_ARGS(is_switch, ip));
889+
TP_PROTO(bool is_switch),
890+
TP_ARGS(is_switch));
891891

892892
DECLARE_TRACE_CONDITION(sched_set_state,
893893
TP_PROTO(struct task_struct *tsk, int state),
894894
TP_ARGS(tsk, state),
895895
TP_CONDITION(!!(tsk->__state) != !!state));
896896

897+
DECLARE_TRACE(sched_set_need_resched,
898+
TP_PROTO(struct task_struct *tsk, int cpu, int tif),
899+
TP_ARGS(tsk, cpu, tif));
900+
897901
#endif /* _TRACE_SCHED_H */
898902

899903
/* This part must be outside protection */

kernel/sched/core.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ static void __resched_curr(struct rq *rq, int tif)
11101110

11111111
cpu = cpu_of(rq);
11121112

1113+
trace_sched_set_need_resched_tp(curr, cpu, tif);
11131114
if (cpu == smp_processor_id()) {
11141115
set_ti_thread_flag(cti, tif);
11151116
if (tif == TIF_NEED_RESCHED)
@@ -1125,6 +1126,11 @@ static void __resched_curr(struct rq *rq, int tif)
11251126
}
11261127
}
11271128

1129+
void __trace_set_need_resched(struct task_struct *curr, int tif)
1130+
{
1131+
trace_sched_set_need_resched_tp(curr, smp_processor_id(), tif);
1132+
}
1133+
11281134
void resched_curr(struct rq *rq)
11291135
{
11301136
__resched_curr(rq, TIF_NEED_RESCHED);
@@ -5329,7 +5335,7 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev)
53295335
* switched the context for the first time. It is returning from
53305336
* schedule for the first time in this path.
53315337
*/
5332-
trace_sched_exit_tp(true, CALLER_ADDR0);
5338+
trace_sched_exit_tp(true);
53335339
preempt_enable();
53345340

53355341
if (current->set_child_tid)
@@ -6678,7 +6684,8 @@ static void __sched notrace __schedule(int sched_mode)
66786684
struct rq *rq;
66796685
int cpu;
66806686

6681-
trace_sched_entry_tp(preempt, CALLER_ADDR0);
6687+
/* Trace preemptions consistently with task switches */
6688+
trace_sched_entry_tp(sched_mode == SM_PREEMPT);
66826689

66836690
cpu = smp_processor_id();
66846691
rq = cpu_rq(cpu);
@@ -6793,7 +6800,7 @@ static void __sched notrace __schedule(int sched_mode)
67936800
__balance_callbacks(rq);
67946801
raw_spin_rq_unlock_irq(rq);
67956802
}
6796-
trace_sched_exit_tp(is_switch, CALLER_ADDR0);
6803+
trace_sched_exit_tp(is_switch);
67976804
}
67986805

67996806
void __noreturn do_task_dead(void)

kernel/trace/rv/monitors/sco/sco.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ static void handle_sched_set_state(void *data, struct task_struct *tsk, int stat
2424
da_handle_start_event_sco(sched_set_state_sco);
2525
}
2626

27-
static void handle_schedule_entry(void *data, bool preempt, unsigned long ip)
27+
static void handle_schedule_entry(void *data, bool preempt)
2828
{
2929
da_handle_event_sco(schedule_entry_sco);
3030
}
3131

32-
static void handle_schedule_exit(void *data, bool is_switch, unsigned long ip)
32+
static void handle_schedule_exit(void *data, bool is_switch)
3333
{
3434
da_handle_start_event_sco(schedule_exit_sco);
3535
}

kernel/trace/rv/monitors/scpd/scpd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ static void handle_preempt_enable(void *data, unsigned long ip, unsigned long pa
3030
da_handle_start_event_scpd(preempt_enable_scpd);
3131
}
3232

33-
static void handle_schedule_entry(void *data, bool preempt, unsigned long ip)
33+
static void handle_schedule_entry(void *data, bool preempt)
3434
{
3535
da_handle_event_scpd(schedule_entry_scpd);
3636
}
3737

38-
static void handle_schedule_exit(void *data, bool is_switch, unsigned long ip)
38+
static void handle_schedule_exit(void *data, bool is_switch)
3939
{
4040
da_handle_event_scpd(schedule_exit_scpd);
4141
}

kernel/trace/rv/monitors/sncid/sncid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ static void handle_irq_enable(void *data, unsigned long ip, unsigned long parent
3030
da_handle_start_event_sncid(irq_enable_sncid);
3131
}
3232

33-
static void handle_schedule_entry(void *data, bool preempt, unsigned long ip)
33+
static void handle_schedule_entry(void *data, bool preempt)
3434
{
3535
da_handle_start_event_sncid(schedule_entry_sncid);
3636
}
3737

38-
static void handle_schedule_exit(void *data, bool is_switch, unsigned long ip)
38+
static void handle_schedule_exit(void *data, bool is_switch)
3939
{
4040
da_handle_start_event_sncid(schedule_exit_sncid);
4141
}

kernel/trace/rv/monitors/snep/snep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ static void handle_preempt_enable(void *data, unsigned long ip, unsigned long pa
3030
da_handle_start_event_snep(preempt_enable_snep);
3131
}
3232

33-
static void handle_schedule_entry(void *data, bool preempt, unsigned long ip)
33+
static void handle_schedule_entry(void *data, bool preempt)
3434
{
3535
da_handle_event_snep(schedule_entry_snep);
3636
}
3737

38-
static void handle_schedule_exit(void *data, bool is_switch, unsigned long ip)
38+
static void handle_schedule_exit(void *data, bool is_switch)
3939
{
4040
da_handle_start_event_snep(schedule_exit_snep);
4141
}

kernel/trace/rv/monitors/tss/tss.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ static void handle_sched_switch(void *data, bool preempt,
2727
da_handle_event_tss(sched_switch_tss);
2828
}
2929

30-
static void handle_schedule_entry(void *data, bool preempt, unsigned long ip)
30+
static void handle_schedule_entry(void *data, bool preempt)
3131
{
3232
da_handle_event_tss(schedule_entry_tss);
3333
}
3434

35-
static void handle_schedule_exit(void *data, bool is_switch, unsigned long ip)
35+
static void handle_schedule_exit(void *data, bool is_switch)
3636
{
3737
da_handle_start_event_tss(schedule_exit_tss);
3838
}

0 commit comments

Comments
 (0)