From patchwork Sat May 11 16:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13662419 Received: from wfhigh4-smtp.messagingengine.com (wfhigh4-smtp.messagingengine.com [64.147.123.155]) (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 88B2A56772; Sat, 11 May 2024 16:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443216; cv=none; b=kUCU7D+mCPojx6m4LmjTOaWaHJ/EfqwAYq5Fwn39GjKknrJN5mGoHxQIaEltZUV79vHBB1tJ0sgcGNu3TVdJ36mEAf+PJmcyw1iXoH4hihacEKmdTjapqSgznLlIcaahkej70X0ELZ1gSVRPA3wxpSkOekkadiWA3u5wuX4Aim8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443216; c=relaxed/simple; bh=TqxmhY10q+PpRT341sEWQQASzTDPa2i1/hqY6sm00Zc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TCfzIM55YFIdRO6zpmqfLLA0ThTNvSUtZ3j5sHV+YsSDTd9ytOYWBsfi1/QFVNDP3JnzrepiCK0hnDplGMwuBDP55UzCDrHOHL3QP+mHxUado1NohJWCT3MNDOmYD/Iqb+7CoU4r7hML2FQedU3B+FU9Rmo0xgBNtTWvNsNadGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=L/DS++my; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ar/3AnV+; arc=none smtp.client-ip=64.147.123.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="L/DS++my"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ar/3AnV+" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id 55E4F1800121; Sat, 11 May 2024 12:00:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 11 May 2024 12:00:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1715443212; x=1715529612; bh=7wgx+OXZ4hvwZVtI7mufV+v5kKWZRYdPaHf/bNfSZ7o=; b= L/DS++mydLkxMus+vn8bennJSWUv4IJg+U4S83viEWD3Adavv7GM7VZnaSyIuLm/ 19h4wdG5/kt4Hs+76+nI/CgC+tXvN5CfwlJn4k6A/xN72nss9O3Ae4S/tpfW6C0F YioHvA/rg1prTx4fifKzqYbEj0XHXcfYfOD45bmDFilf/DSsSRqOWeue4VLuJ2bh exjo1L+bHDKrqu9GC+Wwsbr3SHLqIw5DCgEaQvlhypmLjE2mCL+9MAiPla3xeiCN IxwC2rQXez9J2eM2aOqqlIBv3Xillitr2gN+Ly4Vuq2Un1LokzAoFqxEpXwwFhT9 xpWKjtz057rVgQvS23mCeg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1715443212; x= 1715529612; bh=7wgx+OXZ4hvwZVtI7mufV+v5kKWZRYdPaHf/bNfSZ7o=; b=A r/3AnV+9B0io20k52QE5mSyjby4SCWi4zDqrsflODKmC+3gSIvkfkRocN7/ym5Qc xnkOdr2HZsHtQq9q0SL1qOvJSDjvRgKD2HJKsCkXsDL/PPAWVg9qfCVlPc66RzYQ 07qH/cLjJk1TDa6Sz3YEcwGsoxrn+xWs0vORZ/PfBp4PsjACctaFpFGZBvSCjN96 lnU5N7nzDm/lIbzrclTfi2D9g0Iv3O58kiA1Mtlwy2wFyOpwYMZyvV8kA4Eysdx8 3BJDA+IPsEOwjy6lPSSsh3YrpM4oKaDlf/NDZdZfWKOyXlQQSh1c3m5Fb2s75YPz damNhJDrePQUmjasK6GKw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegtddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffekgedugefhtdduudeghfeu veegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 11 May 2024 12:00:11 -0400 (EDT) From: Jiaxun Yang Date: Sat, 11 May 2024 17:00:08 +0100 Subject: [PATCH 1/7] MIPS: csrc-r4k: Refine rating computation Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240511-mips-clks-v1-1-ddb4a10ee9f9@flygoat.com> References: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> In-Reply-To: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> To: Thomas Bogendoerfer , Serge Semin , Daniel Lezcano , Thomas Gleixner Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1034; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=TqxmhY10q+PpRT341sEWQQASzTDPa2i1/hqY6sm00Zc=; b=owGbwMvMwCHmXMhTe71c8zDjabUkhjT7aZwfpm1/2uLVem7fOyZzm3az/TtPivHURR6taLlcf /ySpdXSjlIWBjEOBlkxRZYQAaW+DY0XF1x/kPUHZg4rE8gQBi5OAZiIgzLDP9OtLYcVSvL/BHPv Eq6ocirxEBE6zPZhf+i614vb3cwXvmBkmPvLJ+7VU6V8u/WhreknO7h7VnZ9/3Hn22amfJVVl+s /sgIA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Increase frequency addend dividend to 100000000 (10MHz) to reasonably accommodate multi GHz level mips_hpt_frequency. Cap rating of csrc-r4k into 299 to ensure it doesn't go into "Desired" range, given all the drama we have with CP0 count registers (SMP sync, behaviour on wait etc). Signed-off-by: Jiaxun Yang --- arch/mips/kernel/csrc-r4k.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c index edc4afc080fa..262896871351 100644 --- a/arch/mips/kernel/csrc-r4k.c +++ b/arch/mips/kernel/csrc-r4k.c @@ -111,7 +111,8 @@ int __init init_r4k_clocksource(void) return -ENXIO; /* Calculate a somewhat reasonable rating value */ - clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000; + clocksource_mips.rating = 200; + clocksource_mips.rating += clamp(mips_hpt_frequency / 100000000, 0, 99); /* * R2 onwards makes the count accessible to user mode so it can be used From patchwork Sat May 11 16:00:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13662420 Received: from wfout1-smtp.messagingengine.com (wfout1-smtp.messagingengine.com [64.147.123.144]) (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 E8D9F5730D; Sat, 11 May 2024 16:00:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443218; cv=none; b=lvJk8Hbvd2f820KkiKCM07ojL7aDuSz/zJ4zRErV6jxMqJ4uvxgwRtg6/5wPAg6RsXVq9hCB5V8I1NB7bsnVptdQXx2a1DFYoMnZS0LzbrzWm5KcjSpFXaWV9Isz+9/Dd32/bLiNQU1DzIuL+svC0udZJZokKMqrJlWdRZsWvTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443218; c=relaxed/simple; bh=xN9LUMC2GUm6xv+BmxTm2mY70hbj5Q6VUPEtmaKqL1o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DKX1JzufvJPsgh8gkk7FwtSYTmDxTaxNyueoRjZ2foaClXLIVyQhEeChLIw8VNTWqW79awRdIS0jI2iO29dGUavYSZ6G3QZH4oXYgGFgDdcI0uvSHfgRqQjWhsRzBy7tQEh2E2rlbh3z3CTlKrG4YKadE3p9zw+G7asoxVkUzTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=xggs+Nvu; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ee3VcNkk; arc=none smtp.client-ip=64.147.123.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="xggs+Nvu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ee3VcNkk" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id D03AF1C000C4; Sat, 11 May 2024 12:00:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 11 May 2024 12:00:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1715443215; x=1715529615; bh=5LhiRvWSlGj8b9Vyp8q5tRJ77PHNOG0JGLU5aD0r8xQ=; b= xggs+NvusRV2aORI4dl4UFKfIci2vSAe/wvctrHrN8ytLUVKbrhTH0/CVYcukZDX qaqkei7akJ26kYJrst6KLHgAOCo2Scb0h/B7NbwRYOVurySAaC6i9r2LaQrE089M P0vQEFYQdp7/9geKyWLeG10p02O2EBZeQE8V72LOmpMqineKdpfd+W0v1Rji034F ALVesL4T4MxHqlWTCvLVhqPs5LIvzc61UF1+kgROmNYKFY18k7qDS1f0gzJvxrYQ IJsWCvF+WyPSWZ2MjIdO+JMD5s0JmdsFlWqAeYRtu07fTSsHfMMcIQ3ZMsvkNZfx +FJpaDQELG5pDyFpz0eang== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1715443215; x= 1715529615; bh=5LhiRvWSlGj8b9Vyp8q5tRJ77PHNOG0JGLU5aD0r8xQ=; b=E e3VcNkk5QjWHSJ8WAlthyHykTsr2zn84DSMgRO5APqaMPKHU2gyytt3+69NCWHph orGtRA8WOTT9vXo1Dz7Uh2GxPypt8vA1+iLVP7cH7edlF13W0p1X9RSrAzeMEj+o i3GwxiHT9Z4dLLDc9XP72xHu3QBVM6s/xZEBCq+6eLRpF+GYgEM7KkNvzJNESURr qImnp8PZViRhlaXeTezsBEnYE+Xlke7gdxIAgp0q3FAVkHSqWiKkzUp+Fqc1KI+m +h3KEOwTIrRArFhFPRnOAOom/fiq0GV6TgrzFJxsUwZiNWjCgsxIM4iiQXTxqUaH Zj7YldazGabnvUFJbaJTQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegtddgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffekgedugefhtdduudeghfeu veegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 11 May 2024 12:00:14 -0400 (EDT) From: Jiaxun Yang Date: Sat, 11 May 2024 17:00:09 +0100 Subject: [PATCH 2/7] MIPS: csrc-r4k: Apply verification clocksource flags Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240511-mips-clks-v1-2-ddb4a10ee9f9@flygoat.com> References: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> In-Reply-To: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> To: Thomas Bogendoerfer , Serge Semin , Daniel Lezcano , Thomas Gleixner Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=920; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=xN9LUMC2GUm6xv+BmxTm2mY70hbj5Q6VUPEtmaKqL1o=; b=owGbwMvMwCHmXMhTe71c8zDjabUkhjT7aZzhPcfmnG9fxsyonGl7om/lnerMsEnppu57i7YsK PqUsvB8RykLgxgHg6yYIkuIgFLfhsaLC64/yPoDM4eVCWQIAxenAEyE6QHD/7xl7HwdLY4u3YW7 xH84PSrUfxo8x+Nk6lw/vfd+O5lDehn+Sutv1J5xNqaE5+Q6SQfNcr5ZPxk72bdmPL557ceXI9Z tDAA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 CP0 counter suffers from various problems like SMP sync, behaviour on wait. Set CLOCK_SOURCE_MUST_VERIFY and CLOCK_SOURCE_VERIFY_PERCPU, as what x86 did to TSC, to let kernel test it before use. Signed-off-by: Jiaxun Yang --- arch/mips/kernel/csrc-r4k.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c index 262896871351..5c37e41e8970 100644 --- a/arch/mips/kernel/csrc-r4k.c +++ b/arch/mips/kernel/csrc-r4k.c @@ -21,7 +21,9 @@ static struct clocksource clocksource_mips = { .name = "MIPS", .read = c0_hpt_read, .mask = CLOCKSOURCE_MASK(32), - .flags = CLOCK_SOURCE_IS_CONTINUOUS, + .flags = CLOCK_SOURCE_IS_CONTINUOUS | + CLOCK_SOURCE_MUST_VERIFY | + CLOCK_SOURCE_VERIFY_PERCPU, }; static u64 __maybe_unused notrace r4k_read_sched_clock(void) From patchwork Sat May 11 16:00:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13662421 Received: from wfhigh4-smtp.messagingengine.com (wfhigh4-smtp.messagingengine.com [64.147.123.155]) (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 7573856760; Sat, 11 May 2024 16:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443220; cv=none; b=kXpOjr05fNmDdKRvbp/e0TKPPraif0j85/C1TfFzZtuWGnojqRmnLfGvf/NWcU5S/V5mcVD/F6Rzvsi5RhQbWWBBiwUUe1N6EY42M22cSTfXGoXdU70NdVbSojZr9LNbX2H5bpgPzMJ1Lg27mGNxNDHsVl4uH9oOGKYy4uxUECQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443220; c=relaxed/simple; bh=XX4ugxlQhFsZAkH9R4LtJMvFZc0CkYDJTh5AfKON094=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kGNe8PHkkL0HJfJvowfH1U0xxwBgsCT3RxlYXkDzHF2t28kfb77zEW4X3RRJLygdF5RZMJIY/Arl1Oh18LtJvFFl8gXiQm6B88YD5ELQKmBPCRxSHTXOlVj3qH5TttPg602VfMKyWCr2UL5vkWcB67lSlEMhShaVWZOstwxQgKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=Y+uKLSTW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZMgtTnEn; arc=none smtp.client-ip=64.147.123.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="Y+uKLSTW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZMgtTnEn" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 364891800106; Sat, 11 May 2024 12:00:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sat, 11 May 2024 12:00:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1715443217; x=1715529617; bh=Lq/pDh+sYDYCgGn5pgPk17tnsYLQeRwbX8kP/SMbYjg=; b= Y+uKLSTWdw3yRR1EpOSTeU27zuDVTBZKGZMdT7nUzeKs4eBbEGfDBY7f5eBilF2+ djB3AFyKPF9N6L4eyBS42VLDm0GzQ1MuBLbc1u7FLdX3zSo8mTmKFcZK6IrVaBcX qDxYt5p4bzFuRzxuqWVD0gLgiZ+A7Ttzy/WCw3mBtTrqgXY2hfJaQ5JDw3fzg0PS cbGGj1s3UPZ+prt+6GGO+U8MI5Iik3VzxpstOFDwNq4Ohmy79n27Qzc4oHMIzjL/ zAcEkpuIKRZYvFPwz9qMtFT7dNN98FEecM3/4A+s8Jo+g2miCXT3vKOam4mk+1RL 80rnJMGyDmg6BfQH4QTuXg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1715443217; x= 1715529617; bh=Lq/pDh+sYDYCgGn5pgPk17tnsYLQeRwbX8kP/SMbYjg=; b=Z MgtTnEnDkTcPuoVEH/7vCMp1CHIqDeQC6BoLQ49qxjLF1+44U7X+AjWbNFXj1DNe KYHJ3ncOgkA1rksD7J283DlN/dWIDLPa6UqcrKek6+yN2wou2z0c19CtI8nznPnV lrkfJGIGsHXev5fH5oY/Sua2XhADmjheOghGgYodu39Ia2YdtxLJy6o2fPnCnwHy JnxNBb4gYIKlyQUylzThmqkR34UEE/P8OIx42Muu/CFV9h4Y9gVWi5ckgbydM/4W McbEp+G5QMX+w0dL3U2G+SQ2M9wWGDYykUoWaVq/TakyiVMkEj16cFeDRl9DKwnl Q44/dCi9snd7XOY/FS8Tw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegtddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffekgedugefhtdduudeghfeu veegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 11 May 2024 12:00:16 -0400 (EDT) From: Jiaxun Yang Date: Sat, 11 May 2024 17:00:10 +0100 Subject: [PATCH 3/7] MIPS: csrc-r4k: Select HAVE_UNSTABLE_SCHED_CLOCK if 64BIT Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240511-mips-clks-v1-3-ddb4a10ee9f9@flygoat.com> References: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> In-Reply-To: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> To: Thomas Bogendoerfer , Serge Semin , Daniel Lezcano , Thomas Gleixner Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=683; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=XX4ugxlQhFsZAkH9R4LtJMvFZc0CkYDJTh5AfKON094=; b=owGbwMvMwCHmXMhTe71c8zDjabUkhjT7aZxc8ez3fnL/P5OzYcGyDM5C/4CLzBPOHjmSWJf2Z tu2678WdZSyMIhxMMiKKbKECCj1bWi8uOD6g6w/MHNYmUCGMHBxCsBE4rQYGbZ6OjIr/D3X+Hnn StO015r3n5nZziroanHUF19ueGO2nQ/DP41jEefexBZyiC86/UOvtuiUT+yfB5/4qyPU94ts0GW bwQUA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 csrc-r4k suffers from SMP synchronization overhead. Select HAVE_UNSTABLE_SCHED_CLOCK to workaround drift between the CPUs on the system. HAVE_UNSTABLE_SCHED_CLOCK requires cmpxchg64, so enable it for 64 bits only. Signed-off-by: Jiaxun Yang --- arch/mips/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index f1aa1bf11166..fa8ca0287568 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -1083,6 +1083,7 @@ config CSRC_IOASIC config CSRC_R4K select CLOCKSOURCE_WATCHDOG if CPU_FREQ + select HAVE_UNSTABLE_SCHED_CLOCK if 64BIT bool config CSRC_SB1250 From patchwork Sat May 11 16:00:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13662422 Received: from wfhigh4-smtp.messagingengine.com (wfhigh4-smtp.messagingengine.com [64.147.123.155]) (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 ACEFD58229; Sat, 11 May 2024 16:00:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443223; cv=none; b=T2Fwqhl63tPNk1c6Xffe2Jox+myD9I4wCkbbEqqiCVgpJjb8yw1IMiUed7zcAhaEQI8PO73eYQ1Q6Ru2pmb4M8YMh/psMp5XkGss8/5xKBm8i5BJxdV0dE6F6+uhU1/u7QX3ZS6pg4qM6CuUpnvXOgtzAY2rBZSJGY2LH1s+BoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443223; c=relaxed/simple; bh=U+UVB4xsBeR9swGFKSPQmDKTBSfdxpeJjE23y7dy0tM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QFXGJHSk0YvwtF4SrhoCFHRjieB9SMyOfALR5xRUtzAjbWDdUoA8JupjfRj5JppLCBAfVSBY3HSPPZBldvc8cOn1RnZiQsdLpPXoiNH65gLmDbH1INtbMYSnxnjzEKX3xphR4UxVcThTd62qqrGVmC8wFz+8GkB2AcIby40uBUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=fsjFzELc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ESe+v6Hr; arc=none smtp.client-ip=64.147.123.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="fsjFzELc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ESe+v6Hr" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 8DBF418000A6; Sat, 11 May 2024 12:00:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sat, 11 May 2024 12:00:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1715443220; x=1715529620; bh=taaP0de1JMrUsTaQ5p3XewSALo/OUNM7p36PinVNGQI=; b= fsjFzELc3eyNlFo4JGEEnuUPt6BiMox1ALJstmWL1fB2+D82TdyRJpRoY2uMg/gu uh8TlQZ3kEmMKI4Kl6YkVJvt19+a4eJZotW/vwj6dqLp3dLoUKsZJN19T9qvMudz S8srSjrmryTfApxr+fDD1UWwlvJ760d2b+1QErxBZ7Ggz8QRRaIW2r5E6hHZol9w /qWd0jLWLVD2k/lrepaK6JtqgRMztRkZmlz/Z8EbAhDQ7ALylbnfmm7DblfbNFG0 1WYtkj/icJ9/uBBTj8npAaeih9pQI1ryZIgWJBk7nKC/oBc8b7sxRWe404P/pMrT hGHSdPfEAx9GLdUBGhv3Tg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1715443220; x= 1715529620; bh=taaP0de1JMrUsTaQ5p3XewSALo/OUNM7p36PinVNGQI=; b=E Se+v6Hrt+xzY4N5CHGJ+KVececDLv2CoixJ8ki1q+Hzr/He7SKDEYjSQP6kO0p/D XHN4v9Hx4N+kmy6LyU+TudwjO/3rXvgBmSuroq5pDanAGl2ChMhDHQ2SrSkqoUyZ WvWoKBv/b2NW+GzckA2VwUJZD6QsS76KvEvJdmiH72agr8F4I8kz59UoORJ08eMa gt6PNX9tUYh2rBKs8cleic6VfvGiuKIX4OtVtbSTv0IqcBECbMxpr55PXW2q5Cdl UomDfSf1hRhrW10jScg1s0ceOa321906ORoP0dTB8rqdd6v63SBjQkupQEr3rbyK xNTAVRcNo0RNVY6w/6VNQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegtddgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffekgedugefhtdduudeghfeu veegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 11 May 2024 12:00:18 -0400 (EDT) From: Jiaxun Yang Date: Sat, 11 May 2024 17:00:11 +0100 Subject: [PATCH 4/7] MIPS: csrc-r4k: Don't register as sched_clock if unfit Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240511-mips-clks-v1-4-ddb4a10ee9f9@flygoat.com> References: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> In-Reply-To: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> To: Thomas Bogendoerfer , Serge Semin , Daniel Lezcano , Thomas Gleixner Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1593; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=U+UVB4xsBeR9swGFKSPQmDKTBSfdxpeJjE23y7dy0tM=; b=owGbwMvMwCHmXMhTe71c8zDjabUkhjT7aZxhCwuns22+arsnRadMyG7Ki6lhPkvj2ULbZiz+y jVjg4ReRykLgxgHg6yYIkuIgFLfhsaLC64/yPoDM4eVCWQIAxenAEzET5Xhv99VXtd33x5sEn51 7texgJoSg8mbS3JCuiM/lp5QM0nn9GBk6NhuLqtcGCBW3Mn5vYnN0/z9gS+Zp4JSurPDFLt3uZx mAAA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 When we have more than one CPU in system, counter synchronisation overhead can lead to a scenario that sched_clock goes backward when being read from different CPUs. This is accommodated by CONFIG_HAVE_UNSTABLE_SCHED_CLOCK, but it's unavailable on 32bit kernel. We don't want to risk sched_clock correctness, so if we have multiple CPU in system and CONFIG_HAVE_UNSTABLE_SCHED_CLOCK is not set, we just don't use counter as sched_clock source. Signed-off-by: Jiaxun Yang --- arch/mips/kernel/csrc-r4k.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c index 5c37e41e8970..18733a2ec594 100644 --- a/arch/mips/kernel/csrc-r4k.c +++ b/arch/mips/kernel/csrc-r4k.c @@ -68,6 +68,18 @@ static bool rdhwr_count_usable(void) return false; } +static inline __init bool count_can_be_sched_clock(void) +{ + if (IS_ENABLED(CONFIG_CPU_FREQ)) + return false; + + if (num_possible_cpus() > 1 && + !IS_ENABLED(CONFIG_HAVE_UNSTABLE_SCHED_CLOCK)) + return false; + + return true; +} + #ifdef CONFIG_CPU_FREQ static bool __read_mostly r4k_clock_unstable; @@ -125,9 +137,8 @@ int __init init_r4k_clocksource(void) clocksource_register_hz(&clocksource_mips, mips_hpt_frequency); -#ifndef CONFIG_CPU_FREQ - sched_clock_register(r4k_read_sched_clock, 32, mips_hpt_frequency); -#endif + if (count_can_be_sched_clock()) + sched_clock_register(r4k_read_sched_clock, 32, mips_hpt_frequency); return 0; } From patchwork Sat May 11 16:00:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13662423 Received: from wfhigh4-smtp.messagingengine.com (wfhigh4-smtp.messagingengine.com [64.147.123.155]) (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 0D9DB5FBB3; Sat, 11 May 2024 16:00:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443226; cv=none; b=lCwzV4W9y4UszLumf9DchHwcjmuBGgtg0RDP6na3FHXnJHCr60RiALugN0GvqfYry1cCtJvHR8YKTBcqZVOGNgvJ9D1Uh5rD+nPaqD8ZItISn/HOOUKTGM5/5ZVX/6kt4sQixG6Hj7KhmW0Ps6foeWtOTPq4FqMZdYNihk/faQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443226; c=relaxed/simple; bh=vxanEcE2Mr1tKNocf5KCWHHXM7grqfxfWMlrDZsCP4Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qm0l9xSrRt6Pkz6SEYr2fmHU9jP9LWA6EvfotpHYftbozOL4MIDDTEO3nLUVNuJwd/i7C6/zWqnOEiU+st3x4v4apdK+4kLJk5au2dO3QWRs9CQl9SxktfYa5Acr0TcGgJjScQESdprcTyTar8wVbEEqX9msI1nIBidKKXsdMN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=Po7L01ss; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ceb5zvo5; arc=none smtp.client-ip=64.147.123.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="Po7L01ss"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ceb5zvo5" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id EC00F180012E; Sat, 11 May 2024 12:00:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 11 May 2024 12:00:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1715443222; x=1715529622; bh=dosrWgpsYaRA0psqnvr6gShjRONEEutqEr9tOBofmEk=; b= Po7L01ssEsl206nRH+zK3Nu2FItawm+DEdKopoTx3rUQoUx8Js0wui+8DRjcxc14 AEZIfxWVlGS1OX6tqWhhBwntQd+IBSZbZPJEPxmbRcAppFLh0UIZhvAXWUTfxM13 qTEnEA0DzBBsPJL77cZtkWj5cdogr8jDgyAzHT5mcxX7uZXpUvM+cLCvSPdYlCZ3 IXZL/AFt5U5OsFyi94Gkj/jVFxQMNEAGKQT4d1SqIb/Z8k+BUnjKfPffYxdq3jQC DQOy9ivrLDp8e8fzeycahxdZ4jS5xLCNNxXDDVYXp57/4NCy1J/9PdKKTmRC67Dt Fx22Re7nMhL7LOHIfqDF8w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1715443222; x= 1715529622; bh=dosrWgpsYaRA0psqnvr6gShjRONEEutqEr9tOBofmEk=; b=C eb5zvo5G+WXa/szaO336/LewsSrqcrCBzSVDrh5Ya12iotTOxutU2TtpkqoWsriT Do9P1bx+MB3hnhC5cBKKh4TqGIJpO79S8HFb6j2PK353ZfEbu9AO6ZnAbbP1vFQk WUnVhbznKoJs787az4XaTRciVN3iZcq4++w7yO2aHM+je8QSh+sKCngdMgLelH97 5As2MxVJQK1sgpcgvLudQ0L4WankYC3CTHxQ69ndU3UlRBb08DwoIKFKTTO+rgD2 V0DrgFyBPmLvWj1GB4chAs72djeVD+gIgvolNmzsnBs2ULnakUfqR1B+2/UWpWqf Et7nYDMkNmA9D9AbtzXfw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegtddgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffekgedugefhtdduudeghfeu veegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 11 May 2024 12:00:21 -0400 (EDT) From: Jiaxun Yang Date: Sat, 11 May 2024 17:00:12 +0100 Subject: [PATCH 5/7] MIPS: sync-r4k: Rework based on x86 tsc_sync Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240511-mips-clks-v1-5-ddb4a10ee9f9@flygoat.com> References: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> In-Reply-To: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> To: Thomas Bogendoerfer , Serge Semin , Daniel Lezcano , Thomas Gleixner Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=11164; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=vxanEcE2Mr1tKNocf5KCWHHXM7grqfxfWMlrDZsCP4Y=; b=owGbwMvMwCHmXMhTe71c8zDjabUkhjT7aZznLVMPJFyp1n3wrlvQZPdjnUtzk0wv/M5Tbv9y9 fQGD/dLHaUsDGIcDLJiiiwhAkp9GxovLrj+IOsPzBxWJpAhDFycAjAR/lMM//OTZxyS/rXOodt2 Tf20Ghavy6deFhVvnvi9kv3jgS0NrhMZ/hcqTW78Njn/8eb0YrlLcllGokXXLqcVqstV6dxkDRX 6wggA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 The original sync-r4k did a good job on reducing jitter by determine the "next time value", but it has a limitation that when synchronization being performed too many times due to high core count or CPU hotplug, the timewrap on CPU0 will become unaccpetable. Rework the mechanism based on latest x86 tsc_sync. (It seems like the original implementation is based on tsc_sync at that time, so it's just a refresh.) To improve overall performance. Tesed on Loongson64, Boston, QEMU. Signed-off-by: Jiaxun Yang --- arch/mips/include/asm/r4k-timer.h | 5 - arch/mips/kernel/smp.c | 2 - arch/mips/kernel/sync-r4k.c | 281 +++++++++++++++++++++++++++----------- 3 files changed, 202 insertions(+), 86 deletions(-) diff --git a/arch/mips/include/asm/r4k-timer.h b/arch/mips/include/asm/r4k-timer.h index 6e7361629348..432e61dd5204 100644 --- a/arch/mips/include/asm/r4k-timer.h +++ b/arch/mips/include/asm/r4k-timer.h @@ -12,15 +12,10 @@ #ifdef CONFIG_SYNC_R4K -extern void synchronise_count_master(int cpu); extern void synchronise_count_slave(int cpu); #else -static inline void synchronise_count_master(int cpu) -{ -} - static inline void synchronise_count_slave(int cpu) { } diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c index 0b53d35a116e..0362fc5df7b0 100644 --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c @@ -462,8 +462,6 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle) return -EIO; } - synchronise_count_master(cpu); - /* Wait for CPU to finish startup & mark itself online before return */ wait_for_completion(&cpu_running); return 0; diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c index abdd7aaa3311..39156592582e 100644 --- a/arch/mips/kernel/sync-r4k.c +++ b/arch/mips/kernel/sync-r4k.c @@ -2,121 +2,244 @@ /* * Count register synchronisation. * - * All CPUs will have their count registers synchronised to the CPU0 next time - * value. This can cause a small timewarp for CPU0. All other CPU's should - * not have done anything significant (but they may have had interrupts - * enabled briefly - prom_smp_finish() should not be responsible for enabling - * interrupts...) + * Derived from arch/x86/kernel/tsc_sync.c + * Copyright (C) 2006, Red Hat, Inc., Ingo Molnar */ #include #include #include +#include +#include +#include +#include #include -#include -#include #include +#include -static unsigned int initcount = 0; -static atomic_t count_count_start = ATOMIC_INIT(0); -static atomic_t count_count_stop = ATOMIC_INIT(0); - -#define COUNTON 100 -#define NR_LOOPS 3 - -void synchronise_count_master(int cpu) -{ - int i; - unsigned long flags; - - pr_info("Synchronize counters for CPU %u: ", cpu); +#define COUNTON 100 +#define NR_LOOPS 3 +#define LOOP_TIMEOUT 20 - local_irq_save(flags); +/* + * Entry/exit counters that make sure that both CPUs + * run the measurement code at once: + */ +static atomic_t start_count; +static atomic_t stop_count; +static atomic_t test_runs; - /* - * We loop a few times to get a primed instruction cache, - * then the last pass is more or less synchronised and - * the master and slaves each set their cycle counters to a known - * value all at once. This reduces the chance of having random offsets - * between the processors, and guarantees that the maximum - * delay between the cycle counters is never bigger than - * the latency of information-passing (cachelines) between - * two CPUs. - */ +/* + * We use a raw spinlock in this exceptional case, because + * we want to have the fastest, inlined, non-debug version + * of a critical section, to be able to prove counter time-warps: + */ +static arch_spinlock_t sync_lock = __ARCH_SPIN_LOCK_UNLOCKED; - for (i = 0; i < NR_LOOPS; i++) { - /* slaves loop on '!= 2' */ - while (atomic_read(&count_count_start) != 1) - mb(); - atomic_set(&count_count_stop, 0); - smp_wmb(); +static uint32_t last_counter; +static uint32_t max_warp; +static int nr_warps; +static int random_warps; - /* Let the slave writes its count register */ - atomic_inc(&count_count_start); +/* + * Counter warp measurement loop running on both CPUs. + */ +static uint32_t check_counter_warp(void) +{ + uint32_t start, now, prev, end, cur_max_warp = 0; + int i, cur_warps = 0; - /* Count will be initialised to current timer */ - if (i == 1) - initcount = read_c0_count(); + start = read_c0_count(); + end = start + (uint32_t) mips_hpt_frequency / 1000 * LOOP_TIMEOUT; + for (i = 0; ; i++) { /* - * Everyone initialises count in the last loop: + * We take the global lock, measure counter, save the + * previous counter that was measured (possibly on + * another CPU) and update the previous counter timestamp. */ - if (i == NR_LOOPS-1) - write_c0_count(initcount); + arch_spin_lock(&sync_lock); + prev = last_counter; + now = read_c0_count(); + last_counter = now; + arch_spin_unlock(&sync_lock); /* - * Wait for slave to leave the synchronization point: + * Be nice every now and then (and also check whether + * measurement is done [we also insert a 10 million + * loops safety exit, so we dont lock up in case the + * counter is totally broken]): */ - while (atomic_read(&count_count_stop) != 1) - mb(); - atomic_set(&count_count_start, 0); - smp_wmb(); - atomic_inc(&count_count_stop); + if (unlikely(!(i & 7))) { + if (now > end || i > 10000000) + break; + cpu_relax(); + touch_nmi_watchdog(); + } + /* + * Outside the critical section we can now see whether + * we saw a time-warp of the counter going backwards: + */ + if (unlikely(prev > now)) { + arch_spin_lock(&sync_lock); + max_warp = max(max_warp, prev - now); + cur_max_warp = max_warp; + /* + * Check whether this bounces back and forth. Only + * one CPU should observe time going backwards. + */ + if (cur_warps != nr_warps) + random_warps++; + nr_warps++; + cur_warps = nr_warps; + arch_spin_unlock(&sync_lock); + } + } + WARN(!(now-start), + "Warning: zero counter calibration delta: %d [max: %d]\n", + now-start, end-start); + return cur_max_warp; +} + +/* + * The freshly booted CPU initiates this via an async SMP function call. + */ +static void check_counter_sync_source(void *__cpu) +{ + unsigned int cpu = (unsigned long)__cpu; + int cpus = 2; + + atomic_set(&test_runs, NR_LOOPS); +retry: + /* Wait for the target to start. */ + while (atomic_read(&start_count) != cpus - 1) + cpu_relax(); + + /* + * Trigger the target to continue into the measurement too: + */ + atomic_inc(&start_count); + + check_counter_warp(); + + while (atomic_read(&stop_count) != cpus-1) + cpu_relax(); + + /* + * If the test was successful set the number of runs to zero and + * stop. If not, decrement the number of runs an check if we can + * retry. In case of random warps no retry is attempted. + */ + if (!nr_warps) { + atomic_set(&test_runs, 0); + + pr_info("Counter synchronization [CPU#%d -> CPU#%u]: passed\n", + smp_processor_id(), cpu); + } else if (atomic_dec_and_test(&test_runs) || random_warps) { + /* Force it to 0 if random warps brought us here */ + atomic_set(&test_runs, 0); + + pr_info("Counter synchronization [CPU#%d -> CPU#%u]:\n", + smp_processor_id(), cpu); + pr_info("Measured %d cycles counter warp between CPUs", max_warp); + if (random_warps) + pr_warn("Counter warped randomly between CPUs\n"); } - /* Arrange for an interrupt in a short while */ - write_c0_compare(read_c0_count() + COUNTON); - local_irq_restore(flags); + /* + * Reset it - just in case we boot another CPU later: + */ + atomic_set(&start_count, 0); + random_warps = 0; + nr_warps = 0; + max_warp = 0; + last_counter = 0; + + /* + * Let the target continue with the bootup: + */ + atomic_inc(&stop_count); /* - * i386 code reported the skew here, but the - * count registers were almost certainly out of sync - * so no point in alarming people + * Retry, if there is a chance to do so. */ - pr_cont("done.\n"); + if (atomic_read(&test_runs) > 0) + goto retry; } +/* + * Freshly booted CPUs call into this: + */ void synchronise_count_slave(int cpu) { - int i; - unsigned long flags; + uint32_t cur_max_warp, gbl_max_warp, count; + int cpus = 2; - local_irq_save(flags); + if (!cpu_has_counter || !mips_hpt_frequency) + return; + /* Kick the control CPU into the counter synchronization function */ + smp_call_function_single(cpumask_first(cpu_online_mask), + check_counter_sync_source, + (unsigned long *)(unsigned long)cpu, 0); +retry: /* - * Not every cpu is online at the time this gets called, - * so we first wait for the master to say everyone is ready + * Register this CPU's participation and wait for the + * source CPU to start the measurement: */ + atomic_inc(&start_count); + while (atomic_read(&start_count) != cpus) + cpu_relax(); - for (i = 0; i < NR_LOOPS; i++) { - atomic_inc(&count_count_start); - while (atomic_read(&count_count_start) != 2) - mb(); + cur_max_warp = check_counter_warp(); - /* - * Everyone initialises count in the last loop: - */ - if (i == NR_LOOPS-1) - write_c0_count(initcount); + /* + * Store the maximum observed warp value for a potential retry: + */ + gbl_max_warp = max_warp; + + /* + * Ok, we are done: + */ + atomic_inc(&stop_count); + + /* + * Wait for the source CPU to print stuff: + */ + while (atomic_read(&stop_count) != cpus) + cpu_relax(); - atomic_inc(&count_count_stop); - while (atomic_read(&count_count_stop) != 2) - mb(); + /* + * Reset it for the next sync test: + */ + atomic_set(&stop_count, 0); + + /* + * Check the number of remaining test runs. If not zero, the test + * failed and a retry with adjusted counter is possible. If zero the + * test was either successful or failed terminally. + */ + if (!atomic_read(&test_runs)) { + /* Arrange for an interrupt in a short while */ + write_c0_compare(read_c0_count() + COUNTON); + return; } - /* Arrange for an interrupt in a short while */ - write_c0_compare(read_c0_count() + COUNTON); - local_irq_restore(flags); + /* + * If the warp value of this CPU is 0, then the other CPU + * observed time going backwards so this counter was ahead and + * needs to move backwards. + */ + if (!cur_max_warp) + cur_max_warp = -gbl_max_warp; + + count = read_c0_count(); + count += cur_max_warp; + write_c0_count(count); + + pr_debug("Counter compensate: CPU%u observed %d warp\n", cpu, cur_max_warp); + + goto retry; + } -#undef NR_LOOPS From patchwork Sat May 11 16:00:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13662424 Received: from wfout1-smtp.messagingengine.com (wfout1-smtp.messagingengine.com [64.147.123.144]) (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 810D260263; Sat, 11 May 2024 16:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443227; cv=none; b=MslQpF8l/2rdOXlFxwghWzxF87lVRg3AAMx/Q9Mq1ccuDrjcsufY4jazbaUSwPD13kX3keDWgkEzhqXn1Q4U4sqd6FQymUDPWkoCjuGXx44iY+XTXh2C6eQinnTUvyquIFU5HR51PR09zh5w99mQMaUwYWTw/No22e863C+a96k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443227; c=relaxed/simple; bh=LTJ2PdwrtfpyOd9ncjTs/2ypXjc7FhtM/f5PM28BJKg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AoWK0JupGEhN1VltoTWJxTPgYQqjLNRAEFlLyByH2oMN5CGrKB/2KIbp8FPdtGjA9tj3XUpmqVYlWjZLECy7wZt/NqWHwsxl37CqyO4lRSloT9EeZLGPzbwadIZv9/MOqLldpUfNosytnJlwX00fE6040PtEX62nStQwSxcM4mA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=D+6fEmLA; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NDjqs6yi; arc=none smtp.client-ip=64.147.123.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="D+6fEmLA"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NDjqs6yi" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id 53B461C000F1; Sat, 11 May 2024 12:00:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 11 May 2024 12:00:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1715443224; x=1715529624; bh=DsfUiYmStvOvLHJLDxVevwp6/j2FmnRSicicLuBbeWs=; b= D+6fEmLAqgCmr3Sn7n+K567v6Q7raaeJu3EHNZYdmKvuWLXRBdQqxmJGgcwbZACO akGMqy8IdpiSQkakblZ3Wy+J2KLY9iJTl4H/d0Y+ogzSWucTPyUihiv6M2X12Doq PuIcLGAKQUTt0Vs6/8BkOyzG9Y+G4TX+5ZP7sZYirrSumvCD9XaTHOWGtuK1PhmI Clklj6XfuJBOmyds/C+1n+o1U71nDFhnSfioy+xWBroLrUVbKssk3Qg2ROMfzIDK Xr2MC7iuPgDLvqUTxTl1zOKhwlPQ0jPK+uhLOrejvUcbYrG6D50E6R32781VGoap rjBpiLCbO4KSnnDRdlqvxg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1715443224; x= 1715529624; bh=DsfUiYmStvOvLHJLDxVevwp6/j2FmnRSicicLuBbeWs=; b=N Djqs6yi4X5/HQTnuDHcmRGzzL/D+3sUpDZab0A95yw6n26Kw+gRhkATlqBP0upPZ CdjxVZqyqfyObk2MkpseL3qjPsr3VHlVSIAezsUc61ddZSV1hLaWk+HU0i28hwrs OVZNgHty4/2Rr7ftrY8HOSNK9ckv+5zdrt4PsqRgJ8xsF0++P0GgZIrJyfGHWx6V ec0ZJpoUimdW+5bHgCJPaBlKdLHVUe7H7CfCE1ul6sEULkJC1+XOh3iH/02eP8CK rEjQ/73mT6YuZGUV+Zj4IL0wFDN3o7Hvw+jB1tLDj2Z7+zivZyQWs5MB6tvft4nK Z98aLy16/8VD7ppAkIqZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegtddgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffekgedugefhtdduudeghfeu veegffegudekjeelnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 11 May 2024 12:00:23 -0400 (EDT) From: Jiaxun Yang Date: Sat, 11 May 2024 17:00:13 +0100 Subject: [PATCH 6/7] clocksource: mips-gic-timer: Refine rating computation Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240511-mips-clks-v1-6-ddb4a10ee9f9@flygoat.com> References: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> In-Reply-To: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> To: Thomas Bogendoerfer , Serge Semin , Daniel Lezcano , Thomas Gleixner Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1318; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=LTJ2PdwrtfpyOd9ncjTs/2ypXjc7FhtM/f5PM28BJKg=; b=owGbwMvMwCHmXMhTe71c8zDjabUkhjT7aZxhDt9b2IuXV+vqLSm+3HbztMGJzdZ7VrH3ytod/ B4tu9y9o5SFQYyDQVZMkSVEQKlvQ+PFBdcfZP2BmcPKBDKEgYtTACbSeYHhv1/ExzL9gBcC0qqZ Ha+T4myDg7cfeKv5aAUT34R7Rqu/RjAyNBpu5G+9YG+4LXba/e7+v6IqOTrzrJO4++7L/rkonPW JCwA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 It is a good clocksource which usually go as fast as CPU core and have a low access latency, so raise the base of rating from Good to desired when we know that it has a stable frequency. Increase frequency addend dividend to 100000000 (10MHz) to reasonably accommodate multi GHz level clock, also cap rating within current level. Signed-off-by: Jiaxun Yang --- drivers/clocksource/mips-gic-timer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/clocksource/mips-gic-timer.c b/drivers/clocksource/mips-gic-timer.c index b3ae38f36720..67498dc9c5a5 100644 --- a/drivers/clocksource/mips-gic-timer.c +++ b/drivers/clocksource/mips-gic-timer.c @@ -197,7 +197,11 @@ static int __init __gic_clocksource_init(void) gic_clocksource.mask = CLOCKSOURCE_MASK(count_width); /* Calculate a somewhat reasonable rating value. */ - gic_clocksource.rating = 200 + gic_frequency / 10000000; + if (mips_cm_revision() >= CM_REV_CM3 || !IS_ENABLED(CONFIG_CPU_FREQ)) + gic_clocksource.rating = 300; /* Good when frequecy is stable */ + else + gic_clocksource.rating = 200; + gic_clocksource.rating += clamp(gic_frequency / 100000000, 0, 99); ret = clocksource_register_hz(&gic_clocksource, gic_frequency); if (ret < 0) From patchwork Sat May 11 16:00:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13662425 Received: from wfout1-smtp.messagingengine.com (wfout1-smtp.messagingengine.com [64.147.123.144]) (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 0C2B0612EB; Sat, 11 May 2024 16:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443230; cv=none; b=Z9BIhI5t5EFRDQAE3uku95bMpcb/weAqpSL/jDt954rL8v3mATw2RPnJGraZ/TKy3XXCbpVDqVDz0ed1g0UAQynOJ+PPOLm0pQtxu314+SrhThO6ZXmp0Y6zHJ7nFM/eR3yTE95o0W0N4BO0P6RzyyqmKSHnhbGqRaGzVaGmZFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715443230; c=relaxed/simple; bh=QoFq1d4EB6JF/VXmsnCt30uB7ETZJLm1mA9nrZugG5c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EFpcuohycTGcR/r3WQ9uhhcmM9Ze/dxqzu/WY2dTUIJ5iHuQx8i1wiaiN3V8qxImTYEYbSKFas0cVN/DYY2kN9mxoCUpIjBS76TObbJGZQPOjL3H+j18VkKA9HtBuOOydGlIQQ25ABpEWNQEDnH2z37UH34LsB9x1tCfwqEOUms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=qOkc4VzF; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=K5+bVDg0; arc=none smtp.client-ip=64.147.123.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="qOkc4VzF"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="K5+bVDg0" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id E074F1C000C4; Sat, 11 May 2024 12:00:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sat, 11 May 2024 12:00:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1715443227; x=1715529627; bh=vD6rDPAVkIjqWQOwrtHmYQ2cQTTYvi5Iri1uGX4o4Ig=; b= qOkc4VzF1JvExNaogjpWVEW6xmK7tekVQIi2e0HSPcDXLAYhDLGl/IRfKF1MHTPP kKN0CR9BNnP1Ovs3P+oAlbTG/Dxf9O9n4i3xdVwHdJbxNbW50vcSoSVwQVMDen2k 8bMSpHB/tYpyX+8J7q3mZoj99zcdak0dNdyRK4IJLhFtaryIvTs3KiyWiTVI3HFr CTmZfgoU7Tul3eEHPASxRq+4XTysz6nxwvG40JkckXM1USo5Smi0/4bvUO8Gz7Jt TUqFn6qM21tDZEcyM23K++qSvna106MiQ417o0DdLfq1Gm8wuwBaNzpTkd31uR90 rIo3lfzetSxvRSBX6MQ5Mw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1715443227; x= 1715529627; bh=vD6rDPAVkIjqWQOwrtHmYQ2cQTTYvi5Iri1uGX4o4Ig=; b=K 5+bVDg067w7uI21QmH+ip2A90cgGT7EKJGlPvNGFvh1mnjhLCYKGya1DkotarqTG 3OrZFCNQnejzwAg9DJ9NNC6N6ePiE81WLmurgNiXu+SYkyymo37uL9fj9bTcLqtk GadEVgoU8lQA1MKM7QIIC+RtXFVxeCC5Dycgbts/jPkGWBlw1xMUkD1R7Qo+YVXY Og+nXfBL9fU5Xx+tcTyHgvk1YTwrvRCWX2BJ7XRiwGcaXzvZLj6z4XuM2tnpHzZr kRnk5ZoUx1QorYU2D5xJOIzmHqCJPKR2QqMKeYVh2uwLUrOFaSteSh+k1EmDmpQY E1Oj6KgkPzKIuu5miQFjQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegtddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffekgedugefhtdduudeghfeu veegffegudekjeelnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 11 May 2024 12:00:26 -0400 (EDT) From: Jiaxun Yang Date: Sat, 11 May 2024 17:00:14 +0100 Subject: [PATCH 7/7] clocksource: mips-gic-timer: Correct sched_clock width Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240511-mips-clks-v1-7-ddb4a10ee9f9@flygoat.com> References: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> In-Reply-To: <20240511-mips-clks-v1-0-ddb4a10ee9f9@flygoat.com> To: Thomas Bogendoerfer , Serge Semin , Daniel Lezcano , Thomas Gleixner Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1957; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=QoFq1d4EB6JF/VXmsnCt30uB7ETZJLm1mA9nrZugG5c=; b=owGbwMvMwCHmXMhTe71c8zDjabUkhjT7aZwcr/WclZZ8rzkRMqco7veuiZEM50SNZM7+3Ke6O Vb27ZztHaUsDGIcDLJiiiwhAkp9GxovLrj+IOsPzBxWJpAhDFycAjCRgjSG/95RmfFeJXe+rEgr tmI4y8DhHmYzJ2XChrVmCgxbzZgEvBj+B082ituR2Zid4aYudfrB9EW3unnsmu68CKkL4GPeuSm TCwA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Counter width of GIC is configurable and can be read from a register. Use width value from the register for sched_clock. Signed-off-by: Jiaxun Yang Reviewed-by: Philippe Mathieu-Daudé --- drivers/clocksource/mips-gic-timer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/clocksource/mips-gic-timer.c b/drivers/clocksource/mips-gic-timer.c index 67498dc9c5a5..47143e49fc44 100644 --- a/drivers/clocksource/mips-gic-timer.c +++ b/drivers/clocksource/mips-gic-timer.c @@ -19,6 +19,7 @@ static DEFINE_PER_CPU(struct clock_event_device, gic_clockevent_device); static int gic_timer_irq; static unsigned int gic_frequency; +static unsigned int gic_count_width; static bool __read_mostly gic_clock_unstable; static void gic_clocksource_unstable(char *reason); @@ -186,15 +187,14 @@ static void gic_clocksource_unstable(char *reason) static int __init __gic_clocksource_init(void) { - unsigned int count_width; int ret; /* Set clocksource mask. */ - count_width = read_gic_config() & GIC_CONFIG_COUNTBITS; - count_width >>= __ffs(GIC_CONFIG_COUNTBITS); - count_width *= 4; - count_width += 32; - gic_clocksource.mask = CLOCKSOURCE_MASK(count_width); + gic_count_width = read_gic_config() & GIC_CONFIG_COUNTBITS; + gic_count_width >>= __ffs(GIC_CONFIG_COUNTBITS); + gic_count_width *= 4; + gic_count_width += 32; + gic_clocksource.mask = CLOCKSOURCE_MASK(gic_count_width); /* Calculate a somewhat reasonable rating value. */ if (mips_cm_revision() >= CM_REV_CM3 || !IS_ENABLED(CONFIG_CPU_FREQ)) @@ -264,7 +264,7 @@ static int __init gic_clocksource_of_init(struct device_node *node) if (mips_cm_revision() >= CM_REV_CM3 || !IS_ENABLED(CONFIG_CPU_FREQ)) { sched_clock_register(mips_cm_is64 ? gic_read_count_64 : gic_read_count_2x32, - 64, gic_frequency); + gic_count_width, gic_frequency); } return 0;