Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1381209rdb; Fri, 16 Feb 2024 14:06:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW1sZPGqRKMnnC7C2r3WVAr0k0YAbnnOZo4UD/ODafzlFEYa1m5FCpOT+iyTlJWR8aAbayCvn/B2VeFxDjRs2wGIibDb41CBdKb30Tang== X-Google-Smtp-Source: AGHT+IEe8GXV5GGTHMYzKZjby85Hm/7dUCWRn1kDBSvmwqOFK4OcNWOjQ0EDqS12Sm3xHzJBes8g X-Received: by 2002:a17:90a:bb8b:b0:299:54bb:5cac with SMTP id v11-20020a17090abb8b00b0029954bb5cacmr208922pjr.11.1708121198375; Fri, 16 Feb 2024 14:06:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708121198; cv=pass; d=google.com; s=arc-20160816; b=ZPgAWXgtN33YpJe6cWpi/kU7dqDCqRCvZ68AlQo6oa8f3ZwGv2SwR/HsHqDoUzyiQt AW6U6vKBQTg9KthKQPUfXqG3Kb/GS65jaax1UjapBjxasjziOG/MDCNCa4GOK7tw9syU wcUgxg8nz7LcGl07ky5TyNj9IzCjRLy//xIPGsvV6o/acGhXuoP8jucLXEL/FoU6OQaV u6NTt9vqLT+HDPIMQ8McZS2fq1P8ymnq13bGbuOOpFL9NC6u+7zVxKFG/6I3bjXlhkft KvicnrCWMcc9mutAxQZQjqIKdt2erMoDmnwfMpBmPUDdVKwsVCK8cfUX59bhhHa2gqrn rkEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:dkim-signature; bh=Awar1dWU9KAHnvt7ackrhqeT8JNkSM3TV7hP8AU9Xd4=; fh=cZaZT4+krdwI5zBWnO1/SIrXTa0UqzOwkIVEtSJF3+k=; b=Qsg0VP9eRlD7pN6Y7mGEYNBVkqIHoRo6oPR5N8wzIb72gwggjiap7JwDg8QhKvVWNp 65vdNxfalTqzWEuwikxHZhm5+bA8awvXIe1rApFtk6BL+RoBoPqm+C77K1UX892OBuxb bZcIbCNLWjY1ipHQXeGXfl2FC7XafPNbviP1CYEmsg7dSajEPW5jB/q4LoAn4EVQDOeN OiUtMSJr8Te3g1KLbQBdhzY3qyqEYcyMsam33QhPNfR7zL/mCdssDkupPQDWHAFM9LYX TsiFE7Yffzz7KBgx2/qkL1KK8CsadnI77eLryTPpyWw5AoDqzl7o3ek5QNc/HD73XjYE 3K3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=UvjVpO7k; arc=pass (i=1 spf=pass spfdomain=rere.qmqm.pl dkim=pass dkdomain=rere.qmqm.pl dmarc=pass fromdomain=rere.qmqm.pl); spf=pass (google.com: domain of linux-kernel+bounces-69383-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69383-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=rere.qmqm.pl Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id oj13-20020a17090b4d8d00b00296fa0a582fsi584722pjb.35.2024.02.16.14.06.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 14:06:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69383-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=UvjVpO7k; arc=pass (i=1 spf=pass spfdomain=rere.qmqm.pl dkim=pass dkdomain=rere.qmqm.pl dmarc=pass fromdomain=rere.qmqm.pl); spf=pass (google.com: domain of linux-kernel+bounces-69383-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69383-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=rere.qmqm.pl 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 C6464289EC6 for ; Fri, 16 Feb 2024 21:56:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 815231482FF; Fri, 16 Feb 2024 21:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="UvjVpO7k" Received: from rere.qmqm.pl (rere.qmqm.pl [91.227.64.183]) (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 520D31468FE for ; Fri, 16 Feb 2024 21:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.227.64.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708120560; cv=none; b=GePhnXEDNp2cSz1gHVOBbMvoraYbZZWb5ToM7h9868B93bU74r4CKvPUtc9ooiJMT5g1FyfJJuPEo0Bh3czrsPgQkVuyU9ctZ//smUAeqceS0p/LHBnIOEGSGDPhuqlezS2UYklnxjoNXcNNoTdqh1BbT6HOe//+rOnbN15JR+0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708120560; c=relaxed/simple; bh=HtzhTbrig6Q7FsxiULJj6MkqqvnTNQdjjMtBWF11WCU=; h=Date:Message-Id:In-Reply-To:References:Subject:MIME-Version: Content-Type:From:To:Cc; b=CvOHcQg5Nk5VJt1kIWzC11tJ30/rOikwo5ML5aNUVTogBFgk/ISA16TSgTane7AFT5Q4rYtV4XuScMeGF66TDLk85UE0LsPXLCzvD6ztu5uN7AeM4tFX/IVgdCEagefjNxYdAKZV/Jt8tNGS2fYgdH74ar64QRr0+tADQ0E4Lt8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=rere.qmqm.pl; spf=pass smtp.mailfrom=rere.qmqm.pl; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b=UvjVpO7k; arc=none smtp.client-ip=91.227.64.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=rere.qmqm.pl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rere.qmqm.pl Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4Tc5N31Y9MzBj; Fri, 16 Feb 2024 22:55:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1708120547; bh=HtzhTbrig6Q7FsxiULJj6MkqqvnTNQdjjMtBWF11WCU=; h=Date:In-Reply-To:References:Subject:From:To:Cc:From; b=UvjVpO7kHbh1e+/CsN/kZj4Z3jeV5bKfuvUqY+enYSTDUTAgvYVBXwwMdBaMTeJBv XzHwnr7w6HPdx23p6lfEWYXXawNvPcIfkNTyoYxejTnwMgkBw43KqK+WEKFTBAYmLh T6ZbpYvGuFoNvUTe7/fLJ0j/P78Ke1TABieofL83eW0zzbP/CCleXAE3yv+f2rBzsc K15pwVwaMDDmpCKM30FcLuDYr8+edt/0hTa8yq2oUDNPnsMt/76VxbtTmE9tVmTx8L c6UCmO+JqVRwsGJnW+GyweNqoyi70YklulKtCYpRZxxXha5RNaSFGbhNJ9lwuUD29d ufC8Pyd47xnkw== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at mail Date: Fri, 16 Feb 2024 22:55:47 +0100 Message-Id: <3fa064422ddd6b15d6d572fc0c6e99b94eea1235.1708120036.git.mirq-linux@rere.qmqm.pl> In-Reply-To: <64955b50602fc64e2d3c7d4a92a1f9459e8c7ead.1708120036.git.mirq-linux@rere.qmqm.pl> References: <64955b50602fc64e2d3c7d4a92a1f9459e8c7ead.1708120036.git.mirq-linux@rere.qmqm.pl> Subject: [PATCH 2/2] sched: add for_each_sched_group() and use everywhere 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=UTF-8 Content-Transfer-Encoding: 8bit From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , "Joel Fernandes (Google)" , Len Brown , Ricardo Neri Cc: linux-kernel@vger.kernel.org Make code iterating over all sched_groups more straightforward. Note: There's no point in WARN_ON in init_sched_groups_capacity() if we're going to unconditionally dereference a NULL pointer just a few instructions later. Signed-off-by: Michał Mirosław --- kernel/sched/fair.c | 13 +++++-------- kernel/sched/sched.h | 5 +++++ kernel/sched/topology.c | 19 ++++++------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7ac9f4b1d955..a8a011f24a6d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9566,15 +9566,13 @@ void update_group_capacity(struct sched_domain *sd, int cpu) * span the current group. */ - group = child->groups; - do { + for_each_sched_group(child, group) { struct sched_group_capacity *sgc = group->sgc; capacity += sgc->capacity; min_capacity = min(sgc->min_capacity, min_capacity); max_capacity = max(sgc->max_capacity, max_capacity); - group = group->next; - } while (group != child->groups); + } } sdg->sgc->capacity = capacity; @@ -10549,13 +10547,13 @@ static void update_idle_cpu_scan(struct lb_env *env, static inline void update_sd_lb_stats(struct lb_env *env, struct sd_lb_stats *sds) { - struct sched_group *sg = env->sd->groups; struct sg_lb_stats *local = &sds->local_stat; struct sg_lb_stats tmp_sgs; unsigned long sum_util = 0; + struct sched_group *sg; int sg_status = 0; - do { + for_each_sched_group(env->sd, sg) { struct sg_lb_stats *sgs = &tmp_sgs; int local_group; @@ -10586,8 +10584,7 @@ static inline void update_sd_lb_stats(struct lb_env *env, struct sd_lb_stats *sd sds->total_capacity += sgs->group_capacity; sum_util += sgs->group_util; - sg = sg->next; - } while (sg != env->sd->groups); + } /* * Indicate that the child domain of the busiest group prefers tasks diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 2e5a95486a42..88f3cba60b1e 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1902,6 +1902,11 @@ struct sched_group { unsigned long cpumask[]; }; +#define for_each_sched_group(sd, sg) \ + for ((sg) = NULL; \ + likely((sg)) ? (sg) != (sd)->groups : ((((sg) = (sd)->groups)), 1); \ + (void)((((sg) = (sg)->next)) || ({ BUG(); 0; }))) + static inline struct cpumask *sched_group_span(struct sched_group *sg) { return to_cpumask(sg->cpumask); diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 75b1a18783c2..dce29cf28f32 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -758,17 +758,15 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) sd = sd->parent; destroy_sched_domain(tmp); if (sd) { - struct sched_group *sg = sd->groups; + struct sched_group *sg; /* * sched groups hold the flags of the child sched * domain for convenience. Clear such flags since * the child is being destroyed. */ - do { + for_each_sched_group(sd, sg) sg->flags = 0; - sg = sg->next; - } while (sg != sd->groups); sd->child = NULL; } @@ -1290,12 +1288,10 @@ build_sched_groups(struct sched_domain *sd, int cpu) */ static void init_sched_groups_capacity(int cpu, struct sched_domain *sd) { - struct sched_group *sg = sd->groups; struct cpumask *mask = sched_domains_tmpmask2; + struct sched_group *sg; - WARN_ON(!sg); - - do { + for_each_sched_group(sd, sg) { int cpu, cores = 0, max_cpu = -1; sg->group_weight = cpumask_weight(sched_group_span(sg)); @@ -1310,7 +1306,7 @@ static void init_sched_groups_capacity(int cpu, struct sched_domain *sd) sg->cores = cores; if (!(sd->flags & SD_ASYM_PACKING)) - goto next; + continue; for_each_cpu(cpu, sched_group_span(sg)) { if (max_cpu < 0) @@ -1319,10 +1315,7 @@ static void init_sched_groups_capacity(int cpu, struct sched_domain *sd) max_cpu = cpu; } sg->asym_prefer_cpu = max_cpu; - -next: - sg = sg->next; - } while (sg != sd->groups); + } if (cpu != group_balance_cpu(sg)) return; -- 2.39.2