From patchwork Fri Jul 26 10:37:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Anisov X-Patchwork-Id: 11060765 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 08C4C13B1 for ; Fri, 26 Jul 2019 10:39:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E98FB28A85 for ; Fri, 26 Jul 2019 10:39:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAC3A28A8F; Fri, 26 Jul 2019 10:39:34 +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.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 7C78328A85 for ; Fri, 26 Jul 2019 10:39:34 +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 1hqxbj-0006YT-2P; Fri, 26 Jul 2019 10:37:51 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hqxbh-0006YG-Oi for xen-devel@lists.xenproject.org; Fri, 26 Jul 2019 10:37:49 +0000 X-Inumbo-ID: 6890b12e-af91-11e9-8980-bc764e045a96 Received: from mail-lj1-x243.google.com (unknown [2a00:1450:4864:20::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 6890b12e-af91-11e9-8980-bc764e045a96; Fri, 26 Jul 2019 10:37:48 +0000 (UTC) Received: by mail-lj1-x243.google.com with SMTP id t28so51004234lje.9 for ; Fri, 26 Jul 2019 03:37:47 -0700 (PDT) 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=r+8JnlZestTVxlER6RMuaC2epWUTI/v8WDaAeYWwhA0=; b=RErUSs4OfOW/pF16O1aJVbU3Hhci+OMHYQPUk2SEsqu4CYSMr9MwQIgkWyIIPO/yvp qGPQOfBQFNHUiuojaa2stI9YYWn7ptUKN7+6Xisdjrzlv6L5DtPy+qD15r3hpHWGNqRw MyH9te2o+rJVHwlsKBzYnHNAJ/qEPaImQEB+cz0ozfInPKstUj+m5gS4RofLWvphvdJy p1/zSAvhBDeFosLUoqdt7AU7w1JxbdBw0CxwJyo4m6gjUUXqBFgjujvS88TmqIb4EucG eY0hfn8R/bYIeBvpj+DvmG4uZO0AQPY4CyZrBw0/MY6gZ5XTM7Z2vCDm5eAbgbbRBk0U FUYg== 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=r+8JnlZestTVxlER6RMuaC2epWUTI/v8WDaAeYWwhA0=; b=Q2nzZhVjBZ4Rf3kBXs+7iVLDAT3YrRL2/1FFnDtX8KU0vyoZCQdpHokwPDQKjBiw6x hTj5YtEH7FtUGAQTaXdvVmFtSIDiEX8idYP3fzb9rjEuP1AKKSBn3bd6kkHJfLhV5tcP zZtCmrZqGGS336VbgrH0dD2ZWgM2qo0YPC/r9NGSiLn7fftvpP0RY3fg23By4S9TQdxf O4wwcmpttAeKB4qrEv5UHejxLgJVyP8xdfcaX86UmVnwZJlO7pazEcSn0pV4+onUqEQ6 qsFwNtrOq37IDczzv9O37bff0aCfcVB9gkpPVtpIAtjbdkY9R6b+9iyN1tA5bLJfKTGb u//Q== X-Gm-Message-State: APjAAAW1E3qgZyRi7yK8BkflNCatvLTFCPHhGC4Lu5qLaI1CAtrXboh6 +C4qpgGfmDN0Zio6x+uygZbxBxWO X-Google-Smtp-Source: APXvYqzHH/Xa7A2eRVemlcQHIS8r9ZHsUY98TbT8rBeFeaJFRSzBtBgMe01uVPHjzTX70sZs9qqx3g== X-Received: by 2002:a2e:9117:: with SMTP id m23mr49167542ljg.134.1564137466198; Fri, 26 Jul 2019 03:37:46 -0700 (PDT) Received: from aanisov-work.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id m4sm9938274ljc.56.2019.07.26.03.37.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 03:37:45 -0700 (PDT) From: Andrii Anisov To: xen-devel@lists.xenproject.org Date: Fri, 26 Jul 2019 13:37:35 +0300 Message-Id: <1564137460-25629-3-git-send-email-andrii.anisov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1564137460-25629-1-git-send-email-andrii.anisov@gmail.com> References: <1564137460-25629-1-git-send-email-andrii.anisov@gmail.com> Subject: [Xen-devel] [RFC 2/6] schedule: account true system idle time 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: Stefano Stabellini , Andrii Anisov , George Dunlap , Dario Faggioli , Julien Grall , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Andrii Anisov Currently the idle time is being accounted as a idle vcpu runtime. This is not entirely correct, because the entity named idle vcpu is in fact a hypervisor tasks worker. E.g. some softirqs are processed by the idle vcpu. So lets change idle vcpu time accounting and specify system idle time as a idle vcpu blocked time. For this we should appropriately change idle vcpu runstates around the real processor idle entry. Signed-off-by: Andrii Anisov --- xen/arch/arm/domain.c | 24 ++++++++++++++++++++++++ xen/common/schedule.c | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 941bbff..a4e0fd7 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,27 @@ DEFINE_PER_CPU(struct vcpu *, curr_vcpu); +static inline void idle_vcpu_runstate_change( + unsigned int cpu, int new_state, s_time_t new_entry_time) +{ + s_time_t delta; + struct vcpu *v = idle_vcpu[cpu]; + spinlock_t *lock = vcpu_schedule_lock(v); + + ASSERT(v == current); + ASSERT(v->runstate.state != new_state); + + delta = new_entry_time - v->runstate.state_entry_time; + if ( delta > 0 ) + { + v->runstate.time[v->runstate.state] += delta; + v->runstate.state_entry_time = new_entry_time; + } + + v->runstate.state = new_state; + vcpu_schedule_unlock(lock, v); +} + static void do_idle(void) { unsigned int cpu = smp_processor_id(); @@ -51,11 +73,13 @@ static void do_idle(void) process_pending_softirqs(); local_irq_disable(); + idle_vcpu_runstate_change(cpu, RUNSTATE_blocked, NOW()); if ( cpu_is_haltable(cpu) ) { dsb(sy); wfi(); } + idle_vcpu_runstate_change(cpu, RUNSTATE_running, NOW()); local_irq_enable(); sched_tick_resume(); diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 349f962..0a38d4a 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -214,7 +214,7 @@ uint64_t get_cpu_idle_time(unsigned int cpu) if ( cpu_online(cpu) && v ) vcpu_runstate_get(v, &state); - return state.time[RUNSTATE_running]; + return state.time[RUNSTATE_blocked]; } /* @@ -922,6 +922,8 @@ void vcpu_block(void) { struct vcpu *v = current; + ASSERT(!is_idle_vcpu(v)); + set_bit(_VPF_blocked, &v->pause_flags); arch_vcpu_block(v);