From nobody Mon Nov 25 13:42:57 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2083.outbound.protection.outlook.com [40.107.94.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 444F61D2796; Mon, 28 Oct 2024 05:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093756; cv=fail; b=EccitYo+zUtcRxt3Dgl+0lgY/VhSDzg6gn1zqKZcbVBA3NFnI6QKiOhiccLwKOVe58R40IRZFE1HxyjOlJTL42vq/aUOBESq3uflngyWUqokbQ0I1YSrJhsEQXHPJOovb32OM/UMq33ykt4sOtteVBSFX0bawjTGX0wW2CeTwMA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093756; c=relaxed/simple; bh=xRjLm55uZZf34G6ds8D/krpLHmfwoDqavN6Bg0q75aI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ge41Rs7dCo+nhb6myfVSNvUY0//pqlXcrPTTt0+waSd2T063m7jAOXaMDJKHi2Gjob2gXgGymLL+UkZ/gni0DC8ZWbQ/8FIzmOc9/PBa4/IkSkC6N54CcptgVwmcAPN1lWHN2Lb2/EPbG0gEiyCSr0v7y3FsiHRogZ14FILzIow= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=wkyhbzzb; arc=fail smtp.client-ip=40.107.94.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="wkyhbzzb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RxBWfun1C5K3QYxHSmRDLI4zoKfhQCOyCrd41LNKFO+Sn5kMmt4Vko+TuECu9uARDjA7xHvQnPWuOHH7K3T33dOpwE0kvmdnUbCXphVmcbnn9IHzc4cS2tfKKjUeJB78BINNyY2AQbP+4+ZUVB9mB/4qYUP1M8OT9Ikj+1JWm5p92nRpZFVSzsSbMsA5HrnKl6EkjutUzsDKIMKoK2Pt4kRSpJyOSEcUNYsuVclp3wOMl9PTKlTmXiOo0dckr4b/tRNh7GYJjyetjMgGu8fIWo8cLGZ1FApymHbOHGJ8T8IUKqtld3bUt6ZhnIobt/GpaemBCJHWp4xPB9Vf4ShP+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=puOvZD7dMnyP/mSy5fX3y3C0dWkvUQhiYs0GJr6meQc=; b=w7ubDvFJSJa4nRNh/SSjR4sI9NVsUkHhBHLjlz/dWQ2GTJDJK2ngd8GGeN7cuoYE2ZVDmvTQBipHQSDnqI2tsRUTkc0GdqtHBGpNDzs5/XQd8aDFvu8+5u1W4S8OKDrlWCq9TQCkaxwC/kHqLCS7JOiR3lSnIQnBDsbWkIznTwb6/QmJwYy+I8Wp6Zida30M8S4Xt2WozaZHqheg8JSE+4jfZHgD1biErQHkLP80xe1ZAsZPF8YcBsevWj0/+od8zSF8Q4HN2Q0agMXJtmRALFsS8THY8KhCpU2c9fs6xn2Xd3wA5U5aeAmhlX0YnrBtQxl9XdRkGcGltfjHH8UjAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=puOvZD7dMnyP/mSy5fX3y3C0dWkvUQhiYs0GJr6meQc=; b=wkyhbzzb2ThoXvnkmQDLcoCALAG451CbTYXfuIeNHZeB/9ipxeYGvrZauKLVg6G8Ze4imLT9rkbx64puljyf8X+9I7weMyt+5N4w1bSnQnO4IFVknM+oakI4Pq4BCk1NvWeWAMqNcZevBX4yKtrreITA7QcPJkAKEw89Blu85Ak= Received: from SJ0PR13CA0078.namprd13.prod.outlook.com (2603:10b6:a03:2c4::23) by SJ2PR12MB7992.namprd12.prod.outlook.com (2603:10b6:a03:4c3::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Mon, 28 Oct 2024 05:35:50 +0000 Received: from SJ1PEPF00001CE7.namprd03.prod.outlook.com (2603:10b6:a03:2c4:cafe::f2) by SJ0PR13CA0078.outlook.office365.com (2603:10b6:a03:2c4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.14 via Frontend Transport; Mon, 28 Oct 2024 05:35:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF00001CE7.mail.protection.outlook.com (10.167.242.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35:50 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 28 Oct 2024 00:35:45 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , , Alexey Makhalov , "Juergen Gross" , Boris Ostrovsky Subject: [PATCH v14 11/13] tsc: Switch to native sched clock Date: Mon, 28 Oct 2024 11:04:29 +0530 Message-ID: <20241028053431.3439593-12-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE7:EE_|SJ2PR12MB7992:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e117700-9a39-4799-e2c8-08dcf712621c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?BibSuHp9VLA5N+QT33c5AG8UElOKm10GTdb0ISFTqNI0kOoNEWm2oAElcgrt?= =?us-ascii?Q?uyz4BgaRfDa9yJjeEPTqF5oJ5k+w8LxddOJQUY+xjYRrhHchxibTy7GIgc8j?= =?us-ascii?Q?2h3U2UGZLejuLEeCdFJPQ2MkIPMDc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iwwE16m?= =?us-ascii?Q?+P4XQ1veu7tU1+oAYOKUezmryNOgHAm9YNtjLB/HRibIlSQT814Tz1tNyBnW?= =?us-ascii?Q?ghbTGZnOXu7p7u1vj+EpVhbqJ6ia4NbsuZOoJnFqN+lB6H0JC3h5Gy+rYZqz?= =?us-ascii?Q?B+E2X3vm7YVQeB0+rY66vPU+M0eM/IkX65YoCdIaIIGvkhO00nrtzP+bacdy?= =?us-ascii?Q?+46WojWsFmJEFga/LblIG3zZ++P8rwPIN3xJcLbaNBynCWa81ZZnRXdArgBa?= =?us-ascii?Q?l+DvvXjzxHURSBHReWgOkm2Wuysn1Jah+lA2b0KC3B6UnKqaYjgf+lXWgBp6?= =?us-ascii?Q?+mHzykxHuezNndprsCxXrd3WK1QqzDOQJ04w/cJHHYWVraIsa75ZWlIl0x4f?= =?us-ascii?Q?bpm2P/ZNbbhXZmFv3XoQdtc9Xf2Gn8iW3my0MVpXKN8qI+RGnQ=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:50.5737 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e117700-9a39-4799-e2c8-08dcf712621c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7992 Content-Type: text/plain; charset="utf-8" Although the kernel switches over to stable TSC clocksource instead of PV clocksource, the scheduler still keeps on using PV clocks as the sched clock source. This is because KVM, Xen and VMWare, switch the paravirt sched clock handler in their init routines. HyperV is the only PV clock source that checks if the platform provides an invariant TSC and does not switch to PV sched clock. When switching back to stable TSC, restore the scheduler clock to native_sched_clock(). As the clock selection happens in the stop machine context, schedule delayed work to update the static_call() Cc: Alexey Makhalov Cc: Juergen Gross Cc: Boris Ostrovsky Signed-off-by: Nikunj A Dadhania --- arch/x86/kernel/tsc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index cf29ede4ee80..d8f4844244f4 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -272,10 +272,25 @@ bool using_native_sched_clock(void) { return static_call_query(pv_sched_clock) =3D=3D native_sched_clock; } + +static void enable_native_sc_work(struct work_struct *work) +{ + pr_info("using native sched clock\n"); + paravirt_set_sched_clock(native_sched_clock); +} +static DECLARE_DELAYED_WORK(enable_native_sc, enable_native_sc_work); + +static void enable_native_sched_clock(void) +{ + if (!using_native_sched_clock()) + schedule_delayed_work(&enable_native_sc, 0); +} #else u64 sched_clock_noinstr(void) __attribute__((alias("native_sched_clock"))); =20 bool using_native_sched_clock(void) { return true; } + +static void enable_native_sched_clock(void) { } #endif =20 notrace u64 sched_clock(void) @@ -1157,6 +1172,10 @@ static void tsc_cs_tick_stable(struct clocksource *c= s) static int tsc_cs_enable(struct clocksource *cs) { vclocks_set_used(VDSO_CLOCKMODE_TSC); + + /* Restore native_sched_clock() when switching to TSC */ + enable_native_sched_clock(); + return 0; } =20 --=20 2.34.1