From nobody Mon Nov 10 23:14:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1584576784; cv=none; d=zohomail.com; s=zohoarc; b=bGnHkk9mvh9pkUYWIlpSBqaVKw+/eSMg3Rn1zi9asT21ct6+ns5y0gBEjnicSMFUmR9YQ6KInGg8bPT0pn5op+nJZjCl5uLOO2wvl2zIPcZGnRq8ZIYBSPDyOMIxIkjdoWrsjN1L73lZVghJtEoC/mdwPoyk8X5Qfd/Ux0INPYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584576784; 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; bh=pJUF5qZCzHhyicQKF7rxXVhjh/4d8AVARKIVdG3Q8bU=; b=Z93wmewAKagRsMolgRescxOzkt2JS54F4TeIgONlE8q/PN8FXQSjs3bGje6gbxeHiiN0RO5AjivVkyUFSM1pfb72af8U/z+yqfbi0OXouKIJdUfHQXCyAJTva2Iq2+mLP3kMh1Iatv4g6yT8B0Fn1a7I2oVYN0+EYpwGmwoo1SM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1584576784452583.6417616493641; Wed, 18 Mar 2020 17:13:04 -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 1jEin6-0006iN-RM; Thu, 19 Mar 2020 00:12:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jEin5-0006iA-Kh for xen-devel@lists.xenproject.org; Thu, 19 Mar 2020 00:12:03 +0000 Received: from mail-wr1-f66.google.com (unknown [209.85.221.66]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 420207d4-6976-11ea-a6c1-bc764e2007e4; Thu, 19 Mar 2020 00:12:02 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id v11so598594wrm.9 for ; Wed, 18 Mar 2020 17:12:02 -0700 (PDT) Received: from [192.168.0.35] (87.78.186.89.cust.ip.kpnqwest.it. [89.186.78.87]) by smtp.gmail.com with ESMTPSA id 9sm568176wmx.32.2020.03.18.17.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 17:12:01 -0700 (PDT) X-Inumbo-ID: 420207d4-6976-11ea-a6c1-bc764e2007e4 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=6LVaQZsild5ol32UwnzGQmPz19U6z3oNdRtfhkD/Gzs=; b=Oh2hgINdkV9Gtpf2QNp56K77BBr8bJJYw5GL0xVUmWkOCiTZMZ82o2GLSn5eVlv3u+ NjZoKSYGdWiwRAzLzwJCWoCXbw1lBdYPULypWqgoHK8GibLqDZ0EsEVd6iKfTOTnP6lw YNJcss+y/tSC66TqZsfD83JX+MEwGSKuulBGLev3pC5mg7COWrkU7nJDhzmazZL0TVi4 m/urrkau3Y0Ql4wsk9+BfBIhAWjLsbA2k/OJqfHQBVzDz7oxHBej5JRbEErLKClwcigy HhU7P/HT+aGcjMCeaLXR5EipFE59RtOLgbEzeVrb19JmjrBmJlqEdMXaaAfVANDTqGwR JggQ== X-Gm-Message-State: ANhLgQ2j9qEmA3NDk90BL7R9mcPmeBLe67XGUd08xtM2aI38lxpZc1ig rlSnQfPIPVS3sAuguMfiIkZLcC2QDOQ= X-Google-Smtp-Source: ADFU+vuVyNS/z7cEzbfe2PNFKvWjw3T9atmm6oWG989S58iPrh9LWyJ2gLKZFxXvciZxYVtKeAXvvA== X-Received: by 2002:a5d:4c87:: with SMTP id z7mr538933wrs.39.1584576721826; Wed, 18 Mar 2020 17:12:01 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 19 Mar 2020 01:12:00 +0100 Message-ID: <158457672023.11355.16720240521867328301.stgit@Palanthas> In-Reply-To: <158457508246.11355.6457403441669388939.stgit@Palanthas> References: <158457508246.11355.6457403441669388939.stgit@Palanthas> User-Agent: StGit/0.21 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 2/2] xen: credit2: fix credit reset happening too few times 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 , Charles Arnold , Jan Beulich , Glen , George Dunlap , Tomas Mozes , Sarah Newman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" There is a bug in commit 5e4b4199667b9 ("xen: credit2: only reset credit on reset condition"). In fact, the aim of that commit was to make sure that we do not perform too many credit reset operations (which are not super cheap, and in an hot-path). But the check used to determine whether a reset is necessary was the wrong one. In fact, knowing just that some vCPUs have been skipped, while traversing the runqueue (in runq_candidate()), is not enough. We need to check explicitly whether the first vCPU in the runqueue has a negative amount of credit. Since a trace record is changed, this patch updates xentrace format file and xenalyze as well This should be backported. Signed-off-by: Dario Faggioli Acked-by: George Dunlap --- Cc: George Dunlap Cc: Juergen Gross Cc: Jan Beulich Cc: Charles Arnold Cc: Glen Cc: Tomas Mozes Cc: Sarah Newman --- About the Credit2 stall issue reported recently, and mentioned in patch 1 of this series. This second patch, alone, was already mitigating the issue quite substantially. Still, the proper fix for the issue itself is patch 1, while this is a fix for a bug in the code, introduced with a previous change, which happens to help to cure the sympthoms of the problem at hand. --- tools/xentrace/formats | 2 +- tools/xentrace/xenalyze.c | 8 +++----- xen/common/sched/credit2.c | 30 +++++++++++++----------------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/tools/xentrace/formats b/tools/xentrace/formats index 8f126f65f1..deac4d8598 100644 --- a/tools/xentrace/formats +++ b/tools/xentrace/formats @@ -67,7 +67,7 @@ 0x00022210 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) csched2:load_check [ l= rq_id[16]:orq_id[16] =3D 0x%(1)08x, delta =3D %(2)d ] 0x00022211 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) csched2:load_balance [ l= _bavgload =3D 0x%(2)08x%(1)08x, o_bavgload =3D 0x%(4)08x%(3)08x, lrq_id[16]= :orq_id[16] =3D 0x%(5)08x ] 0x00022212 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) csched2:pick_cpu [ b= _avgload =3D 0x%(2)08x%(1)08x, dom:vcpu =3D 0x%(3)08x, rq_id[16]:new_cpu[16= ] =3D %(4)d ] -0x00022213 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) csched2:runq_candidate [ d= om:vcpu =3D 0x%(1)08x, credit =3D %(4)d, skipped_vcpus =3D %(3)d, tickled_c= pu =3D %(2)d ] +0x00022213 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) csched2:runq_candidate [ d= om:vcpu =3D 0x%(1)08x, credit =3D %(3)d, tickled_cpu =3D %(2)d ] 0x00022214 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) csched2:schedule [ r= q:cpu =3D 0x%(1)08x, tasklet[8]:idle[8]:smt_idle[8]:tickled[8] =3D %(2)08x ] 0x00022215 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) csched2:ratelimit [ d= om:vcpu =3D 0x%(1)08x, runtime =3D %(2)d ] 0x00022216 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) csched2:runq_cand_chk [ d= om:vcpu =3D 0x%(1)08x ] diff --git a/tools/xentrace/xenalyze.c b/tools/xentrace/xenalyze.c index d3c8368e9d..b7f4e2bea8 100644 --- a/tools/xentrace/xenalyze.c +++ b/tools/xentrace/xenalyze.c @@ -7855,14 +7855,12 @@ void sched_process(struct pcpu_info *p) if (opt.dump_all) { struct { unsigned vcpuid:16, domid:16; - unsigned tickled_cpu, skipped; + unsigned tickled_cpu; int credit; } *r =3D (typeof(r))ri->d; =20 - printf(" %s csched2:runq_candidate d%uv%u, credit =3D %d, " - "%u vcpus skipped, ", - ri->dump_header, r->domid, r->vcpuid, - r->credit, r->skipped); + printf(" %s csched2:runq_candidate d%uv%u, credit =3D %d, = ", + ri->dump_header, r->domid, r->vcpuid, r->credit); if (r->tickled_cpu =3D=3D (unsigned)-1) printf("no cpu was tickled\n"); else diff --git a/xen/common/sched/credit2.c b/xen/common/sched/credit2.c index cbf9ce2b97..34f05c3e2a 100644 --- a/xen/common/sched/credit2.c +++ b/xen/common/sched/credit2.c @@ -3224,8 +3224,7 @@ csched2_runtime(const struct scheduler *ops, int cpu, static struct csched2_unit * runq_candidate(struct csched2_runqueue_data *rqd, struct csched2_unit *scurr, - int cpu, s_time_t now, - unsigned int *skipped) + int cpu, s_time_t now) { struct list_head *iter, *temp; const struct sched_resource *sr =3D get_sched_res(cpu); @@ -3233,8 +3232,6 @@ runq_candidate(struct csched2_runqueue_data *rqd, struct csched2_private *prv =3D csched2_priv(sr->scheduler); bool yield =3D false, soft_aff_preempt =3D false; =20 - *skipped =3D 0; - if ( unlikely(is_idle_unit(scurr->unit)) ) { snext =3D scurr; @@ -3328,12 +3325,9 @@ runq_candidate(struct csched2_runqueue_data *rqd, (unsigned char *)&d); } =20 - /* Only consider units that are allowed to run on this processor. = */ + /* Only consider vcpus that are allowed to run on this processor. = */ if ( !cpumask_test_cpu(cpu, svc->unit->cpu_hard_affinity) ) - { - (*skipped)++; continue; - } =20 /* * If an unit is meant to be picked up by another processor, and s= uch @@ -3342,7 +3336,6 @@ runq_candidate(struct csched2_runqueue_data *rqd, if ( svc->tickled_cpu !=3D -1 && svc->tickled_cpu !=3D cpu && cpumask_test_cpu(svc->tickled_cpu, &rqd->tickled) ) { - (*skipped)++; SCHED_STAT_CRANK(deferred_to_tickled_cpu); continue; } @@ -3354,7 +3347,6 @@ runq_candidate(struct csched2_runqueue_data *rqd, if ( sched_unit_master(svc->unit) !=3D cpu && snext->credit + CSCHED2_MIGRATE_RESIST > svc->credit ) { - (*skipped)++; SCHED_STAT_CRANK(migrate_resisted); continue; } @@ -3378,14 +3370,13 @@ runq_candidate(struct csched2_runqueue_data *rqd, { struct { unsigned unit:16, dom:16; - unsigned tickled_cpu, skipped; + unsigned tickled_cpu; int credit; } d; d.dom =3D snext->unit->domain->domain_id; d.unit =3D snext->unit->unit_id; d.credit =3D snext->credit; d.tickled_cpu =3D snext->tickled_cpu; - d.skipped =3D *skipped; __trace_var(TRC_CSCHED2_RUNQ_CANDIDATE, 1, sizeof(d), (unsigned char *)&d); @@ -3417,7 +3408,6 @@ static void csched2_schedule( struct csched2_runqueue_data *rqd; struct csched2_unit * const scurr =3D csched2_unit(currunit); struct csched2_unit *snext =3D NULL; - unsigned int skipped_units =3D 0; bool tickled; bool migrated =3D false; =20 @@ -3495,7 +3485,7 @@ static void csched2_schedule( snext =3D csched2_unit(sched_idle_unit(sched_cpu)); } else - snext =3D runq_candidate(rqd, scurr, sched_cpu, now, &skipped_unit= s); + snext =3D runq_candidate(rqd, scurr, sched_cpu, now); =20 /* If switching from a non-idle runnable unit, put it * back on the runqueue. */ @@ -3507,6 +3497,8 @@ static void csched2_schedule( /* Accounting for non-idle tasks */ if ( !is_idle_unit(snext->unit) ) { + int top_credit; + /* If switching, remove this from the runqueue and mark it schedul= ed */ if ( snext !=3D scurr ) { @@ -3534,11 +3526,15 @@ static void csched2_schedule( * 2) no other unit with higher credits wants to run. * * Here, where we want to check for reset, we need to make sure the - * proper unit is being used. In fact, runqueue_candidate() may ha= ve - * not returned the first unit in the runqueue, for various reasons + * proper unit is being used. In fact, runq_candidate() may have n= ot + * returned the first unit in the runqueue, for various reasons * (e.g., affinity). Only trigger a reset when it does. */ - if ( skipped_units =3D=3D 0 && snext->credit <=3D CSCHED2_CREDIT_R= ESET ) + if ( list_empty(&rqd->runq) ) + top_credit =3D snext->credit; + else + top_credit =3D max(snext->credit, runq_elem(rqd->runq.next)->c= redit); + if ( top_credit <=3D CSCHED2_CREDIT_RESET ) { reset_credit(sched_cpu, now, snext); balance_load(ops, sched_cpu, now); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel