From patchwork Fri Jun 17 23:12:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9185141 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 31BB8601C0 for ; Fri, 17 Jun 2016 23:14:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2075D200E7 for ; Fri, 17 Jun 2016 23:14:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1548227F07; Fri, 17 Jun 2016 23:14:07 +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 6B854200E7 for ; Fri, 17 Jun 2016 23:14:06 +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 1bE2vz-0003NB-VU; Fri, 17 Jun 2016 23:12:19 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bE2vy-0003MQ-Lp for xen-devel@lists.xenproject.org; Fri, 17 Jun 2016 23:12:18 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id C0/0B-10998-1D384675; Fri, 17 Jun 2016 23:12:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrHIsWRWlGSWpSXmKPExsXiVRvkqHuxOSX c4Px/EYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPZ32WMBX06FdOfLWVuYFyq1MXIxSEkMINR 4n7nFUYQh0VgDavEtlV/WUAcCYFLrBJvvsxm72LkBHJiJI6emMgEYZdJzGi5CGYLCahI3Ny+i gli1CImibU3r7KAJIQF9CSOHP3BDmF7Spzqu8MMYrMJGEi82bGXFcQWEVCSuLdqMlgzs0ADo8 SEx7vAprIIqErcWvQXqIiDg1fAR+JfdzxImFPAV2L1lV1sEIt9JC6eewRmiwrISay83AI2k1d AUOLkzCcsIK3MApoS63fpg4SZBeQltr+dwzyBUWQWkqpZCFWzkFQtYGRexahenFpUllqka6qX VJSZnlGSm5iZo2toYKqXm1pcnJiempOYVKyXnJ+7iREY/gxAsIPxS7/zIUZJDiYlUd4rlSnhQ nxJ+SmVGYnFGfFFpTmpxYcYNTg4BCacnTudSYolLz8vVUmCd0MTUJ1gUWp6akVaZg4wQmFKJT h4lER4d4KkeYsLEnOLM9MhUqcYdTm2TL23lkkIbIaUOO9mkCIBkKKM0jy4EbBkcYlRVkqYlxH oQCGegtSi3MwSVPlXjOIcjErCvNdApvBk5pXAbXoFdAQT0BGa85JBjihJREhJNTB6dx9faPnI 6n5KgkSHO+PNu/nnJn737y1raa04uetVtxxLZJQP9y07i5+uomLx6V5dyrNM3keZPJTe99zVX mLtQ+vfm022vf67MlPzUfGWWVElETEM3al1dx1nrdirUm9Vs9Lmzx4Hlzlik4u/3mheulVeon n7pHctXNuSg5VueMZFbts8JVSJpTgj0VCLuag4EQA/lnkXEQMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-4.tower-206.messagelabs.com!1466205137!45513106!1 X-Originating-IP: [74.125.82.65] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48559 invoked from network); 17 Jun 2016 23:12:17 -0000 Received: from mail-wm0-f65.google.com (HELO mail-wm0-f65.google.com) (74.125.82.65) by server-4.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 17 Jun 2016 23:12:17 -0000 Received: by mail-wm0-f65.google.com with SMTP id m124so1075907wme.3 for ; Fri, 17 Jun 2016 16:12:17 -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=Px0boRfLU0EvQV0TZVqi1S5TH1crEvn8oab8V+gzHnI=; b=p6+ZH66b+tdWVZEsiuQa4R2KJ7O60qMw9cqAvvIEJSHUBj2xlWiIB/ivRXgAAp0/qY s+4n1porHXRWis3zeNm1c3ZDdsDz+S26vAKz6QgA+3frYxGUXRaBx3w73yWbpDgGzmaV tFQ37MIjJDcXuqucIkS7JbHwC9Z3U3lfLaDtwRvW23iLfodO2rJF4aMmLysyz2v5BUXz qVZ+2YWFHJHwrMZCrw/i+iooKSQNqAj6wdKDxbDZbDe/AKSaZ5dRdIWSrbLlqAftiWOI CWIj5vvaPIbmfWxW5hYGUqvyR8/mmTtXtIBOBShPG/Ltnl8mDRn9fTnOKnTp3poEt7NV 0NQg== 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=Px0boRfLU0EvQV0TZVqi1S5TH1crEvn8oab8V+gzHnI=; b=MnbidxM98/vL3blfie6jLR5xfj03ovOyyl2txmG2pBmW9zaE5o1MEGigPZ0JwYvLZ6 xUaogQl6npWSNBjVeMmmRB2Cz7NR+QTRnCRXhB1H6MLsV3RGTD7b5fpggyg/X55AzFNA WOw/P53M9oSeNATIze5SIk+z0vzZy9oy6RaQPFsGKnFQn8T0rQz4LoL85Jsqe0xXMA5E bn8ahdy37XPUHZJheZZ4vQG6tTNqeFm5RYMaKFNZUwaK6dwFDUfboq9bag24k5J0EZ5/ 4m4ao7l8Wn3Hb/OTHeDkGGOunCL//6HPwoAIp/teZN3/Xi/X8NDQqqZ/naFhMGxH3AAp QzAw== X-Gm-Message-State: ALyK8tIvldfFf4aSQt2TMF6u0l7I05RbuBpbOKDHZQwE1qhrSRa1OE8gsw640Glk7KX80g== X-Received: by 10.28.67.69 with SMTP id q66mr643518wma.81.1466205136971; Fri, 17 Jun 2016 16:12:16 -0700 (PDT) Received: from Solace.fritz.box (net-93-65-149-191.cust.vodafonedsl.it. [93.65.149.191]) by smtp.gmail.com with ESMTPSA id xs9sm47969049wjc.11.2016.06.17.16.12.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2016 16:12:16 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Sat, 18 Jun 2016 01:12:14 +0200 Message-ID: <146620513485.29766.10649586343390103818.stgit@Solace.fritz.box> In-Reply-To: <146620492155.29766.10321123657058307698.stgit@Solace.fritz.box> References: <146620492155.29766.10321123657058307698.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Anshul Makkar , George Dunlap , David Vrabel Subject: [Xen-devel] [PATCH 08/19] xen: credit2: when tickling, check idle cpus first 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 If there are idle pCPUs, it's always better to try to "ship" the new vCPU there, instead than letting it preempting on a currently busy one. This commit also adds a cpumask_test_or_cycle() helper function, to make it easier to code the preference for the pCPU where the vCPU was running before. Signed-off-by: Dario Faggioli Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Anshul Makkar Cc: David Vrabel --- xen/common/sched_credit2.c | 68 +++++++++++++++++++++++++++++--------------- xen/include/xen/cpumask.h | 8 +++++ 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index b73d034..af28e7b 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -568,9 +568,23 @@ __runq_remove(struct csched2_vcpu *svc) void burn_credits(struct csched2_runqueue_data *rqd, struct csched2_vcpu *, s_time_t); -/* Check to see if the item on the runqueue is higher priority than what's - * currently running; if so, wake up the processor */ -static /*inline*/ void +/* + * Check what processor it is best to 'wake', for picking up a vcpu that has + * just been put (back) in the runqueue. Logic is as follows: + * 1. if there are idle processors in the runq, wake one of them; + * 2. if there aren't idle processor, check the one were the vcpu was + * running before to see if we can preempt what's running there now + * (and hence doing just one migration); + * 3. last stand: check all processors and see if the vcpu is in right + * of preempting any of the other vcpus running on them (this requires + * two migrations, and that's indeed why it is left as the last stand). + * + * Note that when we say 'idle processors' what we really mean is (pretty + * much always) both _idle_ and _not_already_tickled_. In fact, if a + * processor has been tickled, it will run csched2_schedule() shortly, and + * pick up some work, so it would be wrong to consider it idle. + */ +static void runq_tickle(const struct scheduler *ops, struct csched2_vcpu *new, s_time_t now) { int i, ipid=-1; @@ -584,22 +598,14 @@ runq_tickle(const struct scheduler *ops, struct csched2_vcpu *new, s_time_t now) BUG_ON(new->rqd != rqd); - /* Look at the cpu it's running on first */ - cur = CSCHED2_VCPU(curr_on_cpu(cpu)); - burn_credits(rqd, cur, now); - - if ( cur->credit < new->credit ) - { - ipid = cpu; - goto tickle; - } - - /* Get a mask of idle, but not tickled, that new is allowed to run on. */ + /* + * Get a mask of idle, but not tickled, processors that new is + * allowed to run on. If that's not empty, choose someone from there + * (preferrably, the one were new was running on already). + */ cpumask_andnot(&mask, &rqd->idle, &rqd->tickled); cpumask_and(&mask, &mask, new->vcpu->cpu_hard_affinity); - - /* If it's not empty, choose one */ - i = cpumask_cycle(cpu, &mask); + i = cpumask_test_or_cycle(cpu, &mask); if ( i < nr_cpu_ids ) { SCHED_STAT_CRANK(tickled_idle_cpu); @@ -607,12 +613,26 @@ runq_tickle(const struct scheduler *ops, struct csched2_vcpu *new, s_time_t now) goto tickle; } - /* Otherwise, look for the non-idle cpu with the lowest credit, - * skipping cpus which have been tickled but not scheduled yet, - * that new is allowed to run on. */ + /* + * Otherwise, look for the non-idle (and non-tickled) processors with + * the lowest credit, among the ones new is allowed to run on. Again, + * the cpu were it was running on would be the best candidate. + */ cpumask_andnot(&mask, &rqd->active, &rqd->idle); cpumask_andnot(&mask, &mask, &rqd->tickled); cpumask_and(&mask, &mask, new->vcpu->cpu_hard_affinity); + if ( cpumask_test_cpu(cpu, &mask) ) + { + cur = CSCHED2_VCPU(curr_on_cpu(cpu)); + burn_credits(rqd, cur, now); + + if ( cur->credit < new->credit ) + { + SCHED_STAT_CRANK(tickled_busy_cpu); + ipid = cpu; + goto tickle; + } + } for_each_cpu(i, &mask) { @@ -624,7 +644,7 @@ runq_tickle(const struct scheduler *ops, struct csched2_vcpu *new, s_time_t now) BUG_ON(is_idle_vcpu(cur->vcpu)); - /* Update credits for current to see if we want to preempt */ + /* Update credits for current to see if we want to preempt. */ burn_credits(rqd, cur, now); if ( cur->credit < lowest ) @@ -647,8 +667,10 @@ runq_tickle(const struct scheduler *ops, struct csched2_vcpu *new, s_time_t now) } } - /* Only switch to another processor if the credit difference is greater - * than the migrate resistance */ + /* + * Only switch to another processor if the credit difference is + * greater than the migrate resistance. + */ if ( ipid == -1 || lowest + CSCHED2_MIGRATE_RESIST > new->credit ) { SCHED_STAT_CRANK(tickled_no_cpu); diff --git a/xen/include/xen/cpumask.h b/xen/include/xen/cpumask.h index 0e7108c..3f340d6 100644 --- a/xen/include/xen/cpumask.h +++ b/xen/include/xen/cpumask.h @@ -266,6 +266,14 @@ static inline int cpumask_cycle(int n, const cpumask_t *srcp) return nxt; } +static inline int cpumask_test_or_cycle(int n, const cpumask_t *srcp) +{ + if ( cpumask_test_cpu(n, srcp) ) + return n; + + return cpumask_cycle(n, srcp); +} + static inline unsigned int cpumask_any(const cpumask_t *srcp) { unsigned int cpu = cpumask_first(srcp);