Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp432465lqp; Sat, 13 Apr 2024 03:38:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtGA5OlbaIN9sPebRw9NvrS1QsGwSz4etHyOh0J0b7GDPAtXpf/FHjf3oB5s3smD+JklyF0UanDoUf5Vxvro+JCLA269FOSrI9UF9Haw== X-Google-Smtp-Source: AGHT+IGGDWmNKb2tSAGBcKWEqX8LGI61XJtrtMU8XgqI40IF3yJJTHzvuZauYRcWzdAymdCt+VxZ X-Received: by 2002:a17:906:e2cd:b0:a52:b11:5406 with SMTP id gr13-20020a170906e2cd00b00a520b115406mr2941762ejb.16.1713004697876; Sat, 13 Apr 2024 03:38:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713004697; cv=pass; d=google.com; s=arc-20160816; b=Eq++CCkXAOKuokUGhnS3c1XwvVA+dPwu/7JmCqgExbXO2z01U4W3hHKVzH1G/7rmEF USwUq04oi7IEFXf3G7x2UT26LWD63nlF2ywi8bl4nHeb2dZ0UW2INo1V6yW/MnPeZISp yupYGIr5ZWv68fjRM8gzlOUL6YGc5yvDGaEyVJ+qolODOaibGmv8ZF4PiBlN4BoQYsOW YU7KG7xwGsQJOYSWcYoY7qrilxmJyfJVWbz/uPeEsWo7VJ+HkqyPp8rkGKDw2SwrJq/5 jJ8fDy6EtR0tTC4RrDvN5iB/myEm30Avox86nVrZtiiPoFGBtFFVt/H7xBZNn2yCYr5L p1Pw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:in-reply-to:content-transfer-encoding :content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:references:message-id:subject:cc:to:from:date; bh=cHBZidiAOUiAOZKW21aHcr6aX9YvXesORJaUv7tLH/U=; fh=oyHdEbstxowzhRqqb/1wDwFJfR5Zhf/EBrABPbUXR/4=; b=SP2lvTqNCgJmH8wBmOC1NlqHeRerdcKTFpLvoTcPjXn4nnugmCJpmw29WpkAqQxD3p CyZ6wT8zSrZCbdLROstq+oylsnwSesG7Art8KT3o6sux6HIF6gDWTjvxE17qL5FMWa/Q H3HQBVLHLCNsR33vUfY6wqspPXtf9TLEhY7Qf2ha3oke2wKSDcnhJfLaCD9L5yu7WZ4L wo9N5QOB5WJCg3ImF+5fSLnIq+nLDt0OyBG6cU53I9KYt3a4CrkWhnwCcn8fwkFmOojC zdbCYbeXaI0V6XbOxni49l9vUAfI1D5QdpwhsAmTLxnqFbhVtt8yjBeUK3SjF6pIAyxE TrQw==; 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-143682-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143682-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. [147.75.80.249]) by mx.google.com with ESMTPS id k19-20020a1709061c1300b00a5227c90830si2062472ejg.17.2024.04.13.03.38.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Apr 2024 03:38:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143682-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-143682-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143682-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 6DD221F218FB for ; Sat, 13 Apr 2024 10:38:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49D7B2110B; Sat, 13 Apr 2024 10:38: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 E1BBF3D977 for ; Sat, 13 Apr 2024 10:37:58 +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=1713004684; cv=none; b=ITho63arfytwDCQ/bs/XZjhTSIebyElF/M5E2yotWHeRC31PtBWTUazSjOeHzXVrOJXMH/HF1bx7xvYN+wT0yXqZjZcCXhLIxKYjlU9PkrPKQTNlE9Ul+faVDWDg0AnIufjFXGJcA+7d9hfl3sOBIh7rbCQH6JWTI+p750GROIs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713004684; c=relaxed/simple; bh=d5furmS1pq1wFFg1paSHtjqBQPAM3IJaVtZhOQFfNJ8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=F++6yw0LaIXcDRrU9LwYa0siU77Cl31+Yuc9l/caBy61QcovDstRyCsa7LSbv3QaWCyMM7OyfXg5cEEE2f2f1fVVHdjsXNAqCOfG5Syx9ZHWIiOecFz2hvdrF4rpyfLdRfL7f+xVWQV2ieZKCIqpKrUXERrBSgxX//9t+TVm7+U= 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: bizesmtpsz1t1713004662ty78y06 X-QQ-Originating-IP: tgrM3jlQGygBOluqjLsoE4ZL5i0fo68aVOKlWGdx0Sk= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 13 Apr 2024 18:37:40 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: LrCnY+iDm+NgXtWeGYp7hKVOOGauFHtIT65JPyis+DR/7tkTjrebGFSDMRPDJ rpGFDG1rwf+PCQwe/Tj4CHkgGs34GwNsglTuen9NNcoaiyXUtB4sxJ8UI2Eoo7PorvDw02l fPZb4cq0ohUyJGfaYl5eezwESi+w52oj6vXdVvN/QHAVu0BOnRix8y1PZOx2G3WJa5plSQB bQEuBxUeQy6gHoqh6KZpiNbbIQL9c8Zp5HJFDCMBpkdQ9XNmlFBXNRnndiEmEQl9XQnJYkd VNrZaWgLOvyBYKchFgpmVCyJbW8kMA/U36euSxE6iMdiRDuH8+V5zvufVIXOg/ajnDQ3jZz e9WxAW+irOq+J1JLo3wtphNucU3rtHz8UY+HZ1Ik+pLHOJSgczri45pub5yXYHZSRGD5KI5 0V4dDWB8gO44dK83HTSvZQ== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 2616944406899746370 Date: Sat, 13 Apr 2024 18:37:40 +0800 From: Dawei Li To: Yury Norov Cc: tglx@linutronix.de, 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, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/6] cpumask: introduce cpumask_first_and_and() Message-ID: <801BE872BDBCD4A1+ZhpgdItKViCouyN+@centos8> References: <20240412105839.2896281-1-dawei.li@shingroup.cn> <20240412105839.2896281-2-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-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 Hi Yury, Thanks for the review. On Fri, Apr 12, 2024 at 07:40:30AM -0700, Yury Norov wrote: > On Fri, Apr 12, 2024 at 3:59 AM Dawei Li wrote: > > > > For some cases, it's required to make intersection between 3 cpumasks > > and return possible cpu bit. Current implementation for these cases are > > /s/possible cpu bit/set cpu/ > > And sometimes you just need an intersection cpumask, and don't need to return > any set cpu. This patch introduces new API, so description should be as > common as possible. > > We've already have some 3-bitmap functions. Can you look at commit messages > there and align your wording? > > I'll be OK if you just skip this part and go straight to "Introduce > ... to get rid of" Ack. > > > allocating a temporary cpumask var(sometimes on stack) storing intermediate > > calculation result. > > > > Introduce cpumask_first_and_and() to get rid of this intermediate orinted > > what the 'orinted' is? Good catch, typo. > > > approach. Instead, cpumask_first_and_and() works in-place with all inputs > > and produce desired output directly. > > /s/produce/procuces/ /s/produce/produces/ :) > > > > > Signed-off-by: Dawei Li > > --- > > include/linux/cpumask.h | 17 +++++++++++++++++ > > include/linux/find.h | 29 +++++++++++++++++++++++++++++ > > lib/find_bit.c | 14 ++++++++++++++ > > 3 files changed, 60 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..047081c6b9f7 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,33 @@ unsigned long find_first_and_bit(const unsigned long *addr1, > > } > > #endif > > > > +#ifndef find_first_and_and_bit > > Don't need to protect new API unless you've got an actual arch implementation. Correct. I will remove it in respin. Thanks, Dawei > > > +/** > > + * 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); > > +} > > +#endif > > + > > #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..fdc5c4117e8b 100644 > > --- a/lib/find_bit.c > > +++ b/lib/find_bit.c > > @@ -116,6 +116,20 @@ unsigned long _find_first_and_bit(const unsigned long *addr1, > > EXPORT_SYMBOL(_find_first_and_bit); > > #endif > > > > +#ifndef find_first_and_and_bit > > +/* > > + * 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); > > +#endif > > + > > #ifndef find_first_zero_bit > > /* > > * Find the first cleared bit in a memory region. > > -- > > 2.27.0 > > >