Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp133409lqb; Tue, 16 Apr 2024 10:46:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXl6un0tCFyicMYuNCmDqTwkqIOsGlZGmyurPwmq+uOK8U+gVZEXQg73kw+yI0MN0IOmhaNekFICHS4pYhPIdhg5bclya7CMpGTvX7cIw== X-Google-Smtp-Source: AGHT+IFDASWZJ+UbgS0TA8e4glta7J64dp6zymwZnEHIdoxrNrzD6CmVbl8k2GSUZwEkPuOZ0sze X-Received: by 2002:a17:90b:1054:b0:2a5:506f:161c with SMTP id gq20-20020a17090b105400b002a5506f161cmr4002378pjb.4.1713289565409; Tue, 16 Apr 2024 10:46:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713289565; cv=pass; d=google.com; s=arc-20160816; b=muds9wAIJ9gOG1PiEBtxSeKppezK4egzud9Rh6JQVa/GaCWGrX5ezcZz2wXATob+G9 Ij2vVXvy1NAKnFCQGu1Zb53nuBOuYCv2FEBqInVdlj4h3rHKzMmY86/54Ds5EnZNAYBc QRz8UWr7UEWj/i+ajbLP7JY5tb+Cmu0rdFVFYtZU40MNJran+zbHyDk+M5Oh2LZszsht 7+rWfC84X0FSRH+5hOswmGhWwAOL4ntvl/qP4Z5j/UQy191iaPb57OheesXRktttPxR+ js2HLM2XrEDi+iAZwQsiaJ32Lbbp1rdnlZFkecQexaxB8bT6kCmnyhO0xTMI+OceWPTV 3ESg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=JeTAsENhmGxz6+PK9ZT/1dVcAVprad3zPiwx2Dlp4rA=; fh=eUkA1FZ+D9Q0HqSqtBZLKiInw7KDtgrMHwYiNq1trqA=; b=BknkVDU5x2p2jxt2EL87Wg+vj6EfDJC4T5MfN+qyR1fOsz6hY0Wxoip758UPx0xn3B bZZNkrNO9wpsi3vMrkv1JldulDYabnGyJu2ovZmorFTYUkE+blu6WLMoPFb4QTFStnlN 0pm10c6yQP6wGBM3SajS6ZeXCOLHyg8s0MwmNxKe+XrpX66IF0+y20c6AVIv56P9rdA9 uvyH0PpH3X8iZjA0KZzCcqdrBtjtBlJc9buiSOyrA8I5uN+MDBoZC1vZsCWQAppJWdV3 KPYrv6wzVEHkkoDlsf7m2HNTZEKvfsHWQsJqm7BY8TyLy2smNsQTi60KOM9VGflbH5tJ sh3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iwtyXygl; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-147329-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y24-20020a17090aa41800b002a52cc3ab02si11741773pjp.178.2024.04.16.10.46.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 10:46:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147329-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=@gmail.com header.s=20230601 header.b=iwtyXygl; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-147329-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 18D5A2828D5 for ; Tue, 16 Apr 2024 17:46:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A7F2133987; Tue, 16 Apr 2024 17:45:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iwtyXygl" Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C03ED1327ED for ; Tue, 16 Apr 2024 17:45:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713289557; cv=none; b=R5oTWoSng8VhUldjUHU572CDAB0CaMM5MJV42FsWDSDKr6M3mHPZV3vBlJWMrjVGZwF3UjXt6ZK4S6MONATteoInva8kQ0XX5R1c1sohMKchH/2c+/785WrRLuGXSdMxDD3uWQbQ/i2Fp9Db93HfVdw4D/1z/4za3rDwHr32+Mg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713289557; c=relaxed/simple; bh=o9HyLcklcw6qXIEmpaLNIUhCnHYpytbuOpal8ZZ3TRY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kz+4ctnf7xRGg187BFSJwZUn30GgTZcqsknU3U+fP2rQtW/pmlhvNdJqkDQq3GaRBQa0zPefImOxnPq3rEk0HAdPLk9E3LCg2ZeZJ2LbkbT7T+Mj082zZbekZFz58J1Kw6pS5N0a+3DS1hwJ/p9IjJbHnKvgs0MKkkn92EBNZSo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iwtyXygl; arc=none smtp.client-ip=209.85.219.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-dc25e12cc63so16967276.0 for ; Tue, 16 Apr 2024 10:45:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713289555; x=1713894355; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=JeTAsENhmGxz6+PK9ZT/1dVcAVprad3zPiwx2Dlp4rA=; b=iwtyXyglelsdXjw2eHFudaEy/QcJaesQ6qlseXfDYr/pTeMP6H19MHrkoxt2rEuVjH O0rlnuHIzRORepeUz0wYsytR1cOI32cjIC2nBnld4Hy6QdIbrArBX2EoYNQLAE447M1c HlDftxrk25bvJ+tlQslZqCKM8v9xM0LEXShbut/29jCqB4pCPw8sQ/Rvig22rVgzdlsh Zd4iTOvrF/fQyEDg8+RleuPdPDRgVqrTTooSnEXZfhrDU0tViFanvOlTn7qbbmW9JT9c sdb0071KreY5fmdVbE8Ezux8CXMIlzeQOvnTmyVSx3on+rlena2SE+AHJkdZprovTFbj 2Rmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713289555; x=1713894355; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JeTAsENhmGxz6+PK9ZT/1dVcAVprad3zPiwx2Dlp4rA=; b=I41/ljYOGmiZk4R11ZkO1cGZycpwftPKMivlLmM/5W+SyR1217/qCBfGiPxgrsdQ87 PcwtCytpZD2aeQ8FgDjaQ6jKmKK3voZMmTMrw0I4pYU5AdMLQ7VSfk/2Qfg6jOV02Fvf PKjK4Mdc7l94GJcTYJtt59WD2pdCxshnH1+mgtUHMHULqPw476g+URgVUTLXHf7JLb37 e+hsh22r34u9CNgO8iZXLVtIyjytYyUfjA1hgkTdaCBKBpzrkHx0ab4hGilOy/73S2Xs PxkazEbfXv32GH8jS76DX1/6Bj30iOur+CsQHSn3L7WOYDYyCC6JYaVKzDj41FPo9WGm L6jw== X-Forwarded-Encrypted: i=1; AJvYcCXqNA0LBVyPUfVQ5Si3nKEAtMbXb7y9GMzMfxLeklv4VKObP94LxX5IDOTRt7U3/rqGMpoEvjLwfOWRvj1wh3xsEuNIjNfKTg0csPus X-Gm-Message-State: AOJu0YxHLl1QjNw9jxGqTzq0xQbeNZ44OHhDKlF7aOKl/+IZLUMSf22L QECUg81jMx0g2divdu8ROnmekdRntz9V2AHDZ7j4fYG/Sm35yXOE X-Received: by 2002:a05:6902:390:b0:dcf:a4a8:5fb3 with SMTP id f16-20020a056902039000b00dcfa4a85fb3mr2335820ybs.11.1713289554526; Tue, 16 Apr 2024 10:45:54 -0700 (PDT) Received: from localhost ([2601:344:8301:57f0:2767:ac3e:3052:cd0]) by smtp.gmail.com with ESMTPSA id u40-20020a25ab2b000000b00dcd307dc310sm2583223ybi.56.2024.04.16.10.45.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 10:45:54 -0700 (PDT) Date: Tue, 16 Apr 2024 10:45:53 -0700 From: Yury Norov To: Dawei Li Cc: tglx@linutronix.de, rafael@kernel.org, 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 Subject: Re: [PATCH v2 1/7] cpumask: introduce cpumask_first_and_and() Message-ID: References: <20240416085454.3547175-1-dawei.li@shingroup.cn> <20240416085454.3547175-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=us-ascii Content-Disposition: inline In-Reply-To: <20240416085454.3547175-2-dawei.li@shingroup.cn> On Tue, Apr 16, 2024 at 04:54:48PM +0800, Dawei Li wrote: > 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 Acked-by: Yury Norov > --- > 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