Skip to content

Commit 2e62c47

Browse files
vingu-linaroingomolnar
authored andcommitted
sched/fair: Remove #ifdefs from scale_rt_capacity()
Reuse cpu_util_irq() that has been defined for schedutil and set irq util to 0 when !CONFIG_IRQ_TIME_ACCOUNTING. But the compiler is not able to optimize the sequence (at least with aarch64 GCC 7.2.1): free *= (max - irq); free /= max; when irq is fixed to 0 Add a new inline function scale_irq_capacity() that will scale utilization when irq is accounted. Reuse this funciton in schedutil which applies similar formula. Suggested-by: Ingo Molnar <mingo@redhat.com> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: rjw@rjwysocki.net Link: http://lkml.kernel.org/r/1532001606-6689-1-git-send-email-vincent.guittot@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 4765096 commit 2e62c47

4 files changed

Lines changed: 23 additions & 15 deletions

File tree

‎kernel/sched/core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static void update_rq_clock_task(struct rq *rq, s64 delta)
177177

178178
rq->clock_task += delta;
179179

180-
#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
180+
#ifdef HAVE_SCHED_AVG_IRQ
181181
if ((irq_delta + steal) && sched_feat(NONTASK_CAPACITY))
182182
update_irq_load_avg(rq, irq_delta + steal);
183183
#endif

‎kernel/sched/cpufreq_schedutil.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ static unsigned long sugov_get_util(struct sugov_cpu *sg_cpu)
247247
* U' = irq + ------- * U
248248
* max
249249
*/
250-
util *= (max - irq);
251-
util /= max;
250+
util = scale_irq_capacity(util, irq, max);
252251
util += irq;
253252

254253
/*

‎kernel/sched/fair.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7551,16 +7551,12 @@ static unsigned long scale_rt_capacity(int cpu)
75517551
struct rq *rq = cpu_rq(cpu);
75527552
unsigned long max = arch_scale_cpu_capacity(NULL, cpu);
75537553
unsigned long used, free;
7554-
#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
75557554
unsigned long irq;
7556-
#endif
75577555

7558-
#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
7559-
irq = READ_ONCE(rq->avg_irq.util_avg);
7556+
irq = cpu_util_irq(rq);
75607557

75617558
if (unlikely(irq >= max))
75627559
return 1;
7563-
#endif
75647560

75657561
used = READ_ONCE(rq->avg_rt.util_avg);
75667562
used += READ_ONCE(rq->avg_dl.util_avg);
@@ -7569,11 +7565,8 @@ static unsigned long scale_rt_capacity(int cpu)
75697565
return 1;
75707566

75717567
free = max - used;
7572-
#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
7573-
free *= (max - irq);
7574-
free /= max;
7575-
#endif
7576-
return free;
7568+
7569+
return scale_irq_capacity(free, irq, max);
75777570
}
75787571

75797572
static void update_cpu_capacity(struct sched_domain *sd, int cpu)

‎kernel/sched/sched.h‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ struct rq {
856856
struct sched_avg avg_rt;
857857
struct sched_avg avg_dl;
858858
#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
859+
#define HAVE_SCHED_AVG_IRQ
859860
struct sched_avg avg_irq;
860861
#endif
861862
u64 idle_stamp;
@@ -2210,17 +2211,32 @@ static inline unsigned long cpu_util_rt(struct rq *rq)
22102211
{
22112212
return READ_ONCE(rq->avg_rt.util_avg);
22122213
}
2214+
#endif
22132215

2214-
#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
2216+
#ifdef HAVE_SCHED_AVG_IRQ
22152217
static inline unsigned long cpu_util_irq(struct rq *rq)
22162218
{
22172219
return rq->avg_irq.util_avg;
22182220
}
2221+
2222+
static inline
2223+
unsigned long scale_irq_capacity(unsigned long util, unsigned long irq, unsigned long max)
2224+
{
2225+
util *= (max - irq);
2226+
util /= max;
2227+
2228+
return util;
2229+
2230+
}
22192231
#else
22202232
static inline unsigned long cpu_util_irq(struct rq *rq)
22212233
{
22222234
return 0;
22232235
}
22242236

2225-
#endif
2237+
static inline
2238+
unsigned long scale_irq_capacity(unsigned long util, unsigned long irq, unsigned long max)
2239+
{
2240+
return util;
2241+
}
22262242
#endif

0 commit comments

Comments
 (0)