From patchwork Fri Mar 18 19:05:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 8623361 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F07279F6E1 for ; Fri, 18 Mar 2016 19:08:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA2F92026F for ; Fri, 18 Mar 2016 19:08:06 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id A1B1F20123 for ; Fri, 18 Mar 2016 19:08:05 +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 1agziV-0000kb-RE; Fri, 18 Mar 2016 19:05:47 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agziU-0000jz-Tm for xen-devel@lists.xenproject.org; Fri, 18 Mar 2016 19:05:47 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id C9/EF-02978-9815CE65; Fri, 18 Mar 2016 19:05:45 +0000 X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1458327945!30275962!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.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49782 invoked from network); 18 Mar 2016 19:05:45 -0000 Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by server-8.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Mar 2016 19:05:45 -0000 Received: by mail-wm0-f66.google.com with SMTP id l68so8158587wml.3 for ; Fri, 18 Mar 2016 12:05:45 -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=dfGLij79PIB1pw6f+Tpl8S0aIIgRtj8zDU7b+Y/92m4=; b=NCX0WxmWjoUakOOJu7ORF2O1fvWeDk2wquQ1iZ010/SUxsJMQSQ8tYybe7vJo/2CAl 9KoBPAcv+aJEeC6N2g1NB0eD/C4BdalSvZmsqEW3qENRZQD8GcyvLflOQ8LuAAuS6JQe OkThqKm2DJ+wfFndilsPkON+XdJen2HHEclyaTBww2cMXofXUaOzS07Oqd12/OVUuhZ7 W30nEmOXo4Rw47lp4uqXRPUGgmINvL+x8Kj5LCoiYnGkmL3/ROsfb3a5lxzYtIJ7TDf5 TtDFgA9/hy9g4tZtYLt2ZNoMzgW9bgjchq/hNNTxURo8fUeqauWkfm7i7DEx3MHOlkiX 62Ng== 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=dfGLij79PIB1pw6f+Tpl8S0aIIgRtj8zDU7b+Y/92m4=; b=bu/ZpoFBJfwqPikxlb54o0XoBZ3FFVecCPbVd5BkPBDoH6bM6bf4jGqHG/DR55LaQO kY3C8fRbZt2NIaVGSW9sHrquZnfaSkH3/kXcA/kvEkuZtQKWsI5xQHhia04lU+Hpwl/u q6GM5SRbyuRqd7/Ot5FXGc667WKxNJuEqZn66lHuas5NZaParVGIRI8z7qGu2tFD8Won WqWvvncCjEuMWbBXRXMSIy2/BXiJxFkDApQ+o96O2B3SO/GhRNkc4Ok3N5zSCCsmBiJF QFHgthPwLUXErGf7qmlGuz7Q58teuto5LG/r8c7Y3NlknZ8PTYElYEoNhrRl/OD/vAoW shJg== X-Gm-Message-State: AD7BkJJC8eZ2K3HEhJ+MuLiDcaVB94uDcsCXDxVeU6yR3VEFs6HN8t8RI3ttoN/ys8BP5A== X-Received: by 10.28.9.71 with SMTP id 68mr922238wmj.33.1458327944831; Fri, 18 Mar 2016 12:05:44 -0700 (PDT) Received: from Solace.station (net-2-35-170-8.cust.vodafonedsl.it. [2.35.170.8]) by smtp.gmail.com with ESMTPSA id gb9sm13421661wjb.26.2016.03.18.12.05.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Mar 2016 12:05:44 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 18 Mar 2016 20:05:38 +0100 Message-ID: <20160318190538.8117.96025.stgit@Solace.station> In-Reply-To: <20160318185524.8117.74837.stgit@Solace.station> References: <20160318185524.8117.74837.stgit@Solace.station> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Juergen Gross , Uma Sharma Subject: [Xen-devel] [PATCH 13/16] xen: sched: allow for choosing credit2 runqueues configuration at boot 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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In fact, credit2 uses CPU topology to decide how to arrange its internal runqueues. Before this change, only 'one runqueue per socket' was allowed. However, experiments have shown that, for instance, having one runqueue per physical core improves performance, especially in case hyperthreading is available. In general, it makes sense to allow users to pick one runqueue arrangement at boot time, so that: - more experiments can be easily performed to even better assess and improve performance; - one can select the best configuration for his specific use case and/or hardware. This patch enables the above. Note that, for correctly arranging runqueues to be per-core, just checking cpu_to_core() on the host CPUs is not enough. In fact, cores (and hyperthreads) on different sockets, can have the same core (and thread) IDs! We, therefore, need to check whether the full topology of two CPUs matches, for them to be put in the same runqueue. Note also that the default (although not functional) for credit2, since now, has been per-socket runqueue. This patch leaves things that way, to avoid mixing policy and technical changes. Finally, it would be a nice feature to be able to select a particular runqueue arrangement, even when creating a Credit2 cpupool. This is left as future work. Signed-off-by: Dario Faggioli Signed-off-by: Uma Sharma --- Cc: George Dunlap Cc: Uma Sharma Cc: Juergen Gross --- Cahnges from v1: * added 'node' and 'global' runqueue arrangements, as suggested during review; --- docs/misc/xen-command-line.markdown | 19 +++++++++ xen/common/sched_credit2.c | 76 +++++++++++++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-command-line.markdown index ca77e3b..0047f94 100644 --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -469,6 +469,25 @@ combination with the `low_crashinfo` command line option. ### credit2\_load\_window\_shift > `= ` +### credit2\_runqueue +> `= core | socket | node | all` + +> Default: `socket` + +Specify how host CPUs are arranged in runqueues. Runqueues are kept +balanced with respect to the load generated by the vCPUs running on +them. Smaller runqueues (as in with `core`) means more accurate load +balancing (for instance, it will deal better with hyperthreading), +but also more overhead. + +Available alternatives, with their meaning, are: +* `core`: one runqueue per each physical core of the host; +* `socket`: one runqueue per each physical socket (which often, + but not always, matches a NUMA node) of the host; +* `node`: one runqueue per each NUMA node of the host; +* `all`: just one runqueue shared by all the logical pCPUs of + the host + ### dbgp > `= ehci[ | @pci:. ]` diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 456b9ea..c242dc4 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -81,10 +81,6 @@ * Credits are "reset" when the next vcpu in the runqueue is less than * or equal to zero. At that point, everyone's credits are "clipped" * to a small value, and a fixed credit is added to everyone. - * - * The plan is for all cores that share an L2 will share the same - * runqueue. At the moment, there is one global runqueue for all - * cores. */ /* @@ -193,6 +189,55 @@ static int __read_mostly opt_overload_balance_tolerance = -3; integer_param("credit2_balance_over", opt_overload_balance_tolerance); /* + * Runqueue organization. + * + * The various cpus are to be assigned each one to a runqueue, and we + * want that to happen basing on topology. At the moment, it is possible + * to choose to arrange runqueues to be: + * + * - per-core: meaning that there will be one runqueue per each physical + * core of the host. This will happen if the opt_runqueue + * parameter is set to 'core'; + * + * - per-node: meaning that there will be one runqueue per each physical + * NUMA node of the host. This will happen if the opt_runqueue + * parameter is set to 'node'; + * + * - per-socket: meaning that there will be one runqueue per each physical + * socket (AKA package, which often, but not always, also + * matches a NUMA node) of the host; This will happen if + * the opt_runqueue parameter is set to 'socket'; + * + * - global: meaning that there will be only one runqueue to which all the + * (logical) processors of the host belongs. This will happen if + * the opt_runqueue parameter is set to 'all'. + * + * Depending on the value of opt_runqueue, therefore, cpus that are part of + * either the same physical core, or of the same physical socket, will be + * put together to form runqueues. + */ +#define OPT_RUNQUEUE_CORE 1 +#define OPT_RUNQUEUE_SOCKET 2 +#define OPT_RUNQUEUE_NODE 3 +#define OPT_RUNQUEUE_ALL 4 +static int __read_mostly opt_runqueue = OPT_RUNQUEUE_SOCKET; + +static void parse_credit2_runqueue(const char *s) +{ + if ( !strncmp(s, "core", 4) && !s[4] ) + opt_runqueue = OPT_RUNQUEUE_CORE; + else if ( !strncmp(s, "socket", 6) && !s[6] ) + opt_runqueue = OPT_RUNQUEUE_SOCKET; + else if ( !strncmp(s, "node", 4) && !s[4] ) + opt_runqueue = OPT_RUNQUEUE_NODE; + else if ( !strncmp(s, "all", 6) && !s[6] ) + opt_runqueue = OPT_RUNQUEUE_ALL; + else + printk("WARNING, unrecognized value of credit2_runqueue option!\n"); +} +custom_param("credit2_runqueue", parse_credit2_runqueue); + +/* * Per-runqueue data */ struct csched2_runqueue_data { @@ -1971,6 +2016,22 @@ static void deactivate_runqueue(struct csched2_private *prv, int rqi) cpumask_clear_cpu(rqi, &prv->active_queues); } +static inline bool_t same_node(unsigned int cpua, unsigned int cpub) +{ + return cpu_to_node(cpua) == cpu_to_node(cpub); +} + +static inline bool_t same_socket(unsigned int cpua, unsigned int cpub) +{ + return cpu_to_socket(cpua) == cpu_to_socket(cpub); +} + +static inline bool_t same_core(unsigned int cpua, unsigned int cpub) +{ + return same_socket(cpua, cpub) && + cpu_to_core(cpua) == cpu_to_core(cpub); +} + static unsigned int cpu_to_runqueue(struct csched2_private *prv, unsigned int cpu) { @@ -2003,7 +2064,10 @@ cpu_to_runqueue(struct csched2_private *prv, unsigned int cpu) BUG_ON(cpu_to_socket(cpu) == XEN_INVALID_SOCKET_ID || cpu_to_socket(peer_cpu) == XEN_INVALID_SOCKET_ID); - if ( cpu_to_socket(cpumask_first(&rqd->active)) == cpu_to_socket(cpu) ) + if ( opt_runqueue == OPT_RUNQUEUE_ALL || + (opt_runqueue == OPT_RUNQUEUE_CORE && same_core(peer_cpu, cpu)) || + (opt_runqueue == OPT_RUNQUEUE_SOCKET && same_socket(peer_cpu, cpu)) || + (opt_runqueue == OPT_RUNQUEUE_NODE && same_node(peer_cpu, cpu)) ) break; } @@ -2157,6 +2221,8 @@ csched2_init(struct scheduler *ops) printk(" load_window_shift: %d\n", opt_load_window_shift); printk(" underload_balance_tolerance: %d\n", opt_underload_balance_tolerance); printk(" overload_balance_tolerance: %d\n", opt_overload_balance_tolerance); + printk(" runqueues arrangement: per-%s\n", + opt_runqueue == OPT_RUNQUEUE_CORE ? "core" : "socket"); if ( opt_load_window_shift < LOADAVG_WINDOW_SHIFT_MIN ) {