From patchwork Fri Jun 23 10:54:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9806255 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 C039D6088A for ; Fri, 23 Jun 2017 10:57:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B21BF285EE for ; Fri, 23 Jun 2017 10:57:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A702328616; Fri, 23 Jun 2017 10:57:23 +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 3A46D28607 for ; Fri, 23 Jun 2017 10:57:23 +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 1dOMEx-0006Ee-Rd; Fri, 23 Jun 2017 10:55:03 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dOMEw-0006EA-L0 for xen-devel@lists.xenproject.org; Fri, 23 Jun 2017 10:55:02 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 31/C8-19466-583FC495; Fri, 23 Jun 2017 10:55:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplleJIrShJLcpLzFFi42K5GNpwSLf1s0+ kQet5aYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNaPxzFrGghfKFXPfrmFuYJwl08XIxSEkMJNR 4siPVcwgDovAGlaJs5d3s4I4EgKXWCX+/P7C3sXICeTESdz8ew7KLpOYcOouM4gtJKAicXP7K iaIUd8ZJZY1vGICSQgL6EkcOfqDHcJ2l5i45wpYnE3AQOLNjr2sILaIgJLEvVWTweLMAqESc9 6dYQOxWQRUJT4fPQ9m8wo4Snye+QGsnlPASWLCqp1MEIsdJVr+vwA7QlRATmLl5RZWiHpBiZM zn7B0MXIAzdSUWL9LH2K8vMT2t3OYJzCKzEJSNQuhahaSqgWMzKsYNYpTi8pSi3SNLPSSijLT M0pyEzNzdA0NTPVyU4uLE9NTcxKTivWS83M3MQIjoJ6BgXEHY98qv0OMkhxMSqK8sWd8IoX4k vJTKjMSizPii0pzUosPMWpwcAhMODt3OpMUS15+XqqSBO/vj0B1gkWp6akVaZk5wBiFKZXg4F ES4d3+ASjNW1yQmFucmQ6ROsVozHHlyrovTBxTDmz/wiQENklKnPcpyCQBkNKM0jy4QbDUcYl RVkqYl5GBgUGIpyC1KDezBFX+FaM4B6OSMK/BJ6ApPJl5JXD7XgGdwgR0yow1YKeUJCKkpBqA pt4xatQxOyGz3N3PZVPD/kUhEUEc+h8aNly+vj69Yq2rnVaGb671DOsQ/V8H3HZ1JeUtOzXF7 JKzpNeN8JWVxbN7I+0DM4LOb1dle6uuNqchcNnyxzWb9zvP/GCwMUaohFP71YGPZkHKotnbbq f/84gx8uNN7Xga8NfoJs/eYI+VO26drVNiKc5INNRiLipOBACC/XdTGAMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1498215301!104566914!1 X-Originating-IP: [209.85.128.194] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5256 invoked from network); 23 Jun 2017 10:55:01 -0000 Received: from mail-wr0-f194.google.com (HELO mail-wr0-f194.google.com) (209.85.128.194) by server-6.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 23 Jun 2017 10:55:01 -0000 Received: by mail-wr0-f194.google.com with SMTP id x23so11635567wrb.0 for ; Fri, 23 Jun 2017 03:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=xadYkX5bS58i8v+DCD2xx9Vdjz7QQf62zqMke4AGf7Q=; b=MasZDVsc6/xBGCsfifaeaHMVCoCYJEwqpr8PgGtWHMK7xcxENkvlbIypsHfNcIm9aj SxKDZeQUHx97XByx3jSNTB3UQ0aOa8kQof5IfasvRMTqUJmn3Hq+s+Og3d/vIZsuU+z7 E4MTifjBDAp15DslcKvSrLDHifg1g7b39QRb2nHJfxvTCzPKFgBvjvMJEiAtaQVCH0SB AxYMRQhqzG5Wm7OOcdX+GQ/CYhG6r1LlWnpWIzEhJsKo9aMW8oKAENsoOA10k3rM3cEe 6YcDyGJREbN5Pxr3cORoZqxVpI3Oq9sBNsS0Msc7+uVT03gHhz9rLWUW+Oqi1Sra70n1 nbjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=xadYkX5bS58i8v+DCD2xx9Vdjz7QQf62zqMke4AGf7Q=; b=XA6Fkyk3njFBid6ygvd2BsbFWodzYtQ6rcZrguGEP434r26luUplNsJ8nCo6UvbdAN N/yNIGwQrQ0GhqJDnDlnq4+Q6gkDw0JU0M6fUygYDCxFyNJQNUVwrPbEx7Cpso7ybqrN AeZYzbk4mBNTMSsE1kWu9+S9maoVPzlwLGY4T/0lF9kt9P30kvo5ig9lPVEyMzCXFTd1 UmfaKvWn4r28FJm+Qb7GDCgDm8BzemBeOjP2fDr5iafqz5y+X+MHKjEaqDdowQ9Xqdtz QTYuX9V1Zo6LoOZ0etjy9v3Q7A4/+YC2/6RZgynSe9Ycd/1MJy4gjh8fnRkj7j3BvU+q n4QQ== X-Gm-Message-State: AKS2vOw8CUKeNLxiFedM99rRf0P/1pTf7eq2io6qwicTuMvwWmqYOfpV 5GNuCDLJxG5+c/Ba X-Received: by 10.28.238.5 with SMTP id m5mr5065274wmh.86.1498215300718; Fri, 23 Jun 2017 03:55:00 -0700 (PDT) Received: from [192.168.0.31] ([80.66.223.81]) by smtp.gmail.com with ESMTPSA id e31sm5692575wre.54.2017.06.23.03.54.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jun 2017 03:55:00 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 23 Jun 2017 12:54:59 +0200 Message-ID: <149821529903.5914.13747796374675013510.stgit@Solace> In-Reply-To: <149821475587.5914.12193327340105859241.stgit@Solace> References: <149821475587.5914.12193327340105859241.stgit@Solace> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Anshul Makkar Subject: [Xen-devel] [PATCH 2/6] xen: credit2: make the cpu to runqueue map per-cpu 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 Instead of keeping an NR_CPUS big array of int-s, directly inside csched2_private, use a per-cpu variable. That's especially beneficial (in terms of saved memory) when there are more instance of Credit2 (in different cpupools), and also helps fitting csched2_private itself into CPU caches. Signed-off-by: Dario Faggioli Acked-by: George Dunlap --- Cc: George Dunlap Cc: Anshul Makkar --- xen/common/sched_credit2.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 10d9488..15862f2 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -383,7 +383,6 @@ struct csched2_private { struct list_head sdom; /* Used mostly for dump keyhandler. */ - int runq_map[NR_CPUS]; cpumask_t active_queues; /* Queues which may have active cpus */ struct csched2_runqueue_data *rqd; @@ -393,6 +392,14 @@ struct csched2_private { }; /* + * Physical CPU + * + * The only per-pCPU information we need to maintain is of which runqueue + * each CPU is part of. + */ +static DEFINE_PER_CPU(int, runq_map); + +/* * Virtual CPU */ struct csched2_vcpu { @@ -448,16 +455,16 @@ static inline struct csched2_dom *csched2_dom(const struct domain *d) } /* CPU to runq_id macro */ -static inline int c2r(const struct scheduler *ops, unsigned int cpu) +static inline int c2r(unsigned int cpu) { - return csched2_priv(ops)->runq_map[(cpu)]; + return per_cpu(runq_map, cpu); } /* CPU to runqueue struct macro */ static inline struct csched2_runqueue_data *c2rqd(const struct scheduler *ops, unsigned int cpu) { - return &csched2_priv(ops)->rqd[c2r(ops, cpu)]; + return &csched2_priv(ops)->rqd[c2r(cpu)]; } /* @@ -1082,7 +1089,7 @@ runq_insert(const struct scheduler *ops, struct csched2_vcpu *svc) ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); ASSERT(!vcpu_on_runq(svc)); - ASSERT(c2r(ops, cpu) == c2r(ops, svc->vcpu->processor)); + ASSERT(c2r(cpu) == c2r(svc->vcpu->processor)); ASSERT(&svc->rqd->runq == runq); ASSERT(!is_idle_vcpu(svc->vcpu)); @@ -1733,7 +1740,7 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) if ( min_rqi == -1 ) { new_cpu = get_fallback_cpu(svc); - min_rqi = c2r(ops, new_cpu); + min_rqi = c2r(new_cpu); min_avgload = prv->rqd[min_rqi].b_avgload; goto out_up; } @@ -2622,7 +2629,7 @@ csched2_schedule( unsigned tasklet:8, idle:8, smt_idle:8, tickled:8; } d; d.cpu = cpu; - d.rq_id = c2r(ops, cpu); + d.rq_id = c2r(cpu); d.tasklet = tasklet_work_scheduled; d.idle = is_idle_vcpu(current); d.smt_idle = cpumask_test_cpu(cpu, &rqd->smt_idle); @@ -2783,7 +2790,7 @@ dump_pcpu(const struct scheduler *ops, int cpu) #define cpustr keyhandler_scratch cpumask_scnprintf(cpustr, sizeof(cpustr), per_cpu(cpu_sibling_mask, cpu)); - printk("CPU[%02d] runq=%d, sibling=%s, ", cpu, c2r(ops, cpu), cpustr); + printk("CPU[%02d] runq=%d, sibling=%s, ", cpu, c2r(cpu), cpustr); cpumask_scnprintf(cpustr, sizeof(cpustr), per_cpu(cpu_core_mask, cpu)); printk("core=%s\n", cpustr); @@ -2930,7 +2937,7 @@ init_pdata(struct csched2_private *prv, unsigned int cpu) } /* Set the runqueue map */ - prv->runq_map[cpu] = rqi; + per_cpu(runq_map, cpu) = rqi; __cpumask_set_cpu(cpu, &rqd->idle); __cpumask_set_cpu(cpu, &rqd->active); @@ -3034,7 +3041,7 @@ csched2_deinit_pdata(const struct scheduler *ops, void *pcpu, int cpu) ASSERT(!pcpu && cpumask_test_cpu(cpu, &prv->initialized)); /* Find the old runqueue and remove this cpu from it */ - rqi = prv->runq_map[cpu]; + rqi = per_cpu(runq_map, cpu); rqd = prv->rqd + rqi; @@ -3055,6 +3062,8 @@ csched2_deinit_pdata(const struct scheduler *ops, void *pcpu, int cpu) else if ( rqd->pick_bias == cpu ) rqd->pick_bias = cpumask_first(&rqd->active); + per_cpu(runq_map, cpu) = -1; + spin_unlock(&rqd->lock); __cpumask_clear_cpu(cpu, &prv->initialized); @@ -3121,10 +3130,8 @@ csched2_init(struct scheduler *ops) return -ENOMEM; } for ( i = 0; i < nr_cpu_ids; i++ ) - { - prv->runq_map[i] = -1; prv->rqd[i].id = -1; - } + /* initialize ratelimit */ prv->ratelimit_us = sched_ratelimit_us;