Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2805082lqz; Wed, 3 Apr 2024 09:04:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5P/ZA5N6yX0mmCtG1vRevaXNbSqGYEwt5Nt4YJRlKvS4UdEBsHTagb0c0db+qYqprTWpPCFC1jUPxagvU/qHUCEB466M5HzAOBGYDPQ== X-Google-Smtp-Source: AGHT+IFul6tEHWSyo38AXjPWfi372Md7VJijA1jjykL49BfhKWNSP3f0hGr9E2E25kUYOPuJTyNQ X-Received: by 2002:a2e:b552:0:b0:2d7:b:da37 with SMTP id a18-20020a2eb552000000b002d7000bda37mr14755ljn.7.1712160283306; Wed, 03 Apr 2024 09:04:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712160283; cv=pass; d=google.com; s=arc-20160816; b=Qi5L90gBCSZg9FRrXoEw0e8QYU+0ggWcyf5ko1ICGeaSBmeJrTKs/iD+2vtEookXMd E/iuyqJaiBUl2xeQwy9kKwQaf+z0iOe83dLWeQEVc+5qVj6Pa7KO6UT2MvtfWA44+QTe JlXMfgT0bV9o6uj/O1H6H3Fv0sedETtA+NtnfCo67EEwtf3EeSRat3cVyv6szm+L9x3D 0nxndIjuvuIMHQCFD3yTsYuudyBXTvp7HvhQC1t12e5pADLUn1bg6wTvvvT0qUcsdFgZ BYgFJaKmQMxgyoloZrchX7etuS35rz+jW5Bcohzi/avNqaLl7dstSmfq1fcTwJTGujXo U2/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=PC3XtrcGOT4+ffogBe31nKIsLbDj1R7MWt1ovsWoI14=; fh=K1EjY/iDKwuQSBahFsPqCvcaIzvvxPUGKK+WBDBIaaQ=; b=wT5ZzVnbCJzjq42v2Q5N2Gy677Nj4mTP9CPN23rnx6cjlGtcS6Ijgtt5SFvy16fD6N 6kY3jaEaGX+skenY1MawzJU7NKAde9z9njYc8025YYUDLPS4J48ekSWOLWSd9CMG193b N6des4dyOw7Y9c3J7OT4Spzno2O7Br7b9C+moU2ul5G+CS7XMe3MR73tR4lw8NWi82Rk Qd2EpEBB3/m67jhH5t/2niWRq7O1WYN270Pr3sMXmsvvaAA7XkGzlnOxl/EtuvG55W4t AjsYYtoG+C6xNE6LgMZ16ow1nySCv7rAMCOU5IRl0aOV0K3qhpNMPVwMZwf72VugKMlz 1MAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-130163-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130163-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m2-20020a50c182000000b00568386368c5si6790299edf.690.2024.04.03.09.04.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 09:04:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130163-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-130163-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130163-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn 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 92AB41F20EE0 for ; Wed, 3 Apr 2024 16:04:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ABE9B14F9C3; Wed, 3 Apr 2024 16:02:42 +0000 (UTC) Received: from smtpbg153.qq.com (smtpbg153.qq.com [13.245.218.24]) (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 D59C314BF93; Wed, 3 Apr 2024 16:02:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.245.218.24 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712160162; cv=none; b=aEShQ1UIG1YsiYwYMii83767NnswdKFG0g5/FTFWdtqcURmn7VkQnp0u5lCBbMzIOC9uJwTxOCSWjGRoJaWDsXW6w2GEzcy/w8xDYn/FinS7gYV2xZqkuKoyKUEla2T9/XfoM22jxFBJLQWRLdxZ8tjFffZ4uAxmOJBk1f2le0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712160162; c=relaxed/simple; bh=8+OYRSORViS6wySTstWl7xfxnB2a4TnBx6JvdVLKcfY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nPCjprckKhlarj/c4euJ9WGYL3YMM7vHwrlrLG+l6egWABMSC3ZZtNp4nvbomdDBNBwHgIeykD+6RJuVzTaCuaAMTEUEbgvNqqjrS5ktddXVqX3LcZG0PRNpqPKsB6iKddcsn9mE2hw8XQQ8k7hll/ci0dWhecjLZSVABzaXPwc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=13.245.218.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtp89t1712160058tfp0piqp X-QQ-Originating-IP: Ouhgj9rA715Lf14sjGY4MXBFcA61tryPUPt6BPHBb+4= Received: from localhost ( [112.0.147.175]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 04 Apr 2024 00:00:56 +0800 (CST) X-QQ-SSF: 01400000000000704000000A0000000 X-QQ-FEAT: U7OmrCiPqqAgGcIcJ4EQJge2PyZ+Km+JBHB9boBCbf4mSuiiyYEUsd+w/udnM E7a/NmH+Oort1p9ZFUTj4CtxjgralxR/Er0+Hk49Mn/bs+XR84/D5Uf1pFHvvcQDMuLMT3a 5xXIl3qGyYF2vQd2Q5e6AOkiDBGa5MVEimdiFzHC/L5EFmsvRBaBffOxkBe8y9iokTgblL7 i1zBC/ofvh0nEpyACdt+VIWU8V4ahIWwrK0ZLDaB3EPl2qDZpbQ3PTZkGXu7ipS3g38rKNQ tKVDPbtb84LoxzqquMMi4Nu/Y6kEVJFoonWbqTtZnr6iqhnSwbap26eDM4nOk9OMvDy+riy iFKuH1Xc/FDZoLAm9mO4pa4BdyDccpJO6+hHNzt5hzK9AEX7QpRSX0DQPMRo7y3wd5v1eLA X-QQ-GoodBg: 2 X-BIZMAIL-ID: 11768828956102275694 From: Dawei Li To: will@kernel.org, mark.rutland@arm.com, yury.norov@gmail.com, linux@rasmusvillemoes.dk Cc: xueshuai@linux.alibaba.com, renyu.zj@linux.alibaba.com, yangyicong@hisilicon.com, jonathan.cameron@huawei.com, andersson@kernel.org, konrad.dybcio@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Dawei Li Subject: [PATCH v3 05/10] perf/arm_dsu: Avoid placing cpumask on the stack Date: Wed, 3 Apr 2024 23:59:45 +0800 Message-Id: <20240403155950.2068109-6-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240403155950.2068109-1-dawei.li@shingroup.cn> References: <20240403155950.2068109-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 In general it's preferable to avoid placing cpumasks on the stack, as for large values of NR_CPUS these can consume significant amounts of stack space and make stack overflows more likely. Use cpumask_any_and_but() to avoid the need for a temporary cpumask on the stack. Suggested-by: Mark Rutland Reviewed-by: Mark Rutland Signed-off-by: Dawei Li --- drivers/perf/arm_dsu_pmu.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c index bae3ca37f846..adc0bbb5fafe 100644 --- a/drivers/perf/arm_dsu_pmu.c +++ b/drivers/perf/arm_dsu_pmu.c @@ -230,15 +230,6 @@ static const struct attribute_group *dsu_pmu_attr_groups[] = { NULL, }; -static int dsu_pmu_get_online_cpu_any_but(struct dsu_pmu *dsu_pmu, int cpu) -{ - struct cpumask online_supported; - - cpumask_and(&online_supported, - &dsu_pmu->associated_cpus, cpu_online_mask); - return cpumask_any_but(&online_supported, cpu); -} - static inline bool dsu_pmu_counter_valid(struct dsu_pmu *dsu_pmu, u32 idx) { return (idx < dsu_pmu->num_counters) || @@ -827,14 +818,16 @@ static int dsu_pmu_cpu_online(unsigned int cpu, struct hlist_node *node) static int dsu_pmu_cpu_teardown(unsigned int cpu, struct hlist_node *node) { - int dst; - struct dsu_pmu *dsu_pmu = hlist_entry_safe(node, struct dsu_pmu, - cpuhp_node); + struct dsu_pmu *dsu_pmu; + unsigned int dst; + + dsu_pmu = hlist_entry_safe(node, struct dsu_pmu, cpuhp_node); if (!cpumask_test_and_clear_cpu(cpu, &dsu_pmu->active_cpu)) return 0; - dst = dsu_pmu_get_online_cpu_any_but(dsu_pmu, cpu); + dst = cpumask_any_and_but(&dsu_pmu->associated_cpus, + cpu_online_mask, cpu); /* If there are no active CPUs in the DSU, leave IRQ disabled */ if (dst >= nr_cpu_ids) return 0; -- 2.27.0