Skip to content

Commit 08c183f

Browse files
Christoph LameterLinus Torvalds
authored andcommitted
[PATCH] sched: add option to serialize load balancing
Large sched domains can be very expensive to scan. Add an option SD_SERIALIZE to the sched domain flags. If that flag is set then we make sure that no other such domain is being balanced. [[email protected]: build fix] 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 1bd77f2 commit 08c183f

File tree

7 files changed

+16
-1
lines changed

7 files changed

+16
-1
lines changed

include/asm-i386/topology.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static inline int node_to_first_cpu(int node)
8989
.flags = SD_LOAD_BALANCE \
9090
| SD_BALANCE_EXEC \
9191
| SD_BALANCE_FORK \
92+
| SD_SERIALIZE \
9293
| SD_WAKE_BALANCE, \
9394
.last_balance = jiffies, \
9495
.balance_interval = 1, \

include/asm-ia64/topology.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void build_cpu_to_node_map(void);
101101
.flags = SD_LOAD_BALANCE \
102102
| SD_BALANCE_EXEC \
103103
| SD_BALANCE_FORK \
104+
| SD_SERIALIZE \
104105
| SD_WAKE_BALANCE, \
105106
.last_balance = jiffies, \
106107
.balance_interval = 64, \

include/asm-powerpc/topology.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static inline int pcibus_to_node(struct pci_bus *bus)
6666
| SD_BALANCE_EXEC \
6767
| SD_BALANCE_NEWIDLE \
6868
| SD_WAKE_IDLE \
69+
| SD_SERIALIZE \
6970
| SD_WAKE_BALANCE, \
7071
.last_balance = jiffies, \
7172
.balance_interval = 1, \

include/asm-x86_64/topology.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern int __node_distance(int, int);
4747
.flags = SD_LOAD_BALANCE \
4848
| SD_BALANCE_FORK \
4949
| SD_BALANCE_EXEC \
50+
| SD_SERIALIZE \
5051
| SD_WAKE_BALANCE, \
5152
.last_balance = jiffies, \
5253
.balance_interval = 1, \

include/linux/sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ enum idle_type
648648
#define SD_SHARE_CPUPOWER 128 /* Domain members share cpu power */
649649
#define SD_POWERSAVINGS_BALANCE 256 /* Balance for power savings */
650650
#define SD_SHARE_PKG_RESOURCES 512 /* Domain members share cpu pkg resources */
651+
#define SD_SERIALIZE 1024 /* Only a single load balancing instance */
651652

652653
#define BALANCE_FOR_MC_POWER \
653654
(sched_smt_power_savings ? SD_POWERSAVINGS_BALANCE : 0)

include/linux/topology.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@
194194
.wake_idx = 0, /* unused */ \
195195
.forkexec_idx = 0, /* unused */ \
196196
.per_cpu_gain = 100, \
197-
.flags = SD_LOAD_BALANCE, \
197+
.flags = SD_LOAD_BALANCE \
198+
| SD_SERIALIZE, \
198199
.last_balance = jiffies, \
199200
.balance_interval = 64, \
200201
.nr_balance_failed = 0, \

kernel/sched.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,7 @@ static void update_load(struct rq *this_rq)
28802880
*
28812881
* Balancing parameters are set up in arch_init_sched_domains.
28822882
*/
2883+
static DEFINE_SPINLOCK(balancing);
28832884

28842885
static void run_rebalance_domains(struct softirq_action *h)
28852886
{
@@ -2909,6 +2910,11 @@ static void run_rebalance_domains(struct softirq_action *h)
29092910
if (unlikely(!interval))
29102911
interval = 1;
29112912

2913+
if (sd->flags & SD_SERIALIZE) {
2914+
if (!spin_trylock(&balancing))
2915+
goto out;
2916+
}
2917+
29122918
if (time_after_eq(jiffies, sd->last_balance + interval)) {
29132919
if (load_balance(this_cpu, this_rq, sd, idle)) {
29142920
/*
@@ -2920,6 +2926,9 @@ static void run_rebalance_domains(struct softirq_action *h)
29202926
}
29212927
sd->last_balance = jiffies;
29222928
}
2929+
if (sd->flags & SD_SERIALIZE)
2930+
spin_unlock(&balancing);
2931+
out:
29232932
if (time_after(next_balance, sd->last_balance + interval))
29242933
next_balance = sd->last_balance + interval;
29252934
}

0 commit comments

Comments
 (0)