From patchwork Tue Jan 17 17:26:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9521587 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 7FF6B601C3 for ; Tue, 17 Jan 2017 17:28:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7193E285F1 for ; Tue, 17 Jan 2017 17:28:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 662C6285F7; Tue, 17 Jan 2017 17:28:57 +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 CBB74285F1 for ; Tue, 17 Jan 2017 17:28:56 +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 1cTXWu-00088h-SH; Tue, 17 Jan 2017 17:26:44 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cTXWt-00088D-8w for xen-devel@lists.xenproject.org; Tue, 17 Jan 2017 17:26:43 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 3B/BE-09053-2D35E785; Tue, 17 Jan 2017 17:26:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLIsWRWlGSWpSXmKPExsXiVRvkrHsxuC7 CoOuLjcX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmrFo/RH2gotaFXc2N7A1MO5W7GLk4hASmM4o sXHLAqYuRk4OFoE1rBLTv/qAJCQELrFKzFj3mQUkISEQI7H71XUmCLtGYubsqWC2kICKxM3tq 5ggJs1ikmj/950VJCEsoCdx5OgPdgjbWWJbWyvYIDYBA4k3O/aC1YgIKEncWzUZbBCzQJFEW+ MuRogrVCVW7jwLVs8r4C0xo3810BwODk4BH4lXZyUh9npL7G26ANYqKiAnsfJyCytEuaDEyZl PWEDKmQU0Jdbv0oeYLi+x/e0c5gmMIrOQVM1CqJqFpGoBI/MqRo3i1KKy1CJdI3O9pKLM9IyS 3MTMHF1DAzO93NTi4sT01JzEpGK95PzcTYzA4GcAgh2Mi9cGHmKU5GBSEuXteFwbIcSXlJ9Sm ZFYnBFfVJqTWnyIUYODQ2DC2bnTmaRY8vLzUpUkeLuD6iKEBItS01Mr0jJzgPEJUyrBwaMkwr sLJM1bXJCYW5yZDpE6xajLsWvX5ZdMQmAzpMR500GKBECKMkrz4EbAUsUlRlkpYV5GoAOFeAp Si3IzS1DlXzGKczAqCfP2g0zhycwrgdv0CugIJqAjrutUgxxRkoiQkmpgPJ3XsXv/v9usi2yK uFY9ZdoRwjQ/nPVRsmsMv2hBR+V5TbaDgT+cZn97V3T86buvq4tK9/hPuPpb4mGTl6Lta+5Es y0qRosK5T27FyR1e6izPgtItH40T+5qQs/HsIUHLkqmus50mNc79+EfpoJl24xSj/TpPlcq18 6ez+f7SrHv/vUDrHJaSizFGYmGWsxFxYkA/ClJ7BADAAA= X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1484674001!29913278!1 X-Originating-IP: [74.125.82.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 42007 invoked from network); 17 Jan 2017 17:26:41 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-2.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 17 Jan 2017 17:26:41 -0000 Received: by mail-wm0-f67.google.com with SMTP id c85so7500915wmi.1 for ; Tue, 17 Jan 2017 09:26:41 -0800 (PST) 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=/eURQTu+l/CNU95MR1FUkNNTYlNZnfwS8TXgmjryxbM=; b=G/CIR24C+D093T+cPjiGtlC7I2swzZ2OZcwfYlrZVfgmY+zoKJeluh9TvhTMzzAd78 /2IgfOCy7U/h1kqrF9RONY9xTSYZRXxjieR2tUeU8oj7m7ANGdhz6rcWCGDhINoL3ogp UXq7ZW5Dy0jG4YZfgHpz/xZyHJKGY9Di1PDWkMuiRg/yPuiS7FXSA5OvzwDfjgTqKl9d 2nBjCgLcsfVTWWKW9TPxDimg4/6nguV23izhibaxqrOaEGc0VCw3RPOH9PygKkIwyfC4 n58vS3qgdjjKIcU8YAHPZLxNsrvc5F1LTmjuNTYpCXDh+KTP0HSqUetchv2ghvPEmaLp eCBQ== 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=/eURQTu+l/CNU95MR1FUkNNTYlNZnfwS8TXgmjryxbM=; b=itpMsbVyGC7l/P9UHH5A0vNoMIIbhaFR1O5fUhZH7EYaFgkD9zcwfyCDayoLRrYONf kfbq1cC8ZiYLKqllRaNRoOZDSeDNQuZq7UI2xb8eDTmYNoYD+L4AmCYmLfLJCp1d5UQB 5wl2Q6Xhm17+aHWXobb2lyOm+GtTbRtbgJD2eYjKJ/6rcuNe/ei0LUVL6+S86X/XX3Fl fIRobK5NgGMmh/O0fPCa9yNJxRtllTxFIxHSrfnfNFdz3JFHijkG1TBQgmxJc0Qk7E6s abzMhZjf9kfjj9FFIiFauob8+pH0f3/kW5VDykbTiouah6QFe9dWJPfLjU8arP/MOG2W 1zNQ== X-Gm-Message-State: AIkVDXLnTKyDd31YfFrhCqrtlpvH2/d+bULpfYFJIbV2DeaPnOgLaBgm/zm4aEWKYcb6Nw== X-Received: by 10.223.155.221 with SMTP id e29mr27875695wrc.107.1484674001487; Tue, 17 Jan 2017 09:26:41 -0800 (PST) Received: from Solace.fritz.box (58-209-66-80.hosts.abilene.it. [80.66.209.58]) by smtp.gmail.com with ESMTPSA id g197sm38552947wmd.15.2017.01.17.09.26.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2017 09:26:40 -0800 (PST) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Tue, 17 Jan 2017 18:26:38 +0100 Message-ID: <148467399874.27920.3501738903081546236.stgit@Solace.fritz.box> In-Reply-To: <148467379229.27920.2367500429219327194.stgit@Solace.fritz.box> References: <148467379229.27920.2367500429219327194.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Jan Beulich Subject: [Xen-devel] [PATCH 1/5] xen: credit2: use the correct scratch cpumask. 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 In fact, there is one scratch mask per each CPU. When you use the one of a CPU, it must be true that: - the CPU belongs to your cpupool and scheduler, - you own the runqueue lock (the one you take via {v,p}cpu_schedule_lock()) for that CPU. This was not the case within the following functions: get_fallback_cpu(), csched2_cpu_pick(): as we can't be sure we either are on, or hold the lock for, the CPU that is in the vCPU's 'v->processor'. migrate(): it's ok, when called from balance_load(), because that comes from csched2_schedule(), which takes the runqueue lock of the CPU where it executes. But it is not ok when we come from csched2_vcpu_migrate(), which can be called from other places. The fix is to explicitly use the scratch space of the CPUs for which we know we hold the runqueue lock. Signed-off-by: Dario Faggioli Reported-by: Jan Beulich Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Jan Beulich --- This is a bugfix, and should be backported to 4.8. --- xen/common/sched_credit2.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index ef8e0d8..523922e 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -510,24 +510,23 @@ void smt_idle_mask_clear(unsigned int cpu, cpumask_t *mask) */ static int get_fallback_cpu(struct csched2_vcpu *svc) { - int cpu; + int fallback_cpu, cpu = svc->vcpu->processor; - if ( likely(cpumask_test_cpu(svc->vcpu->processor, - svc->vcpu->cpu_hard_affinity)) ) - return svc->vcpu->processor; + if ( likely(cpumask_test_cpu(cpu, svc->vcpu->cpu_hard_affinity)) ) + return cpu; - cpumask_and(cpumask_scratch, svc->vcpu->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), svc->vcpu->cpu_hard_affinity, &svc->rqd->active); - cpu = cpumask_first(cpumask_scratch); - if ( likely(cpu < nr_cpu_ids) ) - return cpu; + fallback_cpu = cpumask_first(cpumask_scratch_cpu(cpu)); + if ( likely(fallback_cpu < nr_cpu_ids) ) + return fallback_cpu; cpumask_and(cpumask_scratch, svc->vcpu->cpu_hard_affinity, cpupool_domain_cpumask(svc->vcpu->domain)); - ASSERT(!cpumask_empty(cpumask_scratch)); + ASSERT(!cpumask_empty(cpumask_scratch_cpu(cpu))); - return cpumask_first(cpumask_scratch); + return cpumask_first(cpumask_scratch_cpu(cpu)); } /* @@ -1492,7 +1491,7 @@ static int csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) { struct csched2_private *prv = CSCHED2_PRIV(ops); - int i, min_rqi = -1, new_cpu; + int i, min_rqi = -1, new_cpu, cpu = vc->processor; struct csched2_vcpu *svc = CSCHED2_VCPU(vc); s_time_t min_avgload = MAX_LOAD; @@ -1512,7 +1511,7 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) * just grab the prv lock. Instead, we'll have to trylock, and * do something else reasonable if we fail. */ - ASSERT(spin_is_locked(per_cpu(schedule_data, vc->processor).schedule_lock)); + ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); if ( !read_trylock(&prv->lock) ) { @@ -1539,9 +1538,9 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) } else { - cpumask_and(cpumask_scratch, vc->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), vc->cpu_hard_affinity, &svc->migrate_rqd->active); - new_cpu = cpumask_any(cpumask_scratch); + new_cpu = cpumask_any(cpumask_scratch_cpu(cpu)); if ( new_cpu < nr_cpu_ids ) goto out_up; } @@ -1598,9 +1597,9 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) goto out_up; } - cpumask_and(cpumask_scratch, vc->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), vc->cpu_hard_affinity, &prv->rqd[min_rqi].active); - new_cpu = cpumask_any(cpumask_scratch); + new_cpu = cpumask_any(cpumask_scratch_cpu(cpu)); BUG_ON(new_cpu >= nr_cpu_ids); out_up: @@ -1675,6 +1674,8 @@ static void migrate(const struct scheduler *ops, struct csched2_runqueue_data *trqd, s_time_t now) { + int cpu = svc->vcpu->processor; + if ( unlikely(tb_init_done) ) { struct { @@ -1696,7 +1697,7 @@ static void migrate(const struct scheduler *ops, svc->migrate_rqd = trqd; __set_bit(_VPF_migrating, &svc->vcpu->pause_flags); __set_bit(__CSFLAG_runq_migrate_request, &svc->flags); - cpu_raise_softirq(svc->vcpu->processor, SCHEDULE_SOFTIRQ); + cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); SCHED_STAT_CRANK(migrate_requested); } else @@ -1711,9 +1712,9 @@ static void migrate(const struct scheduler *ops, } __runq_deassign(svc); - cpumask_and(cpumask_scratch, svc->vcpu->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), svc->vcpu->cpu_hard_affinity, &trqd->active); - svc->vcpu->processor = cpumask_any(cpumask_scratch); + svc->vcpu->processor = cpumask_any(cpumask_scratch_cpu(cpu)); ASSERT(svc->vcpu->processor < nr_cpu_ids); __runq_assign(svc, trqd);