From patchwork Sun Aug 27 23:31:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qais Yousef X-Patchwork-Id: 717686 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 16200C83F16 for ; Sun, 27 Aug 2023 23:32:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229577AbjH0XcY (ORCPT ); Sun, 27 Aug 2023 19:32:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjH0XcU (ORCPT ); Sun, 27 Aug 2023 19:32:20 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 494C4D9 for ; Sun, 27 Aug 2023 16:32:17 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31c6cd238e0so2287167f8f.0 for ; Sun, 27 Aug 2023 16:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=layalina-io.20221208.gappssmtp.com; s=20221208; t=1693179136; x=1693783936; 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=TUiAZLE25UP5PNu+kEwnlg+iVrOjDSgPGFYS2eQl6Qk=; b=1lYLM9jj8BcntjwJapi8Vs1a7DRwDl9/ZkXfaYc8TeBsAomajDtHaHsi80//pkWlgV 3qwsTBk+/7iTUhe2/tsHwUSW1gKFeYCekkOEXRaM/KHZGUVrj79GYKHYlgviAfRdAaSe zPPHu8x0CfqtcSnYpK1+rTe4V8sTjR/euYZ3/LLQC9A4LLpazdkeltIjC//VPTPe3cz/ rTdZa+olX7nbsUA+zKk+/JbLOtyb/rm117t3wQqjMZCcMPaFtxrLUvisruFhsGOwNojS Kh2leDDoykJ33nPt1HZkRi/NhKsZjfhOToQ4UWZZ6XLNjdFuflEtIJjQs48C1k0cJ4Xl 03Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693179136; x=1693783936; 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=TUiAZLE25UP5PNu+kEwnlg+iVrOjDSgPGFYS2eQl6Qk=; b=UeAphttamPhMOHNDhcbh6vRbpiF/4LUIDGHOfw7+lO3IFfEDG5DEg7qjkdYflaUVE8 pPIekhM59Kqujo+da180RpQS4tPj/dF0hFXxPHT78SvbHNcrUoWiLj7sAf7iHtqlIKlR t15regOOrwfFDyMa2v3WOEdtS8D1odMZYA7nLBjCVtgsYxUAFOnWJdoVAtnIMDoxteKK h4iFDzl9NUu1OKEm4FPoL89NJmTZNXSlfux3yuS1ACG1GlnKE3YhnWbL1rIfuoW2278z sn7js70YvpQWshR7lKQkXAjcvZuqbQdRiQsClbSXSy2Kwz7cCbypSQy9SUcisLMntwbt RmKw== X-Gm-Message-State: AOJu0YztMcgIlbyqj13ojI2etSfn+OOVteQptbtHLYm+80c259XzYqQV Pin0uVuq2xCVY17xrPwrFQdHVw== X-Google-Smtp-Source: AGHT+IGgPBy9e8n3XpdI/QU8N5OZg9NT4gK9vR0sAWjDjSmuMs1dflKI1vrkQPwpTbVkx8My7SAbQg== X-Received: by 2002:adf:f54a:0:b0:317:597f:3aa6 with SMTP id j10-20020adff54a000000b00317597f3aa6mr20505805wrp.18.1693179135312; Sun, 27 Aug 2023 16:32:15 -0700 (PDT) Received: from airbuntu.. (host109-151-228-137.range109-151.btcentralplus.com. [109.151.228.137]) by smtp.gmail.com with ESMTPSA id 21-20020a05600c029500b003fe1a96845bsm12220395wmk.2.2023.08.27.16.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 16:32:14 -0700 (PDT) From: Qais Yousef To: Ingo Molnar , Peter Zijlstra , "Rafael J. Wysocki" , Viresh Kumar , Vincent Guittot , Dietmar Eggemann Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Lukasz Luba , Qais Yousef Subject: [RFC PATCH 1/7] sched/pelt: Add a new function to approximate the future util_avg value Date: Mon, 28 Aug 2023 00:31:57 +0100 Message-Id: <20230827233203.1315953-2-qyousef@layalina.io> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230827233203.1315953-1-qyousef@layalina.io> References: <20230827233203.1315953-1-qyousef@layalina.io> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Given a util_avg value, the new function will return the future one given a runtime delta. This will be useful in later patches to help replace some magic margins with more deterministic behavior. Signed-off-by: Qais Yousef (Google) --- kernel/sched/pelt.c | 22 +++++++++++++++++++++- kernel/sched/sched.h | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c index 0f310768260c..50322005a0ae 100644 --- a/kernel/sched/pelt.c +++ b/kernel/sched/pelt.c @@ -466,4 +466,24 @@ int update_irq_load_avg(struct rq *rq, u64 running) return ret; } -#endif +#endif /* CONFIG_HAVE_SCHED_AVG_IRQ */ + +/* + * Approximate the new util_avg value assuming an entity has continued to run + * for @delta us. + */ +unsigned long approximate_util_avg(unsigned long util, u64 delta) +{ + struct sched_avg sa = { + .util_sum = util * PELT_MIN_DIVIDER, + .util_avg = util, + }; + + if (unlikely(!delta)) + return util; + + accumulate_sum(delta, &sa, 0, 0, 1); + ___update_load_avg(&sa, 0); + + return sa.util_avg; +} diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 56eeb5b05b50..5f76b8a75a9f 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2997,6 +2997,9 @@ enum cpu_util_type { unsigned long effective_cpu_util(int cpu, unsigned long util_cfs, enum cpu_util_type type, struct task_struct *p); + +unsigned long approximate_util_avg(unsigned long util, u64 delta); + /* * DVFS decision are made at discrete points. If CPU stays busy, the util will * continue to grow, which means it could need to run at a higher frequency