Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp74917pxy; Tue, 4 May 2021 18:56:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh6PH4NhEJ+3ER1/hJUERB4Rg/wVvdgMciXqKlCyqbZBgXyLPyHRfZwIC0eH2VxXqeB+TE X-Received: by 2002:a63:eb12:: with SMTP id t18mr26413952pgh.349.1620179818754; Tue, 04 May 2021 18:56:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620179818; cv=none; d=google.com; s=arc-20160816; b=efQLhoEfikvKOVV4/SnaMphXJW5RHMM95aRhy87ioehJP4/8ju/xF8uh7tQ8MQaDoF /Kh2g3rDe1geOepy79X+A7JassDBbWi6XBurEBxhhhEQkpMzrnG/ostf/aemF86ak4Pu i50ZkUpkzh5PJfjBCocd/kcltVBHFU3dFA29x74gk6ywE6E9Evr91JL1G/oNgCp36D6z Lt82eDHiY5Ce60tziPclkDsuNYcmnCPCjDKg9j4vF55rark5U3d1cbx77rKJB6ye1hk+ xyVRS0JYGbFdJMki6bJI7l/8yTH6uSQyq3fO0UIjYmfVAAEAIr+rsOTsJ/vOWavLkyGN QDPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=sMUAW+2oDIJX5Jnf0vr40VExAiGP3BZMmhSDsatQxbM=; b=MZmWUzg7KdRCQS8nLb89R3X57ZRD2cdwdWbXsLaOkhpM4Ruwfl51K+5PBQEsL1yms3 os2Mo44kN9mmzRIKBHnJ/X5FNYqCbYsJfYyPbPmKyfeNw4JcuBc9pXv/tX+2OQofnTLt kHMqgODlM3OEvsRhHPjkXLk0RP10AS9/0kX9Xk1LjZ4cAL8jBYYsYlclkE1eenZuAiNI 3MS8slNIE1Juqh4fGVLzSXPsTAz48GteOGuZz3OH7BLVqWwSaUtEdMiXxIfOoIRL7V2e DfQ1dXIBRv51Qi/PCTZ94l9BVV/XFyIG5P+FoJaYnmkbvH+b80UchvaDLMU8gRA5d3fm JZKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=g+axrA7s; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s25si6380259pgd.67.2021.05.04.18.56.45; Tue, 04 May 2021 18:56:58 -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=@google.com header.s=20161025 header.b=g+axrA7s; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231523AbhEEA26 (ORCPT + 99 others); Tue, 4 May 2021 20:28:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231466AbhEEA2z (ORCPT ); Tue, 4 May 2021 20:28:55 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3496C061342 for ; Tue, 4 May 2021 17:27:56 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id s8-20020a5b04480000b029049fb35700b9so479617ybp.5 for ; Tue, 04 May 2021 17:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=sMUAW+2oDIJX5Jnf0vr40VExAiGP3BZMmhSDsatQxbM=; b=g+axrA7sDvFIFjAwZ8Cb9FUfBNhQc+xgHh4KbfZ1huGgQJ/Jbv0dZhBLpQA1jVsleN yndgvoaez8lOUUhZxamtRPHWUkYMY3qzdEjALIGDXD6JM4RMaV3Z/UaqvwQ0BqOBeGPo X6ttGtLybbnHV++w0JITVQwMSjxiDPPdZsGH4L8Dg7xAPODA/wgwy7F42FO25oF3gKho Ne10Ipe0+qSIMtcFdUOpdZbNz+VJElOcGkRoywT3k7nIjTn6lWv5hd7hDGnErhJ8yoA3 KF4KRl1rOio9p3beR+n/HIoKMLV+mxMyvqY8qmOJ11qOHs7G5rXdOASXea1/OxirKp+s sftA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=sMUAW+2oDIJX5Jnf0vr40VExAiGP3BZMmhSDsatQxbM=; b=r3OzOeS/Ojn4dWMVU5Jd+kjSGGHz0/w+Q/9D6BLNw4ZAqjYQ09oP+PCcxVJ+gYmqph EbFgJSnyCOtJNZhg1GSpYjVaFKb3592TSTZ82NwYd5cc9ixaTGqwGRjhi9ZlxDgSGmLC xu0eNQlzG2Gpqkfo0tYP+TY96NAvphhJHArILH+2qULtRlvgxVyJ9B+3TQ4mDqxK/Qrl SlEtBB6Yni41UVxaXjrdK1+bn+O+K0nLWEZyRflUzdiV9O0NcHJ6yC72mPe0S9azvgAu Ay8nNc7lCoOzt1+Rk6BAGA8vYfQsD9UVrk614eyyz5dWmL7E3zt6Q0/XFJZdfSs13wmR uPXQ== X-Gm-Message-State: AOAM531GhaSHgKZVL8z1HM1yJihok+rF8O1c9pO4ciL5ywhYXe8LeHi9 Mm36edRnV8aU6S5CFWv3MXaHinRjijI= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:df57:48cb:ea33:a156]) (user=seanjc job=sendgmr) by 2002:a25:2693:: with SMTP id m141mr38110043ybm.212.1620174476249; Tue, 04 May 2021 17:27:56 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 4 May 2021 17:27:32 -0700 In-Reply-To: <20210505002735.1684165-1-seanjc@google.com> Message-Id: <20210505002735.1684165-6-seanjc@google.com> Mime-Version: 1.0 References: <20210505002735.1684165-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog Subject: [PATCH v4 5/8] sched/vtime: Move guest enter/exit vtime accounting to vtime.h From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Michael Tokarev , Christian Borntraeger , Frederic Weisbecker Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide separate helpers for guest enter vtime accounting (in addition to the existing guest exit helpers), and move all vtime accounting helpers to vtime.h where the existing #ifdef infrastructure can be leveraged to better delineate the different types of accounting. This will also allow future cleanups via deduplication of context tracking code. Opportunstically delete the vtime_account_kernel() stub now that all callers are wrapped with CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y. No functional change intended. Signed-off-by: Sean Christopherson --- include/linux/context_tracking.h | 17 +----------- include/linux/vtime.h | 46 +++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h index 4f4556232dcf..56c648bdbde8 100644 --- a/include/linux/context_tracking.h +++ b/include/linux/context_tracking.h @@ -137,14 +137,6 @@ static __always_inline void context_tracking_guest_exit(void) __context_tracking_exit(CONTEXT_GUEST); } -static __always_inline void vtime_account_guest_exit(void) -{ - if (vtime_accounting_enabled_this_cpu()) - vtime_guest_exit(current); - else - current->flags &= ~PF_VCPU; -} - static __always_inline void guest_exit_irqoff(void) { context_tracking_guest_exit(); @@ -163,20 +155,13 @@ static __always_inline void guest_enter_irqoff(void) * to flush. */ instrumentation_begin(); - vtime_account_kernel(current); - current->flags |= PF_VCPU; + vtime_account_guest_enter(); rcu_virt_note_context_switch(smp_processor_id()); instrumentation_end(); } static __always_inline void context_tracking_guest_exit(void) { } -static __always_inline void vtime_account_guest_exit(void) -{ - vtime_account_kernel(current); - current->flags &= ~PF_VCPU; -} - static __always_inline void guest_exit_irqoff(void) { instrumentation_begin(); diff --git a/include/linux/vtime.h b/include/linux/vtime.h index 6a4317560539..3684487d01e1 100644 --- a/include/linux/vtime.h +++ b/include/linux/vtime.h @@ -3,21 +3,18 @@ #define _LINUX_KERNEL_VTIME_H #include +#include + #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE #include #endif - -struct task_struct; - /* * Common vtime APIs */ #ifdef CONFIG_VIRT_CPU_ACCOUNTING extern void vtime_account_kernel(struct task_struct *tsk); extern void vtime_account_idle(struct task_struct *tsk); -#else /* !CONFIG_VIRT_CPU_ACCOUNTING */ -static inline void vtime_account_kernel(struct task_struct *tsk) { } #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */ #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN @@ -55,6 +52,18 @@ static inline void vtime_flush(struct task_struct *tsk) { } static inline bool vtime_accounting_enabled_this_cpu(void) { return true; } extern void vtime_task_switch(struct task_struct *prev); +static __always_inline void vtime_account_guest_enter(void) +{ + vtime_account_kernel(current); + current->flags |= PF_VCPU; +} + +static __always_inline void vtime_account_guest_exit(void) +{ + vtime_account_kernel(current); + current->flags &= ~PF_VCPU; +} + #elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN) /* @@ -86,12 +95,37 @@ static inline void vtime_task_switch(struct task_struct *prev) vtime_task_switch_generic(prev); } +static __always_inline void vtime_account_guest_enter(void) +{ + if (vtime_accounting_enabled_this_cpu()) + vtime_guest_enter(current); + else + current->flags |= PF_VCPU; +} + +static __always_inline void vtime_account_guest_exit(void) +{ + if (vtime_accounting_enabled_this_cpu()) + vtime_guest_exit(current); + else + current->flags &= ~PF_VCPU; +} + #else /* !CONFIG_VIRT_CPU_ACCOUNTING */ -static inline bool vtime_accounting_enabled_cpu(int cpu) {return false; } static inline bool vtime_accounting_enabled_this_cpu(void) { return false; } static inline void vtime_task_switch(struct task_struct *prev) { } +static __always_inline void vtime_account_guest_enter(void) +{ + current->flags |= PF_VCPU; +} + +static __always_inline void vtime_account_guest_exit(void) +{ + current->flags &= ~PF_VCPU; +} + #endif -- 2.31.1.527.g47e6f16901-goog