From patchwork Tue May 28 10:33:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 10964673 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7EEE3112C for ; Tue, 28 May 2019 10:35:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F3022022B for ; Tue, 28 May 2019 10:35:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63C1927C2D; Tue, 28 May 2019 10:35:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B3B00286CF for ; Tue, 28 May 2019 10:35:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hVZRK-0007Ht-A1; Tue, 28 May 2019 10:34:42 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hVZQI-00050k-2W for xen-devel@lists.xenproject.org; Tue, 28 May 2019 10:33:38 +0000 X-Inumbo-ID: 0a3a5ca3-8134-11e9-8980-bc764e045a96 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 0a3a5ca3-8134-11e9-8980-bc764e045a96; Tue, 28 May 2019 10:33:32 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CEB6BB0AE; Tue, 28 May 2019 10:33:31 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Tue, 28 May 2019 12:33:12 +0200 Message-Id: <20190528103313.1343-60-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190528103313.1343-1-jgross@suse.com> References: <20190528103313.1343-1-jgross@suse.com> Subject: [Xen-devel] [PATCH 59/60] xen/sched: support core scheduling for moving cpus to/from cpupools X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Tim Deegan , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Dario Faggioli , Julien Grall , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP With core scheduling active it is necessary to move multiple cpus at the same time to or from a cpupool in order to avoid split scheduling resources in between. Signed-off-by: Juergen Gross --- V1: new patch --- xen/common/cpupool.c | 87 +++++++++++++++++++++++++++++++++++----------- xen/common/schedule.c | 3 +- xen/include/xen/sched-if.h | 1 + 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index ec81124182..4dac7dedca 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -265,23 +265,30 @@ static int cpupool_assign_cpu_locked(struct cpupool *c, unsigned int cpu) { int ret; struct domain *d; + const cpumask_t *cpus; + + cpus = sched_get_opt_cpumask(c->opt_granularity, cpu); if ( (cpupool_moving_cpu == cpu) && (c != cpupool_cpu_moving) ) return -EADDRNOTAVAIL; - ret = schedule_cpu_add(cpu, c); + ret = schedule_cpu_add(cpumask_first(cpus), c); if ( ret ) return ret; - cpumask_clear_cpu(cpu, &cpupool_free_cpus); + rcu_read_lock(&sched_res_rculock); + + cpumask_andnot(&cpupool_free_cpus, &cpupool_free_cpus, cpus); if (cpupool_moving_cpu == cpu) { cpupool_moving_cpu = -1; cpupool_put(cpupool_cpu_moving); cpupool_cpu_moving = NULL; } - cpumask_set_cpu(cpu, c->cpu_valid); + cpumask_or(c->cpu_valid, c->cpu_valid, cpus); cpumask_and(c->res_valid, c->cpu_valid, sched_res_mask); + rcu_read_unlock(&sched_res_rculock); + rcu_read_lock(&domlist_read_lock); for_each_domain_in_cpupool(d, c) { @@ -295,6 +302,7 @@ static int cpupool_assign_cpu_locked(struct cpupool *c, unsigned int cpu) static int cpupool_unassign_cpu_epilogue(struct cpupool *c) { int cpu = cpupool_moving_cpu; + const cpumask_t *cpus; struct domain *d; int ret; @@ -307,7 +315,10 @@ static int cpupool_unassign_cpu_epilogue(struct cpupool *c) */ rcu_read_lock(&domlist_read_lock); ret = cpu_disable_scheduler(cpu); - cpumask_set_cpu(cpu, &cpupool_free_cpus); + + rcu_read_lock(&sched_res_rculock); + cpus = get_sched_res(cpu)->cpus; + cpumask_or(&cpupool_free_cpus, &cpupool_free_cpus, cpus); /* * cpu_disable_scheduler() returning an error doesn't require resetting @@ -320,7 +331,7 @@ static int cpupool_unassign_cpu_epilogue(struct cpupool *c) { ret = schedule_cpu_rm(cpu); if ( ret ) - cpumask_clear_cpu(cpu, &cpupool_free_cpus); + cpumask_andnot(&cpupool_free_cpus, &cpupool_free_cpus, cpus); else { cpupool_moving_cpu = -1; @@ -328,6 +339,7 @@ static int cpupool_unassign_cpu_epilogue(struct cpupool *c) cpupool_cpu_moving = NULL; } } + rcu_read_unlock(&domlist_read_lock); for_each_domain_in_cpupool(d, c) { @@ -342,6 +354,7 @@ static int cpupool_unassign_cpu_prologue(struct cpupool *c, unsigned int cpu) { int ret; struct domain *d; + const cpumask_t *cpus; spin_lock(&cpupool_lock); ret = -EADDRNOTAVAIL; @@ -352,7 +365,11 @@ static int cpupool_unassign_cpu_prologue(struct cpupool *c, unsigned int cpu) if ( !cpumask_test_cpu(cpu, c->cpu_valid) && (cpu != cpupool_moving_cpu) ) goto out; - if ( (c->n_dom > 0) && (cpumask_weight(c->cpu_valid) == 1) && + rcu_read_lock(&sched_res_rculock); + cpus = get_sched_res(cpu)->cpus; + + if ( (c->n_dom > 0) && + (cpumask_weight(c->cpu_valid) == cpumask_weight(cpus)) && (cpu != cpupool_moving_cpu) ) { rcu_read_lock(&domlist_read_lock); @@ -374,9 +391,10 @@ static int cpupool_unassign_cpu_prologue(struct cpupool *c, unsigned int cpu) cpupool_moving_cpu = cpu; atomic_inc(&c->refcnt); cpupool_cpu_moving = c; - cpumask_clear_cpu(cpu, c->cpu_valid); + cpumask_andnot(c->cpu_valid, c->cpu_valid, cpus); cpumask_and(c->res_valid, c->cpu_valid, sched_res_mask); + rcu_read_unlock(&domlist_read_lock); out: spin_unlock(&cpupool_lock); @@ -428,12 +446,12 @@ static int cpupool_unassign_cpu(struct cpupool *c, unsigned int cpu) return ret; } - work_cpu = smp_processor_id(); + work_cpu = sched_get_resource_cpu(smp_processor_id()); if ( work_cpu == cpu ) { work_cpu = cpumask_first(cpupool0->cpu_valid); if ( work_cpu == cpu ) - work_cpu = cpumask_next(cpu, cpupool0->cpu_valid); + work_cpu = cpumask_last(cpupool0->cpu_valid); } return continue_hypercall_on_cpu(work_cpu, cpupool_unassign_cpu_helper, c); } @@ -499,6 +517,7 @@ void cpupool_rm_domain(struct domain *d) static int cpupool_cpu_add(unsigned int cpu) { int ret = 0; + const cpumask_t *cpus; spin_lock(&cpupool_lock); cpumask_clear_cpu(cpu, &cpupool_locked_cpus); @@ -512,7 +531,11 @@ static int cpupool_cpu_add(unsigned int cpu) */ rcu_read_lock(&sched_res_rculock); get_sched_res(cpu)->cpupool = NULL; - ret = cpupool_assign_cpu_locked(cpupool0, cpu); + + cpus = sched_get_opt_cpumask(cpupool0->opt_granularity, cpu); + if ( cpumask_subset(cpus, &cpupool_free_cpus) ) + ret = cpupool_assign_cpu_locked(cpupool0, cpu); + rcu_read_unlock(&sched_res_rculock); spin_unlock(&cpupool_lock); @@ -547,27 +570,33 @@ static void cpupool_cpu_remove(unsigned int cpu) static int cpupool_cpu_remove_prologue(unsigned int cpu) { int ret = 0; + cpumask_t *cpus; + unsigned int master_cpu; spin_lock(&cpupool_lock); - if ( cpumask_test_cpu(cpu, &cpupool_locked_cpus) ) + rcu_read_lock(&sched_res_rculock); + cpus = get_sched_res(cpu)->cpus; + master_cpu = sched_get_resource_cpu(cpu); + if ( cpumask_intersects(cpus, &cpupool_locked_cpus) ) ret = -EBUSY; else cpumask_set_cpu(cpu, &cpupool_locked_cpus); + rcu_read_unlock(&sched_res_rculock); spin_unlock(&cpupool_lock); if ( ret ) return ret; - if ( cpumask_test_cpu(cpu, cpupool0->cpu_valid) ) + if ( cpumask_test_cpu(master_cpu, cpupool0->cpu_valid) ) { /* Cpupool0 is populated only after all cpus are up. */ ASSERT(system_state == SYS_STATE_active); - ret = cpupool_unassign_cpu_prologue(cpupool0, cpu); + ret = cpupool_unassign_cpu_prologue(cpupool0, master_cpu); } - else if ( !cpumask_test_cpu(cpu, &cpupool_free_cpus) ) + else if ( !cpumask_test_cpu(master_cpu, &cpupool_free_cpus) ) ret = -ENODEV; return ret; @@ -657,27 +686,43 @@ int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *op) case XEN_SYSCTL_CPUPOOL_OP_ADDCPU: { unsigned cpu; + const cpumask_t *cpus; cpu = op->cpu; cpupool_dprintk("cpupool_assign_cpu(pool=%d,cpu=%d)\n", op->cpupool_id, cpu); + spin_lock(&cpupool_lock); + + c = cpupool_find_by_id(op->cpupool_id); + ret = -ENOENT; + if ( c == NULL ) + goto addcpu_out; if ( cpu == XEN_SYSCTL_CPUPOOL_PAR_ANY ) - cpu = cpumask_first(&cpupool_free_cpus); + { + for_each_cpu ( cpu, &cpupool_free_cpus ) + { + cpus = sched_get_opt_cpumask(c->opt_granularity, cpu); + if ( cpumask_subset(cpus, &cpupool_free_cpus) ) + break; + } + ret = -ENODEV; + if ( cpu >= nr_cpu_ids ) + goto addcpu_out; + } ret = -EINVAL; if ( cpu >= nr_cpu_ids ) goto addcpu_out; ret = -ENODEV; - if ( !cpumask_test_cpu(cpu, &cpupool_free_cpus) || - cpumask_test_cpu(cpu, &cpupool_locked_cpus) ) - goto addcpu_out; - c = cpupool_find_by_id(op->cpupool_id); - ret = -ENOENT; - if ( c == NULL ) + cpus = sched_get_opt_cpumask(c->opt_granularity, cpu); + if ( !cpumask_subset(cpus, &cpupool_free_cpus) || + cpumask_intersects(cpus, &cpupool_locked_cpus) ) goto addcpu_out; ret = cpupool_assign_cpu_locked(c, cpu); + addcpu_out: spin_unlock(&cpupool_lock); + cpupool_dprintk("cpupool_assign_cpu(pool=%d,cpu=%d) ret %d\n", op->cpupool_id, cpu, ret); } diff --git a/xen/common/schedule.c b/xen/common/schedule.c index b4e65e81b0..fed71b26d2 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -2469,8 +2469,7 @@ static struct notifier_block cpu_schedule_nfb = { .notifier_call = cpu_schedule_callback }; -static const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, - unsigned int cpu) +const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, unsigned int cpu) { const cpumask_t *mask; diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 714d793815..c125236068 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -613,5 +613,6 @@ affinity_balance_cpumask(const struct sched_unit *unit, int step, } void sched_rm_cpu(unsigned int cpu); +const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, unsigned int cpu); #endif /* __XEN_SCHED_IF_H__ */