From nobody Tue Feb 10 05:44:32 2026 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; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1568198027; cv=none; d=zoho.com; s=zohoarc; b=JxcDbfZcklP0X3XICL2TjGrSKFxTvkFgv6HisfMfcgBEtZEIEkZCQb7ue6DYLqdCGWil7ESs/7/rneyGp/4JCEezy4R4gn6opddkc9Wl2A70ENOp55R6iW2I+piVnC21XjKbemxsHJY03aLwz8gCya4N9roog+zCRAbuwmnY+NQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568198027; 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=6xg8i6SQMskfwhzMKn2bhBbh/HcjV7mwcblvLUs+gjc=; b=Xssg5ou+ELhVsg8xPCwBAFNNXl+CqBEAKbvZo/CfMgdBHtB8jvP8CybMGuFOaOdl3RKsWE73Uyr3C+hK6h7tjPj4sspXagoXyWl7dg/9xxgeVtq6hGrM5C1/2rq+WFxtwA+UDRNhKr34iAsWXj4J390FA3FBoIDcJ4rml/DzT8Y= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568198027714643.5432278208774; Wed, 11 Sep 2019 03:33:47 -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 1i7zvO-00006J-9a; Wed, 11 Sep 2019 10:32:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7zvN-000064-8V for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 10:32:33 +0000 Received: from mail-lf1-x142.google.com (unknown [2a00:1450:4864:20::142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 742a4384-d47f-11e9-978d-bc764e2007e4; Wed, 11 Sep 2019 10:32:29 +0000 (UTC) Received: by mail-lf1-x142.google.com with SMTP id t8so15988225lfc.13 for ; Wed, 11 Sep 2019 03:32:29 -0700 (PDT) Received: from aanisov-work.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id w27sm4585275ljd.55.2019.09.11.03.32.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Sep 2019 03:32:26 -0700 (PDT) X-Inumbo-ID: 742a4384-d47f-11e9-978d-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wjAeCZij2Xw6xoNlfZ2Z1Stlf0K5I20sXHD+nMPhkoI=; b=A21Wk5W0TFKbr1uHis+Qk7ZnFcg5HeHxrLmEOi8sRCxC9G9zToYSwqLvQKqGSM5oWN AZgweoS/81b0sSsJN+gDCbLhz06Vnd7vyrf7fS1qaCh8Z+/KcCN8erihO8PolKfDANYz 1T9sNmAsC3yJqP/CRA3XfD3K9hn1nxtq43IAbycKBMbgnwQIsZG/PTRES+/yF/Q1r9DF 9EuxQYsJQLbFdfdn3dcedfCkBvFI5HAgdhSdM5/WEE6VsSF+gaREOaWsS46s3EvsnMV2 AYmgrvpqdsjrheD5gBgvo3Ge5yj0jWgBMdaH86YEiO+t6PeoJL9qKjQ58ZzUsHvtsG00 nysQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wjAeCZij2Xw6xoNlfZ2Z1Stlf0K5I20sXHD+nMPhkoI=; b=cGyaDEMk8Rkawf0Le/WCBDnjJxMJXf6DUiBCH4+NHR2pQwaEuInvy1efB8nw5n7QHP ZJxP5Jyl2fCbZbtw2c8KIJOUpwAmpZYA4EboDNsB5PeqxtbEQMsmG0jY7unhymc+M4Zb b5bOoYUnop/Jmh3U6Ic7rdUaR8pOTPgnI+yf9HK2o0+eMMzEs3MXdyzUwxM4LqhfQ2o0 wcIt4bxpaEhye573FBq+EzzZY45LeFu0KNEKgsm0FtcfskRvRvkU3MJrLBJyqQ+49Yih HLOy9qYVA/ibGCIRGvkUNN+GfZG8UknuShk/byMgOimowZ/yRTgAHi70AeVbMMhiqb7n y3gA== X-Gm-Message-State: APjAAAWOOG6ADwYEQcmDLlaRItZ/IXdQOFFBFIw0lXFQSmYh8R391dm4 rkyQ17QiXQ48exsHklrlZ1qQpwqXkNY= X-Google-Smtp-Source: APXvYqwYktQJELQC55+1f3aWu6a8jxZrzr8GcXcq/hSCeKYctx4MxDcLYm+pOCcoIGjMxfg93iTcCA== X-Received: by 2002:ac2:5203:: with SMTP id a3mr340474lfl.151.1568197947575; Wed, 11 Sep 2019 03:32:27 -0700 (PDT) From: Andrii Anisov To: xen-devel@lists.xenproject.org Date: Wed, 11 Sep 2019 13:32:14 +0300 Message-Id: <1568197942-15374-2-git-send-email-andrii.anisov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1568197942-15374-1-git-send-email-andrii.anisov@gmail.com> References: <1568197942-15374-1-git-send-email-andrii.anisov@gmail.com> Subject: [Xen-devel] [RFC 1/9] schedule: Introduce per-pcpu time accounting 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: Tim Deegan , Stefano Stabellini , Andrii Anisov , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Dario Faggioli , Julien Grall , Jan Beulich MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Andrii Anisov Introduce per-pcpu time accounting what includes the following states: TACC_HYP - the pcpu executes hypervisor code like softirq processing (including scheduling), tasklets and context switches TACC_GUEST - the pcpu executes guests code TACC_IDLE - the low-power state of the pcpu TACC_IRQ - the pcpu performs interrupts processing, without separation to guest or hypervisor interrupts TACC_GSYNC - the pcpu executes hypervisor code to process synchronous trap from the guest. E.g. hypercall processing or io emulation. Currently, the only reenterant state is TACC_IRQ. It is assumed, no changes to state other than TACC_IRQ could happen until we return from nested interrupts. IRQ time is accounted in a distinct way comparing to other stat= es. It is acumulated between other states transition moments, and is substracted from the old state on states transion calculation. Signed-off-by: Andrii Anisov --- xen/common/schedule.c | 81 +++++++++++++++++++++++++++++++++++++++++++++= ++++ xen/include/xen/sched.h | 27 +++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 7b71581..6dd6603 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -1539,6 +1539,87 @@ static void schedule(void) context_switch(prev, next); } =20 +DEFINE_PER_CPU(struct tacc, tacc); + +static void tacc_state_change(enum TACC_STATES new_state) +{ + s_time_t now, delta; + struct tacc* tacc =3D &this_cpu(tacc); + unsigned long flags; + + local_irq_save(flags); + + now =3D NOW(); + delta =3D now - tacc->state_entry_time; + + /* We do not expect states reenterability (at least through this funct= ion)*/ + ASSERT(new_state !=3D tacc->state); + + tacc->state_time[tacc->state] +=3D delta - tacc->irq_time; + tacc->state_time[TACC_IRQ] +=3D tacc->irq_time; + tacc->irq_time =3D 0; + tacc->state =3D new_state; + tacc->state_entry_time =3D now; + + local_irq_restore(flags); +} + +void tacc_hyp(int place) +{ +// printk("\ttacc_hyp %u, place %d\n", smp_processor_id(), place); + tacc_state_change(TACC_HYP); +} + +void tacc_guest(int place) +{ +// printk("\ttacc_guest %u, place %d\n", smp_processor_id(), place); + tacc_state_change(TACC_GUEST); +} + +void tacc_idle(int place) +{ +// printk("\tidle cpu %u, place %d\n", smp_processor_id(), place); + tacc_state_change(TACC_IDLE); +} + +void tacc_gsync(int place) +{ +// printk("\ttacc_gsync %u, place %d\n", smp_processor_id(), place); + tacc_state_change(TACC_GSYNC); +} + +void tacc_irq_enter(int place) +{ + struct tacc* tacc =3D &this_cpu(tacc); + +// printk("\ttacc_irq_enter %u, place %d, cnt %d\n", smp_processor_id()= , place, this_cpu(tacc).irq_cnt); + ASSERT(!local_irq_is_enabled()); + ASSERT(tacc->irq_cnt >=3D 0); + + if ( tacc->irq_cnt =3D=3D 0 ) + { + tacc->irq_enter_time =3D NOW(); + } + + tacc->irq_cnt++; +} + +void tacc_irq_exit(int place) +{ + struct tacc* tacc =3D &this_cpu(tacc); + +// printk("\ttacc_irq_exit %u, place %d, cnt %d\n", smp_processor_id(),= place, tacc->irq_cnt); + ASSERT(!local_irq_is_enabled()); + ASSERT(tacc->irq_cnt > 0); + if ( tacc->irq_cnt =3D=3D 1 ) + { + tacc->irq_time =3D NOW() - tacc->irq_enter_time; + tacc->irq_enter_time =3D 0; + } + + tacc->irq_cnt--; +} + void context_saved(struct vcpu *prev) { /* Clear running flag /after/ writing context to memory. */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index e3601c1..04a8724 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -1002,6 +1002,33 @@ extern void dump_runq(unsigned char key); =20 void arch_do_physinfo(struct xen_sysctl_physinfo *pi); =20 +enum TACC_STATES { + TACC_HYP =3D 0, + TACC_GUEST =3D 1, + TACC_IDLE =3D 2, + TACC_IRQ =3D 3, + TACC_GSYNC =3D 4, + TACC_STATES_MAX +}; + +struct tacc +{ + s_time_t state_time[TACC_STATES_MAX]; + s_time_t state_entry_time; + int state; + + s_time_t guest_time; + + s_time_t irq_enter_time; + s_time_t irq_time; + int irq_cnt; +}; + +DECLARE_PER_CPU(struct tacc, tacc); + +void tacc_hyp(int place); +void tacc_idle(int place); + #endif /* __SCHED_H__ */ =20 /* --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel