From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 B024586350 for ; Wed, 15 Jan 2025 21:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736977779; cv=none; b=AduPDyeekb3MkHmvn/T0JcuQi3cA5iyWduzVr0DPlv8duHGW2Da7Cx0pZRNLfTVSQdZbV0miAIoZHvpF4wUNQBgmMLxFWUrnlC658GMKxE6/zcEUGmtHCAxAVIBE24sOwLVaFWktMpzvgMC08ZI3MN8qKfPEeamwdO2WyrcOcjc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736977779; c=relaxed/simple; bh=I3Ad9XLY4fO9RVP3cYcOe+iuyKue3qbt4UU6mSO+EbA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UQOs3AUGKaGm0Yk3izsf9xcIa7AtwTTeurAdniQTOqeyjRC64GWh6D9Ibej1F7STbE1YonqTHeQw4CDw9cO/EGSrRIDAsBszIAbRmvXlwtYdOXxiM6oGWjE7LvOz5UYUJAgH3ZnHRQxGvfrjR/9PSTiesrXJYm1/76Atc8ecEI8= 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=wDYC0Z6C; arc=none smtp.client-ip=209.85.216.73 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="wDYC0Z6C" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2efa0eb9cfeso576157a91.0 for ; Wed, 15 Jan 2025 13:49:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736977777; x=1737582577; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ri0Hck0RLmnsmN464wmH1M0AsER8Cny8ZtD4ktzxzBQ=; b=wDYC0Z6C+GS9e9/Hjnr9NH8+8IDDt0crAjcneBWglFTeM8Re+48WaxgDqv3hlgMqtx KUFJn5HrbnRjKfpL2b1gS99hvrjZLg2IpM6FfxVfjifViBrNSOPyQXQBuah7/3GwbTtM oq0CzrF3EC2L7qI+x5VmBdm3gwA1H8rB31sArnq4vzJrefChhqsD+94AvhSq+8sotuZT 8eQI+crAzFtHgomv9JI8uN1zQVEfWfzSMckF40nDYlgLX13LdnLFAkdT2UsluqVTNMmh nsTyqAumg8wY039TUo45iYwnTwFbxVisyzD6hLMhXGxD4USCsG6eFvHOQb3TUzb6Au9S +sGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736977777; x=1737582577; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ri0Hck0RLmnsmN464wmH1M0AsER8Cny8ZtD4ktzxzBQ=; b=X1yNEiojV2EiLM7BZfgQI8+TadjZA8HI9dEac1un2Ujhxp324EJTSY47q+4jr/O7wy XwUnp+YYjHDWMe+3B3OWpeXjiimAgDJdS+mEguLIl6oboZ0a3RgVZdKRc4RZLchEkaoS gKH8cjvLgGOtJ1aUeqnDMe6ggHBxm0Y9KhKU+S213yhXfL1JV0IDGV5kl8wS/cc8ndig yAWMOhSqeDEWeFjUv99ugRS3xton6umCaaamIh4D5jYvZmGjPNHSi/tcFz0fw90bwcW6 EttaznD0uKBY9i6g7YwkLpfIPIFico+B91gzprOKx8/1eKpGdglWGwjUSiap8Wjhnv3h CC6Q== X-Forwarded-Encrypted: i=1; AJvYcCX1+uScx/L2zgriEIlg1V1TukZiGXQRfRrCV33xFu6xmNs9agPb869c7mo6oOsFqm9XjWAj8qZRN1CcX2U=@vger.kernel.org X-Gm-Message-State: AOJu0YyPJrBRufF6I+DuC+Bz7xeE16FmFHQKADUu9IZ8cnPaYBCw/5ow G9liaJF1LglYP83I4TsmlxvIKs6ClDWg8IFINLnniKgCF3yCpDTv2gbtSNKLmQeyJHtSz7TavPg gQg== X-Google-Smtp-Source: AGHT+IEEAOEXoLeKdCs3ol8mlXgGgS9EhtuXpM7azVEB0zR853XtvuP2Vhr+cXRn+bjq4NayHaaVQnN0nUY= X-Received: from pjbqo11.prod.google.com ([2002:a17:90b:3dcb:b0:2f5:5e05:ca37]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4b44:b0:2ef:ad48:7175 with SMTP id 98e67ed59e1d1-2f728e687f4mr7025228a91.15.1736977777017; Wed, 15 Jan 2025 13:49:37 -0800 (PST) Date: Wed, 15 Jan 2025 13:49:35 -0800 In-Reply-To: <20250107042202.2554063-2-suleiman@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250107042202.2554063-1-suleiman@google.com> <20250107042202.2554063-2-suleiman@google.com> Message-ID: Subject: Re: [PATCH v3 1/3] kvm: Introduce kvm_total_suspend_ns(). From: Sean Christopherson To: Suleiman Souhlal Cc: Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Chao Gao , David Woodhouse , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, ssouhlal@freebsd.org Content-Type: text/plain; charset="us-ascii" On Tue, Jan 07, 2025, Suleiman Souhlal wrote: > It returns the cumulative nanoseconds that the host has been suspended. > It is intended to be used for reporting host suspend time to the guest. ... > #ifdef CONFIG_HAVE_KVM_PM_NOTIFIER > +static int kvm_pm_notifier(struct kvm *kvm, unsigned long state) > +{ > + switch (state) { > + case PM_HIBERNATION_PREPARE: > + case PM_SUSPEND_PREPARE: > + last_suspend = ktime_get_boottime_ns(); > + case PM_POST_HIBERNATION: > + case PM_POST_SUSPEND: > + total_suspend_ns += ktime_get_boottime_ns() - last_suspend; After spending too much time poking around kvmlock and sched_clock code, I'm pretty sure that accounting *all* suspend time to steal_time is wildly inaccurate for most clocksources that will be used by KVM x86 guests. KVM already adjusts TSC, and by extension kvmclock, to account for the TSC going backwards due to suspend+resume. I haven't dug super deep, buy I assume/hope the majority of suspend time is handled by massaging guest TSC. There's still a notable gap, as KVM's TSC adjustments likely won't account for the lag between CPUs coming online and vCPU's being restarted, but I don't know that having KVM account the suspend duration is the right way to solve that issue.