From patchwork Fri Apr 7 00:34:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9668671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BD29660146 for ; Fri, 7 Apr 2017 00:36:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF5A6204C1 for ; Fri, 7 Apr 2017 00:36:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2B1E285EB; Fri, 7 Apr 2017 00:36:25 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E3642204C1 for ; Fri, 7 Apr 2017 00:36:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwHr3-0005pQ-9v; Fri, 07 Apr 2017 00:34:21 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwHr2-0005oz-84 for xen-devel@lists.xenproject.org; Fri, 07 Apr 2017 00:34:20 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id E3/D4-01936-B8ED6E85; Fri, 07 Apr 2017 00:34:19 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOIsWRWlGSWpSXmKPExsVyMbThkG7nvWc RBrf2all83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBmH/8xgLXhvXPGq8zZ7A+MKjS5GLg4hgZmM Eht7OhhBHBaBNawSjX0tbCCOhMAlVonF++6xdzFyAjkxEsdm9jB1MXIA2dUSW857gISFBFQkb m5fxQQx6RejxLID55hAEsICehJHjv5gB6kXFnCS+PcjBCTMJmAg8WbHXlYQW0RASeLeqslgvc wCNxgl+tbOA9vFIqAqsXb6JFaQXl4Bb4kTE2RAwpwCPhJvJ21nhtjrLXFm/yc2EFtUQE5i5eU WsJm8AoISJ2c+YQFpZRbQlFi/Sx8kzCwgL7H97RzmCYwis5BUzUKomoWkagEj8ypGjeLUorLU Il1DE72kosz0jJLcxMwcXUMDU73c1OLixPTUnMSkYr3k/NxNjMDgZwCCHYxnT3seYpTkYFIS5 VXweRIhxJeUn1KZkVicEV9UmpNafIhRhoNDSYKX/+6zCCHBotT01Iq0zBxgHMKkJTh4lER4xU HSvMUFibnFmekQqVOMxhwvLr9/z8TxZOWP90xCLHn5ealS4rzX7wCVCoCUZpTmwQ2CpYdLjLJ SwryMQKcJ8RSkFuVmlqDKv2IU52BUEuZ9CTKFJzOvBG7fK6BTmIBO8bn1FOSUkkSElFQDY/zS Fb5ij9026avcsW0q4lheNiMt9xb30i1qRxY6Bsd7C7+ertrXccD+d2aM6IlLu7MvzJFa9rW+p /6N5JE9i1e8bp37WGCx9CSNX+vK3u7YeENlO0N5gooEL9dtP/e1/KqM1hdbnhVwd8eKcEqobO HN+Sl3sPzsh6/vlrf0S+TknmTrzt/OqMRSnJFoqMVcVJwIAMGWEg8KAwAA X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1491525257!78302688!1 X-Originating-IP: [209.85.128.194] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11992 invoked from network); 7 Apr 2017 00:34:17 -0000 Received: from mail-wr0-f194.google.com (HELO mail-wr0-f194.google.com) (209.85.128.194) by server-15.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Apr 2017 00:34:17 -0000 Received: by mail-wr0-f194.google.com with SMTP id t20so15671658wra.2 for ; Thu, 06 Apr 2017 17:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=NJIMsEXZll5G5HQ60tObGyVagVWm2maZ27v4uRwFIho=; b=onR7J7malA7YZtuksowYnuDXQfjjnEM0kKF4O4Y0BZ+4sWkFnvQ6gPCg8Lgsmvyfnv OWlenl56ETxRo7nn/u0xkVMd4jaOY9ObmDfGSiGTAfMrueALqZppKdsZHWuRHFchV94J +8PKMnrCFFJeQ7iOP80EMO35GfoXCAsDwXOE0xLdreyQ3Oip8tjmGoDG/796grQDOMoF sRTRad3npXckN1zY7HDAr03XZ5VMQfXSnRgq95E23o1xhcedc/jV5Ma3EKoxNL0rHwfe e9fwG0r271kBWqRDN0V4deiBXCK9UjGQP3GikCiqv65J8bbgJeYInBR3wSfKjACdDXdH XHSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=NJIMsEXZll5G5HQ60tObGyVagVWm2maZ27v4uRwFIho=; b=QwzpT7K8sRwTMBSBQx2nxNUHY4qKiqpFnvJgVGGbvdlOBFfhKRvVm6+qPdJhSlZcu9 /B5v3H/yipI75TEeYdwb7ru7lpVySMTH0dU+kuOR+BGVRzUhHi4kwI9YSrJe1d2StqeE wnvYae24eCp0x7dQw/I3k1LBsSf3R/ACRIy+BEsnGxAVFymOpZY2xs/bbZRu+bvPXo6n XpcCDlxBgeMgrq2x19KSaj2vMLssmmSshPyHDP4GfJNbVFqcQjIy4i0mi13EAenPtYcr 1WBQ3XzWj6sAPXtugRRmf+bevkMmXFEEmkhV+4v1Wdx/oIIw3E1OqftZuyB8kUePGwvp bE5Q== X-Gm-Message-State: AFeK/H0ApXZhGWWn5R1kseyN24HLWd9eCjBQIQvRRzRI/FwLhysFIJlQV/gOsRpvzoZnUg== X-Received: by 10.223.128.194 with SMTP id 60mr25026603wrl.175.1491525257298; Thu, 06 Apr 2017 17:34:17 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.217]) by smtp.gmail.com with ESMTPSA id k13sm4242987wmi.28.2017.04.06.17.34.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Apr 2017 17:34:16 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 07 Apr 2017 02:34:15 +0200 Message-ID: <149152525510.31941.6625917268878264420.stgit@Solace.fritz.box> In-Reply-To: <149152426922.31941.6054159629649244529.stgit@Solace.fritz.box> References: <149152426922.31941.6054159629649244529.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Stefano Stabellini , Jonathan Davies , Julien Grall , George Dunlap , Marcus Granado Subject: [Xen-devel] [PATCH v2 4/5] xen: sched_null: support for hard affinity X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP As a (rudimental) way of directing and affecting the placement logic implemented by the scheduler, support vCPU hard affinity. Basically, a vCPU will now be assigned only to a pCPU that is part of its own hard affinity. If such pCPU(s) is (are) busy, the vCPU will wait, like it happens when there are no free pCPUs. Signed-off-by: Dario Faggioli --- Cc: George Dunlap Cc: Stefano Stabellini Cc: Julien Grall Cc: Jonathan Davies Cc: Marcus Granado --- Changes from v1: - coding style fixes (removed some hard tabs); - better signature for check_nvc_affinity() (also renamed in vcpu_check_affinity()); - fixed bug in null_vcpu_remove() using uninitialized cpumask. --- xen/common/sched_null.c | 50 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index c2c4182..96652a0 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -115,6 +115,14 @@ static inline struct null_dom *null_dom(const struct domain *d) return d->sched_priv; } +static inline bool vcpu_check_affinity(struct vcpu *v, unsigned int cpu) +{ + cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, + cpupool_domain_cpumask(v->domain)); + + return cpumask_test_cpu(cpu, cpumask_scratch_cpu(cpu)); +} + static int null_init(struct scheduler *ops) { struct null_private *prv; @@ -276,16 +284,22 @@ static unsigned int pick_cpu(struct null_private *prv, struct vcpu *v) ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, cpus); + /* - * If our processor is free, or we are assigned to it, and it is - * also still valid, just go for it. + * If our processor is free, or we are assigned to it, and it is also + * still valid and part of our affinity, just go for it. + * (Note that we may call vcpu_check_affinity(), but we deliberately + * don't, so we get to keep in the scratch cpumask what we have just + * put in it.) */ if ( likely((per_cpu(npc, cpu).vcpu == NULL || per_cpu(npc, cpu).vcpu == v) - && cpumask_test_cpu(cpu, cpus)) ) + && cpumask_test_cpu(cpu, cpumask_scratch_cpu(cpu))) ) return cpu; - /* If not, just go for a valid free pCPU, if any */ - cpumask_and(cpumask_scratch_cpu(cpu), &prv->cpus_free, cpus); + /* If not, just go for a free pCPU, within our affinity, if any */ + cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), + &prv->cpus_free); new_cpu = cpumask_first(cpumask_scratch_cpu(cpu)); if ( likely(new_cpu != nr_cpu_ids) ) @@ -302,7 +316,8 @@ static unsigned int pick_cpu(struct null_private *prv, struct vcpu *v) * as we will actually assign the vCPU to the pCPU we return from here, * only if the pCPU is free. */ - return cpumask_any(cpus); + cpumask_and(cpumask_scratch_cpu(cpu), cpus, v->cpu_hard_affinity); + return cpumask_any(cpumask_scratch_cpu(cpu)); } static void vcpu_assign(struct null_private *prv, struct vcpu *v, @@ -361,6 +376,7 @@ static void null_vcpu_insert(const struct scheduler *ops, struct vcpu *v) { struct null_private *prv = null_priv(ops); struct null_vcpu *nvc = null_vcpu(v); + unsigned int cpu; spinlock_t *lock; ASSERT(!is_idle_vcpu(v)); @@ -368,23 +384,25 @@ static void null_vcpu_insert(const struct scheduler *ops, struct vcpu *v) lock = vcpu_schedule_lock_irq(v); retry: - v->processor = pick_cpu(prv, v); + cpu = v->processor = pick_cpu(prv, v); spin_unlock(lock); lock = vcpu_schedule_lock(v); + cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, + cpupool_domain_cpumask(v->domain)); + /* If the pCPU is free, we assign v to it */ - if ( likely(per_cpu(npc, v->processor).vcpu == NULL) ) + if ( likely(per_cpu(npc, cpu).vcpu == NULL) ) { /* * Insert is followed by vcpu_wake(), so there's no need to poke * the pcpu with the SCHEDULE_SOFTIRQ, as wake will do that. */ - vcpu_assign(prv, v, v->processor); + vcpu_assign(prv, v, cpu); } - else if ( cpumask_intersects(&prv->cpus_free, - cpupool_domain_cpumask(v->domain)) ) + else if ( cpumask_intersects(&prv->cpus_free, cpumask_scratch_cpu(cpu)) ) { /* * If the pCPU is not free (e.g., because we raced with another @@ -413,7 +431,6 @@ static void null_vcpu_insert(const struct scheduler *ops, struct vcpu *v) static void _vcpu_remove(struct null_private *prv, struct vcpu *v) { unsigned int cpu = v->processor; - struct domain *d = v->domain; struct null_vcpu *wvc; ASSERT(list_empty(&null_vcpu(v)->waitq_elem)); @@ -425,7 +442,7 @@ static void _vcpu_remove(struct null_private *prv, struct vcpu *v) * If yes, we assign it to cpu, in spite of v. */ wvc = list_first_entry_or_null(&prv->waitq, struct null_vcpu, waitq_elem); - if ( wvc && cpumask_test_cpu(cpu, cpupool_domain_cpumask(d)) ) + if ( wvc && vcpu_check_affinity(wvc->vcpu, cpu) ) { list_del_init(&wvc->waitq_elem); vcpu_assign(prv, wvc->vcpu, cpu); @@ -547,11 +564,12 @@ static void null_vcpu_migrate(const struct scheduler *ops, struct vcpu *v, * 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. * - * In the former case, we should assign v to it, and try to get it to run. + * In the former case, we should assign v to it, and try to get it to run, + * if possible, according to affinity. * * In latter, all we can do is to park v in the waitqueue. */ - if ( per_cpu(npc, new_cpu).vcpu == NULL ) + if ( per_cpu(npc, new_cpu).vcpu == NULL && vcpu_check_affinity(v, new_cpu) ) { /* v might have been in the waitqueue, so remove it */ spin_lock(&prv->waitq_lock); @@ -635,7 +653,7 @@ static struct task_slice null_schedule(const struct scheduler *ops, { spin_lock(&prv->waitq_lock); wvc = list_first_entry_or_null(&prv->waitq, struct null_vcpu, waitq_elem); - if ( wvc ) + if ( wvc && vcpu_check_affinity(wvc->vcpu, cpu) ) { vcpu_assign(prv, wvc->vcpu, cpu); list_del_init(&wvc->waitq_elem);