From nobody Sun Feb 8 14:34:26 2026 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 3AEA2C04A6A for ; Wed, 2 Aug 2023 15:24:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234815AbjHBPYJ (ORCPT ); Wed, 2 Aug 2023 11:24:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235307AbjHBPXG (ORCPT ); Wed, 2 Aug 2023 11:23:06 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 863C4421E for ; Wed, 2 Aug 2023 08:19:39 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6B99721A7E; Wed, 2 Aug 2023 15:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1690989491; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wlFk5dvM8K/mJr6kxmbHlFDi02aaVykLxV2u1JfHHgA=; b=CZQ5PhLdOHyWQN6tTzJMrLCItZfFSZ/2dVhgUewDh3csulP44eitM4QsDQfxMRKdCDRAnn 6SbZ1rFF0UljI8ioElywV6wEnRA3cXYAYduqXWgu8XyHRwsi/CupP0ekgDyT+adVXt2xgh 59E/5bO0IKssmr0eQcIYq39DmK2uaUc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1690989491; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wlFk5dvM8K/mJr6kxmbHlFDi02aaVykLxV2u1JfHHgA=; b=r13tfUpXUfo0p+Ag951rgi/GIczAL7OPNXwvaWelnCluQCukST+8NZQ9h5E7dzpU/y9L6B yCkstgGOhLLDV/Aw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 582FB13919; Wed, 2 Aug 2023 15:18:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Vik1FLNzymRiKAAAMHmgww (envelope-from ); Wed, 02 Aug 2023 15:18:11 +0000 From: Cyril Hrubis To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org Cc: ltp@lists.linux.it, Cyril Hrubis , Jiri Bohac , Petr Vorel Subject: [PATCH 1/2 RESEND] sched/rt: Fix sysctl_sched_rr_timeslice intial value Date: Wed, 2 Aug 2023 17:19:05 +0200 Message-ID: <20230802151906.25258-2-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802151906.25258-1-chrubis@suse.cz> References: <20230802151906.25258-1-chrubis@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There is a 10% rounding error in the intial value of the sysctl_sched_rr_timeslice with CONFIG_HZ_300=3Dy. This was found with LTP test sched_rr_get_interval01: sched_rr_get_interval01.c:57: TPASS: sched_rr_get_interval() passed sched_rr_get_interval01.c:64: TPASS: Time quantum 0s 99999990ns sched_rr_get_interval01.c:72: TFAIL: /proc/sys/kernel/sched_rr_timeslice_ms= !=3D 100 got 90 sched_rr_get_interval01.c:57: TPASS: sched_rr_get_interval() passed sched_rr_get_interval01.c:64: TPASS: Time quantum 0s 99999990ns sched_rr_get_interval01.c:72: TFAIL: /proc/sys/kernel/sched_rr_timeslice_ms= !=3D 100 got 90 What this test does is to compare the return value from the sched_rr_get_interval() and the sched_rr_timeslice_ms sysctl file and fails if they do not match. The problem it found is the intial sysctl file value which was computed as: static int sysctl_sched_rr_timeslice =3D (MSEC_PER_SEC / HZ) * RR_TIMESLICE; which works fine as long as MSEC_PER_SEC is multiple of HZ, however it introduces 10% rounding error for CONFIG_HZ_300: (MSEC_PER_SEC / HZ) * (100 * HZ / 1000) (1000 / 300) * (100 * 300 / 1000) 3 * 30 =3D 90 This can be easily fixed by reversing the order of the multiplication and division. After this fix we get: (MSEC_PER_SEC * (100 * HZ / 1000)) / HZ (1000 * (100 * 300 / 1000)) / 300 (1000 * 30) / 300 =3D 100 CC: Jiri Bohac Fixes: 975e155ed873 ("sched/rt: Show the 'sched_rr_timeslice' SCHED_RR time= slice tuning knob in milliseconds") Signed-off-by: Cyril Hrubis Acked-by: Mel Gorman Reviewed-by: Petr Vorel Tested-by: Petr Vorel --- kernel/sched/rt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 00e0e5074115..185d3d749f6b 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -25,7 +25,7 @@ unsigned int sysctl_sched_rt_period =3D 1000000; int sysctl_sched_rt_runtime =3D 950000; =20 #ifdef CONFIG_SYSCTL -static int sysctl_sched_rr_timeslice =3D (MSEC_PER_SEC / HZ) * RR_TIMESLIC= E; +static int sysctl_sched_rr_timeslice =3D (MSEC_PER_SEC * RR_TIMESLICE) / H= Z; static int sched_rt_handler(struct ctl_table *table, int write, void *buff= er, size_t *lenp, loff_t *ppos); static int sched_rr_handler(struct ctl_table *table, int write, void *buff= er, --=20 2.41.0 From nobody Sun Feb 8 14:34:26 2026 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 DAD6BC001DF for ; Wed, 2 Aug 2023 15:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235020AbjHBPYM (ORCPT ); Wed, 2 Aug 2023 11:24:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235302AbjHBPXG (ORCPT ); Wed, 2 Aug 2023 11:23:06 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FDAD30FA for ; Wed, 2 Aug 2023 08:19:39 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E5D0E1F8A4; Wed, 2 Aug 2023 15:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1690989491; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pKIweQamxfw0ZZ0aSOi6JqFL+eQxAp+j1VDPErEK1gA=; b=KJRZPyx+5B/Ak0fQd2ZrAyISKSzXy2B+oMdHxqCaPaBRFNwVPz7+F2cTybcjx+QWJIWHLY F2rhlPeoEWnZKxdoh6rFW2G2mMXrYTtIk+gedFc/ka+Wg7e7LAX61toOdjJdSLDwHx6K3V YrDsLFYcpFZs2v/UBPRag+e+BsckDy4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1690989491; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pKIweQamxfw0ZZ0aSOi6JqFL+eQxAp+j1VDPErEK1gA=; b=L2RlHRWU0ZWPXiqwbtP1Ze5XJSUg75pgzizNBuqHtuM7BkMJzrv7bkY13k7N/roXmcknDP rbqY4Mu+kGq6nyDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D073313919; Wed, 2 Aug 2023 15:18:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kRCWMbNzymRnKAAAMHmgww (envelope-from ); Wed, 02 Aug 2023 15:18:11 +0000 From: Cyril Hrubis To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org Cc: ltp@lists.linux.it, Cyril Hrubis , Jiri Bohac , Petr Vorel Subject: [PATCH 2/2 RESEND] sched/rt: sysctl_sched_rr_timeslice show default timeslice after reset Date: Wed, 2 Aug 2023 17:19:06 +0200 Message-ID: <20230802151906.25258-3-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802151906.25258-1-chrubis@suse.cz> References: <20230802151906.25258-1-chrubis@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The sched_rr_timeslice can be reset to default by writing value that is <=3D 0. However after reading from this file we always got the last value written, which is not useful at all. $ echo -1 > /proc/sys/kernel/sched_rr_timeslice_ms $ cat /proc/sys/kernel/sched_rr_timeslice_ms -1 Fix this by setting the variable that holds the sysctl file value to the jiffies_to_msecs(RR_TIMESLICE) in case that <=3D 0 value was written. CC: Jiri Bohac Signed-off-by: Cyril Hrubis Acked-by: Mel Gorman Reviewed-by: Petr Vorel Tested-by: Petr Vorel --- kernel/sched/rt.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 185d3d749f6b..0597ba0f85ff 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -3062,6 +3062,9 @@ static int sched_rr_handler(struct ctl_table *table, = int write, void *buffer, sched_rr_timeslice =3D sysctl_sched_rr_timeslice <=3D 0 ? RR_TIMESLICE : msecs_to_jiffies(sysctl_sched_rr_timeslice); + + if (sysctl_sched_rr_timeslice <=3D 0) + sysctl_sched_rr_timeslice =3D jiffies_to_msecs(RR_TIMESLICE); } mutex_unlock(&mutex); =20 --=20 2.41.0