From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94F32407CDC for ; Fri, 29 May 2026 15:08:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780067315; cv=none; b=ILr4TasQvGJGJ9eITEwco83K9dO9oMJl5AyHIIGNfEyZSxu+EyJOYNPJo6Yp6ZrleP4C9VbWE838wFZA8ehge5nxw0m++3QBXhDGmzWnwu1MOz0/6kpjNaXI0E545BhiaQCkBztDs+3WTGYcCKsrao8HpGsWx5ndpiVsYT5nUwM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780067315; c=relaxed/simple; bh=4EM21BPya+I+Yh2sqhdfbU6L/IzTuUdE/Zaa6ZzwnUE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kdDP2NKojKpjD2jJcxMx6QqKGZhPOLLUSz8yG4oA0F3YvwtUWXMLHzshwomqhRyRthgptZhAqxv9ZiPTFqu/RRvJcCxUuHm0eVr0YMi1PrQfxpElKG5XwWiK9pSzDWoZO0ocnfMkoem16mwWBSHKi7PV1W7QPHhe8x7XzVHmfds= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UsHMfdjV; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UsHMfdjV" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2bf11699875so19374645ad.1 for ; Fri, 29 May 2026 08:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780067313; x=1780672113; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=UfrlcsEyKDSqAVUZDFPjPbjb9qd7cdvAZhMFheCkbts=; b=UsHMfdjVsyqUYN96PfvF1fVaupZDLBIc+ZGKhs3dqP/q5M3nB2jc/D/gLsRQ3YAqNN lj6wzR1nNZ9Y4vDlICXqzLoo5QJ9At1k+WpmhlGGnzSHXt+NlMPoLgS+9ar4rBE2CEuT UBNEjUUqzgdXG6VEObbiJWMqLE6Ghm2AJITcMu7Uiipf8yDANqoIJ3jlyNiSrQPbmaGW CzgqdO12oqj6eDZS/5nfetzBrhwLUBt1AFwl7HWNDgYAJ2OIa9p+HuJhxE4pgnawDNoj d9zizW60k9NzfS5KVi+T/+YE8Vg4Bg2M7pvL4rR+HI9AGhMxam4FQUrwPuy60xX7xWKW Q7aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780067313; x=1780672113; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UfrlcsEyKDSqAVUZDFPjPbjb9qd7cdvAZhMFheCkbts=; b=gXfEFt+LE8sdVBKjB4zcHdrdX7xmyvnS0uMN+dq7KC+zavj1bHEDgPcs85uzAr2WRT RqTWhsgr2GknySlxLPOuMpfCo/tp9HwvnkDqfwkv3mC/kqVeLq+GrXMqUJiLmH8m2YiC 4Sh5Tu8oxbProCYKzOqvsyWc2pTud6uMe0IQ1FgUlrrA0HXly/WFbhffhEPeHs9FOamF aWcAJPTmZO8DbfX7tWjHbpoJcw/KI0VtGnQvRSg9B5gj9TJTFGPLGByRDtu0yqa+bg7j 0+IGSytMNGgowVFBt8txEHxfZhWapOuvJDg83yqzn7wxHeDH82664b0UinQ0sRqv9woH pSgg== X-Forwarded-Encrypted: i=1; AFNElJ8kpzBT2EArSP0aOlhqBgQTqqY7ZZKhRQI2emtelzKE+nUuBU6M7FTbClvbzIj9oWgmXIy8sUW/K2LRzLQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzzC7BWWueePEqc5mjpoOk7Ey5tGRlR3biltPjD32KtDjDYjEYo DSUGjKSL3c3Ou/OqEGOnU9DT79duMssLvpMMUn3CRbAR5D2tW/PgVXlZ5KRSKjkDT82ozJGXqBl rCnqpTg== X-Received: from plpp10.prod.google.com ([2002:a17:902:c70a:b0:2bd:56ce:d8ea]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:fc85:b0:2bc:ac76:c1d0 with SMTP id d9443c01a7336-2bf20de3033mr36747075ad.17.1780067312791; Fri, 29 May 2026 08:08:32 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 29 May 2026 08:08:30 -0700 In-Reply-To: <20260529144435.704127-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-hyperv@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260529144435.704127-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260529150830.715007-1-seanjc@google.com> Subject: [PATCH v4 45/47] x86/kvmclock: Use TSC for sched_clock if it's constant and non-stop From: Sean Christopherson To: Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Sean Christopherson , "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Andy Lutomirski , Peter Zijlstra , Juergen Gross , Daniel Lezcano , John Stultz Cc: "H . Peter Anvin" , Rick Edgecombe , Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, xen-devel@lists.xenproject.org, David Woodhouse , Tom Lendacky , Nikunj A Dadhania , David Woodhouse , Michael Kelley , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Prefer the TSC over kvmclock for sched_clock if the TSC is constant, nonstop, and not marked unstable via command line. I.e. use the same criteria as tweaking the clocksource rating so that TSC is preferred over kvmclock. Per the below comment from native_sched_clock(), sched_clock is more tolerant of slop than clocksource; using TSC for clocksource but not sched_clock makes little to no sense, especially now that KVM CoCo guests with a trusted TSC use TSC, not kvmclock. /* * Fall back to jiffies if there's no TSC available: * ( But note that we still use it if the TSC is marked * unstable. We do this because unlike Time Of Day, * the scheduler clock tolerates small errors and it's * very important for it to be as fast as the platform * can achieve it. ) */ The only advantage of using kvmclock is that doing so allows for early and common detection of PVCLOCK_GUEST_STOPPED, but that code has been broken for over two years with nary a complaint, i.e. it can't be _that_ valuable. And as above, certain types of KVM guests are losing the functionality regardless, i.e. acknowledging PVCLOCK_GUEST_STOPPED needs to be decoupled from sched_clock() no matter what. Link: https://lore.kernel.org/all/Z4hDK27OV7wK572A@google.com Reviewed-by: David Woodhouse Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 1336c24f59cf..cd65ad328637 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -374,7 +374,6 @@ void __init kvmclock_init(bool prefer_tsc) PVCLOCK_TSC_STABLE_BIT; } - kvm_sched_clock_init(stable); if (!x86_init.hyper.get_tsc_khz) x86_init.hyper.get_tsc_khz = kvmclock_get_tsc_khz; @@ -394,6 +393,8 @@ void __init kvmclock_init(bool prefer_tsc) */ if (prefer_tsc) kvm_clock.rating = 299; + else + kvm_sched_clock_init(stable); clocksource_register_hz(&kvm_clock, NSEC_PER_SEC); pv_info.name = "KVM"; -- 2.54.0.823.g6e5bcc1fc9-goog