From patchwork Fri Sep 30 02:53:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9357463 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 C0A206077A for ; Fri, 30 Sep 2016 02:56:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B518529D3E for ; Fri, 30 Sep 2016 02:56:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A655929D40; Fri, 30 Sep 2016 02:56:11 +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 293CC29D43 for ; Fri, 30 Sep 2016 02:56:10 +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 1bpnxJ-0001pG-9K; Fri, 30 Sep 2016 02:53:45 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpnxH-0001ow-BR for xen-devel@lists.xenproject.org; Fri, 30 Sep 2016 02:53:43 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id 32/04-21986-6B3DDE75; Fri, 30 Sep 2016 02:53:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLIsWRWlGSWpSXmKPExsXiVRvkpLv18tt wg59LrS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyubU3sBbMNKvZfNG5gvKLaxcjFISQwg1Fi +q15rCAOi8AaVonl33+zgDgSApdYJb693A2U4QRyYiTaL6xmgbDLJHrWnGYCsYUEVCRubl/FB DHqF6PE+idv2EASwgJ6EkeO/mDvYuQAsj0knndbgoTZBAwk3uzYCzZTREBJ4t6qyWC9zAJLGC WuPpsFtoBFQFXiY/9iZpBeXgEfiaOnrEDCnAK+Er+2vWCB2Osj8Xv5crBVogJyEisvt4DN5BU QlDg58wkLSCuzgKbE+l36IGFmAXmJ7W/nME9gFJmFpGoWQtUsJFULGJlXMWoUpxaVpRbpGprq JRVlpmeU5CZm5ugaGpjp5aYWFyemp+YkJhXrJefnbmIEBj8DEOxg/LYs4BCjJAeTkiiv7NG34 UJ8SfkplRmJxRnxRaU5qcWHGDU4OAQmnJ07nUmKJS8/L1VJgnftJaA6waLU9NSKtMwcYHzClE pw8CiJ8CoAY1SIt7ggMbc4Mx0idYpRl2PL1HtrmYTAZkiJ8zaBzBAAKcoozYMbAUsVlxhlpYR 5GYEOFOIpSC3KzSxBlX/FKM7BqCTMWwYyhSczrwRu0yugI5iAjsg/+gbkiJJEhJRUA2M+72M/ /1lfHy7t+LJ61ePF5vdsnQVfXJZnWnXtiEC5SoHdb+cLt27f2LPCR+Ik95b8aSoy5Yv6LrwRC 1A4ZMn6X+PWtdJlyie+fdjT1X3vpNXeqJ2nCwKf3tn6vC3tbKh/srO2rd+lvVVLCuXuz+42vv DrBtdBo3zVz8UXImyOK7M0shRcP+2sxFKckWioxVxUnAgA5pItqhADAAA= X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1475204021!35660813!1 X-Originating-IP: [74.125.82.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 16365 invoked from network); 30 Sep 2016 02:53:41 -0000 Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by server-15.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 30 Sep 2016 02:53:41 -0000 Received: by mail-wm0-f66.google.com with SMTP id b184so1384577wma.3 for ; Thu, 29 Sep 2016 19:53:41 -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=d4dcaBHRafyr4OiaCgYmYywkfgd5SF/aLFl9U/wCUbk=; b=XA2CWwi1JzuskQnS4PN+K6r7NwHB9i+hDNDClnCJMWyoqI2JEdIDR6lQLerIp1bn5+ WzMbOhJMDPX8YzvI6BCBW2PgGej7Gv+7CHAdJx5PL7kn9zWayybelBugy87/hKzel2VD NQbd4NG5l2+bOBX0ED75ckuDt1yQ9ZbkVaZxKj6qQKvdt1cpZ8FhiM/jO5sM3k98ghkE bn2Qz6KXOTDaFEnC+VN+PPWkM2A56xBB0z5rC9RbhCfCTEEQf+O2WO03c1sh4GWgyP3k PbBpAWo8JH1RpSyA9dQFPCoqVlfL0CEquYLF2odahMA4TAaWe4rbKFcMfCVfX94Cb1a2 oPhA== 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=d4dcaBHRafyr4OiaCgYmYywkfgd5SF/aLFl9U/wCUbk=; b=VHZJKXxmnViVRkvrCV7erJIRXo/IROq9daRUFW3feyPbjE9nPE6h40ChRrA0b7+oGL y+XonWGWs7lNb7pDotapvtbKlbQglmnf03stRSF8xiLPyAumdviF10v0cVoSy3fPjqb1 g4mlEz/Yy3hP3QtUH9dUG3y9J7hyCrhU4S1Lglj4CBUfqZTIEEEDCNIeFACoTJoeBxdH g3gCHAqXXXSAnAdul8wxDVxTE3iwRuNl7qM2914KKaaWsB3cZ/mNN4oxumyv5Dza6ZBw /P+midvtkHIe5c8Udw1WoEopZlDcGxcW8Zu5RfEYYz55PLtiggBvhQPHdWgLcCBPQ9MT lP9g== X-Gm-Message-State: AA6/9RkXQvzM0iX3Vjmbm4u0QOon2OA90w8CZDf+N75koBXooBTRqjE8R2koos1lK7PyJw== X-Received: by 10.28.18.11 with SMTP id 11mr1563803wms.79.1475204021397; Thu, 29 Sep 2016 19:53:41 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.126]) by smtp.gmail.com with ESMTPSA id s7sm17174120wjc.34.2016.09.29.19.53.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Sep 2016 19:53:40 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 30 Sep 2016 04:53:39 +0200 Message-ID: <147520401933.22544.13337692634316589872.stgit@Solace.fritz.box> In-Reply-To: <147520253247.22544.10673844222866363947.stgit@Solace.fritz.box> References: <147520253247.22544.10673844222866363947.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Andrew Cooper , Anshul Makkar , George Dunlap , Jan Beulich Subject: [Xen-devel] [PATCH v2 03/10] xen: credit2: make tickling more deterministic 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 Right now, the following scenario can occurr: - upon vcpu v wakeup, v itself is put in the runqueue, and pcpu X is tickled; - pcpu Y schedules (for whatever reason), sees v in the runqueue and picks it up. This may seem ok (or even a good thing), but it's not. In fact, if runq_tickle() decided X is where v should run, it did it for a reason (load distribution, SMT support, cache hotness, affinity, etc), and we really should try as hard as possible to stick to that. Of course, we can't be too strict, or we risk leaving vcpus in the runqueue while there is available CPU capacity. So, we only leave v in runqueue --for X to pick it up-- if we see that X has been tickled and has not scheduled yet, i.e., it will have a real chance of actually select and schedule v. If that is not the case, we schedule it on Y (or, at least, we consider that), as running somewhere non-ideal is better than not running at all. The commit also adds performance counters for each of the possible situations. Signed-off-by: Dario Faggioli Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Anshul Makkar Cc: Jan Beulich Cc: Andrew Cooper --- Changes from v1: * always initialize tickled_cpu to -1, also for idle vcpus (in which cases, it just won't ever change to anything else than that), for improved readability and understandability; * logic for reporting back to csched_schedule() whether any vcpu was skipped, within runq_candidate(), and to only reset the credits if that did not happen moved out from here, to another patch. --- xen/common/sched_credit2.c | 37 ++++++++++++++++++++++++++++++++++++- xen/include/xen/perfc_defn.h | 3 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 5c7d0dc..3986441 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -54,6 +54,7 @@ #define TRC_CSCHED2_LOAD_CHECK TRC_SCHED_CLASS_EVT(CSCHED2, 16) #define TRC_CSCHED2_LOAD_BALANCE TRC_SCHED_CLASS_EVT(CSCHED2, 17) #define TRC_CSCHED2_PICKED_CPU TRC_SCHED_CLASS_EVT(CSCHED2, 19) +#define TRC_CSCHED2_RUNQ_CANDIDATE TRC_SCHED_CLASS_EVT(CSCHED2, 20) /* * WARNING: This is still in an experimental phase. Status and work can be found at the @@ -398,6 +399,7 @@ struct csched2_vcpu { int credit; s_time_t start_time; /* When we were scheduled (used for credit) */ unsigned flags; /* 16 bits doesn't seem to play well with clear_bit() */ + int tickled_cpu; /* cpu tickled for picking us up (-1 if none) */ /* Individual contribution to load */ s_time_t load_last_update; /* Last time average was updated */ @@ -1049,6 +1051,10 @@ runq_tickle(const struct scheduler *ops, struct csched2_vcpu *new, s_time_t now) __cpumask_set_cpu(ipid, &rqd->tickled); smt_idle_mask_clear(ipid, &rqd->smt_idle); cpu_raise_softirq(ipid, SCHEDULE_SOFTIRQ); + + if ( unlikely(new->tickled_cpu != -1) ) + SCHED_STAT_CRANK(tickled_cpu_overwritten); + new->tickled_cpu = ipid; } /* @@ -1276,6 +1282,7 @@ csched2_alloc_vdata(const struct scheduler *ops, struct vcpu *vc, void *dd) svc->credit = CSCHED2_IDLE_CREDIT; svc->weight = 0; } + svc->tickled_cpu = -1; SCHED_STAT_CRANK(vcpu_alloc); @@ -2268,6 +2275,17 @@ runq_candidate(struct csched2_runqueue_data *rqd, if ( !cpumask_test_cpu(cpu, svc->vcpu->cpu_hard_affinity) ) continue; + /* + * If a vcpu is meant to be picked up by another processor, and such + * processor has not scheduled yet, leave it in the runqueue for him. + */ + if ( svc->tickled_cpu != -1 && svc->tickled_cpu != cpu && + cpumask_test_cpu(svc->tickled_cpu, &rqd->tickled) ) + { + SCHED_STAT_CRANK(deferred_to_tickled_cpu); + continue; + } + /* If this is on a different processor, don't pull it unless * its credit is at least CSCHED2_MIGRATE_RESIST higher. */ if ( svc->vcpu->processor != cpu @@ -2284,9 +2302,25 @@ runq_candidate(struct csched2_runqueue_data *rqd, /* In any case, if we got this far, break. */ break; + } + if ( unlikely(tb_init_done) ) + { + struct { + unsigned vcpu:16, dom:16; + unsigned tickled_cpu; + } d; + d.dom = snext->vcpu->domain->domain_id; + d.vcpu = snext->vcpu->vcpu_id; + d.tickled_cpu = snext->tickled_cpu; + __trace_var(TRC_CSCHED2_RUNQ_CANDIDATE, 1, + sizeof(d), + (unsigned char *)&d); } + if ( unlikely(snext->tickled_cpu != -1 && snext->tickled_cpu != cpu) ) + SCHED_STAT_CRANK(tickled_cpu_overridden); + return snext; } @@ -2351,7 +2385,7 @@ csched2_schedule( snext = CSCHED2_VCPU(idle_vcpu[cpu]); } else - snext=runq_candidate(rqd, scurr, cpu, now); + snext = runq_candidate(rqd, scurr, cpu, now); /* If switching from a non-idle runnable vcpu, put it * back on the runqueue. */ @@ -2390,6 +2424,7 @@ csched2_schedule( } snext->start_time = now; + snext->tickled_cpu = -1; /* Safe because lock for old processor is held */ if ( snext->vcpu->processor != cpu ) diff --git a/xen/include/xen/perfc_defn.h b/xen/include/xen/perfc_defn.h index a336c71..4a835b8 100644 --- a/xen/include/xen/perfc_defn.h +++ b/xen/include/xen/perfc_defn.h @@ -66,6 +66,9 @@ PERFCOUNTER(runtime_max_timer, "csched2: runtime_max_timer") PERFCOUNTER(migrated, "csched2: migrated") PERFCOUNTER(migrate_resisted, "csched2: migrate_resisted") PERFCOUNTER(credit_reset, "csched2: credit_reset") +PERFCOUNTER(deferred_to_tickled_cpu,"csched2: deferred_to_tickled_cpu") +PERFCOUNTER(tickled_cpu_overwritten,"csched2: tickled_cpu_overwritten") +PERFCOUNTER(tickled_cpu_overridden, "csched2: tickled_cpu_overridden") PERFCOUNTER(need_flush_tlb_flush, "PG_need_flush tlb flushes")