Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5717134rwb; Mon, 5 Dec 2022 03:11:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf5tCL7GdoiHBNStJ6ALDswlspCu7mN6jnpI7b1A3TSaogbw2Pr/MyXbGh2bD/B2lCXeOTa2 X-Received: by 2002:a17:90b:3c85:b0:218:4a32:1924 with SMTP id pv5-20020a17090b3c8500b002184a321924mr90884248pjb.24.1670238686445; Mon, 05 Dec 2022 03:11:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670238686; cv=none; d=google.com; s=arc-20160816; b=NjF/19ktQPpfXOP2I8vfTBrQWVQCrAi0zlYZT6PWWYa85ppHYUZ25Osz3mTfLoI8tu /7qyjtvZercUwJj0u4wlYyZ53NzZ9GqqgTOL24Lh3+GCB06Zg/0GAf2qcGapXXp/3aLc SurcWES1nbgy9REnMBnLENfxDQKhj+0G5dBisl+XKvGAaLTe7Qx6bzfEmAYDwX+VbZ20 NkiEXyj7WjG37CPDNI3ETA5vV6uWsiPM/H4koIy9CWLQ/dSg0D+WXBjnBe4KEvF7/kXC vd2dnMnakOkEiFYONHyBDwUkIAq+r9bIvjj2UvknxAM+GYndCCsfR6VRtDLu0RXiX8Co nhKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=hd5qIitc5st6tCQXO3G+rJW6Qfu7Fi9EIJWTKkLH8RE=; b=R2IAC/644urS+Psg1W8oH5wCpD9EItKbs5NFxs5GvP+hchgpoS2nyemDw7QNGuAnv5 V4Q8WzFjE+8+7D8Ag5toj2xZEGN8rB98do5ELEvduN+XOunm6ibKkQYtoEPVvSVfjDnB KLDs5/FadA2WIOLlUm78PuA9GEzA0pEdo9BFJFUOb2VmgMpKbY0Ez4c0ZbCjKFfwHe3z Fu6+RNKnDBxWPdNiERqzPgRpqYYQtvSqKDf09YxRAOo9tecfiqMJrYCD7JWx/Iz1ptg3 /DIz+e76tvNaBmEhg/z+zXvv7Al7T8BPJtkBTaJfAsydzOIdWEFhrNsK3jSDpj26mVTx Wu9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Zzfuv0eV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 73-20020a63034c000000b00478446557b9si10104205pgd.677.2022.12.05.03.11.14; Mon, 05 Dec 2022 03:11:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Zzfuv0eV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbiLEJ7Y (ORCPT + 82 others); Mon, 5 Dec 2022 04:59:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231487AbiLEJ7U (ORCPT ); Mon, 5 Dec 2022 04:59:20 -0500 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F88BDF8D for ; Mon, 5 Dec 2022 01:59:19 -0800 (PST) Received: by mail-il1-x12c.google.com with SMTP id m15so4870432ilq.2 for ; Mon, 05 Dec 2022 01:59:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=hd5qIitc5st6tCQXO3G+rJW6Qfu7Fi9EIJWTKkLH8RE=; b=Zzfuv0eVoa4L46mknEqr92eiI6b21awhnrd4/xYvwHIBeNl7dG9cl3d7LVFZDe3Isk XCeB//P8QMVAIBDOpdse77S3JiHccKt/iMCaeWLMzOsygHwK+MbO7RanTS/sBDoD/3Mm xvYnflmpLahL/w1mNl/rmKCbaIW1prnvJjS5L+HJqirKNhdH4uD+JCxlcTcTuYvsXSLu 2dhzNGGttxz8JKdMGQtpkl3GZyqLUyvEnRxoog9v5szmCvUPhh81ivFH1zHqeZOv0lTV zjqiQSr7ifq+w5tQf2gnVYUMxsPQdcFlbl9wIam9TCsHG7HbcowZ3D66zqeLUW89hH53 OOnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hd5qIitc5st6tCQXO3G+rJW6Qfu7Fi9EIJWTKkLH8RE=; b=EIY3DJIWJ8SCoXuU0TlxVXUAHoLnYJ4hRtSkkK4rrqOKAaelmKnFRvoWgYVkyB48kh 7sZJEd8MBxI4HyOWlg3XsbHKnKdFQO2oAujpuul6ztBt3WK5IevwNyUMFmMTuE8ZQoAr /yHUQC4cBZqTcNvBRvUZ7oSS9XA6X+VA3/EVWvA+PYEqy69vl4lqeYtw1szPacHQcbYM KWAlqiGJ/zOJnKjpnHLw7wN7VZprPwKj1qjx6sU9XLr/0pMUwxpO4rEwJfcfcClMkQv0 wiFle92xGqphWo8aOfKR6FI+tnsHIsmR4C+fpqB5P1j2vUoI5ZLth1Izqcmtkc8DQr4U Mefw== X-Gm-Message-State: ANoB5pnLRMN0oFgVzFMJDTqt1ZoJti1VjOPszTqBYHeuJYFUwnBuBrxs UbGwiQYFodsDPDCOdsw56HEvsSW19wSFo2s9D+LtfQ== X-Received: by 2002:a05:6e02:5c6:b0:303:22ca:60ca with SMTP id l6-20020a056e0205c600b0030322ca60camr13358679ils.22.1670234358271; Mon, 05 Dec 2022 01:59:18 -0800 (PST) MIME-Version: 1.0 References: <3A5DA66F-4330-4FC4-9229-998CF98F663E@joelfernandes.org> In-Reply-To: From: Vincent Guittot Date: Mon, 5 Dec 2022 10:59:06 +0100 Message-ID: Subject: Re: [PATCH v3 1/2] sched/fair: Introduce short duration task check To: Chen Yu Cc: Joel Fernandes , Honglei Wang , Peter Zijlstra , Tim Chen , Mel Gorman , Juri Lelli , Rik van Riel , Aaron Lu , Abel Wu , K Prateek Nayak , Yicong Yang , "Gautham R . Shenoy" , Ingo Molnar , Dietmar Eggemann , Steven Rostedt , Ben Segall , Daniel Bristot de Oliveira , Valentin Schneider , Hillf Danton , Len Brown , Chen Yu , Tianchen Ding , Josh Don , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 5 Dec 2022 at 09:39, Chen Yu wrote: > > Hi Joel, > On 2022-12-03 at 10:35:46 -0500, Joel Fernandes wrote: > > > > > > > On Dec 3, 2022, at 2:50 AM, Chen Yu wrote: > > > > > > =EF=BB=BFHi Honglei, > > >> On 2022-12-02 at 15:44:18 +0800, Honglei Wang wrote: > > >> > > >> > > >>> On 2022/12/1 16:44, Chen Yu wrote: > > >>> Introduce short-duration task checks, as there is requirement > > >>> to leverage this attribute for better task placement. > > >>> > > >>> There are several choices of metrics that could be used to > > >>> indicate if a task is a short-duration task. > > >>> > > >>> At first thought the (p->se.sum_exec_runtime / p->nvcsw) > > >>> could be used to measure the task duration. However, the > > >>> history long past was factored too heavily in such a formula. > > >>> Ideally, the old activity should decay and not affect > > >>> the current status too much. > > >>> > > >>> Although something based on PELT could be used, se.util_avg might > > >>> not be appropriate to describe the task duration: > > >>> 1. Task p1 and task p2 are doing frequent ping-pong scheduling on > > >>> one CPU, both p1 and p2 have a short duration, but the util_avg > > >>> can be up to 50%. > > >>> 2. Suppose a task lasting less than 4ms is regarded as a short task= . > > >>> If task p3 runs for 6ms and sleeps for 32ms, p3 should not be a > > >>> short-duration task. However, PELT would decay p3's accumulated > > >>> running time from 6ms to 3ms, because 32ms is the half-life in P= ELT. > > >>> As a result, p3 would be incorrectly treated as a short task. > > >>> > > >>> It was found that there was once a similar feature to track the > > >>> duration of a task, which is in Commit ad4b78bbcbab ("sched: Add > > >>> new wakeup preemption mode: WAKEUP_RUNNING"). Unfortunately, it > > >>> was reverted because it was an experiment. So pick the patch up > > >>> again, by recording the average duration when a task voluntarily > > >>> switches out. Introduce SIS_SHORT to control this strategy. > > >>> > > >>> The threshold of short duration reuses sysctl_sched_min_granularity= , > > >>> so it can be tuned by the user. Ideally there should be a dedicated > > >>> parameter for the threshold, but that might introduce complexity. > > >>> > > >>> Suggested-by: Tim Chen > > >>> Suggested-by: Vincent Guittot > > >>> Signed-off-by: Chen Yu > > >>> --- > > >>> include/linux/sched.h | 4 ++++ > > >>> kernel/sched/core.c | 2 ++ > > >>> kernel/sched/fair.c | 17 +++++++++++++++++ > > >>> kernel/sched/features.h | 1 + > > >>> 4 files changed, 24 insertions(+) > > >>> > > >>> diff --git a/include/linux/sched.h b/include/linux/sched.h > > >>> index ffb6eb55cd13..64b7acb77a11 100644 > > >>> --- a/include/linux/sched.h > > >>> +++ b/include/linux/sched.h > > >>> @@ -558,6 +558,10 @@ struct sched_entity { > > >>> u64 nr_migrations; > > >>> + u64 prev_sum_exec_runtime_vol; > > >>> + /* average duration of a task */ > > >>> + u64 dur_avg; > > >>> + > > >>> #ifdef CONFIG_FAIR_GROUP_SCHED > > >>> int depth; > > >>> struct sched_entity *parent; > > >>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > >>> index daff72f00385..c5202f1be3f7 100644 > > >>> --- a/kernel/sched/core.c > > >>> +++ b/kernel/sched/core.c > > >>> @@ -4348,6 +4348,8 @@ static void __sched_fork(unsigned long clone_= flags, struct task_struct *p) > > >>> p->se.prev_sum_exec_runtime =3D 0; > > >>> p->se.nr_migrations =3D 0; > > >>> p->se.vruntime =3D 0; > > >>> + p->se.dur_avg =3D 0; > > >>> + p->se.prev_sum_exec_runtime_vol =3D 0; > > >>> INIT_LIST_HEAD(&p->se.group_node); > > >>> #ifdef CONFIG_FAIR_GROUP_SCHED > > >>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > >>> index e4a0b8bd941c..a4b314b664f8 100644 > > >>> --- a/kernel/sched/fair.c > > >>> +++ b/kernel/sched/fair.c > > >>> @@ -6200,6 +6200,16 @@ static int wake_wide(struct task_struct *p) > > >>> return 1; > > >>> } > > >>> +/* > > >>> + * If a task switches in and then voluntarily relinquishes the > > >>> + * CPU quickly, it is regarded as a short duration task. > > >>> + */ > > >>> +static inline int is_short_task(struct task_struct *p) > > >>> +{ > > >>> + return sched_feat(SIS_SHORT) && > > >>> + (p->se.dur_avg <=3D sysctl_sched_min_granularity); > > >>> +} > > >>> + > > >> > > >> Hi Yu, > > >> > > >> I still have a bit concern about the sysctl_sched_min_granularity st= uff.. > > >> This grab can be set to different value which will impact the action= of this > > >> patch and make things not totally under control. > > > > There are already ways to misconfigure sched sysctl to make bad/weird t= hings happen. > > > > >> Not sure if we can add a new grab for this.. The test result shows g= ood > > >> improvement for short task, and with this grab, admins will be able = to > > >> custom the system base on their own 'short task' view. > > >> > > > It would be ideal to have a dedicated parameter to tweak this. For ex= ample, > > > something under /sys/kernel/debug/sched/, and initilized to sysctl_sc= hed_min_granularity > > > by default. > > > > It would be nice to not have to introduce a new knob for this. IMO, min= _granularity is reasonable. > > > OK, got it, thanks for the suggestion. Sorry for the late answer. We don't want to add more dedicated knobs. So using sysctl_sched_min_granularity as you are doing in this patch looks ok > > thanks, > Chenyu