Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1286708lqh; Mon, 6 May 2024 03:05:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVTCptga8LSUehcnb2s/652eUF/xK2RBobv7RVBRnk99zA8cEK+xUsXOO6IaQu81LPQPQ1bIrmc5oXalrSzKQZCGC787w8WE6B14CkF9A== X-Google-Smtp-Source: AGHT+IEk+cuNPe/5Px5kSco5XUxCkgDkR50SgoIvkYeKZaw/icb2ocnaERMuxl6hSWA1x4jz0ooC X-Received: by 2002:a50:9e87:0:b0:56e:2452:f867 with SMTP id a7-20020a509e87000000b0056e2452f867mr6265381edf.37.1714989936966; Mon, 06 May 2024 03:05:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714989936; cv=pass; d=google.com; s=arc-20160816; b=ObdiMwakZVYDA077ngBUJPwlkIddeWg+RimQsNIdWfCjytXCb8KwqURiB3ulfw07Eu NTtkIyTl1BpaI6Y7hNeLmmbv7SVBQPiLXQP7bq7nAEFExzTz/CI93joiE4jtdSRh5yTy mD7XnN6BWdtnRWeATldmiYEjqohckyVCd5OybzZOrIP5QqO8pIcnlVo7dr/oHFb2rHhh yC5LEjmInkR/W5GGe6aacRXJl5S0S2FKXEfvGAjFTfDiEDJ5Jpcv5MoNaIiUURMiBizJ tWDLS9oJDdDkOZ/VoK14kmXm8B0zvnn7R8l81oD6iKcq2MpyuF8pE8W9NqoBHEAo9cDL uCng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gujvUI0jJiy6Uc9SM3tuP8isJLFkBNShH34rayX/gjo=; fh=8TI8d9KpTq9Bv5i1NZMgFvrSzGExbT+PoSxjGmihqJU=; b=z+rdOVTgtupmaJuUjLaBXLexctA7EwYLcUVAyDnZ/BMGCCzmVeHy7J4sRzJSnOCHgq /iyMQy1BBlf5YRB0BPazyymvmAFlqivPxyQHGAGtlZjgsNJjZfTVwANgm0Kx8IohR5SZ j0H7p91/1duwSdUQw3qVF86CYR+5NJaa9yLlMOzhiSyMBsjaJtpE7m6cnido494AEv+H reqUh2n1na6mavLbpLUqgbtVgKcr5otz0tRahhXxi4Jrbm5JUt7nPvyjncxEp5dfZWET NcV66rHJnZNmTIET8oRG54N/70uB9Vm1s+5sLsgnQ1TynunQftcSJshr2MaQ//pkPYbb WD4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Zt7VphGZ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-169638-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169638-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n14-20020aa7db4e000000b00572a201ca34si4783565edt.436.2024.05.06.03.05.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 03:05:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169638-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Zt7VphGZ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-169638-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169638-linux.lists.archive=gmail.com@vger.kernel.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 am.mirrors.kernel.org (Postfix) with ESMTPS id AA5DB1F22DB2 for ; Mon, 6 May 2024 10:05:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2B8F1428EA; Mon, 6 May 2024 10:05:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Zt7VphGZ" Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10BDB4205F; Mon, 6 May 2024 10:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714989927; cv=none; b=CuDlAJGIWJ1nYIj9OfbUbA5TIYesrpo6AtCqIZHUTMOrZoewcYX/sqAD4Z4bFlOy+wZ6dJ4ANSj+7FR95o3oFS8XezR5QrAPzyHUMTo1uhUWFL6ma9gbNALe7R/yH7E1bWYVbLxriPRX80w8sBeTZqq7xjQQ+oxYYVlppzos5Jk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714989927; c=relaxed/simple; bh=PMC3ofutk9JYD37ah6GDWluGJeD9/vKLh7tqGvV6Wko=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kKloFXxTPohlxEc+75kiLDGB+EdDV84rmv4hd1oftwtvVrEJ7d/oLX0YWQ/gMwVr+vRjLI8PMuII+x+ITjlAh1M0g+OkhwhhD9URLhag2yxYhLZZaj4n/EMgcq3Wn1Dt/vda8MId8v4J0gTkuM2aDQbid5poTSyLFy0MYc5MFOA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Zt7VphGZ; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=gujvUI0jJiy6Uc9SM3tuP8isJLFkBNShH34rayX/gjo=; b=Zt7VphGZw/XbV3in9sMkbdqs6i DwJx/nLZJJZCbciPUllM2ReQnRuJd1CtECfrw1HqokhXeznibZE0ZCacmim4zEzhaJ18FnWX+mRCQ +0NaOR8bpvR1InY533f+A7kHhx42/RvF5D5tDqIzQapK6sm7TK4d5qAZcmnnwt5q+4EN45F4zJTtn VslpYSI5iUN/GUdaUig2QP+B2/lDr4D5dqtag/FHzN1tu4yl0U1ENY3kOFqVjmPx0pRsIanlBMZiZ PtMvVhveUCGLc/GOkRsNhADWH6soXkJ1IOpIoR8C5C+1ACx8PA3il82I+dWRHun3x8K+u7lwIYYm0 +i1jChLQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s3vDZ-00000001fVA-1ytr; Mon, 06 May 2024 10:05:10 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 1A972300362; Mon, 6 May 2024 12:05:09 +0200 (CEST) Date: Mon, 6 May 2024 12:05:09 +0200 From: Peter Zijlstra To: Qais Yousef Cc: "Rafael J. Wysocki" , Viresh Kumar , Ingo Molnar , Vincent Guittot , 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 Subject: Re: [PATCH v2] sched: Consolidate cpufreq updates Message-ID: <20240506100509.GL40213@noisy.programming.kicks-ass.net> References: <20240505233103.168766-1-qyousef@layalina.io> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240505233103.168766-1-qyousef@layalina.io> On Mon, May 06, 2024 at 12:31:03AM +0100, Qais Yousef wrote: > +static inline void update_cpufreq_ctx_switch(struct rq *rq, struct task_struct *prev) > +{ > +#ifdef CONFIG_CPU_FREQ > + unsigned int flags = 0; > + > +#ifdef CONFIG_SMP > + if (unlikely(current->sched_class == &stop_sched_class)) > + return; > +#endif why do we care about the stop class? It shouldn't, in general, consume a lot of cycles. > + > + if (unlikely(current->sched_class == &idle_sched_class)) > + return; And why do we care about idle? Specifically this test doesn't capture force-idle threads. Notably see is_idle_task(). > + > + if (unlikely(task_has_idle_policy(current))) > + return; > + > + if (likely(fair_policy(current->policy))) { > + > + if (unlikely(current->in_iowait)) { > + flags |= SCHED_CPUFREQ_IOWAIT | SCHED_CPUFREQ_FORCE_UPDATE; > + goto force_update; > + } > + > +#ifdef CONFIG_SMP > + /* > + * Allow cpufreq updates once for every update_load_avg() decay. > + */ > + if (unlikely(rq->cfs.decayed)) { > + rq->cfs.decayed = false; > + goto force_update; > + } > +#endif > + return; > + } > + > + /* > + * RT and DL should always send a freq update. But we can do some > + * simple checks to avoid it when we know it's not necessary. > + */ > + if (rt_task(current) && rt_task(prev)) { IIRC dl tasks also match rt_task, so your else clause might not work the way you've intended. > +#ifdef CONFIG_UCLAMP_TASK > + unsigned long curr_uclamp_min = uclamp_eff_value(current, UCLAMP_MIN); > + unsigned long prev_uclamp_min = uclamp_eff_value(prev, UCLAMP_MIN); > + > + if (curr_uclamp_min == prev_uclamp_min) > +#endif > + return; > + } else if (dl_task(current) && current->dl.flags & SCHED_FLAG_SUGOV) { Notably DL tasks also match rt_task(), so I don't think this clause exactly does as you expect. Also, isn't the flags check sufficient on it's own? > + /* Ignore sugov kthreads, they're responding to our requests */ > + return; > + } > + > + flags |= SCHED_CPUFREQ_FORCE_UPDATE; > + > +force_update: > + cpufreq_update_util(rq, flags); > +#endif > +} But over-all the thing seems very messy, mixing sched_class, policy and prio based selection methods. Can't this be cleaned up somewhat? Notably, if you structure it something like so: if (fair_policy(current)) { ... return; } if (rt_policy(current)) { if (dl_task(current) && current->dl.flags & SCHED_FLAG_SUGOV) return; if (rt_policy(prev) && uclamps_match(current, prev)) return; ... return; } /* everybody else gets nothing */ return; You get a lot less branches in the common paths, no?