Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1927311lqp; Tue, 16 Apr 2024 01:56:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU54fvk8q3cgMK5qKQera80HyJ0EpfgKObWOyoFraQiZvEjHvdCQEM3t64SgToycjkTG7WTxYcrBiiZqCy0/ofEJyvj5BTj163EY4rClA== X-Google-Smtp-Source: AGHT+IGbiXhkXlRP5e1m992qWuYyTsNPrEECKQRVvNHQeNZeI4cEONLQFtTCfsgno0hzXDO4faIG X-Received: by 2002:a05:6a21:398f:b0:1a9:fe63:90f0 with SMTP id ad15-20020a056a21398f00b001a9fe6390f0mr6221560pzc.53.1713257777865; Tue, 16 Apr 2024 01:56:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713257777; cv=pass; d=google.com; s=arc-20160816; b=kBT8HO86QrmSGoUkxBcn7OvCKZIjnySsIZtoSVF/SHm/45fHzQf1nf1ccwvtEF0eEk 3ltAZn3EGp57UTESGP4KaAda2oOAs9ztbAq+m4rjmTwZRADmMU+yJ8kaeCP3e7dkCmRk 6fbfJVokd78ye/LIAVVatnee/OxvoTt1RqT/yUAqTTnkcc+ldOI13gpa0gnCz2fJT2fg tDHaxY/29WC35gURVkoZtA4E9+Y+GTdfb6HSndKMK8zZsWUwwM1lVTyWzZNE6TF/Ftsq GhlY/tX4KqGh6hn6Io6mddE+Yb+MxMVihzibQfzVkJLshAQLENytiDB4YvFND8jyCZUI H0ww== 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=qQr3UBtlrCtyUZjh7ErHJNnZoqO5W8rF+DODZ3RTNEM=; fh=jY7gwwwm9TCzamW30esTQOtJrNF3m0oBBIyoF9sx+6c=; b=E56/tkXa0G95rDTLAibEDocVc0/8Vi5tVGJpJYnmB3kmze3N1CUNbF40SjUvuS7Pll xKMkoUIBS4Ve+8+3zSA2UjiHuhdVgSy4cgxkrPVl6497VNXiQLWov2f8Fmy5Wsv3AKYi vlenqSO65Sto8M1ThAAMdTffC/zgrSjAikNYRKXYg8MfNSRwmNAikkoreVRNaSGAdWxh 0Pp47x9cXtqAKcB7azFOnUHqe51VqaXvH2KhJuH2ia/2NxTm42ZRjFUBQJ8vuxirqMnW WhZQwJnoA8ujJ0Xf+s3WkQwyX728LJKwUBfcU7pZwOsg1De/07W6WqTvFt82eBrTRkL5 0jcg==; 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-146520-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146520-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m10-20020a170902db0a00b001dcd4f9fd0dsi9733290plx.455.2024.04.16.01.56.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 01:56:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146520-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; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-146520-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146520-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8C0C7284276 for ; Tue, 16 Apr 2024 08:56:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7578A84FC9; Tue, 16 Apr 2024 08:56:05 +0000 (UTC) Received: from smtpbg154.qq.com (smtpbg154.qq.com [15.184.224.54]) (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 9BAC384A3E for ; Tue, 16 Apr 2024 08:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=15.184.224.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713257764; cv=none; b=ghB8D5qR87xsNi1pVMyuGozPNoOigoi49QOqSOw0dJZEW6SFDheuuvyybGeL5W8w+3mFcUQ36cBUGZ1a5Kmo62+y96QGjJTS0D+4SKVOu+277xyPprpOLpLEXwgK3pSh/zV78LinE5GzSxqKKfSF2qjo2YuM/fZVC4u57+FQtdc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713257764; c=relaxed/simple; bh=MWsZw2xAnYzew3mAR/4hOT+/JOvbHTbm2HiiGwv43ZA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O2KZs251NE9aMG1Cf+o3xhuSZ+5RA0WKvTCrk4NBK/3bsQf3uPvy7fpCZdN+t3t3HCW3lq/h77TJ4c3Bq2ZulQMBnoiPe+RsB32hnnx1yV781D3jjAQQzV58HTQ1TyZdlSQHVLwvQrubEe8/GMrJ19CiC7jsCQxH/zEEk0rF7HQ= 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=15.184.224.54 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: bizesmtp86t1713257723t6x31fvw X-QQ-Originating-IP: WatDBIqlqkEbhBW9b+x8m3/vWdvHewLtHdIAOQ/7O8c= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 16 Apr 2024 16:55:21 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: H21jX+7aWYbgzlTnzlsOCCpV6BUAK1vvoOUgDWvSPPEkNN8e8v5NqbHiz4AIp OTQGH/RpD7/ddJ5hJ8EGGPeTyF7iSrbIXZzthHIgzy7JLrWLNlyWvnTQfeeddjsBk7udAXJ oV4YouBL/O98r5xkt4RxhfC++Sdjf6AjyOrrR6xkAHWfmsc8UzW6yEALuJAiauTryEL9p5L 0PHMLrtB5AMPD8z7TLiBgul0VUr1oO4VlA+2Wq8WhZ+xn7DAAonLAuWR0QV56VeMJHc6PMX VEvv/dFUAQxPVhengYCficlfz8shhzd+r3NDgWhXv/Q5NabaBTJqZ8hZwamG0uLbBBtE4XY JXdjdM35/V1RrDhY8vAQjOWCjRVSNi4qNjY3QfqOU486NAHuFyIpf6+e2KhtdBVuqQbmr91 dBj7/8PzwoFZd0sWTTyG7KE3aWreNZbp X-QQ-GoodBg: 2 X-BIZMAIL-ID: 5318237287310536978 From: Dawei Li To: tglx@linutronix.de, yury.norov@gmail.com, rafael@kernel.org Cc: akpm@linux-foundation.org, maz@kernel.org, florian.fainelli@broadcom.com, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, anup@brainfault.org, palmer@dabbelt.com, samuel.holland@sifive.com, linux@rasmusvillemoes.dk, daniel.lezcano@linaro.org, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH v2 1/7] cpumask: introduce cpumask_first_and_and() Date: Tue, 16 Apr 2024 16:54:48 +0800 Message-Id: <20240416085454.3547175-2-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240416085454.3547175-1-dawei.li@shingroup.cn> References: <20240416085454.3547175-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 Introduce cpumask_first_and_and() to get intersection between 3 cpumasks, free of any intermediate cpumask variable. Instead, cpumask_first_and_and() works in-place with all inputs and produce desired output directly. Signed-off-by: Dawei Li --- include/linux/cpumask.h | 17 +++++++++++++++++ include/linux/find.h | 27 +++++++++++++++++++++++++++ lib/find_bit.c | 12 ++++++++++++ 3 files changed, 56 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 1c29947db848..c46f9e9e1d66 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -187,6 +187,23 @@ unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumask return find_first_and_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), small_cpumask_bits); } +/** + * cpumask_first_and_and - return the first cpu from *srcp1 & *srcp2 & *srcp3 + * @srcp1: the first input + * @srcp2: the second input + * @srcp3: the third input + * + * Return: >= nr_cpu_ids if no cpus set in all. + */ +static inline +unsigned int cpumask_first_and_and(const struct cpumask *srcp1, + const struct cpumask *srcp2, + const struct cpumask *srcp3) +{ + return find_first_and_and_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), + cpumask_bits(srcp3), small_cpumask_bits); +} + /** * cpumask_last - get the last CPU in a cpumask * @srcp: - the cpumask pointer diff --git a/include/linux/find.h b/include/linux/find.h index c69598e383c1..28ec5a03393a 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -29,6 +29,8 @@ unsigned long __find_nth_and_andnot_bit(const unsigned long *addr1, const unsign unsigned long n); extern unsigned long _find_first_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size); +unsigned long _find_first_and_and_bit(const unsigned long *addr1, const unsigned long *addr2, + const unsigned long *addr3, unsigned long size); extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size); extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long size); @@ -345,6 +347,31 @@ unsigned long find_first_and_bit(const unsigned long *addr1, } #endif +/** + * find_first_and_and_bit - find the first set bit in 3 memory regions + * @addr1: The first address to base the search on + * @addr2: The second address to base the search on + * @addr3: The third address to base the search on + * @size: The bitmap size in bits + * + * Returns the bit number for the first set bit + * If no bits are set, returns @size. + */ +static inline +unsigned long find_first_and_and_bit(const unsigned long *addr1, + const unsigned long *addr2, + const unsigned long *addr3, + unsigned long size) +{ + if (small_const_nbits(size)) { + unsigned long val = *addr1 & *addr2 & *addr3 & GENMASK(size - 1, 0); + + return val ? __ffs(val) : size; + } + + return _find_first_and_and_bit(addr1, addr2, addr3, size); +} + #ifndef find_first_zero_bit /** * find_first_zero_bit - find the first cleared bit in a memory region diff --git a/lib/find_bit.c b/lib/find_bit.c index 32f99e9a670e..dacadd904250 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -116,6 +116,18 @@ unsigned long _find_first_and_bit(const unsigned long *addr1, EXPORT_SYMBOL(_find_first_and_bit); #endif +/* + * Find the first set bit in three memory regions. + */ +unsigned long _find_first_and_and_bit(const unsigned long *addr1, + const unsigned long *addr2, + const unsigned long *addr3, + unsigned long size) +{ + return FIND_FIRST_BIT(addr1[idx] & addr2[idx] & addr3[idx], /* nop */, size); +} +EXPORT_SYMBOL(_find_first_and_and_bit); + #ifndef find_first_zero_bit /* * Find the first cleared bit in a memory region. -- 2.27.0