Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp493815lqh; Tue, 7 May 2024 05:54:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUewiYy+mkDWxZFDK5NMz+v08ISYUHJyE2ezeogYKy7899lcrUpcTjaosxYf5kP4LFkyaD8/8cIhyx6c6orXuCkKcU62Gh1JABKhy3hAg== X-Google-Smtp-Source: AGHT+IEuFCiU8zczQsm9dKhvJOSA5817vy3pkddkYQv9gHc0OsDHT6d5akPGTWmd28AkYaC1Edr3 X-Received: by 2002:a17:90a:4889:b0:2b5:afcf:10bf with SMTP id b9-20020a17090a488900b002b5afcf10bfmr3675096pjh.0.1715086451909; Tue, 07 May 2024 05:54:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715086451; cv=pass; d=google.com; s=arc-20160816; b=kRgcTGYvSLu7+A/aZ1bAqLZrrSbTtBHbZClByXlJbSHSyJHnLNVAWERMxhu7NJzz6c scPdctZXkLj2nKJqmlNpjvDjTAMuk8YyYQVn80yGJraJm/2FvJuCtK9Jve1oiCnHiAOj c1DvMtuukW1YZpq/Fh7c38/PRqfoTdqfq4R4S+Tve7WPmBVs+DlVhlPffdJwbFNGxP8W zhncUIOoPWWjiGBwhUcBbd1H3opefg79Cjmoec0yFG9jfS1MCt5t7AUZ/9jRhml8Pl3W V0/xMx5HH+TCb1A0n1yqmjmfOs/jmCYKBzWnBVXPmoeOm1ZcRqWAMuIarof5xyZElEPT CtSA== 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=qXGfUlEuyq9acMc9wdmCRc4sbAYNXOqxy6N3x85FJp4=; fh=sHzDc6uCeqO95PnBo831lXoA5Bf29sMTK6CVAPGDPK4=; b=DnWUTO1RZgfD8izqC20YLgEFz+Bmy78UcxWAj8XwRnkurXvzQKm9yKeXPJiE91jLmI 5dl+ENLlMpxo1KgHqYpEb++KIccfHMLEza7SKv9ntUtrmcFc2cIM/Kz2U6Bp71zCkWWO LxaIsXShYGUxd7kiDbHdesC0H3V+ABO06s0TzCQOccT7ItEgWsF7SUNEw8gI689DuudE 7/sQg9qArAlr3S43jr1DQIYD1BTHj9KUkcecrJ7hk8qTthWhne513Jo3pamuGDlAf5kf 4Qogto2BIKAZs6SofEesmvIMtDphg66J0C1tP4yJBnwgpLO11YClwJnV1Y6JG3VQwF3o Cgsg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QmKz/7si"; 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-171318-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171318-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id gv9-20020a17090b11c900b002a52f22f658si10035652pjb.126.2024.05.07.05.54.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 05:54:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171318-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QmKz/7si"; 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-171318-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171318-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 8760428BB77 for ; Tue, 7 May 2024 12:54:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBD1015D5A1; Tue, 7 May 2024 12:54:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="QmKz/7si" Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (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 6414C156885 for ; Tue, 7 May 2024 12:54:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715086441; cv=none; b=DKS131XMWam6WSoCPTI8A5xjuAQV7Xt3qCYVW6BAc1UBxJ1/wWawAuIxOdHLzBlV9JeRIBE8o5QE9gWFUbK2LH8L+f9uOEhGPkDyec589gAiZU9jjpJjxu2zJNKzwleKvOg22Wn4d4eXXlzVvQTLheIbMO/i76+smyRldNusK0Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715086441; c=relaxed/simple; bh=qXGfUlEuyq9acMc9wdmCRc4sbAYNXOqxy6N3x85FJp4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=sRGS/8PwPaDH2XU22FJHh8RokCNQwrsDGTAbxfL870Dg6RHdRDIqhMst3vDGD2za/a5C1gxrlt6QxH5Bn0m12BBZIccFXDVKcUYIP2AKlzpAdtA5hdKZlDYhXUnlmWAKW6qdXYMhuwuzM3kPi7eGGomowrML8pTfYTirFf3rCLI= 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=QmKz/7si; arc=none smtp.client-ip=209.85.215.175 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-pg1-f175.google.com with SMTP id 41be03b00d2f7-5e4f79007ffso2071692a12.2 for ; Tue, 07 May 2024 05:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715086440; x=1715691240; 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=qXGfUlEuyq9acMc9wdmCRc4sbAYNXOqxy6N3x85FJp4=; b=QmKz/7si5sk2ZXhDFfHm4Abf4ivIBe+F8/ofEZwcQM6a1sH52euRDjf1S4sFC4JZXe QJHq0XNWEv14zgxHPhrg1AdTzEKyHT6UR5NIcBeiq64oANkoFufMvh/PpM15KyRH+vtG Z32UxiV+6US1OyOlTs/NNpmtDtMQC6+7BLPQ8HN2ITL3shQZGHt/gyF2zQE2lmn9uTF4 TMaMlNfH8V1YLsuVf8JENZ6gzgdOhgDieRM/HTW24gD2DV/23T4oh+XhADHLxga2cG2y zLJv2oF3L5h7H3p6QoIVexAKiq8FFgEP9sM+wkSYvd5LC7UBeIUnoGm7W4iGFUJOR0Hl XkBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715086440; x=1715691240; 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=qXGfUlEuyq9acMc9wdmCRc4sbAYNXOqxy6N3x85FJp4=; b=kUQGt84AWRetPbmELSphksn3kEtMP4qIJha6jBQSdH0KFhuhZ2fpQDG1Br0TDX//NZ lVHd7tN/0/PpO1vFlziOGnkPusWFbN8GLD/Zy6itnm5b6ox6cvpVnM4rGVVkSkkUmoq7 jN3SeyD3c+i1i32L4Juw5JIS4VZW2CuX42mcTDqsuEmSZLX5BRQOqSdUpCVsmVpvDHQp Cf244o21nsASbhL9fP2RC40iRTtxUZpRM+UdpBiBuIOLIM91GE+d4nQIv32Q4+QPO9NQ cXkEYmufxmtan0iqPQZ3gfldV84rgt0dWEs5y5XMa+EaVNXpW/TxAhFcXqqVpiOpEsOZ GRrQ== X-Forwarded-Encrypted: i=1; AJvYcCXe+SH4xheY98rhYcQ96rqwCGXh0rgTmc5bunv1jNqdXKpQsqbq23/6Q0/PknNgy71XHX3mY2DQOk/ARMPIQaZ0YDw5yL9y8D+Y300w X-Gm-Message-State: AOJu0Yz5S4mqXBWBjBZ5JLyUaUaFtej21NrI+XDFJ1uqky5qyLorrE4y A1NIe7lenw1rhD41CBVRuhwjdXBuUu1vgYh4z2tDvyNjxKZSilNdmR+7QsqRwPC4xnF6V7em29o TF0sUEW1M4gdpYRYlJ3nop+MDGu6DdKUQXgoKoA== X-Received: by 2002:a17:90a:930c:b0:2a1:f586:d203 with SMTP id p12-20020a17090a930c00b002a1f586d203mr10241315pjo.41.1715086438068; Tue, 07 May 2024 05:53:58 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240505233103.168766-1-qyousef@layalina.io> <20240507110809.a45amdmhy5vr5cuw@airbuntu> In-Reply-To: <20240507110809.a45amdmhy5vr5cuw@airbuntu> From: Vincent Guittot Date: Tue, 7 May 2024 14:53:46 +0200 Message-ID: Subject: Re: [PATCH v2] sched: Consolidate cpufreq updates To: Qais Yousef Cc: "Rafael J. Wysocki" , Viresh Kumar , Ingo Molnar , Peter Zijlstra , Juri Lelli , Steven Rostedt , Dietmar Eggemann , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Christian Loehle , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Tue, 7 May 2024 at 13:08, Qais Yousef wrote: > > On 05/07/24 10:58, Vincent Guittot wrote: > > On Mon, 6 May 2024 at 01:31, Qais Yousef wrote: > > > > > > Improve the interaction with cpufreq governors by making the > > > cpufreq_update_util() calls more intentional. > > > > > > At the moment we send them when load is updated for CFS, bandwidth for > > > DL and at enqueue/dequeue for RT. But this can lead to too many updates > > > sent in a short period of time and potentially be ignored at a critical > > > moment due to the rate_limit_us in schedutil. > > > > > > For example, simultaneous task enqueue on the CPU where 2nd task is > > > bigger and requires higher freq. The trigger to cpufreq_update_util() by > > > the first task will lead to dropping the 2nd request until tick. Or > > > another CPU in the same policy triggers a freq update shortly after. > > > > > > Updates at enqueue for RT are not strictly required. Though they do help > > > to reduce the delay for switching the frequency and the potential > > > observation of lower frequency during this delay. But current logic > > > doesn't intentionally (at least to my understanding) try to speed up the > > > request. > > > > > > To help reduce the amount of cpufreq updates and make them more > > > purposeful, consolidate them into these locations: > > > > > > 1. context_switch() > > > > I don't see any cpufreq update when switching from idle to CFS. We > > You mean SCHED_IDLE to SCHED_NORMAL, right? Yes, if we switch policies even > from fair to RT an update could be missed. No I mean going out of idle. On an idle cpu, nothing happens at CFS task wakeup and we have to wait for the next tick to apply the new freq. This happens for both short task with uclamp min or long running/sleeping task (i.e. with high util_est) > > I'll need to think more about it, but I think adding an update when we switch > policies in the syscall looks sufficient to me, if the task is on rq already. > Agreed? > > > have to wait for the next tick to get a freq update whatever the value > > of util_est and uclamp > > > > > 2. task_tick_fair() > > > > Updating only during tick is ok with a tick at 1000hz/1000us when we > > compare it with the1048us slice of pelt but what about 4ms or even > > 10ms tick ? we can have an increase of almost 200 in 10ms > > IMHO the current code can still fail with these setups to update frequencies in > time. If there's a single task on the rq, then the only freq update will happen > at tick. So this is an existing problem. But any newly enqueued task can trigger a freq update without waiting 1/4/10ms whereas we need to wait for next tick with this patch > > The way I see it is that setting such high TICK values implies low > responsiveness by definition. So the person who selects this setup needs to > cater that their worst case scenario is that and be happy with it. And this > worst case scenario does not change. > > That said, the right way to cater for this is via my other series to remove the > magic margins. DVFS headroom should rely on TICK value to ensure we run at > adequate frequency until the next worst case scenario update, which relies on > TICK. Which is sufficient to handle util_est changes. See below for uclamp. > > Wake up preemption should cause context switches to happen sooner than a tick > too as we add more tasks on the rq. So I think the worst case scenario is not > really changing that much. In my view, it's better to be consistent about the > behavior. > > > > > > 3. {attach, detach}_entity_load_avg() > > > > At enqueue/dequeue, the util_est will be updated and can make cpu > > utilization quite different especially with long sleeping tasks. The > > same applies for uclamp_min/max hints of a newly enqueued task. We > > might end up waiting 4/10ms depending of the tick period. > > uclamp_min is a property of the task. And waiting for the task that needs the > boost to run is fine IMHO. And I am actually hoping to remove uclamp max() But you will delay all CPU work and the running time fo the task And what about util_est ? > aggregation in favour of applying boosts/caps when tasks are RUNNING. But more > things need to be improved first. > > We are missing a freq update when uclamp values change by the way. This is > a known bug and I keep forgetting to post a patch to fix it. Let me do this > along update freq when policy changes. > > Thanks!