From patchwork Mon Jul 18 19:28:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12921674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29BC1C43334 for ; Mon, 18 Jul 2022 19:29:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8C48940012; Mon, 18 Jul 2022 15:29:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B74EF94000D; Mon, 18 Jul 2022 15:29:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1895940012; Mon, 18 Jul 2022 15:29:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 93FBC94000D for ; Mon, 18 Jul 2022 15:29:05 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 743BC34762 for ; Mon, 18 Jul 2022 19:29:05 +0000 (UTC) X-FDA: 79701208650.15.05C72BA Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf16.hostedemail.com (Postfix) with ESMTP id 03BAD180054 for ; Mon, 18 Jul 2022 19:29:04 +0000 (UTC) Received: by mail-qt1-f170.google.com with SMTP id y9so6164756qtv.5 for ; Mon, 18 Jul 2022 12:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=tA2rl8RctZ6HL9V5x9xFMH8oSgBBwUuElKQvWOHzbeI=; b=hP/RxbCCEkxGibcmzYfoczVfz2LGpVvZkrG5wlu75XNiAI1BfNZJPMtwQd0PYtFa4k 9sqDaS6kmGHiRQpzGl3YHVh0l8qAJUfrnfctlEXZsk+yJaCHbydmsJ/FIeyIMRe2QYYS AB02g9p+c9CoMw9OrSZ9omO4Oxfqs9oeUUaFdWEZpJcv2MJ7cdtPYz3Fd8zBnbGvz1Iw o7jHZpB3NBZRj1mxkRUcREMvO38UFX1tl3lIgHvmj+MBAc2h6f3RXJF3Q60pUT+dIr1T Zgt4vkyg0W1HEu5nB4dG2ctBT26OjozQ53zCuCaHayZmI0SZj41p5lheZfaXVwMwGzSd cd+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tA2rl8RctZ6HL9V5x9xFMH8oSgBBwUuElKQvWOHzbeI=; b=TsP5kpJDHgNae2dwKnzsVwfvY8ctCZ3I7czPFq1OADNOrOxTJkC56MIvQ1c8S5GW5G WRovRLwRybITd87lehcTSgsoCofZFimvO7UL3fb+fyp0LJvHNah8WR3CGpjX33a3O4+G cB0Mo52ZXYEN+vCDhdbAA2psLI6tVXb06ymqD2EfMr5glKVedlASnqTpsS4rAOhp6RF9 MwAkp6EATTwFgMgb5l6/mSLAZjjpya+tFzII0i/OzvezM2jg6eUyFi9s7cJ9apg+Km1s VYtdux8LgNOUbXetwXF6JpJ5dFEkM4ZDI6GKvEpyAkL76cNWLwN+OIDNOb1NYpBlaOFJ cOQQ== X-Gm-Message-State: AJIora8Eg96X6G1KqATl5jgy3RWBaFJSrLsjvcKX03Cz5IcoY2uRnKZg txt+o14aZcwL1eT5DAQa038= X-Google-Smtp-Source: AGRyM1vQmvbkX1kTEORONuNSMwS4ZWos+Eg2Ylq19DBEaI61zIn7vgC2XHqbVwUo3RPShBlZ/+yVwg== X-Received: by 2002:ac8:5790:0:b0:31e:f69a:1b9e with SMTP id v16-20020ac85790000000b0031ef69a1b9emr2408133qta.103.1658172544528; Mon, 18 Jul 2022 12:29:04 -0700 (PDT) Received: from localhost ([2601:4c1:c100:1230:ab01:d009:465a:5ab1]) by smtp.gmail.com with ESMTPSA id v17-20020ac85791000000b0031ee2080c73sm6310369qta.54.2022.07.18.12.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 12:29:04 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Alexander Lobakin , Alexei Starovoitov , Alexey Klimov , Andrew Morton , Andrii Nakryiko , Andy Shevchenko , Ben Segall , Christoph Lameter , Dan Williams , Daniel Borkmann , Daniel Bristot de Oliveira , Dennis Zhou , Dietmar Eggemann , Eric Dumazet , Frederic Weisbecker , Guenter Roeck , Ingo Molnar , Isabella Basso , John Fastabend , Josh Poimboeuf , Juergen Gross , Juri Lelli , KP Singh , Kees Cook , Martin KaFai Lau , Mel Gorman , Miroslav Benes , Nathan Chancellor , "Paul E . McKenney" , Peter Zijlstra , Randy Dunlap , Rasmus Villemoes , Sebastian Andrzej Siewior , Song Liu , Steven Rostedt , Tejun Heo , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vlastimil Babka , Yonghong Song , Yury Norov , linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 15/16] sched/topology: optimize topology_span_sane() Date: Mon, 18 Jul 2022 12:28:43 -0700 Message-Id: <20220718192844.1805158-16-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220718192844.1805158-1-yury.norov@gmail.com> References: <20220718192844.1805158-1-yury.norov@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658172545; a=rsa-sha256; cv=none; b=gz07YJMrVhqxtjPHCsw4QoozdKKLyQyvxbpyvl16KHf0u93Tl1F+CcQwNvboP+y1+/Su5F Y51yZ5Hh5osNhcwq2e2dXdJH6UPXxxH/a9G7La0zKfI/Zzlr7oqRgDpOUBArU0dNyVRvbA P8PMaL8tuUFEJ4sYnjIe8vc/rML9esc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="hP/RxbCC"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658172545; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tA2rl8RctZ6HL9V5x9xFMH8oSgBBwUuElKQvWOHzbeI=; b=UWXJTPutYhR3/gA9DZYXF7ae3eAK4VV5+/A2kTlO15huix6B66EQxMcpF29dENQuwbzuRX TkcQ9aqBWWHxHfAHZrXm7kCUH7T6oRuFwC8P+ZBg0n3IQQ81+qKizCbWrX+3AhDVf9oc1o PN1XpjZ1ntl/aE6F4bMgW53TdWMg+iw= X-Rspamd-Queue-Id: 03BAD180054 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="hP/RxbCC"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-Rspamd-Server: rspam08 X-Stat-Signature: ododus8u44k6996gkfz5cng4f5p7qmxx X-HE-Tag: 1658172544-35138 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: topology_span_sane() checks if cpu == i before calling cpumask_equal(tl->mask(cpu), tl->mask(i)). However, tl->mask(cpu) and tl->mask(i) may point to the same cpumask even if i != cpu. Fix the check accordingly. While here, move tl->mask(cpu) out of the loop, and make the in-loop code calculating tl->mask(i) only once. Catched with CONFIG_DEBUG_BITMAP: [ 0.867917] Call Trace: [ 0.868209] [ 0.868471] build_sched_domains+0x36f/0x1a40 [ 0.868576] sched_init_smp+0x44/0xba [ 0.869012] ? mtrr_aps_init+0x84/0xa0 [ 0.869465] kernel_init_freeable+0x12e/0x26e [ 0.869982] ? rest_init+0xd0/0xd0 [ 0.870406] kernel_init+0x16/0x120 [ 0.870821] ret_from_fork+0x22/0x30 [ 0.871244] [ 0.871502] ---[ end trace 0000000000000000 ]--- [ 0.872040] b1: ffffffffb1fd3480 [ 0.872041] b2: ffffffffb1fd3480 [ 0.872041] b3: 0 [ 0.872042] nbits: 256 [ 0.872042] start: 0 [ 0.872042] off: 0 [ 0.872043] Bitmap: parameters check failed [ 0.872043] include/linux/bitmap.h [427]: bitmap_equal Signed-off-by: Yury Norov --- kernel/sched/topology.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 05b6c2ad90b9..ad32d0a43424 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2211,6 +2211,8 @@ static struct sched_domain *build_sched_domain(struct sched_domain_topology_leve static bool topology_span_sane(struct sched_domain_topology_level *tl, const struct cpumask *cpu_map, int cpu) { + const struct cpumask *mc = tl->mask(cpu); + const struct cpumask *mi; int i; /* NUMA levels are allowed to overlap */ @@ -2226,14 +2228,18 @@ static bool topology_span_sane(struct sched_domain_topology_level *tl, for_each_cpu(i, cpu_map) { if (i == cpu) continue; + + mi = tl->mask(i); + if (mi == mc) + continue; + /* * We should 'and' all those masks with 'cpu_map' to exactly * match the topology we're about to build, but that can only * remove CPUs, which only lessens our ability to detect * overlaps */ - if (!cpumask_equal(tl->mask(cpu), tl->mask(i)) && - cpumask_intersects(tl->mask(cpu), tl->mask(i))) + if (!cpumask_equal(mc, mi) && cpumask_intersects(mc, mi)) return false; }