Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5854538rwb; Mon, 5 Dec 2022 05:08:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf7gSe5hiACVjEZVyzJGTkfZYW8xJjYTba4HJR2lAv05RD+bOrTiauo0bYsFaOnLnMb+7u4f X-Received: by 2002:a17:903:26d1:b0:189:c429:f61c with SMTP id jg17-20020a17090326d100b00189c429f61cmr11990527plb.63.1670245715535; Mon, 05 Dec 2022 05:08:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670245715; cv=none; d=google.com; s=arc-20160816; b=D7eYejP1Tt3tKQJYOqEHHZSayOptoFFwd50V0KKMBvvFcUAQ+tgbLXkYXDG2DwCZaa wJnKj453NtOPKIaeoFZuWfXl7omRq5Gpja7gtY8i/Ek8ELCSePAAIfk91hNXVNIjV6vt yFWWxCV48rYcLXceW3iF6olqlnhulAkBeHyBFg88wuC26gvRwHZY3RvH2/IvX48fU0WR oQom6nojMfbTtHsWeEAfpKkdou5/VZOkC6VhQfDFTX4zYeDHHFf70sgxnUH2tMTiIOPF E1S3FwShFOUE+7WeFbru5mS7+6q2WouvZYWScXv1W0gfo0lig0M9ENBK22ijbybYxqSn ag/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=N9AByblogyksZmUUDYbnQyVNZj7XMWQtmh4r5hKiB7g=; b=zFAiFn6Br/Vk9YMHietJov4SRqYzFTwqJdAd7yPyjQ12tE36ajNqExs6Br0Zocgu5H z6ZNKusqDPjOe14+EguAYua67m4SXRmS96n6YRo4bydziw+4MmGk1LehS/Mr6ZJbtvCa XfrwsckllpppOBXmcn9/TZKN2dFPJze1CJookxk6hIPQe91AS4YGPKlDWin3P+KxDe1x x4OIwCFGpt2Z9O6huKIHA8EM/xFIF6AniEAPtCwsGpnhe31IcCuJAVvDLSjG7tKZSuDx 9IP+w5eLbmGg+LGUrD/lIu4S0LBjzuVJoxjWwkpszr7iTrTGp8yyuWuaoVnb/QmemDOM JZUQ== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k7-20020a056a00134700b00558991a667esi15371111pfu.359.2022.12.05.05.08.22; Mon, 05 Dec 2022 05:08:35 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231880AbiLEMkW (ORCPT + 83 others); Mon, 5 Dec 2022 07:40:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231819AbiLEMkI (ORCPT ); Mon, 5 Dec 2022 07:40:08 -0500 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECA701A808; Mon, 5 Dec 2022 04:40:07 -0800 (PST) Received: by mail-qk1-f174.google.com with SMTP id k2so4781867qkk.7; Mon, 05 Dec 2022 04:40:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=N9AByblogyksZmUUDYbnQyVNZj7XMWQtmh4r5hKiB7g=; b=wxBS0fJ1lmwiwMEoEdaQWdjPpas0pU4AYBJyctcII+bk0tdHaLWW+fj+aaNpl8aKyE KPRbT/6NqTH1rlECTvmlM6ozZ7LEmozTFoc0qLkJ/hMJD/mlElj6czDEXl1a6Uk1phtq C/LZdkes1uDmyY2D0S3IQqVNfnCl3YF6K6DHlddd7aMYTyn/IOT6rxevDJ7RpRIjN+U8 Ip565WSbDQdJoa64piDmH3upYenhLOGocc83isZApXI11YX4e2Kfv7xe2B5Y/5LTKcs8 TLmpgxqPeyaHd4AvvxhhdJ2d/KQgiW6uiTqVhL1wzQC66CNSxGWtZ9BESipzf27gnhvC zzyg== X-Gm-Message-State: ANoB5pk8yvrCVY/L2q9hJ9oBgsJpY/9UvduOHj3k8S3ZHxAL4g15lNQh yAheUtpPWfn2qAGmo6SVgHd9CGpDcI+lwntkbAY= X-Received: by 2002:a05:620a:4611:b0:6fa:af7e:927c with SMTP id br17-20020a05620a461100b006faaf7e927cmr71442383qkb.443.1670244007067; Mon, 05 Dec 2022 04:40:07 -0800 (PST) MIME-Version: 1.0 References: <20221127141742.1644023-1-qyousef@layalina.io> <20221127141742.1644023-4-qyousef@layalina.io> <20221203143216.oezd2u6dpxodpuc3@airbuntu> In-Reply-To: <20221203143216.oezd2u6dpxodpuc3@airbuntu> From: "Rafael J. Wysocki" Date: Mon, 5 Dec 2022 13:39:52 +0100 Message-ID: Subject: Re: [RFC PATCH 3/3] sched/fair: Traverse cpufreq policies to detect capacity inversion To: Qais Yousef Cc: "Rafael J. Wysocki" , Ingo Molnar , Peter Zijlstra , Vincent Guittot , Dietmar Eggemann , Viresh Kumar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Lukasz Luba , Wei Wang , Xuewen Yan , Hank , Jonathan JMChen Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 Sat, Dec 3, 2022 at 3:32 PM Qais Yousef wrote: > > On 11/30/22 19:27, Rafael J. Wysocki wrote: > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > > index 7c0dd57e562a..4bbbca85134b 100644 > > > --- a/kernel/sched/fair.c > > > +++ b/kernel/sched/fair.c > > > @@ -8856,23 +8856,20 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu) > > > * * Thermal pressure will impact all cpus in this perf domain > > > * equally. > > > */ > > > - if (sched_energy_enabled()) { > > > + if (static_branch_unlikely(&sched_asym_cpucapacity)) { > > > unsigned long inv_cap = capacity_orig - thermal_load_avg(rq); > > > - struct perf_domain *pd = rcu_dereference(rq->rd->pd); > > > + struct cpufreq_policy *policy, __maybe_unused *policy_n; > > > > > > rq->cpu_capacity_inverted = 0; > > > > > > - SCHED_WARN_ON(!rcu_read_lock_held()); > > > - > > > - for (; pd; pd = pd->next) { > > > - struct cpumask *pd_span = perf_domain_span(pd); > > > + for_each_active_policy_safe(policy, policy_n) { > > > > 1. Is the "safe" part sufficient for protection against concurrent > > deletion and freeing of list entries? cpufreq driver removal can do > > that AFAICS. > > The freeing part is not safe probably. Well, I don't even think that the traversal part is safe against concurrent removal of list entries (it is safe against removal of list entries in the loop itself). list_for_each_entry_safe() assumes that n will always point to a valid list entry, but what if the entry pointed to by it is deleted by a concurrent thread? > I need to research this more. Do you > have issues against the exportation of this traversal in principle? > > Switching them to be RCU protected could be the best safe option, anything > against that too? Not really, it just occurred to me that you may end up dealing with a corrupted list here. > I might not end up needing that. I need to dig more. > > > 2. For a casual reader of this code it may not be clear why cpufreq > > policies matter here. > > I'm looking for a way to traverse the list of capacities of the system and > know their related CPUs. So why don't you mention this in a comment, for instance? > AFAICT this information already exists in the performance domains and > cpufreq_policy. Performance domains are conditional to energy model and > schedutil. So trying to switch to cpufreq_policy. > > Assuming this question wasn't a request to add a comment :-) Yes, it was. :-) That said though, this change makes the scheduler kind of depend on cpufreq which feels a bit like a corner cut TBH. I do realize that cpufreq happens to be maintaining a data structure that turns out to be useful here, but the reason why it is there has nothing to do with this code AFAICS.