Skip to content

Commit 7835b98

Browse files
Christoph LameterLinus Torvalds
authored andcommitted
[PATCH] sched: extract load calculation from rebalance_tick
A load calculation is always done in rebalance_tick() in addition to the real load balancing activities that only take place when certain jiffie counts have been reached. Move that processing into a separate function and call it directly from scheduler_tick(). Also extract the time slice handling from scheduler_tick and put it into a separate function. Then we can clean up scheduler_tick significantly. It will no longer have any gotos. Signed-off-by: Christoph Lameter <[email protected]> Cc: Peter Williams <[email protected]> Cc: Nick Piggin <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: "Siddha, Suresh B" <[email protected]> Cc: "Chen, Kenneth W" <[email protected]> Acked-by: Ingo Molnar <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent fe2eea3 commit 7835b98

File tree

1 file changed

+54
-42
lines changed

1 file changed

+54
-42
lines changed

kernel/sched.c

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,20 +2833,9 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu)
28332833
spin_unlock(&target_rq->lock);
28342834
}
28352835

2836-
/*
2837-
* rebalance_tick will get called every timer tick, on every CPU.
2838-
*
2839-
* It checks each scheduling domain to see if it is due to be balanced,
2840-
* and initiates a balancing operation if so.
2841-
*
2842-
* Balancing parameters are set up in arch_init_sched_domains.
2843-
*/
2844-
2845-
static void
2846-
rebalance_tick(int this_cpu, struct rq *this_rq, enum idle_type idle)
2836+
static void update_load(struct rq *this_rq)
28472837
{
2848-
unsigned long this_load, interval;
2849-
struct sched_domain *sd;
2838+
unsigned long this_load;
28502839
int i, scale;
28512840

28522841
this_load = this_rq->raw_weighted_load;
@@ -2866,6 +2855,22 @@ rebalance_tick(int this_cpu, struct rq *this_rq, enum idle_type idle)
28662855
new_load += scale-1;
28672856
this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) / scale;
28682857
}
2858+
}
2859+
2860+
/*
2861+
* rebalance_tick will get called every timer tick, on every CPU.
2862+
*
2863+
* It checks each scheduling domain to see if it is due to be balanced,
2864+
* and initiates a balancing operation if so.
2865+
*
2866+
* Balancing parameters are set up in arch_init_sched_domains.
2867+
*/
2868+
2869+
static void
2870+
rebalance_tick(int this_cpu, struct rq *this_rq, enum idle_type idle)
2871+
{
2872+
unsigned long interval;
2873+
struct sched_domain *sd;
28692874

28702875
for_each_domain(this_cpu, sd) {
28712876
if (!(sd->flags & SD_LOAD_BALANCE))
@@ -2897,12 +2902,15 @@ rebalance_tick(int this_cpu, struct rq *this_rq, enum idle_type idle)
28972902
/*
28982903
* on UP we do not need to balance between CPUs:
28992904
*/
2900-
static inline void rebalance_tick(int cpu, struct rq *rq, enum idle_type idle)
2905+
static inline void rebalance_tick(int cpu, struct rq *rq)
29012906
{
29022907
}
29032908
static inline void idle_balance(int cpu, struct rq *rq)
29042909
{
29052910
}
2911+
static inline void update_load(struct rq *this_rq)
2912+
{
2913+
}
29062914
#endif
29072915

29082916
static inline int wake_priority_sleeper(struct rq *rq)
@@ -3052,35 +3060,12 @@ void account_steal_time(struct task_struct *p, cputime_t steal)
30523060
cpustat->steal = cputime64_add(cpustat->steal, tmp);
30533061
}
30543062

3055-
/*
3056-
* This function gets called by the timer code, with HZ frequency.
3057-
* We call it with interrupts disabled.
3058-
*
3059-
* It also gets called by the fork code, when changing the parent's
3060-
* timeslices.
3061-
*/
3062-
void scheduler_tick(void)
3063+
static void task_running_tick(struct rq *rq, struct task_struct *p)
30633064
{
3064-
unsigned long long now = sched_clock();
3065-
struct task_struct *p = current;
3066-
int cpu = smp_processor_id();
3067-
struct rq *rq = cpu_rq(cpu);
3068-
3069-
update_cpu_clock(p, rq, now);
3070-
3071-
rq->timestamp_last_tick = now;
3072-
3073-
if (p == rq->idle) {
3074-
if (wake_priority_sleeper(rq))
3075-
goto out;
3076-
rebalance_tick(cpu, rq, SCHED_IDLE);
3077-
return;
3078-
}
3079-
3080-
/* Task might have expired already, but not scheduled off yet */
30813065
if (p->array != rq->active) {
3066+
/* Task has expired but was not scheduled yet */
30823067
set_tsk_need_resched(p);
3083-
goto out;
3068+
return;
30843069
}
30853070
spin_lock(&rq->lock);
30863071
/*
@@ -3148,8 +3133,35 @@ void scheduler_tick(void)
31483133
}
31493134
out_unlock:
31503135
spin_unlock(&rq->lock);
3151-
out:
3152-
rebalance_tick(cpu, rq, NOT_IDLE);
3136+
}
3137+
3138+
/*
3139+
* This function gets called by the timer code, with HZ frequency.
3140+
* We call it with interrupts disabled.
3141+
*
3142+
* It also gets called by the fork code, when changing the parent's
3143+
* timeslices.
3144+
*/
3145+
void scheduler_tick(void)
3146+
{
3147+
unsigned long long now = sched_clock();
3148+
struct task_struct *p = current;
3149+
int cpu = smp_processor_id();
3150+
struct rq *rq = cpu_rq(cpu);
3151+
enum idle_type idle = NOT_IDLE;
3152+
3153+
update_cpu_clock(p, rq, now);
3154+
3155+
rq->timestamp_last_tick = now;
3156+
3157+
if (p == rq->idle) {
3158+
/* Task on the idle queue */
3159+
if (!wake_priority_sleeper(rq))
3160+
idle = SCHED_IDLE;
3161+
} else
3162+
task_running_tick(rq, p);
3163+
update_load(rq);
3164+
rebalance_tick(cpu, rq, idle);
31533165
}
31543166

31553167
#ifdef CONFIG_SCHED_SMT

0 commit comments

Comments
 (0)