From patchwork Sat Apr 20 15:24:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 10910349 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1554922 for ; Sat, 20 Apr 2019 15:26:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9538B28698 for ; Sat, 20 Apr 2019 15:26:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85727289A3; Sat, 20 Apr 2019 15:26:37 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E00CA28698 for ; Sat, 20 Apr 2019 15:26:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hHrrC-00049L-UZ; Sat, 20 Apr 2019 15:24:46 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hHrrA-000495-O1 for xen-devel@lists.xenproject.org; Sat, 20 Apr 2019 15:24:44 +0000 X-Inumbo-ID: 6bf64945-6380-11e9-92d7-bc764e045a96 Received: from mail-wm1-f66.google.com (unknown [209.85.128.66]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 6bf64945-6380-11e9-92d7-bc764e045a96; Sat, 20 Apr 2019 15:24:43 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id z6so10876058wmi.0 for ; Sat, 20 Apr 2019 08:24:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=aN8ovK6MLgPyDT9K6fPdxnO4TPJN6/GOvyeYdsc0Fpg=; b=n+eZRJEaqq49LnhqPkbv0ul1OPQgU7pnidiCyXtD8UKVn98BDGQQ42KmcphPKm88v0 naTXEwAq0UACkRbHFIuqUQgrUotuhgS6MRTxP/PeVcilJg3DzCF9ScOhV2sqeXAtwqlX V8GoJCARmZ7d/ScnM5elFWRQo0MYzOqX6umZ+/aqzOM+F5Ty5n8UUdGjxIp4omRIi5wE WohGxqQdgyQ87HGg6k4BONpnBoCksbZw3goNrf9THaBr/MBfqY0rTAmvDXlp9vlx3bVP NEhEagaob6xkA2LumXSEXI/f99Fau72QAvIANqkHU+2DVjswVlF7s/Z5VL1SJ5iFjOoT drMA== X-Gm-Message-State: APjAAAWx0ZX+3J2N4XqQXjz3bswAaNEE2rcis8KCg2w2L+dwg9Z2HEPc hUb1IAIhYbTnLxYo6zRSErMnWkqO3ao= X-Google-Smtp-Source: APXvYqzpdll8nS2reTTJvTDKDq740iswK8KazTs0ntvlreoNntvgGZW93JelwHzh/TiOgGrSsBHc6w== X-Received: by 2002:a7b:c147:: with SMTP id z7mr6407423wmi.67.1555773882349; Sat, 20 Apr 2019 08:24:42 -0700 (PDT) Received: from [127.0.0.1] (87.78.186.89.cust.ip.kpnqwest.it. [89.186.78.87]) by smtp.gmail.com with ESMTPSA id y3sm7093626wmi.27.2019.04.20.08.24.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Apr 2019 08:24:41 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Sat, 20 Apr 2019 17:24:40 +0200 Message-ID: <155577388014.25746.13361382203794112287.stgit@wayrath> In-Reply-To: <155577364571.25746.11988517450711182732.stgit@wayrath> References: <155577364571.25746.11988517450711182732.stgit@wayrath> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/2] xen: credit2: avoid using cpumask_weight() in hot-paths X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP cpumask_weight() is known to be expensive. In Credit2, we use it in load-balancing, but only for knowing how many CPUs are active in a runqueue. Keeping such count in an integer field of the per-runqueue data structure we have, completely avoids the need for cpumask_weight(). While there, remove as much other uses of it as we can, even if not in hot-paths. Signed-off-by: Dario Faggioli Reviewed-by: Andrii Anisov --- Cc: George Dunlap --- xen/common/sched_credit2.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 6958b265fc..7034325243 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -466,6 +466,7 @@ struct csched2_runqueue_data { spinlock_t lock; /* Lock for this runqueue */ struct list_head runq; /* Ordered list of runnable vms */ + int nr_cpus; /* How many CPUs are sharing this runqueue */ int id; /* ID of this runqueue (-1 if invalid) */ int load; /* Instantaneous load (num of non-idle vcpus) */ @@ -2613,8 +2614,8 @@ retry: if ( st.orqd->b_avgload > load_max ) load_max = st.orqd->b_avgload; - cpus_max = cpumask_weight(&st.lrqd->active); - i = cpumask_weight(&st.orqd->active); + cpus_max = st.lrqd->nr_cpus; + i = st.orqd->nr_cpus; if ( i > cpus_max ) cpus_max = i; @@ -3697,7 +3698,7 @@ csched2_dump(const struct scheduler *ops) "\tinstload = %d\n" "\taveload = %"PRI_stime" (~%"PRI_stime"%%)\n", i, - cpumask_weight(&prv->rqd[i].active), + prv->rqd[i].nr_cpus, nr_cpu_ids, cpumask_bits(&prv->rqd[i].active), prv->rqd[i].max_weight, prv->rqd[i].pick_bias, @@ -3818,6 +3819,9 @@ init_pdata(struct csched2_private *prv, struct csched2_pcpu *spc, __cpumask_set_cpu(cpu, &prv->initialized); __cpumask_set_cpu(cpu, &rqd->smt_idle); + rqd->nr_cpus++; + ASSERT(cpumask_weight(&rqd->active) == rqd->nr_cpus); + /* On the boot cpu we are called before cpu_sibling_mask has been set up. */ if ( cpu == 0 && system_state < SYS_STATE_active ) __cpumask_set_cpu(cpu, &csched2_pcpu(cpu)->sibling_mask); @@ -3829,8 +3833,11 @@ init_pdata(struct csched2_private *prv, struct csched2_pcpu *spc, __cpumask_set_cpu(rcpu, &csched2_pcpu(cpu)->sibling_mask); } - if ( cpumask_weight(&rqd->active) == 1 ) + if ( rqd->nr_cpus == 1 ) + { + ASSERT(cpumask_weight(&rqd->active) == 1); rqd->pick_bias = cpu; + } return spc->runq_id; } @@ -3944,8 +3951,12 @@ csched2_deinit_pdata(const struct scheduler *ops, void *pcpu, int cpu) __cpumask_clear_cpu(cpu, &rqd->smt_idle); __cpumask_clear_cpu(cpu, &rqd->active); - if ( cpumask_empty(&rqd->active) ) + rqd->nr_cpus--; + ASSERT(cpumask_weight(&rqd->active) == rqd->nr_cpus); + + if ( rqd->nr_cpus == 0 ) { + ASSERT(cpumask_empty(&rqd->active)); printk(XENLOG_INFO " No cpus left on runqueue, disabling\n"); deactivate_runqueue(prv, spc->runq_id); } From patchwork Sat Apr 20 15:24:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 10910353 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 529D4922 for ; Sat, 20 Apr 2019 15:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 431FF28698 for ; Sat, 20 Apr 2019 15:27:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3722D289A3; Sat, 20 Apr 2019 15:27:18 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C1D9128698 for ; Sat, 20 Apr 2019 15:27:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hHrrJ-0004AS-C1; Sat, 20 Apr 2019 15:24:53 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hHrrI-0004AK-0D for xen-devel@lists.xenproject.org; Sat, 20 Apr 2019 15:24:52 +0000 X-Inumbo-ID: 702e8544-6380-11e9-92d7-bc764e045a96 Received: from mail-wr1-f65.google.com (unknown [209.85.221.65]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 702e8544-6380-11e9-92d7-bc764e045a96; Sat, 20 Apr 2019 15:24:50 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id c12so4224711wrt.8 for ; Sat, 20 Apr 2019 08:24:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=HdwtS9Q12sY8RiIdCGepx9QrSu+Ygt1WZ4O5X6T9wI0=; b=AiOkrZIc77wiWqliNuGunz1NI+3IOE7vUD4lqwUQscaOQgvekn4cIz98As4yxhwwgp FNBn3NiE5MPzhw5vMA1R4On6DbjD8g7bo5A3FWS4wmYOvoGyXJIQzuXJoUnTVBiYxVcT 2eT42qXglKrRJOPQMn7QU41nwAn+QJISZLU6itg47YocTBPLZ7dgIRoIla658U8mGB/T 2Vi5uZJrkU7Tti/liy3SxNYvFyd2BTT/gFSb5jkNQs32A9BzVsdElTrSknA8VjLHc85t nq1+4njB7+wcOkdw7O+saFC5gV8D3cYw7N2ou4eyD5tgcZZGCxKH01JPwfhbASefwZU0 +gmg== X-Gm-Message-State: APjAAAV7muYkPUSsCzAN+iRplNOU2SABJRHRQ05cKpv6VrwMPoCJdnfG OvsBixswtHTKcQndaUvcD5M= X-Google-Smtp-Source: APXvYqx3EkjjqVALgHPJoh2cJLbVZN00oylHQa2+zn9b2uliM3IIy7YPVpB+7a99kd2t6JCOy943Dw== X-Received: by 2002:a5d:4742:: with SMTP id o2mr6291485wrs.298.1555773889569; Sat, 20 Apr 2019 08:24:49 -0700 (PDT) Received: from [127.0.0.1] (87.78.186.89.cust.ip.kpnqwest.it. [89.186.78.87]) by smtp.gmail.com with ESMTPSA id j3sm10471589wre.51.2019.04.20.08.24.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Apr 2019 08:24:48 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Sat, 20 Apr 2019 17:24:47 +0200 Message-ID: <155577388740.25746.3780283868034526234.stgit@wayrath> In-Reply-To: <155577364571.25746.11988517450711182732.stgit@wayrath> References: <155577364571.25746.11988517450711182732.stgit@wayrath> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/2] xen: sched: we never get into context_switch() with prev==next X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Wei Liu , Andrew Cooper , George Dunlap , Julien Grall , Jan Beulich , Roger Pau =?utf-8?b?TW9ubsOp?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In schedule(), if we pick, as the next vcpu to run (next) the same one that is running already (prev), we never get to call context_switch(). We can, therefore, get rid of all the `if`-s testing prev and next being different, trading them with an ASSERT() (on ARM, the ASSERT() was even already there!) Signed-off-by: Dario Faggioli Suggested-by: Juergen Gross Acked-by: Julien Grall Reviewed-by: Andrii Anisov Acked-by: Andrew Cooper --- Cc: Stefano Stabellini Cc: Julien Grall Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monné" Cc: George Dunlap Cc: Juergen Gross --- xen/arch/arm/domain.c | 3 +-- xen/arch/x86/domain.c | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 6dc633ed50..915ae0b4c6 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -343,8 +343,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) ASSERT(prev != next); ASSERT(!vcpu_cpu_dirty(next)); - if ( prev != next ) - update_runstate_area(prev); + update_runstate_area(prev); local_irq_disable(); diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 9eaa978ce5..d2d9f2fc3c 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1721,6 +1721,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) const struct domain *prevd = prev->domain, *nextd = next->domain; unsigned int dirty_cpu = next->dirty_cpu; + ASSERT(prev != next); ASSERT(local_irq_is_enabled()); get_cpu_info()->use_pv_cr3 = false; @@ -1732,12 +1733,9 @@ void context_switch(struct vcpu *prev, struct vcpu *next) flush_mask(cpumask_of(dirty_cpu), FLUSH_VCPU_STATE); } - if ( prev != next ) - { - _update_runstate_area(prev); - vpmu_switch_from(prev); - np2m_schedule(NP2M_SCHEDLE_OUT); - } + _update_runstate_area(prev); + vpmu_switch_from(prev); + np2m_schedule(NP2M_SCHEDLE_OUT); if ( is_hvm_domain(prevd) && !list_empty(&prev->arch.hvm.tm_list) ) pt_save_timer(prev); @@ -1794,14 +1792,10 @@ void context_switch(struct vcpu *prev, struct vcpu *next) context_saved(prev); - if ( prev != next ) - { - _update_runstate_area(next); - - /* Must be done with interrupts enabled */ - vpmu_switch_to(next); - np2m_schedule(NP2M_SCHEDLE_IN); - } + _update_runstate_area(next); + /* Must be done with interrupts enabled */ + vpmu_switch_to(next); + np2m_schedule(NP2M_SCHEDLE_IN); /* Ensure that the vcpu has an up-to-date time base. */ update_vcpu_system_time(next);