From patchwork Wed Aug 17 17:18:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9286207 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 45FF260839 for ; Wed, 17 Aug 2016 17:20:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3658A294A2 for ; Wed, 17 Aug 2016 17:20:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B371294B8; Wed, 17 Aug 2016 17:20:41 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 7DFA6294A2 for ; Wed, 17 Aug 2016 17:20:40 +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 1ba4U0-0008QD-0l; Wed, 17 Aug 2016 17:18:28 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ba4Ty-0008PY-Ix for xen-devel@lists.xenproject.org; Wed, 17 Aug 2016 17:18:26 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 58/E3-30284-16C94B75; Wed, 17 Aug 2016 17:18:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEIsWRWlGSWpSXmKPExsXiVRvkpJswZ0u 4wYw1Fhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0bLg1UsBS80K1bvKmhgfCTfxcjFISQwnVHi 1PXtbCAOi8AaVom5uz8zgjgSApdYJY7sWM7excgJ5MRItCzcwgZhV0tsfHGSGcQWElCRuLl9F RPEqLlMElM3PGMFSQgL6EkcOfqDHcIOlzgy5yGYzSZgIPFmx16wGhEBJYl7qyYzgdjMAlESZ5 Y3gw1lEVCVWNG1GczmFfCR2HXxBVgNJ5B9a/VvFojF3hKHJ/eAHSQqICex8nILK0S9oMTJmU+ AajiAZmpKrN+lDzFeXmL72znMExhFZiGpmoVQNQtJ1QJG5lWMGsWpRWWpRbpGJnpJRZnpGSW5 iZk5uoYGpnq5qcXFiempOYlJxXrJ+bmbGIHhX8/AwLiD8eZkv0OMkhxMSqK8d6q3hAvxJeWnV GYkFmfEF5XmpBYfYpTh4FCS4O2ZDZQTLEpNT61Iy8wBRiJMWoKDR0mEdydImre4IDG3ODMdIn WKUZdjy9R7a5mEWPLy81KlxHlTQIoEQIoySvPgRsCSwiVGWSlhXkYGBgYhnoLUotzMElT5V4z iHIxKwrzLQKbwZOaVwG16BXQEE9ARvPxgR5QkIqSkGhgXrDVbaDtL9EOgoOzdOapGLn8nWrw+ pqdi+rJG86jLVp/7ch8fW594Gmq9OqE9M6PGjE1twq7Xumveb11oJqp1o9thye7g0KkWN4sqR L5wK1+I6Rf+zxj1ZhlblNe/zyfMUqfNNhSImXnA/lvDxy/88t+KcvevZE6Kf8cueVVN8doGLz b5i9+UWIozEg21mIuKEwFrUYeeBQMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1471454304!42815715!1 X-Originating-IP: [74.125.82.66] X-SpamReason: No, hits=0.2 required=7.0 tests=RCVD_ILLEGAL_IP X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1027 invoked from network); 17 Aug 2016 17:18:24 -0000 Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by server-11.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 17 Aug 2016 17:18:24 -0000 Received: by mail-wm0-f66.google.com with SMTP id i5so26280283wmg.2 for ; Wed, 17 Aug 2016 10:18:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=irpJnKeXAd4+nWdaNMrRNC79U/Sg26BDKFH2PZvrIZY=; b=ZG9N7W48EQDPwfsekpBFOhvsFblP67DOLIHHWTbK4qcRPxWtJvo9au+WNd3/OnPjhl 7JmxK2OxJDm7LYVYsBjm+LspofPCduhsH9jqRAfsaAl1ZSjjkvBR8MI3xiaTaMkU6xTG rmtw01dA811esjQNukaJezhEGHFaU60nlNeGaDGedQ2jQuZOib41ezuughaqHy8pPKdO LgS3aIRPQlAxIh8OyR2RLlhN36eKuQM1q35h27ecg4KTGySbKEUP9YFpp96h/T6hjCtt IXMH07Se4hWURTWtADpGG15PYFSUu74551HW6ScXLAKA/9oefJh+baKavh19+Q7Dw2Nd 2SMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; 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=irpJnKeXAd4+nWdaNMrRNC79U/Sg26BDKFH2PZvrIZY=; b=XkB263/NPac54Ocp9jDTyYGXE4W/DIUe8rOmaWG6T68iGM79RDo+vzQP5Ndt0owKkD JsjlptBnTcA6qjWScEmS4cvX3511UYblW3LtIqaJzZ6uM4qqEDsv6lKoybI+/7E3NhEl D6DqSeRsMW9djrEyPjV4Fi4jdq4Ndp9n7UpE3eXElP8kUozzTbbMQr9LcHHGYAXKPs6Q saM1KYrRyuLKiwg0vByOATCzV0wGvaPaLR7nEC4wf9CYdPsWTRtHzMcD/9mLyO4P5iD9 ijMlY5xxgdO+5AOhUfEgT+2LC6IUPuGoYbneslCTRwYJ+t2eKV/bPVQfSf+PLdwRa0Ep SjzQ== X-Gm-Message-State: AEkoouuf2Urr51iAF7JBNWWn7C/kWzAx1NesEbYCFJpQtlfBVcxMBaRRmyKIbH4Md03lrQ== X-Received: by 10.28.62.204 with SMTP id l195mr11803227wma.117.1471454304430; Wed, 17 Aug 2016 10:18:24 -0700 (PDT) Received: from Solace.fritz.box (net-2-32-14-104.cust.vodafonedsl.it. [2.32.14.104]) by smtp.gmail.com with ESMTPSA id e65sm27542739wmg.3.2016.08.17.10.18.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Aug 2016 10:18:23 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Wed, 17 Aug 2016 19:18:22 +0200 Message-ID: <147145430260.25877.10888566175316568591.stgit@Solace.fritz.box> In-Reply-To: <147145358844.25877.7490417583264534196.stgit@Solace.fritz.box> References: <147145358844.25877.7490417583264534196.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Anshul Makkar Subject: [Xen-devel] [PATCH 07/24] xen: sched: don't rate limit context switches in case of yields 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 both Credit1 and Credit2, if a vcpu yields, let it... well... yield! In fact, context switch rate limiting has been primarily introduced to avoid too heavy context switch rate due to interrupts, and, in general, asynchronous events. In a vcpu "voluntarily" yields, we really should let it give up the cpu for a while. For instance, the reason may be that it's about to start spinning, and there's few point in forcing a vcpu to spin for (potentially) the entire rate-limiting period. Signed-off-by: Dario Faggioli --- Cc: George Dunlap Cc: Anshul Makkar --- xen/common/sched_credit.c | 20 +++++++++++-------- xen/common/sched_credit2.c | 47 +++++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 3f439a0..ca04732 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1771,9 +1771,18 @@ csched_schedule( * cpu and steal it. */ - /* If we have schedule rate limiting enabled, check to see - * how long we've run for. */ - if ( !tasklet_work_scheduled + /* + * If we have schedule rate limiting enabled, check to see + * how long we've run for. + * + * If scurr is yielding, however, we don't let rate limiting kick in. + * In fact, it may be the case that scurr is about to spin, and there's + * no point forcing it to do so until rate limiting expires. + * + * While there, take the chance for clearing the yield flag at once. + */ + if ( !test_and_clear_bit(CSCHED_FLAG_VCPU_YIELD, &scurr->flags) + && !tasklet_work_scheduled && prv->ratelimit_us && vcpu_runnable(current) && !is_idle_vcpu(current) @@ -1808,11 +1817,6 @@ csched_schedule( } /* - * Clear YIELD flag before scheduling out - */ - clear_bit(CSCHED_FLAG_VCPU_YIELD, &scurr->flags); - - /* * SMP Load balance: * * If the next highest priority local runnable VCPU has already eaten diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 569174b..c8e0ee7 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -2267,36 +2267,40 @@ runq_candidate(struct csched2_runqueue_data *rqd, struct list_head *iter; struct csched2_vcpu *snext = NULL; struct csched2_private *prv = CSCHED2_PRIV(per_cpu(scheduler, cpu)); - int yield_bias = 0; - - /* Default to current if runnable, idle otherwise */ - if ( vcpu_runnable(scurr->vcpu) ) - { - /* - * The way we actually take yields into account is like this: - * if scurr is yielding, when comparing its credits with other - * vcpus in the runqueue, act like those other vcpus had yield_bias - * more credits. - */ - if ( unlikely(scurr->flags & CSFLAG_vcpu_yield) ) - yield_bias = CSCHED2_YIELD_BIAS; - - snext = scurr; - } - else - snext = CSCHED2_VCPU(idle_vcpu[cpu]); + /* + * The way we actually take yields into account is like this: + * if scurr is yielding, when comparing its credits with other vcpus in + * the runqueue, act like those other vcpus had yield_bias more credits. + */ + int yield_bias = __test_and_clear_bit(__CSFLAG_vcpu_yield, &scurr->flags) ? + CSCHED2_YIELD_BIAS : 0; /* * Return the current vcpu if it has executed for less than ratelimit. * Adjuststment for the selected vcpu's credit and decision * for how long it will run will be taken in csched2_runtime. + * + * Note that, if scurr is yielding, we don't let rate limiting kick in. + * In fact, it may be the case that scurr is about to spin, and there's + * no point forcing it to do so until rate limiting expires. + * + * To check whether we are yielding, it's enough to look at yield_bias + * (as CSCHED2_YIELD_BIAS can't be zero). Also, note that the yield flag + * has been cleared already above. */ - if ( prv->ratelimit_us && !is_idle_vcpu(scurr->vcpu) && + if ( !yield_bias && + prv->ratelimit_us && !is_idle_vcpu(scurr->vcpu) && vcpu_runnable(scurr->vcpu) && (now - scurr->vcpu->runstate.state_entry_time) < MICROSECS(prv->ratelimit_us) ) return scurr; + /* Default to current if runnable, idle otherwise */ + if ( vcpu_runnable(scurr->vcpu) ) + snext = scurr; + else + snext = CSCHED2_VCPU(idle_vcpu[cpu]); + list_for_each( iter, &rqd->runq ) { struct csched2_vcpu * svc = list_entry(iter, struct csched2_vcpu, runq_elem); @@ -2423,7 +2427,8 @@ csched2_schedule( */ if ( tasklet_work_scheduled ) { - trace_var(TRC_CSCHED2_SCHED_TASKLET, 1, 0, NULL); + __clear_bit(__CSFLAG_vcpu_yield, &scurr->flags); + trace_var(TRC_CSCHED2_SCHED_TASKLET, 1, 0, NULL); snext = CSCHED2_VCPU(idle_vcpu[cpu]); } else @@ -2436,8 +2441,6 @@ csched2_schedule( && vcpu_runnable(current) ) __set_bit(__CSFLAG_delayed_runq_add, &scurr->flags); - __clear_bit(__CSFLAG_vcpu_yield, &scurr->flags); - ret.migrated = 0; /* Accounting for non-idle tasks */