From patchwork Fri Mar 18 19:06:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 8623351 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 391CFC0553 for ; Fri, 18 Mar 2016 19:08:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4B0A22026F for ; Fri, 18 Mar 2016 19:08:02 +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 5BE9720123 for ; Fri, 18 Mar 2016 19:08:01 +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 1agzis-0000yv-Eu; Fri, 18 Mar 2016 19:06:10 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agziq-0000y2-Vv for xen-devel@lists.xenproject.org; Fri, 18 Mar 2016 19:06:09 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id A7/52-03814-0A15CE65; Fri, 18 Mar 2016 19:06:08 +0000 X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1458327967!13433094!1 X-Originating-IP: [74.125.82.68] X-SpamReason: No, hits=0.7 required=7.0 tests=BODY_RANDOM_LONG, RCVD_ILLEGAL_IP X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30664 invoked from network); 18 Mar 2016 19:06:07 -0000 Received: from mail-wm0-f68.google.com (HELO mail-wm0-f68.google.com) (74.125.82.68) by server-12.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Mar 2016 19:06:07 -0000 Received: by mail-wm0-f68.google.com with SMTP id l124so8126959wmf.2 for ; Fri, 18 Mar 2016 12:06:07 -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=Q+sq+rcgcPHV01PYiLle2BII5k6m6RUKZ7/CKHwCZi0=; b=e4iJ5BVcdbHYBJjwjex60+7gYMwfqrK0eyx7DjBAsyqtqQs86PZlTfXgwyOIkxF0Ba MglcXSvNuwEql+VwNPQzR74xc/7q/lUfkmkIwP4t/5XSj2QbzZRraEAsFfOD5xqSJCUL uvBILcAqhjsXbuB/jVvqwuXJqTRJSbGKW5hYpvMqcYtJA8Tj/ypNETYp/cW4I847/5me HRE0JhDviMO7J1FTee/0b44kiVtZHZ16k1M7IQ+FFw+kV0pThjxEAN4p7FVF1Mf3x2hU zCaan+GoYvkAvgVZToMrZ4dYytKU94rJVinDcvu+RspEg7Nwf890YfpEzs/UtrW0omtN XdHg== 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=Q+sq+rcgcPHV01PYiLle2BII5k6m6RUKZ7/CKHwCZi0=; b=C8FkjVHu9x/jTvwprIRsUeHid2lWEYC7I4fKJB/g2uyZvEzDBQ0WYTJGZ8zn4kkwxM WYAFqOqvlO8Di1gAIbIwLM1ElBy0rmO0iwEasfUyT8SWFMY6Lx9dEd7ARqpVP77RD82i PxRT/wQZpezVzzwEj4PGDZmxvrxLY0D8X9zr8N1Hhi2izxOIDEXvwMzhI0pDev28dGhY 6q++OYk/Wfl9Xnkoi9PC+lpS5idnrU/UP/FUgsQsB8R5HkXQjROH6MFUoCm1avUx4MTg kYrlGwv2O+7b+WtrHf8qNb1WBz7c7fzO2NsxV4PeONwOC82l3ZgHuXIs6WcS318xkZi3 8zuw== X-Gm-Message-State: AD7BkJIzlKbsENtEoiVYHun+FiRpObZH3glJZ6BoA3raOG2Z2TCIrJE6Ks5+ZaPUkA0OiA== X-Received: by 10.28.177.134 with SMTP id a128mr968044wmf.55.1458327967522; Fri, 18 Mar 2016 12:06:07 -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 a16sm581906wmi.0.2016.03.18.12.06.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Mar 2016 12:06:06 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 18 Mar 2016 20:06:01 +0100 Message-ID: <20160318190601.8117.67010.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 Subject: [Xen-devel] [PATCH 15/16] xen: sched: scratch space for cpumasks on Credit2 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 like what's there already in both Credit1 and RTDS. In fact, when playing with affinity, a lot of cpumask manipulation is necessary, inside of various functions. To avoid having a lot of cpumask_var_t on the stack, this patch introduces a global scratch area. Signed-off-by: Dario Faggioli --- Cc: George Dunlap --- xen/common/sched_credit2.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 07b8c67..a650216 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -238,6 +238,23 @@ static void parse_credit2_runqueue(const char *s) custom_param("credit2_runqueue", parse_credit2_runqueue); /* + * Scratch space, useful to avoid having too many cpumask_var_t on the stack. + * + * We want to only allocate the array the first time an instance of this + * scheduler is used, and avoid reallocating it (e.g., when more instances + * are activated inside new cpupools) or leaking it (e.g., when the last + * instance is de-inited). + * + * Counting the number of active Credit2 instances is all we need, and it + * does not even have to happen via atomic_t operations, as the counter + * only changes during during boot, or under the cpupool_lock. + */ +static cpumask_t **_cpumask_scratch; +#define cpumask_scratch _cpumask_scratch[smp_processor_id()] + +static unsigned int nr_csched2_ops; + +/* * Per-runqueue data */ struct csched2_runqueue_data { @@ -2166,6 +2183,15 @@ csched2_switch_sched(struct scheduler *new_ops, unsigned int cpu, spin_unlock_irq(&prv->lock); } +static void * +csched2_alloc_pdata(const struct scheduler *ops, int cpu) +{ + if ( !zalloc_cpumask_var(&_cpumask_scratch[cpu]) ) + return ERR_PTR(-ENOMEM); + + return NULL; +} + static void csched2_free_pdata(const struct scheduler *ops, void *pcpu, int cpu) { @@ -2205,6 +2231,9 @@ csched2_free_pdata(const struct scheduler *ops, void *pcpu, int cpu) spin_unlock_irqrestore(&prv->lock, flags); + free_cpumask_var(_cpumask_scratch[cpu]); + _cpumask_scratch[cpu] = NULL; + return; } @@ -2239,6 +2268,19 @@ csched2_init(struct scheduler *ops) if ( prv == NULL ) return -ENOMEM; ops->sched_data = prv; + + ASSERT( _cpumask_scratch == NULL || nr_csched2_ops > 0 ); + if ( !_cpumask_scratch ) + { + _cpumask_scratch = xmalloc_array(cpumask_var_t, nr_cpu_ids); + if ( !_cpumask_scratch ) + { + xfree(prv); + return -ENOMEM; + } + } + nr_csched2_ops++; + spin_lock_init(&prv->lock); INIT_LIST_HEAD(&prv->sdom); @@ -2259,6 +2301,13 @@ csched2_deinit(struct scheduler *ops) { struct csched2_private *prv; + ASSERT( _cpumask_scratch && nr_csched2_ops > 0 ); + if ( (--nr_csched2_ops) == 0 ) + { + xfree(_cpumask_scratch); + _cpumask_scratch = NULL; + } + prv = CSCHED2_PRIV(ops); ops->sched_data = NULL; xfree(prv); @@ -2293,6 +2342,7 @@ static const struct scheduler sched_credit2_def = { .alloc_vdata = csched2_alloc_vdata, .free_vdata = csched2_free_vdata, .init_pdata = csched2_init_pdata, + .alloc_pdata = csched2_alloc_pdata, .free_pdata = csched2_free_pdata, .switch_sched = csched2_switch_sched, .alloc_domdata = csched2_alloc_domdata,