From nobody Sun Feb 8 16:53:22 2026 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) (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 0513513B791 for ; Fri, 7 Feb 2025 06:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738908939; cv=none; b=PEQATiJnW1yxgmhMN2TA1kLi/YK6JIQj9qbxOhJlB0P1vhE4yAHb/CCJFRxnmXDEFW9J8WAFy/jssNm141pgXH1g3gTU57XYPUkZcaX/25JE7QW4YQ1zP3FmE2MC9NR48rYM5KHqtFAQqd9WC0GAUqb5sN1jqpTzHO1Pyws68l0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738908939; c=relaxed/simple; bh=M8TXGk/PYHN7tZ/qk9weZpHSf5KfVZ+12wEOEPBvsNE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EyAWmA/FadW4O189V1odFbfl9Lj0FuxVi7qZTBuDTytGSfemUvHIGvweP9niPlpFE+0tzI2eI87/Z8aE78TwO+gVK/jdMwkr+MX/o8txv5mRiQiDOTbYppoUX5o+Q26bwoeNswt7cndJUgK+C2c+IlmAo1EpV0lM3JWaRW/OVbE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aqocwG8M; arc=none smtp.client-ip=209.85.214.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aqocwG8M" Received: by mail-pl1-f196.google.com with SMTP id d9443c01a7336-21f0bc811dbso41535175ad.1 for ; Thu, 06 Feb 2025 22:15:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738908937; x=1739513737; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pc0d3IeUyKXn7ajlIilqfGDxOeSfWxBgCDj0yI4TU/I=; b=aqocwG8MdPmajzWUb8ejN9wKoqJUgy5USvgcYpQdDaiieYPY5mmW2bcB3euO5FHBjV VmbfigmvREablYtFnn8cfzvtEfGybxLKFzWf89HovLmkUAnFiBvgYxwFW89QkQqV3ev+ TiK93CM2svMlNf2gTSzjR5hxqEiJHUHPOiqSXIlXHsT33dN9b2iD6w/IzTQ4ErfzLF9h I+wPOE1kpvX86kTzMJH4RYD1DZHdXK3QKKZw6brcac1gKWJBWqA6LfeTizqt0qAHyHy+ 8i1MuQtovEP5AJkEOltv5gnLaEPR2RqXhXX5p0Z1NlFnZmWFRg2uAfCFpQUp6xTQX9S2 LYVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738908937; x=1739513737; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pc0d3IeUyKXn7ajlIilqfGDxOeSfWxBgCDj0yI4TU/I=; b=bLYEbpYgk3OX5gtOMMT4eIXryRBPhQzIFTElXhQt+JF97rdWRdbBtHZozXUI2IIkuG b9ctxoDQfB5Px9yC4sO+gFqBizutumGM+eq4Lox5L11EfRAkoK/djdsT3/NdABAEN63U Fdkakc8iMbLa7aKgJVrqUsIGhp2yKysBMPOH0OfrMZewDTKoPKRQGczHqbdYHVuGvhLw O7WKUEtPpnoEkPvYCgVjA5YKP6ywOxCbDa3F1jpBmH/TSjnwZa+OGFM6KfeF43Cacfno M/uXrHxDuNoHPUTHgVK1zMRNgdVAOGaN+6hZxpICCKevhoDVOWaugEktDmiZCtIHLi9W Q9SQ== X-Forwarded-Encrypted: i=1; AJvYcCU0m+dGCEVFA4r8GRRemRYGDnWM8KFzvCh4BygK7CU3LhxDm+xvWNfAPungGZ9jcGw36/78T24yKqU8T64=@vger.kernel.org X-Gm-Message-State: AOJu0Ywm0TY+3OBB1Ic2h9YoKt5QL394rOJBqYQ3NG1UyC9Al/NG5S9t rDEw47cHhd9VL62GTFlTB+JEU4ySgzSdkXbIERgq8oPmgh60SirH X-Gm-Gg: ASbGncvWNf1g0/Cy86XmPM8LLYjaqw7O3/lIqHBCSXA/betx3kVRsBAPyUJbOXWH/D6 +qx65XYl5AtHYsEqvyCwieT+xY8FvQ+9dsEZ58onbpAClyDHeyISxtamsI07L6zu+0eFgcnKfCJ VZu6uqtsbHNelm4KqPDs3F3gW8j12SORhU8Eu2P3SQZG7kEikMZsO8MqnwpXc0JyPnt9Uihu17g qakhnZE4uGJUm1FR6JLe0d+o7RlVjjL1EUEGBjL2jz67ob2mZYX9jcge6DI5fHw9KO4aS6f/6fF Aelv4jE+SqwUX1vhHcuc5MXybOEbt/B9FIs= X-Google-Smtp-Source: AGHT+IGp5Au8lMSsNEuE09EeQNPJ2JqbpcpsDFsXUrLsQqibKO9Z07VGbPoCUjT3m+PqUgdJjyEopw== X-Received: by 2002:a17:902:f745:b0:215:b18d:ca with SMTP id d9443c01a7336-21f2f1e7263mr119073955ad.18.1738908937124; Thu, 06 Feb 2025 22:15:37 -0800 (PST) Received: from localhost.localdomain ([114.67.205.189]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ad51aee5bb1sm2309779a12.38.2025.02.06.22.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 22:15:36 -0800 (PST) From: zihan zhou <15645113830zzh@gmail.com> To: 15645113830zzh@gmail.com Cc: bsegall@google.com, dietmar.eggemann@arm.com, juri.lelli@redhat.com, linux-kernel@vger.kernel.org, mgorman@suse.de, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, vincent.guittot@linaro.org, vschneid@redhat.com Subject: [PATCH V2 1/2] sched: Reduce the default slice to avoid tasks getting an extra tick Date: Fri, 7 Feb 2025 14:14:00 +0800 Message-Id: <20250207061359.31442-1-15645113830zzh@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250207060917.30201-1-15645113830zzh@gmail.com> References: <20250207060917.30201-1-15645113830zzh@gmail.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 Content-Type: text/plain; charset="utf-8" Reduce the default slice, add a comment explaining why this modification was made. Signed-off-by: zihan zhou <15645113830zzh@gmail.com> Reviewed-by: Vincent Guittot --- kernel/sched/fair.c | 47 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 26958431deb7..754b0785eaa0 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -71,10 +71,49 @@ unsigned int sysctl_sched_tunable_scaling =3D SCHED_TUN= ABLESCALING_LOG; /* * Minimal preemption granularity for CPU-bound tasks: * - * (default: 0.75 msec * (1 + ilog(ncpus)), units: nanoseconds) - */ -unsigned int sysctl_sched_base_slice =3D 750000ULL; -static unsigned int normalized_sysctl_sched_base_slice =3D 750000ULL; + * (default: 0.70 msec * (1 + ilog(ncpus)), units: nanoseconds) + * + * The old default value for slice is 0.75 msec * (1 + ilog(ncpus)) which + * means that we have a default slice of + * 0.75 for 1 cpu + * 1.50 up to 3 cpus + * 2.25 up to 7 cpus + * 3.00 for 8 cpus and above. + * + * For HZ=3D250 and HZ=3D100, because of the tick accuracy, the runtime of= tasks + * is far higher than their slice. + * For HZ=3D1000 with 8 cpus or more, the accuracy of tick is already + * satisfactory, but there is still an issue that tasks will get an extra + * tick because the tick often arrives a little faster than expected. In t= his + * case, the task can only wait until the next tick to consider that it has + * reached its deadline, and will run 1ms longer. + * + * vruntime + sysctl_sched_base_slice =3D deadline + * |-----------|-----------|-----------|-----------| + * 1ms 1ms 1ms 1ms + * ^ ^ ^ ^ + * tick1 tick2 tick3 tick4(nearly 4ms) + * + * There are two reasons for tick error: clockevent precision and the + * CONFIG_IRQ_TIME_ACCOUNTING/CONFIG_PARAVIRT_TIME_ACCOUNTING. + * with CONFIG_IRQ_TIME_ACCOUNTING every tick will be less than 1ms, but e= ven + * without it, because of clockevent precision, tick still often less than + * 1ms. + * + * In order to make scheduling more precise, we changed 0.75 to 0.70, + * Using 0.70 instead of 0.75 should not change much for other configs + * and would fix this issue: + * 0.70 for 1 cpu + * 1.40 up to 3 cpus + * 2.10 up to 7 cpus + * 2.8 for 8 cpus and above. + * + * This does not guarantee that tasks can run the slice time accurately ev= ery + * time, but occasionally running an extra tick has little impact. + * + */ +unsigned int sysctl_sched_base_slice =3D 700000ULL; +static unsigned int normalized_sysctl_sched_base_slice =3D 700000ULL; =20 const_debug unsigned int sysctl_sched_migration_cost =3D 500000UL; =20 --=20 2.33.0 From nobody Sun Feb 8 16:53:22 2026 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) (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 BCAD3282F4 for ; Fri, 7 Feb 2025 06:25:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738909512; cv=none; b=TNxsq1qykGY54jvPi+mqDQ0+odvdP6ZnHxZ6CNVN2RC3r9tMGgzY0CmixhK0YZRfrInezX93V1ABEDQKbXWfv6qYcMjlqfNmCsYGRqx/ycQzt207selp/e1K4SN2NdLBeu0V99G+RO97vbY53bDN7aMScF9pTEiP4Xddn/10oy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738909512; c=relaxed/simple; bh=T3syE1O2tH2Vw9HuBQ5pQPa71ss68twxacIAl/K+4vE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cWdhGWeciEXa5URQbjr3843NK2b34GriYBMgajsZhDO1wPyshwKOWNikvDxqUgJX3q7OSYXFhe5Q6d4yq88675S7nL00rvb5LynRYlSQP1BTZ08tohPu47XSTwt54BqijHVbAdCcwkWJZX9/X29O1Kn70btNHTWB/yIDciL4dQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VPpULExR; arc=none smtp.client-ip=209.85.214.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VPpULExR" Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-2163dc5155fso34635055ad.0 for ; Thu, 06 Feb 2025 22:25:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738909510; x=1739514310; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VMx2ra2tOFUB7h4xNM4Q/KmWMEPeS3JDz1QEiEqKl8U=; b=VPpULExRGegzG7idiNig/ddFxI0AOJr7D+tmsU78AcxZ3e3505o6tkFkXWVqw3XOXO e8/8dvfaU0lWiZmLYqD6p0DJvBumSkdDQNH2dHpRYbYFBbmk68RSdXjatuHGI25nsop+ AhGpYQvsp8b8JcSFqFGkMIra7b/FDipSUzqx7CIAJ6WYde498XymzK2RyHUZ9WGtjEye RrFS9K/qKVt09raMUFidLmkPTAAcfMFzxQxJzqPX3m+77GJhrYa0YHwpNaNLSi/URxv2 eqyh9XzXm+l/HhFFY25Gb4FYrX/MNwvhuv6s5Z1yZUsUPXqyGiTB/o718oZ2rBaunKXJ o2Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738909510; x=1739514310; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VMx2ra2tOFUB7h4xNM4Q/KmWMEPeS3JDz1QEiEqKl8U=; b=vmlPjeCv/e2dc4a6eHc/rqn3cR6U77de4Cpja0cEBBGh+0hJwx28cfRbDBwlikVnmL jAg301aVtrUPsPUzGSQFrIAScdZvg81LY05pynQxy+OGHkk3Ac9tS0VgofCxFppJGd7f fb/vV1CH0+vN/JMpKkUv+btSYDKm0OjL30mNOC+mRcV2v5mJeU5fZ9PgPvV/kBf/S3QX CtIkLoi4aW0/PlI/OsKwtFd2JRMOK9shyFvb79PVbGy6CfnhRLjKahRMlR3FPR5f3Hdn 5u9TRxAUy5R3Me/gNIsvWXjOf6a/RIwaQll5kdolyVFCRIUlSERhZbh80YIvlnh36bOo cdAw== X-Forwarded-Encrypted: i=1; AJvYcCUMo8DkHuZGWv84Pph+B88KDpU1lXDiXMf94HE0f6+noRdWM9WBvgVlFoxE48lApafOSGl2aDD06MQRSO0=@vger.kernel.org X-Gm-Message-State: AOJu0YzF935tJn9r64Z75DO7+UlfvEObJjZpNenb+oMhMn9cpUeyq9XN G9X0ZsdaPAEy/9VWEpVkc9G1VAp0+2c8/gT6UUnAEi/aBEK8ibJO X-Gm-Gg: ASbGncuNsJsEl0z/8+aysN+NLKvYeKSFWeFQPABZLpI+zFOy7T7+WqAjkzNhWmz+qS5 7uYZGN0SAiAlsYDm6qSNfAu2nk7otfE8J4xupRqAQ62KrlWPaa8T0IMFezufK3fbzG5PL0//GAG I8bPMD3S7MfehLjohWsN5V6um4zNbefVEco6LbVlHk25umPt8zhBZzhI2eEEHmC2VVUNTRWTD1j 9vawwn1kNaV7XW2FnX3sJNBPB5PY40NnZUphLKy6r63EwpbQf54Rx/GkAxVEyMeARF9WJ85Z3ds tH1cbw5Zu23/GzimnPEtoCf23BHOhKnJPyA= X-Google-Smtp-Source: AGHT+IHvIinbFS+Iq6UoWwI5zSifwznlydpeDCSHXdcuUzfBe6I3l5gk+34wnrdBE9YJIN+W9+GzHA== X-Received: by 2002:a05:6a21:170f:b0:1e0:c56f:7daf with SMTP id adf61e73a8af0-1ee03a21dddmr4361970637.6.1738909508593; Thu, 06 Feb 2025 22:25:08 -0800 (PST) Received: from localhost.localdomain ([114.67.205.189]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ad51af78126sm2324069a12.68.2025.02.06.22.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 22:25:08 -0800 (PST) From: zihan zhou <15645113830zzh@gmail.com> To: 15645113830zzh@gmail.com Cc: bsegall@google.com, dietmar.eggemann@arm.com, juri.lelli@redhat.com, linux-kernel@vger.kernel.org, mgorman@suse.de, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, vincent.guittot@linaro.org, vschneid@redhat.com Subject: [PATCH V2 2/2] sched: Reduce the default slice to avoid tasks getting an extra tick Date: Fri, 7 Feb 2025 14:24:03 +0800 Message-Id: <20250207062402.33725-1-15645113830zzh@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250207060917.30201-1-15645113830zzh@gmail.com> References: <20250207060917.30201-1-15645113830zzh@gmail.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 Content-Type: text/plain; charset="utf-8" update sysctl_sched_base_slice with debugfs, limit its value and update normalized_sysctl_sched_base_slice. Signed-off-by: zihan zhou <15645113830zzh@gmail.com> --- kernel/sched/debug.c | 51 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index fd7e85220715..70dda949a69a 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -166,6 +166,55 @@ static const struct file_operations sched_feat_fops = =3D { .release =3D single_release, }; =20 + +static ssize_t sched_base_slice_write(struct file *filp, const char __user= *ubuf, + size_t cnt, loff_t *ppos) +{ + char buf[16]; + unsigned int base_slice; + + if (cnt > 15) + cnt =3D 15; + + if (copy_from_user(&buf, ubuf, cnt)) + return -EFAULT; + buf[cnt] =3D '\0'; + + if (kstrtouint(buf, 10, &base_slice)) + return -EINVAL; + + + base_slice =3D clamp_t(u64, base_slice, + NSEC_PER_MSEC/10, /* HZ=3D1000 * 10 */ + NSEC_PER_MSEC*100); /* HZ=3D100 / 10 */ + + sysctl_sched_base_slice =3D base_slice; + + sched_update_scaling(); + + *ppos +=3D cnt; + return cnt; +} + +static int sched_base_slice_show(struct seq_file *m, void *v) +{ + seq_printf(m, "%d\n", sysctl_sched_base_slice); + return 0; +} + +static int sched_base_slice_open(struct inode *inode, struct file *filp) +{ + return single_open(filp, sched_base_slice_show, NULL); +} + +static const struct file_operations sched_base_slice_fops =3D { + .open =3D sched_base_slice_open, + .write =3D sched_base_slice_write, + .read =3D seq_read, + .llseek =3D seq_lseek, + .release =3D single_release, +}; + #ifdef CONFIG_SMP =20 static ssize_t sched_scaling_write(struct file *filp, const char __user *u= buf, @@ -505,7 +554,7 @@ static __init int sched_init_debug(void) debugfs_create_file("preempt", 0644, debugfs_sched, NULL, &sched_dynamic_= fops); #endif =20 - debugfs_create_u32("base_slice_ns", 0644, debugfs_sched, &sysctl_sched_ba= se_slice); + debugfs_create_file("base_slice_ns", 0644, debugfs_sched, NULL, &sched_ba= se_slice_fops); =20 debugfs_create_u32("latency_warn_ms", 0644, debugfs_sched, &sysctl_resche= d_latency_warn_ms); debugfs_create_u32("latency_warn_once", 0644, debugfs_sched, &sysctl_resc= hed_latency_warn_once); --=20 2.33.0