Skip to content

Commit ea14b57

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/cpufreq: Provide migration hint
It was suggested that a migration hint might be usefull for the CPU-freq governors. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Juri Lelli <juri.lelli@arm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Viresh Kumar <viresh.kumar@linaro.org> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 00357f5 commit ea14b57

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

include/linux/sched/cpufreq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#define SCHED_CPUFREQ_IOWAIT (1U << 0)
12+
#define SCHED_CPUFREQ_MIGRATION (1U << 1)
1213

1314
#ifdef CONFIG_CPU_FREQ
1415
struct update_util_data {

kernel/sched/fair.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ void post_init_entity_util_avg(struct sched_entity *se)
772772
* For !fair tasks do:
773773
*
774774
update_cfs_rq_load_avg(now, cfs_rq);
775-
attach_entity_load_avg(cfs_rq, se);
775+
attach_entity_load_avg(cfs_rq, se, 0);
776776
switched_from_fair(rq, p);
777777
*
778778
* such that the next switched_to_fair() has the
@@ -3009,11 +3009,11 @@ static inline void update_cfs_group(struct sched_entity *se)
30093009
}
30103010
#endif /* CONFIG_FAIR_GROUP_SCHED */
30113011

3012-
static inline void cfs_rq_util_change(struct cfs_rq *cfs_rq)
3012+
static inline void cfs_rq_util_change(struct cfs_rq *cfs_rq, int flags)
30133013
{
30143014
struct rq *rq = rq_of(cfs_rq);
30153015

3016-
if (&rq->cfs == cfs_rq) {
3016+
if (&rq->cfs == cfs_rq || (flags & SCHED_CPUFREQ_MIGRATION)) {
30173017
/*
30183018
* There are a few boundary cases this might miss but it should
30193019
* get called often enough that that should (hopefully) not be
@@ -3028,7 +3028,7 @@ static inline void cfs_rq_util_change(struct cfs_rq *cfs_rq)
30283028
*
30293029
* See cpu_util().
30303030
*/
3031-
cpufreq_update_util(rq, 0);
3031+
cpufreq_update_util(rq, flags);
30323032
}
30333033
}
30343034

@@ -3686,7 +3686,7 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
36863686
#endif
36873687

36883688
if (decayed)
3689-
cfs_rq_util_change(cfs_rq);
3689+
cfs_rq_util_change(cfs_rq, 0);
36903690

36913691
return decayed;
36923692
}
@@ -3699,7 +3699,7 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
36993699
* Must call update_cfs_rq_load_avg() before this, since we rely on
37003700
* cfs_rq->avg.last_update_time being current.
37013701
*/
3702-
static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
3702+
static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
37033703
{
37043704
u32 divider = LOAD_AVG_MAX - 1024 + cfs_rq->avg.period_contrib;
37053705

@@ -3735,7 +3735,7 @@ static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
37353735

37363736
add_tg_cfs_propagate(cfs_rq, se->avg.load_sum);
37373737

3738-
cfs_rq_util_change(cfs_rq);
3738+
cfs_rq_util_change(cfs_rq, flags);
37393739
}
37403740

37413741
/**
@@ -3754,7 +3754,7 @@ static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
37543754

37553755
add_tg_cfs_propagate(cfs_rq, -se->avg.load_sum);
37563756

3757-
cfs_rq_util_change(cfs_rq);
3757+
cfs_rq_util_change(cfs_rq, 0);
37583758
}
37593759

37603760
/*
@@ -3784,7 +3784,14 @@ static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
37843784

37853785
if (!se->avg.last_update_time && (flags & DO_ATTACH)) {
37863786

3787-
attach_entity_load_avg(cfs_rq, se);
3787+
/*
3788+
* DO_ATTACH means we're here from enqueue_entity().
3789+
* !last_update_time means we've passed through
3790+
* migrate_task_rq_fair() indicating we migrated.
3791+
*
3792+
* IOW we're enqueueing a task on a new CPU.
3793+
*/
3794+
attach_entity_load_avg(cfs_rq, se, SCHED_CPUFREQ_MIGRATION);
37883795
update_tg_load_avg(cfs_rq, 0);
37893796

37903797
} else if (decayed && (flags & UPDATE_TG))
@@ -3880,13 +3887,13 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
38803887

38813888
static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int not_used1)
38823889
{
3883-
cfs_rq_util_change(cfs_rq);
3890+
cfs_rq_util_change(cfs_rq, 0);
38843891
}
38853892

38863893
static inline void remove_entity_load_avg(struct sched_entity *se) {}
38873894

38883895
static inline void
3889-
attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) {}
3896+
attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) {}
38903897
static inline void
38913898
detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) {}
38923899

@@ -9726,7 +9733,7 @@ static void attach_entity_cfs_rq(struct sched_entity *se)
97269733

97279734
/* Synchronize entity with its cfs_rq */
97289735
update_load_avg(cfs_rq, se, sched_feat(ATTACH_AGE_LOAD) ? 0 : SKIP_AGE_LOAD);
9729-
attach_entity_load_avg(cfs_rq, se);
9736+
attach_entity_load_avg(cfs_rq, se, 0);
97309737
update_tg_load_avg(cfs_rq, false);
97319738
propagate_entity_cfs_rq(se);
97329739
}

0 commit comments

Comments
 (0)