From patchwork Fri Jul 26 06:25:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 11060359 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 F27ED746 for ; Fri, 26 Jul 2019 06:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E321B205A9 for ; Fri, 26 Jul 2019 06:27:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D752D28A4F; Fri, 26 Jul 2019 06:27:18 +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 49096205A9 for ; Fri, 26 Jul 2019 06:27:18 +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 1hqtg0-00039d-J5; Fri, 26 Jul 2019 06:26:00 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hqtfz-00039P-J8 for xen-devel@lists.xenproject.org; Fri, 26 Jul 2019 06:25:59 +0000 X-Inumbo-ID: 3a8deccd-af6e-11e9-8980-bc764e045a96 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 3a8deccd-af6e-11e9-8980-bc764e045a96; Fri, 26 Jul 2019 06:25:58 +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 3B627AD31; Fri, 26 Jul 2019 06:25:57 +0000 (UTC) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 26 Jul 2019 08:25:56 +0200 Message-ID: <156412235656.2385.13861979113936528474.stgit@Palanthas> In-Reply-To: <156412188377.2385.12588508835559819141.stgit@Palanthas> References: <156412188377.2385.12588508835559819141.stgit@Palanthas> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 2/4] xen: sched: deal with vCPUs being or becoming online or offline 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: George Dunlap , Stefano Stabellini , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP If a vCPU is, or is going, offline we want it to be neither assigned to a pCPU, nor in the wait list, so: - if an offline vcpu is inserted (or migrated) it must not go on a pCPU, nor in the wait list; - if an offline vcpu is removed, we are sure that it is neither on a pCPU nor in the wait list already, so we should just bail, avoiding doing any further action; - if a vCPU goes offline we need to remove it either from its pCPU or from the wait list. Signed-off-by: Dario Faggioli Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Stefano Stabellini Cc: Roger Pau Monne --- Changes from v1: * improved wording in changelog and comments * this patch is the result of the merge of patches 2 and 3 from v1 --- xen/common/sched_null.c | 80 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index c47c1b5aae..10e96f21dd 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -339,6 +339,8 @@ static unsigned int pick_cpu(struct null_private *prv, struct vcpu *v) static void vcpu_assign(struct null_private *prv, struct vcpu *v, unsigned int cpu) { + ASSERT(is_vcpu_online(v)); + per_cpu(npc, cpu).vcpu = v; v->processor = cpu; cpumask_clear_cpu(cpu, &prv->cpus_free); @@ -358,7 +360,8 @@ static void vcpu_assign(struct null_private *prv, struct vcpu *v, } } -static void vcpu_deassign(struct null_private *prv, struct vcpu *v) +/* Returns true if a cpu was tickled */ +static bool vcpu_deassign(struct null_private *prv, struct vcpu *v) { unsigned int bs; unsigned int cpu = v->processor; @@ -403,11 +406,13 @@ static void vcpu_deassign(struct null_private *prv, struct vcpu *v) vcpu_assign(prv, wvc->vcpu, cpu); cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); spin_unlock(&prv->waitq_lock); - return; + return true; } } } spin_unlock(&prv->waitq_lock); + + return false; } /* Change the scheduler of cpu to us (null). */ @@ -445,8 +450,14 @@ static void null_vcpu_insert(const struct scheduler *ops, struct vcpu *v) ASSERT(!is_idle_vcpu(v)); lock = vcpu_schedule_lock_irq(v); - retry: + if ( unlikely(!is_vcpu_online(v)) ) + { + vcpu_schedule_unlock_irq(lock, v); + return; + } + + retry: cpu = v->processor = pick_cpu(prv, v); spin_unlock(lock); @@ -500,6 +511,14 @@ static void null_vcpu_remove(const struct scheduler *ops, struct vcpu *v) lock = vcpu_schedule_lock_irq(v); + /* If offline, the vcpu shouldn't be assigned, nor in the waitqueue */ + if ( unlikely(!is_vcpu_online(v)) ) + { + ASSERT(per_cpu(npc, v->processor).vcpu != v); + ASSERT(list_empty(&nvc->waitq_elem)); + goto out; + } + /* If v is in waitqueue, just get it out of there and bail */ if ( unlikely(!list_empty(&nvc->waitq_elem)) ) { @@ -549,11 +568,33 @@ static void null_vcpu_wake(const struct scheduler *ops, struct vcpu *v) static void null_vcpu_sleep(const struct scheduler *ops, struct vcpu *v) { + struct null_private *prv = null_priv(ops); + unsigned int cpu = v->processor; + bool tickled = false; + ASSERT(!is_idle_vcpu(v)); + /* + * Check if the vcpu is in the process of being offlined. if yes, + * we need to remove it from either its pCPU or the waitqueue. + */ + if ( unlikely(!is_vcpu_online(v)) ) + { + struct null_vcpu *nvc = null_vcpu(v); + + if ( unlikely(!list_empty(&nvc->waitq_elem)) ) + { + spin_lock(&prv->waitq_lock); + list_del_init(&nvc->waitq_elem); + spin_unlock(&prv->waitq_lock); + } + else if ( per_cpu(npc, cpu).vcpu == v ) + tickled = vcpu_deassign(prv, v); + } + /* If v is not assigned to a pCPU, or is not running, no need to bother */ - if ( curr_on_cpu(v->processor) == v ) - cpu_raise_softirq(v->processor, SCHEDULE_SOFTIRQ); + if ( likely(!tickled && curr_on_cpu(cpu) == v) ) + cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); SCHED_STAT_CRANK(vcpu_sleep); } @@ -589,24 +630,34 @@ static void null_vcpu_migrate(const struct scheduler *ops, struct vcpu *v, } /* - * v is either assigned to a pCPU, or in the waitqueue. - * - * In the former case, the pCPU to which it was assigned would - * become free, and we, therefore, should check whether there is - * anyone in the waitqueue that can be assigned to it. - * - * In the latter, there is just nothing to do. + * If v is assigned to a pCPU, then such pCPU becomes free, and we + * should look in the waitqueue if anyone else can be assigned to it. */ - if ( likely(list_empty(&nvc->waitq_elem)) ) + if ( likely(per_cpu(npc, v->processor).vcpu == v) ) { vcpu_deassign(prv, v); SCHED_STAT_CRANK(migrate_running); } - else + else if ( !list_empty(&nvc->waitq_elem) ) SCHED_STAT_CRANK(migrate_on_runq); SCHED_STAT_CRANK(migrated); + /* + * If a vcpu is (going) offline, we want it to be neither assigned + * to a pCPU, nor in the waitqueue. + * + * If it was on a cpu, we've removed it from there above. If it is + * in the waitqueue, we remove it from there now. And then we bail. + */ + if ( unlikely(!is_vcpu_online(v)) ) + { + spin_lock(&prv->waitq_lock); + list_del_init(&nvc->waitq_elem); + spin_unlock(&prv->waitq_lock); + goto out; + } + /* * Let's now consider new_cpu, which is where v is being sent. It can be * either free, or have a vCPU already assigned to it. @@ -646,6 +697,7 @@ static void null_vcpu_migrate(const struct scheduler *ops, struct vcpu *v, * at least. In case of suspend, any temporary inconsistency caused * by this, will be fixed-up during resume. */ + out: v->processor = new_cpu; }