Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp405231ybk; Sat, 9 May 2020 06:28:34 -0700 (PDT) X-Google-Smtp-Source: APiQypLBTeEAmHL6jQWfQf/cSVGfznpmu4EJmQUiyyzbEZXo3NF2b7j4WOdAK8gKLfvzLPUpILtn X-Received: by 2002:a17:906:528e:: with SMTP id c14mr1780886ejm.123.1589030914317; Sat, 09 May 2020 06:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589030914; cv=none; d=google.com; s=arc-20160816; b=XhueW82M4jJmK5yvNARD87VDRoFUglj7ymcIA5DZ+7BcFvFl0oww64ftWqX3EtMgYr K+FFEmELB6xaf6bli7TaEaSIwcgyJYteoqUBy8vEgRqCi7dgyf++OT0Gcy+d3AWGr1Jl w2YX7e56dnkrvINWeByrKSjHtWn23OVjU6PVnNH90zYINUTUo76wpuVpsi7x8QP4aevf HFYUV1JT8CJv3HAVLCH63zFQ4rke1pGxl8qi9hI1hjicD/o4PWT6iWQxz1Ns7dYAKY24 i4D4lpA/2bmft1omUeWGKqqrCDUcX6BJHEFPva9/cWR7B1JGSdhyoKUpL7tmzXMLTPI3 9E6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=yJ5RDywFb8p02L3LFUPRLr4TwiBeNt4sPEKLa6XsCZ8=; b=s8lX6xM1bKcz1YHTOK3RCRvPABtZiK8x089whzwWUzr40PrIiSDGJoRzvJKGhcCeM4 1eHl9LX2Lsdbrtg4oi0Sgi7YmePF9ctn8pdeRhIZXbbsFKUjdNzD3SeKkK7Qbh9rOyuG 5f6eWJYtxvAsgR6huO/zxAInhPRZeRLryMPCWnXqCv1ez7rZ07jGUjMiEIPnqqYkcpoE OMSrUbA1pjQG0081PH/VYGWDy81C1TpYizEWVtScB3zwvCqR9D5UpPiVepD4cUcDu/Rm 4VVXr9Z7ahgTa77WS4LeKFSLh/ewN4/7+w8MqgrHXuuJsWMTd9LZBcM1mslqjwEttlEX 9uSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RwP6PDtl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m16si2739431edq.329.2020.05.09.06.28.11; Sat, 09 May 2020 06:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RwP6PDtl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727844AbgEIN0G (ORCPT + 99 others); Sat, 9 May 2020 09:26:06 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:47508 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727092AbgEIN0G (ORCPT ); Sat, 9 May 2020 09:26:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589030764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yJ5RDywFb8p02L3LFUPRLr4TwiBeNt4sPEKLa6XsCZ8=; b=RwP6PDtlaCZfCdkahnKMqxJyX76eodVZ+sseM83tc8row/R96I81zOEDSOTDIzyFMUartV hvvM6Qnv3DHOx3ZxPJFnWt3wTis4YK4qFWmQwoYqmUWw6t5XaAIeHD9C+cAZ+j7J54l2Tv O/1nimbJtz2vb168pjyhrcejQilu8HY= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-101-TT5sWhjpNf2O0V2yzYUufQ-1; Sat, 09 May 2020 09:26:03 -0400 X-MC-Unique: TT5sWhjpNf2O0V2yzYUufQ-1 Received: by mail-wr1-f72.google.com with SMTP id g30so430424wrb.4 for ; Sat, 09 May 2020 06:26:02 -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:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=yJ5RDywFb8p02L3LFUPRLr4TwiBeNt4sPEKLa6XsCZ8=; b=d2hSwKRE/yLADTCu+oCJtub84hRACH6NTVH/d+OLfUUzVaHxg5vYrUGTA2n0vxGtFu qesnBJ2UFNw641PPKGUdjKG6fWFgeXB2uUnHz4fDoxGpc+vHPkN+5CdnWK45B/szOe6C Lpb5s0Vy1lsC/cfgcG4feyn1GElfjPeUQEHcnoMBnoW91UaOOqrb5iPaodm8dRmmaeX9 rFbvPINnd2AJf7Dds7lKZZcPo3n5lw6/mAE/NFsVHU/irzJ+7Wf/SSl1MaMeIjbWO3wo IROyfTVijoAxJJUwEOHVHWfEEkqO7pF+wtrQZCdbg1mS2cdKRNrBdqziHCOdrbL0MLx2 CvqA== X-Gm-Message-State: AGi0PuYbTV9kXb8exNnrKLHjlsexGqKsf+YXIigHYjlyuNa/DYyeQ+6s NQJ6+4KWUklSiMqj+6l2ZFiHghYRUGOVQQj7vNcKHRQDq9ga6dIQ8jiKoazQlYrYjQbN6DFUucs 6Miyg8RhnMS2WyNKa3VavJ/rQ X-Received: by 2002:a5d:6b86:: with SMTP id n6mr8361515wrx.113.1589030761404; Sat, 09 May 2020 06:26:01 -0700 (PDT) X-Received: by 2002:a5d:6b86:: with SMTP id n6mr8361495wrx.113.1589030761153; Sat, 09 May 2020 06:26:01 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:1cb4:2b36:6750:73ce? ([2001:b07:6468:f312:1cb4:2b36:6750:73ce]) by smtp.gmail.com with ESMTPSA id h74sm8565819wrh.76.2020.05.09.06.26.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 May 2020 06:26:00 -0700 (PDT) Subject: Re: [PATCH] kvm: add halt-polling cpu usage stats To: Jon Cargille , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: David Matlack References: <20200508182240.68440-1-jcargill@google.com> From: Paolo Bonzini Message-ID: <914f1aec-de5e-dcc9-9f99-4ffbcd7e8a53@redhat.com> Date: Sat, 9 May 2020 15:25:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200508182240.68440-1-jcargill@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/05/20 20:22, Jon Cargille wrote: > From: David Matlack > > Two new stats for exposing halt-polling cpu usage: > halt_poll_success_ns > halt_poll_fail_ns > > Thus sum of these 2 stats is the total cpu time spent polling. "success" > means the VCPU polled until a virtual interrupt was delivered. "fail" > means the VCPU had to schedule out (either because the maximum poll time > was reached or it needed to yield the CPU). > > To avoid touching every arch's kvm_vcpu_stat struct, only update and > export halt-polling cpu usage stats if we're on x86. I fixed all the other architectures and queued it, thanks. Paolo > > Exporting cpu usage as a u64 and in nanoseconds means we will overflow at > ~500 years, which seems reasonably large. > > Signed-off-by: David Matlack > Signed-off-by: Jon Cargille > Reviewed-by: Jim Mattson > > --- > arch/x86/include/asm/kvm_host.h | 2 ++ > arch/x86/kvm/x86.c | 2 ++ > virt/kvm/kvm_main.c | 20 +++++++++++++++++--- > 3 files changed, 21 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index a239a297be33..3287159ab15b 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1032,6 +1032,8 @@ struct kvm_vcpu_stat { > u64 irq_injections; > u64 nmi_injections; > u64 req_event; > + u64 halt_poll_success_ns; > + u64 halt_poll_fail_ns; > }; > > struct x86_instruction_info; > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 8c0b77ac8dc6..9736d91ce877 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -217,6 +217,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { > VCPU_STAT("nmi_injections", nmi_injections), > VCPU_STAT("req_event", req_event), > VCPU_STAT("l1d_flush", l1d_flush), > + VCPU_STAT( "halt_poll_success_ns", halt_poll_success_ns), > + VCPU_STAT( "halt_poll_fail_ns", halt_poll_fail_ns), > VM_STAT("mmu_shadow_zapped", mmu_shadow_zapped), > VM_STAT("mmu_pte_write", mmu_pte_write), > VM_STAT("mmu_pte_updated", mmu_pte_updated), > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 33e1eee96f75..348b4a6bde53 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -2664,19 +2664,30 @@ static int kvm_vcpu_check_block(struct kvm_vcpu *vcpu) > return ret; > } > > +static inline void > +update_halt_poll_stats(struct kvm_vcpu *vcpu, u64 poll_ns, bool waited) > +{ > +#ifdef CONFIG_X86 > + if (waited) > + vcpu->stat.halt_poll_fail_ns += poll_ns; > + else > + vcpu->stat.halt_poll_success_ns += poll_ns; > +#endif > +} > + > /* > * The vCPU has executed a HLT instruction with in-kernel mode enabled. > */ > void kvm_vcpu_block(struct kvm_vcpu *vcpu) > { > - ktime_t start, cur; > + ktime_t start, cur, poll_end; > DECLARE_SWAITQUEUE(wait); > bool waited = false; > u64 block_ns; > > kvm_arch_vcpu_blocking(vcpu); > > - start = cur = ktime_get(); > + start = cur = poll_end = ktime_get(); > if (vcpu->halt_poll_ns && !kvm_arch_no_poll(vcpu)) { > ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns); > > @@ -2692,7 +2703,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) > ++vcpu->stat.halt_poll_invalid; > goto out; > } > - cur = ktime_get(); > + poll_end = cur = ktime_get(); > } while (single_task_running() && ktime_before(cur, stop)); > } > > @@ -2712,6 +2723,9 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) > kvm_arch_vcpu_unblocking(vcpu); > block_ns = ktime_to_ns(cur) - ktime_to_ns(start); > > + update_halt_poll_stats( > + vcpu, ktime_to_ns(ktime_sub(poll_end, start)), waited); > + > if (!kvm_arch_no_poll(vcpu)) { > if (!vcpu_valid_wakeup(vcpu)) { > shrink_halt_poll_ns(vcpu); >