From patchwork Thu Apr 6 08:16:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9666331 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 27CF260364 for ; Thu, 6 Apr 2017 08:18:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 161832849F for ; Thu, 6 Apr 2017 08:18:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AE4E284BC; Thu, 6 Apr 2017 08:18:39 +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 E24AC2849F for ; Thu, 6 Apr 2017 08:18:37 +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 1cw2ap-0000bD-Oo; Thu, 06 Apr 2017 08:16:35 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cw2ao-0000aW-1z for xen-devel@lists.xenproject.org; Thu, 06 Apr 2017 08:16:34 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 90/82-23940-169F5E85; Thu, 06 Apr 2017 08:16:33 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmleJIrShJLcpLzFFi42K5GNpwUDfu59M Ig3NnJS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozjn9vZCvZKVyy5fJupgXGjaBcjF4eQwAxG iVPrVrOAOCwCa1glPrT+YwVxJAQusUo0n53J2MXICeTESdy6+ZwFwq6UOPrlJhuILSSgInFz+ yomiFG/GCVeXn/EDJIQFtCTOHL0BzuE7SLx73Qb2CA2AQOJNzv2soLYIgJKEvdWTWYCsZkFoi TOLG8G62URUJVY9OMSWJxXwFti2t93QDYHB6eAj8SKZnEQUwgoPPd1AUiFqICcxMrLLawQ1YI SJ2c+YQEpYRbQlFi/Sx9iuLzE9rdzmCcwisxCUjULoWoWkqoFjMyrGDWKU4vKUot0jUz1kooy 0zNKchMzc3QNDYz1clOLixPTU3MSk4r1kvNzNzECg7+egYFxB2PrCb9DjJIcTEqivAo+TyKE+ JLyUyozEosz4otKc1KLDzFqcHAITDg7dzqTFEtefl6qkgRv0I+nEUKCRanpqRVpmTnA+IQple DgURLhbQdJ8xYXJOYWZ6ZDpE4xGnO8uPz+PRPHk5U/3jMJgU2SEufNASkVACnNKM2DGwRLG5c YZaWEeRkZGBiEeApSi3IzS1DlXzGKczAqCfNeApnCk5lXArfvFdApTECn+NwCO6UkESEl1cBY u9P7gNTXHf+dW0u0lfs/CSqkmCjXPHCtZNnvUszzOpWL72V+/6QmE66G2/6vZjJnB19e5BA2q STNvXbHEWXlxKJfXy5cv7ucwTPy/7IdObtuTV/G1H/0TJru+ksyFtcebWXf5PXqyOzpL7dlnT FRmiJgdf7I69Ni/7dXfWJ/X1W+3btipZiGEktxRqKhFnNRcSIAEGkj3BYDAAA= X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-16.tower-31.messagelabs.com!1491466590!86899850!1 X-Originating-IP: [209.85.128.193] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22970 invoked from network); 6 Apr 2017 08:16:30 -0000 Received: from mail-wr0-f193.google.com (HELO mail-wr0-f193.google.com) (209.85.128.193) by server-16.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 6 Apr 2017 08:16:30 -0000 Received: by mail-wr0-f193.google.com with SMTP id o21so3896164wrb.3 for ; Thu, 06 Apr 2017 01:16:30 -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=WrgtRz34YzXHyZ04u1nAmbUjIqE557lbekDX9tBLQwE=; b=l/BAfQnkZAXLop74i0aMbCNo9rQQQnUovp6Hc9+3rhq0ig+dhqUEYlclpz7ReW4SP6 eiuYWvlEhT1o4/+l+qcdsfV2AxFJSq0ISzcCutMa2a23fY0PARkY3hwrDBnffdCTTDD2 OQxTl5dzQN+kvXSJUU78lQKXf7a7xZt6yUugUIcrNpj/QfmajgpQL0WklB3hgGmtE2sG c4PHa2iTbj0qJLc8lOnf6j97zsbtArP8ZdyBHsrHeTkihmc8wivpwQPJg38oSpwy0OZk sUHUQGYMkZSt+/5X/EhaxATmnGDBt5kwdFoGyvdVv+t0vYWesMxxVLkGy0Y//QQMt0H6 9Wtw== 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=WrgtRz34YzXHyZ04u1nAmbUjIqE557lbekDX9tBLQwE=; b=WK/O6IoWUVVKFi3w/14DHeFffN1Hn3rVWbSoQcZY5pnRlvpT22TUBs8RU7I7CnwiFI B9ZA3OBKhQeyknuDaUPbGR5Znx5Hd/IsX9asYAhvEqJgDQrVz+HQjFhZG5oqRlnAUZUx anvdq8qIScBM/ZZ1uY/eyfhNyHPz8L9PQLmPNqHYznq0dlVHkVuNAJN2GbTL5SB+Jzcr 1z2Zz8Tm9xR4LiQb2LV8FzYDDqfcTJUWSTZlrG+X1EIn5YGmK0zuj/qQw+2kKSFm+RHU U3Pu9vBMMdA1nORR1ON5ADcxJGNJ6biUpdbkFtP04p3YXNZvMVUVP7+VJn1JDFfXsyYR hbWA== X-Gm-Message-State: AFeK/H1XKFrfV5s77V5XJeLSSjhM1ZAhwNnmfPIvlzHEwX5eWlRYWs4i 7sB9lphBDoJeMA== X-Received: by 10.28.20.202 with SMTP id 193mr16355646wmu.43.1491466590034; Thu, 06 Apr 2017 01:16:30 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.217]) by smtp.gmail.com with ESMTPSA id m21sm1433543wma.19.2017.04.06.01.16.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Apr 2017 01:16:29 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 06 Apr 2017 10:16:28 +0200 Message-ID: <149146658605.21348.4731246857836407966.stgit@Solace.fritz.box> In-Reply-To: <149146456487.21348.8554211499146017782.stgit@Solace.fritz.box> References: <149146456487.21348.8554211499146017782.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Anshul Makkar Subject: [Xen-devel] [PATCH v2 3/7] xen: credit: consider tickled pCPUs as busy. 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 Currently, it can happen that __runq_tickle(), running on pCPU 2 because vCPU x woke up, decides to tickle pCPU 3, because it's idle. Just after that, but before pCPU 3 manages to schedule and pick up x, either __runq_tickel() or __csched_cpu_pick(), running on pCPU 6, sees that idle pCPUs are 0, 1 and also 3, and for whatever reason it also chooses 3 for waking up (or migrating) vCPU y. When pCPU 3 goes through the scheduler, it will pick up, say, vCPU x, and y will sit in its runqueue, even if there are idle pCPUs. Alleviate this by marking a pCPU to be idle right away when tickling it (like, e.g., it happens in Credit2). Note that this does not eliminate the race. That is not possible without introducing proper locking for the cpumasks the scheduler uses. It significantly reduces the window during which it can happen, though. Introduce proper locking for the cpumask can, in theory, be done, and may be investigated in future. It is a significant amount of work to do it properly (e.g., avoiding deadlock), and it is likely to adversely affect scalability, and so it may be a path it is just not worth following. Signed-off-by: Dario Faggioli --- Cc: George Dunlap Cc: Anshul Makkar --- xen/common/sched_credit.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 5a3f13f..c753089 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -489,7 +489,17 @@ static inline void __runq_tickle(struct csched_vcpu *new) __trace_var(TRC_CSCHED_TICKLE, 1, sizeof(cpu), &cpu); } - /* Send scheduler interrupts to designated CPUs */ + /* + * Mark the designated CPUs as busy and send them all the scheduler + * interrupt. We need the for_each_cpu for dealing with the + * !opt_tickle_one_idle case. We must use cpumask_clear_cpu() and + * can't use cpumask_andnot(), because prv->idlers needs atomic access. + * + * In the default (and most common) case, when opt_rickle_one_idle is + * true, the loop does only one step, and only one bit is cleared. + */ + for_each_cpu(cpu, &mask) + cpumask_clear_cpu(cpu, prv->idlers); cpumask_raise_softirq(&mask, SCHEDULE_SOFTIRQ); } else @@ -985,6 +995,8 @@ csched_vcpu_acct(struct csched_private *prv, unsigned int cpu) SCHED_VCPU_STAT_CRANK(svc, migrate_r); SCHED_STAT_CRANK(migrate_running); set_bit(_VPF_migrating, ¤t->pause_flags); + ASSERT(!cpumask_test_cpu(cpu, + CSCHED_PRIV(per_cpu(scheduler, cpu))->idlers)); cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); } } @@ -1077,13 +1089,17 @@ static void csched_vcpu_sleep(const struct scheduler *ops, struct vcpu *vc) { struct csched_vcpu * const svc = CSCHED_VCPU(vc); + unsigned int cpu = vc->processor; SCHED_STAT_CRANK(vcpu_sleep); BUG_ON( is_idle_vcpu(vc) ); - if ( curr_on_cpu(vc->processor) == vc ) - cpu_raise_softirq(vc->processor, SCHEDULE_SOFTIRQ); + if ( curr_on_cpu(cpu) == vc ) + { + ASSERT(!cpumask_test_cpu(cpu, CSCHED_PRIV(per_cpu(scheduler, cpu))->idlers)); + cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); + } else if ( __vcpu_on_runq(svc) ) __runq_remove(svc); }