From nobody Sat Apr 27 13:46:55 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1555773960; cv=none; d=zoho.com; s=zohoarc; b=HLDCWWyQXGBDbmJp2r78Lwx3mpdeXP0Z5GVgSAeYhSKYYKtiH/Ekvg67ogU5Wcy47mrnHpsDiv37nptOgpn0AXYDT71iz7tHRcF0AUkR5bMtHDYbVHP7k/3LLyFD1WwFgINf1mGbfunpwRiJ+rRZHnq8l3KKVsZzdNB4BPpTk+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555773960; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=MvDUntJc2Y+FWeXy33AxE+Vjz7c9NUYLStol3dGOv1k=; b=oBDvZ7Px+FkJ/ApZ4fyYkrTgm5kcqWfbSiV+iiUkkzQSXdj+Y5t22JwUWwBNYKB3Q92Ag/T2BxDkYY8jQaW/5KHw+gGh6rSLfeE6VQEN+6CIhTzmsvjvzjstoxHUpsgdJVTJMU9TAQRbdlDHcrSp6oS1CkK6jWP2umEjdBfaVAI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1555773960555817.0694872003228; Sat, 20 Apr 2019 08:26:00 -0700 (PDT) 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 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) 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) X-Inumbo-ID: 6bf64945-6380-11e9-92d7-bc764e045a96 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 = */ =20 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) = */ =20 int load; /* Instantaneous load (num of non-idle vcpu= s) */ @@ -2613,8 +2614,8 @@ retry: if ( st.orqd->b_avgload > load_max ) load_max =3D st.orqd->b_avgload; =20 - cpus_max =3D cpumask_weight(&st.lrqd->active); - i =3D cpumask_weight(&st.orqd->active); + cpus_max =3D st.lrqd->nr_cpus; + i =3D st.orqd->nr_cpus; if ( i > cpus_max ) cpus_max =3D i; =20 @@ -3697,7 +3698,7 @@ csched2_dump(const struct scheduler *ops) "\tinstload =3D %d\n" "\taveload =3D %"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 csched= 2_pcpu *spc, __cpumask_set_cpu(cpu, &prv->initialized); __cpumask_set_cpu(cpu, &rqd->smt_idle); =20 + rqd->nr_cpus++; + ASSERT(cpumask_weight(&rqd->active) =3D=3D rqd->nr_cpus); + /* On the boot cpu we are called before cpu_sibling_mask has been set = up. */ if ( cpu =3D=3D 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 csche= d2_pcpu *spc, __cpumask_set_cpu(rcpu, &csched2_pcpu(cpu)->sibling_mask); } =20 - if ( cpumask_weight(&rqd->active) =3D=3D 1 ) + if ( rqd->nr_cpus =3D=3D 1 ) + { + ASSERT(cpumask_weight(&rqd->active) =3D=3D 1); rqd->pick_bias =3D cpu; + } =20 return spc->runq_id; } @@ -3944,8 +3951,12 @@ csched2_deinit_pdata(const struct scheduler *ops, vo= id *pcpu, int cpu) __cpumask_clear_cpu(cpu, &rqd->smt_idle); __cpumask_clear_cpu(cpu, &rqd->active); =20 - if ( cpumask_empty(&rqd->active) ) + rqd->nr_cpus--; + ASSERT(cpumask_weight(&rqd->active) =3D=3D rqd->nr_cpus); + + if ( rqd->nr_cpus =3D=3D 0 ) { + ASSERT(cpumask_empty(&rqd->active)); printk(XENLOG_INFO " No cpus left on runqueue, disabling\n"); deactivate_runqueue(prv, spc->runq_id); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat Apr 27 13:46:55 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1555774200; cv=none; d=zoho.com; s=zohoarc; b=VZMWO8X49putEf/ck4xKY1mjPiX6pDurgJ39wFxP91flBCox9bxd06TbO7/sPCe/bl1R/4h2kOl7MltN/K1A7IPvGAaA5Upo9LGQKbDfa2VwV+svKndfroAFVWAYBd4XVKuQFge2MSi5RVnvdbDzZAm6QvCmEb077y937pg9g3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555774200; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=PLNrgH1rOXFMqWk4Hou9yF/5aJfXchVozWgT4vnfu7s=; b=Vc5fK3UR9Obx1illpXMpWsmSttWbehmRcSsx9WBkbMQK2fCqEWtWImB3vOx7dIRIi14tut/e5GYdtKdk878M9g0WwgkHp6mP3KpRhatVTNLbLv8ioL3zLtvIgqzWtS/L/sx2vs+exx37JTpz00t/if9PAnImlPAI1btxt1uJq98= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1555774200604615.4308875617778; Sat, 20 Apr 2019 08:30:00 -0700 (PDT) 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 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) 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) X-Inumbo-ID: 702e8544-6380-11e9-92d7-bc764e045a96 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) 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?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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: Andrew Cooper Acked-by: Julien Grall Reviewed-by: Andrii Anisov --- Cc: Stefano Stabellini Cc: Julien Grall Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" 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 *nex= t) ASSERT(prev !=3D next); ASSERT(!vcpu_cpu_dirty(next)); =20 - if ( prev !=3D next ) - update_runstate_area(prev); + update_runstate_area(prev); =20 local_irq_disable(); =20 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 *n= ext) const struct domain *prevd =3D prev->domain, *nextd =3D next->domain; unsigned int dirty_cpu =3D next->dirty_cpu; =20 + ASSERT(prev !=3D next); ASSERT(local_irq_is_enabled()); =20 get_cpu_info()->use_pv_cr3 =3D false; @@ -1732,12 +1733,9 @@ void context_switch(struct vcpu *prev, struct vcpu *= next) flush_mask(cpumask_of(dirty_cpu), FLUSH_VCPU_STATE); } =20 - if ( prev !=3D 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); =20 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) =20 context_saved(prev); =20 - if ( prev !=3D 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); =20 /* Ensure that the vcpu has an up-to-date time base. */ update_vcpu_system_time(next); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel