Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1811661rbb; Tue, 27 Feb 2024 01:43:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWWqSL6AVtsZzOHoE7pQZScvMCSxyNC2esx5Gnskt+SgETe/cC/h133LfP+jgRmUIWbQlMnQKXchFg1kTB/N0w9u4D/YGFB+RJVSni+nQ== X-Google-Smtp-Source: AGHT+IFoqwwOmQYGxry1PJF8ZJwZrVq4LTFmK/8HKML1ISZ+TQlSAL6Zs5I1h0Oc/ADmkaH0siRZ X-Received: by 2002:a25:b783:0:b0:dc7:48ef:433e with SMTP id n3-20020a25b783000000b00dc748ef433emr1663960ybh.10.1709027039277; Tue, 27 Feb 2024 01:43:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709027039; cv=pass; d=google.com; s=arc-20160816; b=O3kNvl7z984vbpH14MxZQbQBLvHF9bDbT1njsXcnA9aQ7DA763PB8HhvQtsnX2y2aD OoeS70TEqa7FTwX6wREZUQ5jWAcHa8zw97m+ae7PE7ajgH3ddTCQ9KlP07UdMb0rCQYZ u5xoPab3EWNvRkSLQdJWABoYG39fvt+tOycLn/1++i5KCpdGZT+Zw4Wz5maMqnSTGm6f BmlMdNGtksX4WUyvTs/LshlkyIQrScpiQlbWiXBVJvLKj2ge9WVf0qmVlyZGgrFJWaAG OpNinbIx/eUsvDWAPA9uCgXGr1EyTIP/v/9hcq0WF89NN9bz6egTCnzBxMr6V0iJOFqN FOLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=3m4eOxCQLGPj0LjnWc1LH4mnn+Evyeez2a0gZM6gi9I=; fh=2VekOIZWfk7PcPbM/B/TQL8ZpKLzC2TLPZw8e15Icj0=; b=q6qCCY2K6xk+GRADELOmx6/5HdZB/YiLlVE7VNkPzgCfJ7zcmErWx4wxW1OKUsyBk3 96hxIml0oOsZtV2n9V2HegYoXb2TOAy3qY/bzj8uSw/CuZbFqo+MwYfvdHvM1etWGnvS 71sfPjE/cjiOT9pq27uTmBld5ZhegTcg92p87YptRuG5XZ7EyLQEil58d56Lqb3ioF+e AtAtolNNaIPLhsh7OhQH+2hfbUV4vMIT+6mmFMDD/Is6MqgmsAEkh72TJt9Je8r5M/b4 26OEYFTPq1njLMWJlNtWSf2Doh1Eerw3miTsV5clvt2sn5JaWskcMKgQ3a1xmlWTiVh9 9tOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-82985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t13-20020a05621421ad00b0068fea247884si6956050qvc.88.2024.02.27.01.43.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 01:43:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-82985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0D1A81C219E6 for ; Tue, 27 Feb 2024 09:43:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5DC91386A5; Tue, 27 Feb 2024 09:43:07 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 330B51369BB for ; Tue, 27 Feb 2024 09:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709026987; cv=none; b=Sv222bBTfkZ+YkxApiAK0578ENpwaPzOXjKiaKQb6Ivi9k9vbaXCBTQj9pq0UBC2jItuFX3oU9Ne1EoXJapY2BaXH5DyWc1XRv5zxWbKa7cm7ZMmuV46VNYjYAqmpeAlV6zwbVZrmRMFlZlP3H1XWMao74/kjfS6Eanz4k3x0lo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709026987; c=relaxed/simple; bh=1XTPpshTG3t8hNZuApNCvZ6UkkCZaeQ+3fXnxMkcyTo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=acMXmkMa618no8g3X1gJRxs1NAZcdPTz97u7NsazyrtJK4EnuOClTRRJd4QfHCrUpttuLKW7M+4ysoTwCGKuJdp9MUCGvtOeZJ8Mb/Y1GiLHNyV7vUcK+0zzbCGxjDW4txCjC0GsMjGtnQKXaE2nyqJPK08Qr6fQDv+ynmvvks4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CB5ABDA7; Tue, 27 Feb 2024 01:43:42 -0800 (PST) Received: from [192.168.178.6] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8CB2F3F762; Tue, 27 Feb 2024 01:43:03 -0800 (PST) Message-ID: Date: Tue, 27 Feb 2024 10:42:55 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 2/4] sched/fair: Check a task has a fitting cpu when updating misfit Content-Language: en-US To: Qais Yousef , Ingo Molnar , Peter Zijlstra , Vincent Guittot Cc: linux-kernel@vger.kernel.org, Pierre Gondois References: <20240220225622.2626569-1-qyousef@layalina.io> <20240220225622.2626569-3-qyousef@layalina.io> From: Dietmar Eggemann In-Reply-To: <20240220225622.2626569-3-qyousef@layalina.io> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 20/02/2024 23:56, Qais Yousef wrote: > If a misfit task is affined to a subset of the possible cpus, we need to > verify that one of these cpus can fit it. Otherwise the load balancer > code will continuously trigger needlessly leading the balance_interval > to increase in return and eventually end up with a situation where real > imbalances take a long time to address because of this impossible > imbalance situation. > > This can happen in Android world where it's common for background tasks > to be restricted to little cores. > > Similarly if we can't fit the biggest core, triggering misfit is > pointless as it is the best we can ever get on this system. > > To be able to detect that; we use asym_cap_list to iterate through > capacities in the system to see if the task is able to run at a higher > capacity level based on its p->cpus_ptr. We do that when the affinity > change, a fair task is forked, or when a task switched to fair policy. > We store the max_allowed_capacity in task_struct to allow for cheap > comparison in the fast path. > > Improve check_misfit_status() function by removing redundant checks. > misfit_task_load will be 0 if the task can't move to a bigger CPU. And > nohz_load_balance() already checks for cpu_check_capacity() before s/nohz_load_balance()/nohz_balancer_kick() ? > calling check_misfit_status(). Isn't there an issue with CPU hotplug. On a tri-geared Juno: root@juno:~# cat /sys/devices/system/cpu/cpu*/cpu_capacity 513 1024 1024 513 256 256 root@juno:~# taskset -pc 0,3-5 $$ [ 108.248425] set_task_max_allowed_capacity() [bash 1636] max_allowed_capacity=513 nr_cpus_allowed=4 cpus_mask=0,3-5 echo 0 > /sys//devices/system/cpu/cpu0/online echo 0 > /sys//devices/system/cpu/cpu3/online [ 134.136887] set_task_max_allowed_capacity() [bash 1639] max_allowed_capacity=513 nr_cpus_allowed=4 cpus_mask=0,3-5 Cpuset seems to be fine since it set task's cpumask. [...] > +/* > + * Check the max capacity the task is allowed to run at for misfit detection. Nitpick: It's rather a setter function so s/check/set here ? > + */ > +static void set_task_max_allowed_capacity(struct task_struct *p) > +{ > + struct asym_cap_data *entry; > + > + if (!sched_asym_cpucap_active()) > + return; > + > + rcu_read_lock(); > + list_for_each_entry_rcu(entry, &asym_cap_list, link) { > + cpumask_t *cpumask; > + > + cpumask = cpu_capacity_span(entry); > + if (!cpumask_intersects(p->cpus_ptr, cpumask)) > + continue; > + > + p->max_allowed_capacity = entry->capacity; > + break; > + } > + rcu_read_unlock(); > +} [...] > @@ -9601,16 +9644,10 @@ check_cpu_capacity(struct rq *rq, struct sched_domain *sd) > (arch_scale_cpu_capacity(cpu_of(rq)) * 100)); > } > > -/* > - * Check whether a rq has a misfit task and if it looks like we can actually > - * help that task: we can migrate the task to a CPU of higher capacity, or > - * the task's current CPU is heavily pressured. > - */ > -static inline int check_misfit_status(struct rq *rq, struct sched_domain *sd) > +/* Check if the rq has a misfit task */ > +static inline bool check_misfit_status(struct rq *rq, struct sched_domain *sd) `struct sched_domain *sd` is not needed anymore. Since there is only 1 user of check_misfit_status() you might remove it entirely and use `rq->rq->misfit_task_load` directly in nohz_balancer_kick() ? [...]