Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4837AC433F5 for ; Wed, 5 Jan 2022 22:53:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245345AbiAEWxa (ORCPT ); Wed, 5 Jan 2022 17:53:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245174AbiAEWv7 (ORCPT ); Wed, 5 Jan 2022 17:51:59 -0500 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15B81C034000 for ; Wed, 5 Jan 2022 14:51:57 -0800 (PST) Received: by mail-ot1-x329.google.com with SMTP id g79-20020a9d12d5000000b0058f08f31338so1098914otg.2 for ; Wed, 05 Jan 2022 14:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FRh+AxN1SKs9JlRo4qZ0RFdMICo2/fomT2kNzxO2p68=; b=AJ2Hph8NuF5lvpIdO8l9446b1i/7pjZoaXMicjA5dBbx836WEQhoZQgyo6VPfnASCE UYtl7kgsDPaPZQZSQtWBBCe+2u96rE3xl/T8BbMJqVvZk84O0N/nw8FbV5hpY/MnDZrY Wqlt4xX6KARDAwsMOZA0r/ydD2JuVaTTtb0qn8i49xfmgIQJY/J+rP6blqhFu6A+YawG 2rBFq+j0OossdgTcFcHtJaWeR99Rq9vAvukUQPSVzfPx9cgfUkOeWqxXqGwmsmXg/riT rbrPKObUcs6PlnIWoDtSHPGSoKKv2h3gXNP9IRxX823yKTSj1r5aWL+6X4oB8EJ76MzN btyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FRh+AxN1SKs9JlRo4qZ0RFdMICo2/fomT2kNzxO2p68=; b=0w/s2G1HEoZOYJ2wJ9WLIhtiETxoETUdWpPE3IjMt6azinlFNltdnDHjS+lUSfYGhL LYMp9IiM4qW3mGHgdA252m1WpFy6oHKWPgAOfVgTW6aJYylFA2AEwQbv/vUCYpmIMgwB dzZjVjMMeiGi+a3lJ6Kwq4dxqrVpQX2Y1ldYpE0niMqmGVHHrxuJprpXMYL9U4ulrc48 Z5c3psEBBMSLLkLHPEsRNmQJC/HED99i9ESbKRI8HKE7H54wpRFTN0wWu/JxPsufo8fB 3cVDvN7oqBqVtmFta0ED96sybjoV/0Id/6mg8/qq3MycA1H1qoEgYpcLS4/o0eZmBon8 n/pA== X-Gm-Message-State: AOAM531YdeNNr2TlMLipESPYVvMXCPTnT30ctaWNiXinBw7ffejinWu0 C8JxNSxUBvz3woJgsMfZAQXSq41Wzxci4ELfD4alwg== X-Google-Smtp-Source: ABdhPJxb9CzJIsfVy90wyaAPuF99n20endVT8kYcg2HVTpgbJ2dwEq9m3bKWp7pg3xrsTOD/xM78FhWyEBD1Wue8bpg= X-Received: by 2002:a9d:67c1:: with SMTP id c1mr42474949otn.299.1641423116181; Wed, 05 Jan 2022 14:51:56 -0800 (PST) MIME-Version: 1.0 References: <20211222133428.59977-1-likexu@tencent.com> <22776732-0698-c61b-78d9-70db7f1b907d@gmail.com> In-Reply-To: From: Jim Mattson Date: Wed, 5 Jan 2022 14:51:44 -0800 Message-ID: Subject: Re: [PATCH v2] KVM: X86: Emulate APERF/MPERF to report actual vCPU frequency To: Like Xu Cc: Paolo Bonzini , Vitaly Kuznetsov , Joerg Roedel , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Like Xu , Dongli Cao , Li RongQing , Wanpeng Li , "Thomas Gleixner (kernel-recipes.org)" , "Borislav Petkov (kernel-recipes.org)" , Sean Christopherson Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 30, 2021 at 11:48 PM Like Xu wrote: > > On 31/12/2021 9:29 am, Jim Mattson wrote: > > At sched-in: > > 1. Save host APERF/MPERF values from the MSRs. > > 2. Load the "current" guest APERF/MPERF values into the MSRs (if the > > vCPU configuration allows for unintercepted reads). > > > > At sched-out: > > 1. Calculate the guest APERF/MPERF deltas for use in step 3. > > 2. Save the "current" guest APERF/MPERF values. > > 3. "Restore" the host APERF/MPERF values, but add in the deltas from step 1. > > > > Without any writes to IA32_MPERF, I would expect these MSRs to be > > synchronized across all logical processors, and the proposal above > > would break that synchronization. I am learning more about IA32_APERF and IA32_MPERF this year. :-) My worry above is unfounded. These MSRs only increment in C0, so they are not likely to be synchronized. This also raises another issue with your original fast-path implementation: the host MSRs will continue to count while the guest is halted. However, the guest MSRs should not count while the guest is halted.