diff options
author | Max Krasnyansky <maxk@qualcomm.com> | 2008-07-15 07:43:49 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-07-18 07:22:25 -0400 |
commit | e761b7725234276a802322549cee5255305a0930 (patch) | |
tree | 27b351a7d5fc9a93590e0effce1c5adb1bfcebc0 /kernel/sched.c | |
parent | 7ebefa8ceefed44cc321be70afc54a585a68ac0b (diff) |
cpu hotplug, sched: Introduce cpu_active_map and redo sched domain managment (take 2)
This is based on Linus' idea of creating cpu_active_map that prevents
scheduler load balancer from migrating tasks to the cpu that is going
down.
It allows us to simplify domain management code and avoid unecessary
domain rebuilds during cpu hotplug event handling.
Please ignore the cpusets part for now. It needs some more work in order
to avoid crazy lock nesting. Although I did simplfy and unify domain
reinitialization logic. We now simply call partition_sched_domains() in
all the cases. This means that we're using exact same code paths as in
cpusets case and hence the test below cover cpusets too.
Cpuset changes to make rebuild_sched_domains() callable from various
contexts are in the separate patch (right next after this one).
This not only boots but also easily handles
while true; do make clean; make -j 8; done
and
while true; do on-off-cpu 1; done
at the same time.
(on-off-cpu 1 simple does echo 0/1 > /sys/.../cpu1/online thing).
Suprisingly the box (dual-core Core2) is quite usable. In fact I'm typing
this on right now in gnome-terminal and things are moving just fine.
Also this is running with most of the debug features enabled (lockdep,
mutex, etc) no BUG_ONs or lockdep complaints so far.
I believe I addressed all of the Dmitry's comments for original Linus'
version. I changed both fair and rt balancer to mask out non-active cpus.
And replaced cpu_is_offline() with !cpu_active() in the main scheduler
code where it made sense (to me).
Signed-off-by: Max Krasnyanskiy <maxk@qualcomm.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Gregory Haskins <ghaskins@novell.com>
Cc: dmitry.adamushko@gmail.com
Cc: pj@sgi.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/sched.c')
-rw-r--r-- | kernel/sched.c | 108 |
1 files changed, 45 insertions, 63 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index 1ee18dbb4516..c237624a8a04 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -2881,7 +2881,7 @@ static void sched_migrate_task(struct task_struct *p, int dest_cpu) | |||
2881 | 2881 | ||
2882 | rq = task_rq_lock(p, &flags); | 2882 | rq = task_rq_lock(p, &flags); |
2883 | if (!cpu_isset(dest_cpu, p->cpus_allowed) | 2883 | if (!cpu_isset(dest_cpu, p->cpus_allowed) |
2884 | || unlikely(cpu_is_offline(dest_cpu))) | 2884 | || unlikely(!cpu_active(dest_cpu))) |
2885 | goto out; | 2885 | goto out; |
2886 | 2886 | ||
2887 | /* force the process onto the specified CPU */ | 2887 | /* force the process onto the specified CPU */ |
@@ -3849,7 +3849,7 @@ int select_nohz_load_balancer(int stop_tick) | |||
3849 | /* | 3849 | /* |
3850 | * If we are going offline and still the leader, give up! | 3850 | * If we are going offline and still the leader, give up! |
3851 | */ | 3851 | */ |
3852 | if (cpu_is_offline(cpu) && | 3852 | if (!cpu_active(cpu) && |
3853 | atomic_read(&nohz.load_balancer) == cpu) { | 3853 | atomic_read(&nohz.load_balancer) == cpu) { |
3854 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) | 3854 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) |
3855 | BUG(); | 3855 | BUG(); |
@@ -5876,7 +5876,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) | |||
5876 | struct rq *rq_dest, *rq_src; | 5876 | struct rq *rq_dest, *rq_src; |
5877 | int ret = 0, on_rq; | 5877 | int ret = 0, on_rq; |
5878 | 5878 | ||
5879 | if (unlikely(cpu_is_offline(dest_cpu))) | 5879 | if (unlikely(!cpu_active(dest_cpu))) |
5880 | return ret; | 5880 | return ret; |
5881 | 5881 | ||
5882 | rq_src = cpu_rq(src_cpu); | 5882 | rq_src = cpu_rq(src_cpu); |
@@ -7554,18 +7554,6 @@ void __attribute__((weak)) arch_update_cpu_topology(void) | |||
7554 | } | 7554 | } |
7555 | 7555 | ||
7556 | /* | 7556 | /* |
7557 | * Free current domain masks. | ||
7558 | * Called after all cpus are attached to NULL domain. | ||
7559 | */ | ||
7560 | static void free_sched_domains(void) | ||
7561 | { | ||
7562 | ndoms_cur = 0; | ||
7563 | if (doms_cur != &fallback_doms) | ||
7564 | kfree(doms_cur); | ||
7565 | doms_cur = &fallback_doms; | ||
7566 | } | ||
7567 | |||
7568 | /* | ||
7569 | * Set up scheduler domains and groups. Callers must hold the hotplug lock. | 7557 | * Set up scheduler domains and groups. Callers must hold the hotplug lock. |
7570 | * For now this just excludes isolated cpus, but could be used to | 7558 | * For now this just excludes isolated cpus, but could be used to |
7571 | * exclude other special cases in the future. | 7559 | * exclude other special cases in the future. |
@@ -7643,7 +7631,7 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7643 | * ownership of it and will kfree it when done with it. If the caller | 7631 | * ownership of it and will kfree it when done with it. If the caller |
7644 | * failed the kmalloc call, then it can pass in doms_new == NULL, | 7632 | * failed the kmalloc call, then it can pass in doms_new == NULL, |
7645 | * and partition_sched_domains() will fallback to the single partition | 7633 | * and partition_sched_domains() will fallback to the single partition |
7646 | * 'fallback_doms'. | 7634 | * 'fallback_doms', it also forces the domains to be rebuilt. |
7647 | * | 7635 | * |
7648 | * Call with hotplug lock held | 7636 | * Call with hotplug lock held |
7649 | */ | 7637 | */ |
@@ -7657,12 +7645,8 @@ void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | |||
7657 | /* always unregister in case we don't destroy any domains */ | 7645 | /* always unregister in case we don't destroy any domains */ |
7658 | unregister_sched_domain_sysctl(); | 7646 | unregister_sched_domain_sysctl(); |
7659 | 7647 | ||
7660 | if (doms_new == NULL) { | 7648 | if (doms_new == NULL) |
7661 | ndoms_new = 1; | 7649 | ndoms_new = 0; |
7662 | doms_new = &fallback_doms; | ||
7663 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | ||
7664 | dattr_new = NULL; | ||
7665 | } | ||
7666 | 7650 | ||
7667 | /* Destroy deleted domains */ | 7651 | /* Destroy deleted domains */ |
7668 | for (i = 0; i < ndoms_cur; i++) { | 7652 | for (i = 0; i < ndoms_cur; i++) { |
@@ -7677,6 +7661,14 @@ match1: | |||
7677 | ; | 7661 | ; |
7678 | } | 7662 | } |
7679 | 7663 | ||
7664 | if (doms_new == NULL) { | ||
7665 | ndoms_cur = 0; | ||
7666 | ndoms_new = 1; | ||
7667 | doms_new = &fallback_doms; | ||
7668 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | ||
7669 | dattr_new = NULL; | ||
7670 | } | ||
7671 | |||
7680 | /* Build new domains */ | 7672 | /* Build new domains */ |
7681 | for (i = 0; i < ndoms_new; i++) { | 7673 | for (i = 0; i < ndoms_new; i++) { |
7682 | for (j = 0; j < ndoms_cur; j++) { | 7674 | for (j = 0; j < ndoms_cur; j++) { |
@@ -7707,17 +7699,10 @@ match2: | |||
7707 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) | 7699 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) |
7708 | int arch_reinit_sched_domains(void) | 7700 | int arch_reinit_sched_domains(void) |
7709 | { | 7701 | { |
7710 | int err; | ||
7711 | |||
7712 | get_online_cpus(); | 7702 | get_online_cpus(); |
7713 | mutex_lock(&sched_domains_mutex); | 7703 | rebuild_sched_domains(); |
7714 | detach_destroy_domains(&cpu_online_map); | ||
7715 | free_sched_domains(); | ||
7716 | err = arch_init_sched_domains(&cpu_online_map); | ||
7717 | mutex_unlock(&sched_domains_mutex); | ||
7718 | put_online_cpus(); | 7704 | put_online_cpus(); |
7719 | 7705 | return 0; | |
7720 | return err; | ||
7721 | } | 7706 | } |
7722 | 7707 | ||
7723 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | 7708 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) |
@@ -7783,59 +7768,49 @@ int sched_create_sysfs_power_savings_entries(struct sysdev_class *cls) | |||
7783 | } | 7768 | } |
7784 | #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */ | 7769 | #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */ |
7785 | 7770 | ||
7771 | #ifndef CONFIG_CPUSETS | ||
7786 | /* | 7772 | /* |
7787 | * Force a reinitialization of the sched domains hierarchy. The domains | 7773 | * Add online and remove offline CPUs from the scheduler domains. |
7788 | * and groups cannot be updated in place without racing with the balancing | 7774 | * When cpusets are enabled they take over this function. |
7789 | * code, so we temporarily attach all running cpus to the NULL domain | ||
7790 | * which will prevent rebalancing while the sched domains are recalculated. | ||
7791 | */ | 7775 | */ |
7792 | static int update_sched_domains(struct notifier_block *nfb, | 7776 | static int update_sched_domains(struct notifier_block *nfb, |
7793 | unsigned long action, void *hcpu) | 7777 | unsigned long action, void *hcpu) |
7794 | { | 7778 | { |
7779 | switch (action) { | ||
7780 | case CPU_ONLINE: | ||
7781 | case CPU_ONLINE_FROZEN: | ||
7782 | case CPU_DEAD: | ||
7783 | case CPU_DEAD_FROZEN: | ||
7784 | partition_sched_domains(0, NULL, NULL); | ||
7785 | return NOTIFY_OK; | ||
7786 | |||
7787 | default: | ||
7788 | return NOTIFY_DONE; | ||
7789 | } | ||
7790 | } | ||
7791 | #endif | ||
7792 | |||
7793 | static int update_runtime(struct notifier_block *nfb, | ||
7794 | unsigned long action, void *hcpu) | ||
7795 | { | ||
7795 | int cpu = (int)(long)hcpu; | 7796 | int cpu = (int)(long)hcpu; |
7796 | 7797 | ||
7797 | switch (action) { | 7798 | switch (action) { |
7798 | case CPU_DOWN_PREPARE: | 7799 | case CPU_DOWN_PREPARE: |
7799 | case CPU_DOWN_PREPARE_FROZEN: | 7800 | case CPU_DOWN_PREPARE_FROZEN: |
7800 | disable_runtime(cpu_rq(cpu)); | 7801 | disable_runtime(cpu_rq(cpu)); |
7801 | /* fall-through */ | ||
7802 | case CPU_UP_PREPARE: | ||
7803 | case CPU_UP_PREPARE_FROZEN: | ||
7804 | detach_destroy_domains(&cpu_online_map); | ||
7805 | free_sched_domains(); | ||
7806 | return NOTIFY_OK; | 7802 | return NOTIFY_OK; |
7807 | 7803 | ||
7808 | |||
7809 | case CPU_DOWN_FAILED: | 7804 | case CPU_DOWN_FAILED: |
7810 | case CPU_DOWN_FAILED_FROZEN: | 7805 | case CPU_DOWN_FAILED_FROZEN: |
7811 | case CPU_ONLINE: | 7806 | case CPU_ONLINE: |
7812 | case CPU_ONLINE_FROZEN: | 7807 | case CPU_ONLINE_FROZEN: |
7813 | enable_runtime(cpu_rq(cpu)); | 7808 | enable_runtime(cpu_rq(cpu)); |
7814 | /* fall-through */ | 7809 | return NOTIFY_OK; |
7815 | case CPU_UP_CANCELED: | 7810 | |
7816 | case CPU_UP_CANCELED_FROZEN: | ||
7817 | case CPU_DEAD: | ||
7818 | case CPU_DEAD_FROZEN: | ||
7819 | /* | ||
7820 | * Fall through and re-initialise the domains. | ||
7821 | */ | ||
7822 | break; | ||
7823 | default: | 7811 | default: |
7824 | return NOTIFY_DONE; | 7812 | return NOTIFY_DONE; |
7825 | } | 7813 | } |
7826 | |||
7827 | #ifndef CONFIG_CPUSETS | ||
7828 | /* | ||
7829 | * Create default domain partitioning if cpusets are disabled. | ||
7830 | * Otherwise we let cpusets rebuild the domains based on the | ||
7831 | * current setup. | ||
7832 | */ | ||
7833 | |||
7834 | /* The hotplug lock is already held by cpu_up/cpu_down */ | ||
7835 | arch_init_sched_domains(&cpu_online_map); | ||
7836 | #endif | ||
7837 | |||
7838 | return NOTIFY_OK; | ||
7839 | } | 7814 | } |
7840 | 7815 | ||
7841 | void __init sched_init_smp(void) | 7816 | void __init sched_init_smp(void) |
@@ -7855,8 +7830,15 @@ void __init sched_init_smp(void) | |||
7855 | cpu_set(smp_processor_id(), non_isolated_cpus); | 7830 | cpu_set(smp_processor_id(), non_isolated_cpus); |
7856 | mutex_unlock(&sched_domains_mutex); | 7831 | mutex_unlock(&sched_domains_mutex); |
7857 | put_online_cpus(); | 7832 | put_online_cpus(); |
7833 | |||
7834 | #ifndef CONFIG_CPUSETS | ||
7858 | /* XXX: Theoretical race here - CPU may be hotplugged now */ | 7835 | /* XXX: Theoretical race here - CPU may be hotplugged now */ |
7859 | hotcpu_notifier(update_sched_domains, 0); | 7836 | hotcpu_notifier(update_sched_domains, 0); |
7837 | #endif | ||
7838 | |||
7839 | /* RT runtime code needs to handle some hotplug events */ | ||
7840 | hotcpu_notifier(update_runtime, 0); | ||
7841 | |||
7860 | init_hrtick(); | 7842 | init_hrtick(); |
7861 | 7843 | ||
7862 | /* Move init over to a non-isolated CPU */ | 7844 | /* Move init over to a non-isolated CPU */ |