From: Wanpeng Li <kernellwp@gmail.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
Thomas Gleixner <tglx@linutronix.de>,
Michael Tokarev <mjt@tls.msk.ru>
Subject: [PATCH v2 2/3] context_tracking: Provide separate vtime accounting functions
Date: Tue, 13 Apr 2021 15:16:08 +0800 [thread overview]
Message-ID: <1618298169-3831-3-git-send-email-wanpengli@tencent.com> (raw)
In-Reply-To: <1618298169-3831-1-git-send-email-wanpengli@tencent.com>
From: Wanpeng Li <wanpengli@tencent.com>
Provide separate vtime accounting functions, because having proper
wrappers for that case would be too consistent and less confusing.
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
include/linux/context_tracking.h | 50 ++++++++++++++++++++++++++++++----------
1 file changed, 38 insertions(+), 12 deletions(-)
diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h
index d8ad844..491f889 100644
--- a/include/linux/context_tracking.h
+++ b/include/linux/context_tracking.h
@@ -102,6 +102,40 @@ extern void context_tracking_init(void);
static inline void context_tracking_init(void) { }
#endif /* CONFIG_CONTEXT_TRACKING_FORCE */
+static __always_inline void vtime_account_guest_enter(void)
+{
+ if (IS_ENABLED(CONFIG_VIRT_CPU_ACCOUNTING_GEN)) {
+ if (vtime_accounting_enabled_this_cpu())
+ vtime_guest_enter(current);
+ else
+ current->flags |= PF_VCPU;
+ } else {
+ vtime_account_kernel(current);
+ current->flags |= PF_VCPU;
+ }
+}
+
+static __always_inline void __vtime_account_guest_exit(void)
+{
+ if (IS_ENABLED(CONFIG_VIRT_CPU_ACCOUNTING_GEN)) {
+ if (vtime_accounting_enabled_this_cpu())
+ vtime_guest_exit(current);
+ } else {
+ vtime_account_kernel(current);
+ }
+}
+
+static __always_inline void vtime_account_guest_exit(void)
+{
+ __vtime_account_guest_exit();
+ current->flags &= ~PF_VCPU;
+}
+
+static __always_inline void vcpu_account_guest_exit(void)
+{
+ if (!vtime_accounting_enabled_this_cpu())
+ current->flags &= ~PF_VCPU;
+}
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
static __always_inline void context_guest_enter_irqoff(void)
@@ -127,10 +161,7 @@ static __always_inline void context_guest_enter_irqoff(void)
static __always_inline void guest_enter_irqoff(void)
{
instrumentation_begin();
- if (vtime_accounting_enabled_this_cpu())
- vtime_guest_enter(current);
- else
- current->flags |= PF_VCPU;
+ vtime_account_guest_enter();
instrumentation_end();
context_guest_enter_irqoff();
@@ -147,10 +178,7 @@ static __always_inline void guest_exit_irqoff(void)
context_guest_exit_irqoff();
instrumentation_begin();
- if (vtime_accounting_enabled_this_cpu())
- vtime_guest_exit(current);
- else
- current->flags &= ~PF_VCPU;
+ vtime_account_guest_exit();
instrumentation_end();
}
@@ -170,8 +198,7 @@ static __always_inline void guest_enter_irqoff(void)
* to flush.
*/
instrumentation_begin();
- vtime_account_kernel(current);
- current->flags |= PF_VCPU;
+ vtime_account_guest_enter();
instrumentation_end();
context_guest_enter_irqoff();
@@ -183,8 +210,7 @@ static __always_inline void guest_exit_irqoff(void)
{
instrumentation_begin();
/* Flush the guest cputime we spent on the guest */
- vtime_account_kernel(current);
- current->flags &= ~PF_VCPU;
+ vtime_account_guest_exit();
instrumentation_end();
}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
--
2.7.4
next prev parent reply other threads:[~2021-04-13 7:16 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-13 7:16 [PATCH v2 0/3] KVM: Properly account for guest CPU time Wanpeng Li
2021-04-13 7:16 ` [PATCH v2 1/3] context_tracking: Split guest_enter/exit_irqoff Wanpeng Li
2021-04-13 7:35 ` Christian Borntraeger
2021-04-13 7:38 ` Wanpeng Li
2021-04-13 7:48 ` Christian Borntraeger
2021-04-13 7:52 ` Wanpeng Li
2021-04-13 8:07 ` Christian Borntraeger
2021-04-13 7:16 ` Wanpeng Li [this message]
2021-04-13 7:16 ` [PATCH v2 3/3] x86/kvm: Fix vtime accounting Wanpeng Li
2021-04-13 8:32 ` [PATCH v2 0/3] KVM: Properly account for guest CPU time Christian Borntraeger
2021-04-13 17:25 ` Sean Christopherson
2021-04-14 9:36 ` Wanpeng Li
2021-04-15 0:49 ` Sean Christopherson
2021-04-15 1:23 ` Wanpeng Li
2021-04-15 19:02 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1618298169-3831-3-git-send-email-wanpengli@tencent.com \
--to=kernellwp@gmail.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjt@tls.msk.ru \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).