Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2514441rdb; Wed, 21 Feb 2024 09:51:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXTP0G9j2SHSjF1WlSej4NfL5UGzamaE1z5oDmO4jVAK0xE/XaU+U1/TJfRQlMyGazj1Y+84EH/le6iXU/9zCYWvyyLgFUi7MJAPdF3xA== X-Google-Smtp-Source: AGHT+IHGRS24mnPcjHIwHcb5CBpbGukIGCtmKvd8gy8MA/RKdjAhJL4QI6yD/ZUNJOBmY0eN2eQH X-Received: by 2002:a05:6a21:8ccc:b0:1a0:5885:5f9e with SMTP id ta12-20020a056a218ccc00b001a058855f9emr24113685pzb.50.1708537904378; Wed, 21 Feb 2024 09:51:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708537904; cv=pass; d=google.com; s=arc-20160816; b=tflHoLH4qVvp3iezYoIhtns3j4G1SPITTBZVl2lucSRBGpV9qrykNsteT6QbyUzJxw IBor7M0strvkoUOrN5K3nzluWGfP+y34HhKZwbRtHDnV88eIHW6bAwMmpl1t/PNvfbC9 QbIRh0R5xqNtXqkywyahoYhRoL8TW/TQkbn2+wA5LYtpTecqirBQclpbqCOFMVBjkOzG zJN/CpyQdBjrEV6cNtb4ySGq+Uws/UDrTkXkW/2x6lakvi7dlDAU5a8CgZn1ILtaarkj X9xzkvr48wyUtabpn//QUZDoT55C1MBJCNvuavBAQAFhQE+kcu4hF/EfMH7Sb71Ih6Q8 6eyw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=4c6JOQ+FrSe0D6YFyR6qod+/IDocW0FckRUNcekKjE4=; fh=xfieWX8pR2IEZVMTlsk7oMXcQK5m1B189TWU7Bp9X9k=; b=zdEJMqGHl/QqFJBqsRof7baRh/F/3Rleng4ZduBiVJE31XLjbqo/SSUNoKSOrDFcpg Z/wweKyHZV7l+Z71QCs2e/FvsDSkJbhsObM8MbmSIR5Vs3X2/dS0Clo+mNIF9pfGjVxn uc+0HcVg9ao27yXfhzBKuW7qNLXDLIEeLDo7JXGqLfAk9BTSkESReckoK6BMnpsKtT+i eL3cAKd5vazHahfCkSkjuVA1MtG4QydjKYka3qHjzsW473F+YgLpv0CGqP0iCxxzeHju NLqsMUu8L/nw4Yzz1iaId9RqoqFuloJs3Ec4DHIS03zBU4/yuEGzEnvr9l6H/CMf4c2s /4fg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dGvbddyI; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-75227-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75227-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id fn16-20020a056a002fd000b006e3d627f231si7132556pfb.305.2024.02.21.09.51.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 09:51:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75227-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dGvbddyI; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-75227-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75227-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 177B028562F for ; Wed, 21 Feb 2024 17:51:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94DAD84FA5; Wed, 21 Feb 2024 17:51:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dGvbddyI" Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 1C619839F9 for ; Wed, 21 Feb 2024 17:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708537897; cv=none; b=egDJXwcdvv0f141i5+khC+COZrZ3Pn9eT5oVlTHEu8on4A2Hb4U8O71n/EeiTzX5jmmSWGpx86ndlJok1twZ+imJ1uG2JIFFIA93DLyg44BwOZhlZVwo95lJYtv83v21IQ3FKgfU/9GNLKcckYdKLceZDRlTj0zdll0cqyhWaQw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708537897; c=relaxed/simple; bh=Fda278FTR/5zMJ4YPLlXLcjCkr0VfwBO0Aaliz79MDs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=gdYD4186G1IRnqC7ebyz3cgo7/XvF3WBV2n8yQH1EbcyyXfnXVcN948Lw8Umhb5R9Lxg8TpZy2OzWwU0G6E4sgP8rFjKGv3z2GsPXuigCA64Vzvi3J7oeCaDubU0gnDQtxi2f4R/0O0+ZnADZRqrrdkZe4/sES5bwRcQjhdcHhM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=dGvbddyI; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2997c5fe6abso670641a91.1 for ; Wed, 21 Feb 2024 09:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708537895; x=1709142695; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=4c6JOQ+FrSe0D6YFyR6qod+/IDocW0FckRUNcekKjE4=; b=dGvbddyIeumIz6Od+KrvNb3kslvCS3xj46z4eTtCR+TR1QXsym+onhiFVfYsuYXCKB 1/Z4dq98kNTASH6y8h+IJFkDD/a7c1IPtsha4KIH8+ypRj5F+7gay18en9G77OrRV1Mm 5BVvcxQxDGu4K34ZieRVhkyqcfAkWm8F8EyKlkY9RD7YiHS4BUxWbw3/hm8ZPeSiK9e0 VdxTVJ3z5Ca5LMUsfhr6T0friwd6qXJVxLlDh5uW/0LnDcu4MuWCgEjIWjmIsdXJaWn3 L0DP++Pdg9PRjt8WcCa6hwaU3hXx1RpEMsXiXAtd6gxTO+IbZdzuvpZXVc0arZF8tO8D 6inw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708537895; x=1709142695; h=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=4c6JOQ+FrSe0D6YFyR6qod+/IDocW0FckRUNcekKjE4=; b=R4Cbajr5LY2a4MmJy9LE6o7so++Ay5Jc7JcYpR86XZdDqj2pYusGqw171cAX2qcyhw 14o0aVWL0AY3TwimCdM5BTYD4uQTkVG27dEiYhUR11TG1f/sRqLKBsqzVG8zf1GylysA lSccYHc/0yDTsSM1trZN1YMZx5LwXT6jWROAHiS1Vi3wHaKVm2/W7hJ3uPnai8sr3BNv AAz+rfOqfiQ/0GX6r7gMhq088JinmqwbgTSNZ1ui4u+isCcQcmAN617UVk97oGeu5gTZ kOOKB0TxRgTbsXeviv7Qp9yHjfwMnBCwbA/7LMYXIy3mPrVPJHTGhEDtmV0kXsT2oQ/7 N+aw== X-Forwarded-Encrypted: i=1; AJvYcCVJYL7XVRGuKqDbbh4DBHVFLY91sM3uwSr0YkHjZZS1EDfeuEoS1feQSvStB126ap/1D1AJazDJNRWcPpWLsA60C7oG+tRCOqLxcvWn X-Gm-Message-State: AOJu0YxZSFkAt2FFjSa+ISjPQ3VZlWvi6c9CwPYo39GYDBtFlVinwhkF 2J563xosqsa4jNRRfm42i6nDsDXuCok85pSuX/RVXzB30y0MgjzUot+QFk19TrCrg7q7B9tdSnB plTQCLFslyVPHf3KGwm2Zx9e06O6pY3WpCFGSxQ== X-Received: by 2002:a17:90a:d157:b0:299:64d8:10ef with SMTP id t23-20020a17090ad15700b0029964d810efmr10391553pjw.10.1708537895370; Wed, 21 Feb 2024 09:51:35 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240220061542.489922-1-zhaoyang.huang@unisoc.com> In-Reply-To: <20240220061542.489922-1-zhaoyang.huang@unisoc.com> From: Vincent Guittot Date: Wed, 21 Feb 2024 18:51:23 +0100 Message-ID: Subject: Re: [PATCH 1/2] sched: introduce helper function to calculate distribution over sched class To: "zhaoyang.huang" Cc: Peter Zijlstra , Ingo Molnar , Juri Lelli , Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Zhaoyang Huang , steve.kang@unisoc.com Content-Type: text/plain; charset="UTF-8" On Tue, 20 Feb 2024 at 07:16, zhaoyang.huang wrote: > > From: Zhaoyang Huang > > As RT, DL, IRQ time could be deemed as lost time of CFS's task, some It's lost only if cfs has been actually preempted > timing value want to know the distribution of how these spread > approximately by using utilization account value (nivcsw is not enough > sometimes). This commit would like to introduce a helper function to > achieve this goal. > > eg. > Effective part of A = Total_time * cpu_util_cfs / cpu_util > > Timing value A > (should be a process last for several TICKs or statistics of a repeadted > process) > > Timing start > | > | > preempted by RT, DL or IRQ > |\ > | This period time is nonvoluntary CPU give up, need to know how long > |/ preempted means that a cfs task stops running on the cpu and lets another rt/dl task or an irq run on the cpu instead. We can't know that. We know an average ratio of time spent in rt/dl and irq contexts but not if the cpu was idle or running cfs task > sched in again > | > | > | > Timing end > > Signed-off-by: Zhaoyang Huang > --- > include/linux/sched.h | 1 + > kernel/sched/core.c | 20 ++++++++++++++++++++ > 2 files changed, 21 insertions(+) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 77f01ac385f7..99cf09c47f72 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -2318,6 +2318,7 @@ static inline bool owner_on_cpu(struct task_struct *owner) > > /* Returns effective CPU energy utilization, as seen by the scheduler */ > unsigned long sched_cpu_util(int cpu); > +unsigned long cfs_prop_by_util(struct task_struct *tsk, unsigned long val); > #endif /* CONFIG_SMP */ > > #ifdef CONFIG_RSEQ > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 802551e0009b..217e2220fdc1 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -7494,6 +7494,26 @@ unsigned long sched_cpu_util(int cpu) > { > return effective_cpu_util(cpu, cpu_util_cfs(cpu), ENERGY_UTIL, NULL); > } > + > +/* > + * Calculate the approximate proportion of timing value consumed in cfs. > + * The user must be aware of this is done by avg_util which is tracked by > + * the geometric series as decaying the load by y^32 = 0.5 (unit is 1ms). > + * That is, only the period last for at least several TICKs or the statistics > + * of repeated timing value are suitable for this helper function. > + */ > +unsigned long cfs_prop_by_util(struct task_struct *tsk, unsigned long val) > +{ > + unsigned int cpu = task_cpu(tsk); > + struct rq *rq = cpu_rq(cpu); > + unsigned long util; > + > + if (tsk->sched_class != &fair_sched_class) > + return val; > + util = cpu_util_rt(rq) + cpu_util_cfs(cpu) + cpu_util_irq(rq) + cpu_util_dl(rq); This is not correct as irq is not on the same clock domain: look at effective_cpu_util() You don't care about idle time ? > + return min(val, cpu_util_cfs(cpu) * val / util); > +} > + > #endif /* CONFIG_SMP */ > > /** > -- > 2.25.1 >