Skip to content

Commit 78becc2

Browse files
fweisbecingomolnar
authored andcommitted
sched: Use an accessor to read the rq clock
Read the runqueue clock through an accessor. This prepares for adding a debugging infrastructure to detect missing or redundant calls to update_rq_clock() between a scheduler's entry and exit point. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Li Zhong <zhong@linux.vnet.ibm.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Paul Turner <pjt@google.com> Cc: Mike Galbraith <efault@gmx.de> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1365724262-20142-6-git-send-email-fweisbec@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 1a55af2 commit 78becc2

6 files changed

Lines changed: 47 additions & 37 deletions

File tree

‎kernel/sched/core.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ void sched_avg_update(struct rq *rq)
667667
{
668668
s64 period = sched_avg_period();
669669

670-
while ((s64)(rq->clock - rq->age_stamp) > period) {
670+
while ((s64)(rq_clock(rq) - rq->age_stamp) > period) {
671671
/*
672672
* Inline assembly required to prevent the compiler
673673
* optimising this loop into a divmod call.
@@ -1328,7 +1328,7 @@ ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)
13281328
p->sched_class->task_woken(rq, p);
13291329

13301330
if (rq->idle_stamp) {
1331-
u64 delta = rq->clock - rq->idle_stamp;
1331+
u64 delta = rq_clock(rq) - rq->idle_stamp;
13321332
u64 max = 2*sysctl_sched_migration_cost;
13331333

13341334
if (delta > max)
@@ -2106,7 +2106,7 @@ static u64 do_task_delta_exec(struct task_struct *p, struct rq *rq)
21062106

21072107
if (task_current(rq, p)) {
21082108
update_rq_clock(rq);
2109-
ns = rq->clock_task - p->se.exec_start;
2109+
ns = rq_clock_task(rq) - p->se.exec_start;
21102110
if ((s64)ns < 0)
21112111
ns = 0;
21122112
}

‎kernel/sched/fair.c‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ __update_curr(struct cfs_rq *cfs_rq, struct sched_entity *curr,
704704
static void update_curr(struct cfs_rq *cfs_rq)
705705
{
706706
struct sched_entity *curr = cfs_rq->curr;
707-
u64 now = rq_of(cfs_rq)->clock_task;
707+
u64 now = rq_clock_task(rq_of(cfs_rq));
708708
unsigned long delta_exec;
709709

710710
if (unlikely(!curr))
@@ -736,7 +736,7 @@ static void update_curr(struct cfs_rq *cfs_rq)
736736
static inline void
737737
update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
738738
{
739-
schedstat_set(se->statistics.wait_start, rq_of(cfs_rq)->clock);
739+
schedstat_set(se->statistics.wait_start, rq_clock(rq_of(cfs_rq)));
740740
}
741741

742742
/*
@@ -756,14 +756,14 @@ static void
756756
update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
757757
{
758758
schedstat_set(se->statistics.wait_max, max(se->statistics.wait_max,
759-
rq_of(cfs_rq)->clock - se->statistics.wait_start));
759+
rq_clock(rq_of(cfs_rq)) - se->statistics.wait_start));
760760
schedstat_set(se->statistics.wait_count, se->statistics.wait_count + 1);
761761
schedstat_set(se->statistics.wait_sum, se->statistics.wait_sum +
762-
rq_of(cfs_rq)->clock - se->statistics.wait_start);
762+
rq_clock(rq_of(cfs_rq)) - se->statistics.wait_start);
763763
#ifdef CONFIG_SCHEDSTATS
764764
if (entity_is_task(se)) {
765765
trace_sched_stat_wait(task_of(se),
766-
rq_of(cfs_rq)->clock - se->statistics.wait_start);
766+
rq_clock(rq_of(cfs_rq)) - se->statistics.wait_start);
767767
}
768768
#endif
769769
schedstat_set(se->statistics.wait_start, 0);
@@ -789,7 +789,7 @@ update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
789789
/*
790790
* We are starting a new run period:
791791
*/
792-
se->exec_start = rq_of(cfs_rq)->clock_task;
792+
se->exec_start = rq_clock_task(rq_of(cfs_rq));
793793
}
794794

795795
/**************************************************
@@ -1515,7 +1515,7 @@ static void update_cfs_rq_blocked_load(struct cfs_rq *cfs_rq, int force_update)
15151515

15161516
static inline void update_rq_runnable_avg(struct rq *rq, int runnable)
15171517
{
1518-
__update_entity_runnable_avg(rq->clock_task, &rq->avg, runnable);
1518+
__update_entity_runnable_avg(rq_clock_task(rq), &rq->avg, runnable);
15191519
__update_tg_runnable_avg(&rq->avg, &rq->cfs);
15201520
}
15211521

@@ -1530,7 +1530,7 @@ static inline void enqueue_entity_load_avg(struct cfs_rq *cfs_rq,
15301530
* accumulated while sleeping.
15311531
*/
15321532
if (unlikely(se->avg.decay_count <= 0)) {
1533-
se->avg.last_runnable_update = rq_of(cfs_rq)->clock_task;
1533+
se->avg.last_runnable_update = rq_clock_task(rq_of(cfs_rq));
15341534
if (se->avg.decay_count) {
15351535
/*
15361536
* In a wake-up migration we have to approximate the
@@ -1625,7 +1625,7 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
16251625
tsk = task_of(se);
16261626

16271627
if (se->statistics.sleep_start) {
1628-
u64 delta = rq_of(cfs_rq)->clock - se->statistics.sleep_start;
1628+
u64 delta = rq_clock(rq_of(cfs_rq)) - se->statistics.sleep_start;
16291629

16301630
if ((s64)delta < 0)
16311631
delta = 0;
@@ -1642,7 +1642,7 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
16421642
}
16431643
}
16441644
if (se->statistics.block_start) {
1645-
u64 delta = rq_of(cfs_rq)->clock - se->statistics.block_start;
1645+
u64 delta = rq_clock(rq_of(cfs_rq)) - se->statistics.block_start;
16461646

16471647
if ((s64)delta < 0)
16481648
delta = 0;
@@ -1823,9 +1823,9 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
18231823
struct task_struct *tsk = task_of(se);
18241824

18251825
if (tsk->state & TASK_INTERRUPTIBLE)
1826-
se->statistics.sleep_start = rq_of(cfs_rq)->clock;
1826+
se->statistics.sleep_start = rq_clock(rq_of(cfs_rq));
18271827
if (tsk->state & TASK_UNINTERRUPTIBLE)
1828-
se->statistics.block_start = rq_of(cfs_rq)->clock;
1828+
se->statistics.block_start = rq_clock(rq_of(cfs_rq));
18291829
}
18301830
#endif
18311831
}
@@ -2100,7 +2100,7 @@ static inline u64 cfs_rq_clock_task(struct cfs_rq *cfs_rq)
21002100
if (unlikely(cfs_rq->throttle_count))
21012101
return cfs_rq->throttled_clock_task;
21022102

2103-
return rq_of(cfs_rq)->clock_task - cfs_rq->throttled_clock_task_time;
2103+
return rq_clock_task(rq_of(cfs_rq)) - cfs_rq->throttled_clock_task_time;
21042104
}
21052105

21062106
/* returns 0 on failure to allocate runtime */
@@ -2159,7 +2159,7 @@ static void expire_cfs_rq_runtime(struct cfs_rq *cfs_rq)
21592159
struct rq *rq = rq_of(cfs_rq);
21602160

21612161
/* if the deadline is ahead of our clock, nothing to do */
2162-
if (likely((s64)(rq->clock - cfs_rq->runtime_expires) < 0))
2162+
if (likely((s64)(rq_clock(rq_of(cfs_rq)) - cfs_rq->runtime_expires) < 0))
21632163
return;
21642164

21652165
if (cfs_rq->runtime_remaining < 0)
@@ -2248,7 +2248,7 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
22482248
#ifdef CONFIG_SMP
22492249
if (!cfs_rq->throttle_count) {
22502250
/* adjust cfs_rq_clock_task() */
2251-
cfs_rq->throttled_clock_task_time += rq->clock_task -
2251+
cfs_rq->throttled_clock_task_time += rq_clock_task(rq) -
22522252
cfs_rq->throttled_clock_task;
22532253
}
22542254
#endif
@@ -2263,7 +2263,7 @@ static int tg_throttle_down(struct task_group *tg, void *data)
22632263

22642264
/* group is entering throttled state, stop time */
22652265
if (!cfs_rq->throttle_count)
2266-
cfs_rq->throttled_clock_task = rq->clock_task;
2266+
cfs_rq->throttled_clock_task = rq_clock_task(rq);
22672267
cfs_rq->throttle_count++;
22682268

22692269
return 0;
@@ -2302,7 +2302,7 @@ static void throttle_cfs_rq(struct cfs_rq *cfs_rq)
23022302
rq->nr_running -= task_delta;
23032303

23042304
cfs_rq->throttled = 1;
2305-
cfs_rq->throttled_clock = rq->clock;
2305+
cfs_rq->throttled_clock = rq_clock(rq);
23062306
raw_spin_lock(&cfs_b->lock);
23072307
list_add_tail_rcu(&cfs_rq->throttled_list, &cfs_b->throttled_cfs_rq);
23082308
raw_spin_unlock(&cfs_b->lock);
@@ -2323,7 +2323,7 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq)
23232323
update_rq_clock(rq);
23242324

23252325
raw_spin_lock(&cfs_b->lock);
2326-
cfs_b->throttled_time += rq->clock - cfs_rq->throttled_clock;
2326+
cfs_b->throttled_time += rq_clock(rq) - cfs_rq->throttled_clock;
23272327
list_del_rcu(&cfs_rq->throttled_list);
23282328
raw_spin_unlock(&cfs_b->lock);
23292329

@@ -2726,7 +2726,7 @@ static void __maybe_unused unthrottle_offline_cfs_rqs(struct rq *rq)
27262726
#else /* CONFIG_CFS_BANDWIDTH */
27272727
static inline u64 cfs_rq_clock_task(struct cfs_rq *cfs_rq)
27282728
{
2729-
return rq_of(cfs_rq)->clock_task;
2729+
return rq_clock_task(rq_of(cfs_rq));
27302730
}
27312731

27322732
static void account_cfs_rq_runtime(struct cfs_rq *cfs_rq,
@@ -3966,7 +3966,7 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
39663966
* 2) too many balance attempts have failed.
39673967
*/
39683968

3969-
tsk_cache_hot = task_hot(p, env->src_rq->clock_task, env->sd);
3969+
tsk_cache_hot = task_hot(p, rq_clock_task(env->src_rq), env->sd);
39703970
if (!tsk_cache_hot ||
39713971
env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
39723972

@@ -4322,7 +4322,7 @@ static unsigned long scale_rt_power(int cpu)
43224322
age_stamp = ACCESS_ONCE(rq->age_stamp);
43234323
avg = ACCESS_ONCE(rq->rt_avg);
43244324

4325-
total = sched_avg_period() + (rq->clock - age_stamp);
4325+
total = sched_avg_period() + (rq_clock(rq) - age_stamp);
43264326

43274327
if (unlikely(total < avg)) {
43284328
/* Ensures that power won't end up being negative */
@@ -5261,7 +5261,7 @@ void idle_balance(int this_cpu, struct rq *this_rq)
52615261
int pulled_task = 0;
52625262
unsigned long next_balance = jiffies + HZ;
52635263

5264-
this_rq->idle_stamp = this_rq->clock;
5264+
this_rq->idle_stamp = rq_clock(this_rq);
52655265

52665266
if (this_rq->avg_idle < sysctl_sched_migration_cost)
52675267
return;

‎kernel/sched/rt.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ static void update_curr_rt(struct rq *rq)
886886
if (curr->sched_class != &rt_sched_class)
887887
return;
888888

889-
delta_exec = rq->clock_task - curr->se.exec_start;
889+
delta_exec = rq_clock_task(rq) - curr->se.exec_start;
890890
if (unlikely((s64)delta_exec <= 0))
891891
return;
892892

@@ -896,7 +896,7 @@ static void update_curr_rt(struct rq *rq)
896896
curr->se.sum_exec_runtime += delta_exec;
897897
account_group_exec_runtime(curr, delta_exec);
898898

899-
curr->se.exec_start = rq->clock_task;
899+
curr->se.exec_start = rq_clock_task(rq);
900900
cpuacct_charge(curr, delta_exec);
901901

902902
sched_rt_avg_update(rq, delta_exec);
@@ -1345,7 +1345,7 @@ static struct task_struct *_pick_next_task_rt(struct rq *rq)
13451345
} while (rt_rq);
13461346

13471347
p = rt_task_of(rt_se);
1348-
p->se.exec_start = rq->clock_task;
1348+
p->se.exec_start = rq_clock_task(rq);
13491349

13501350
return p;
13511351
}
@@ -1997,7 +1997,7 @@ static void set_curr_task_rt(struct rq *rq)
19971997
{
19981998
struct task_struct *p = rq->curr;
19991999

2000-
p->se.exec_start = rq->clock_task;
2000+
p->se.exec_start = rq_clock_task(rq);
20012001

20022002
/* The running task is never eligible for pushing */
20032003
dequeue_pushable_task(rq, p);

‎kernel/sched/sched.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,16 @@ DECLARE_PER_CPU(struct rq, runqueues);
548548
#define cpu_curr(cpu) (cpu_rq(cpu)->curr)
549549
#define raw_rq() (&__raw_get_cpu_var(runqueues))
550550

551+
static inline u64 rq_clock(struct rq *rq)
552+
{
553+
return rq->clock;
554+
}
555+
556+
static inline u64 rq_clock_task(struct rq *rq)
557+
{
558+
return rq->clock_task;
559+
}
560+
551561
#ifdef CONFIG_SMP
552562

553563
#define rcu_dereference_check_sched_domain(p) \

‎kernel/sched/stats.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static inline void sched_info_reset_dequeued(struct task_struct *t)
6161
*/
6262
static inline void sched_info_dequeued(struct task_struct *t)
6363
{
64-
unsigned long long now = task_rq(t)->clock, delta = 0;
64+
unsigned long long now = rq_clock(task_rq(t)), delta = 0;
6565

6666
if (unlikely(sched_info_on()))
6767
if (t->sched_info.last_queued)
@@ -79,7 +79,7 @@ static inline void sched_info_dequeued(struct task_struct *t)
7979
*/
8080
static void sched_info_arrive(struct task_struct *t)
8181
{
82-
unsigned long long now = task_rq(t)->clock, delta = 0;
82+
unsigned long long now = rq_clock(task_rq(t)), delta = 0;
8383

8484
if (t->sched_info.last_queued)
8585
delta = now - t->sched_info.last_queued;
@@ -100,7 +100,7 @@ static inline void sched_info_queued(struct task_struct *t)
100100
{
101101
if (unlikely(sched_info_on()))
102102
if (!t->sched_info.last_queued)
103-
t->sched_info.last_queued = task_rq(t)->clock;
103+
t->sched_info.last_queued = rq_clock(task_rq(t));
104104
}
105105

106106
/*
@@ -112,7 +112,7 @@ static inline void sched_info_queued(struct task_struct *t)
112112
*/
113113
static inline void sched_info_depart(struct task_struct *t)
114114
{
115-
unsigned long long delta = task_rq(t)->clock -
115+
unsigned long long delta = rq_clock(task_rq(t)) -
116116
t->sched_info.last_arrival;
117117

118118
rq_sched_info_depart(task_rq(t), delta);

‎kernel/sched/stop_task.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static struct task_struct *pick_next_task_stop(struct rq *rq)
2828
struct task_struct *stop = rq->stop;
2929

3030
if (stop && stop->on_rq) {
31-
stop->se.exec_start = rq->clock_task;
31+
stop->se.exec_start = rq_clock_task(rq);
3232
return stop;
3333
}
3434

@@ -57,7 +57,7 @@ static void put_prev_task_stop(struct rq *rq, struct task_struct *prev)
5757
struct task_struct *curr = rq->curr;
5858
u64 delta_exec;
5959

60-
delta_exec = rq->clock_task - curr->se.exec_start;
60+
delta_exec = rq_clock_task(rq) - curr->se.exec_start;
6161
if (unlikely((s64)delta_exec < 0))
6262
delta_exec = 0;
6363

@@ -67,7 +67,7 @@ static void put_prev_task_stop(struct rq *rq, struct task_struct *prev)
6767
curr->se.sum_exec_runtime += delta_exec;
6868
account_group_exec_runtime(curr, delta_exec);
6969

70-
curr->se.exec_start = rq->clock_task;
70+
curr->se.exec_start = rq_clock_task(rq);
7171
cpuacct_charge(curr, delta_exec);
7272
}
7373

@@ -79,7 +79,7 @@ static void set_curr_task_stop(struct rq *rq)
7979
{
8080
struct task_struct *stop = rq->stop;
8181

82-
stop->se.exec_start = rq->clock_task;
82+
stop->se.exec_start = rq_clock_task(rq);
8383
}
8484

8585
static void switched_to_stop(struct rq *rq, struct task_struct *p)

0 commit comments

Comments
 (0)