From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 95D731B583B; Thu, 20 Jun 2024 17:57:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906234; cv=none; b=IV5oNt9rTBFrOOIFeUNuHVzq/YbBN4wqaT8gmNf6N9yYXa3IOyIbxs9PvSmTMtxY+IER6wQybArOQmO+iaaEIgetxxK330XfYFLa8IL3RjxqecmomNzMvmOT9lsd7OYNPp6vUXlhjWLSQJebgc1dS9GbMF83j7ebkymux/HFyWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906234; c=relaxed/simple; bh=NJiSXR/2q9k2YAA0gEDwZCqD1aqsLC5sqUDA5CWKQZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VkIFafNLrLI8S1P9g3VUjeNKg+ZLpIW3w84KBEOAPX1tJyam3kbrVrRVUdkOXba2UtZIZehybYvPY7G6sDWkhb/fx9WlLc+nlOfLt7VH8QkaHIh7m3aBacCqAa7BpXaxCAY5MufzxrezOeR2ic4j4lffjKtV1oaceggaRsGjPdA= 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=UEmSor8g; arc=none smtp.client-ip=209.85.214.182 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UEmSor8g" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1f6a837e9a3so8127765ad.1; Thu, 20 Jun 2024 10:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906232; x=1719511032; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HgI5gEOuAZO9UYkmZKgqrzsmCGfdpvzU4+T+xEGqCGc=; b=UEmSor8gpsJWxrtWzxyHfWjhaYbI1h3q1L6shSKcG32gc31J0LUvUypWmTfNI80ahQ zgY2cL+Q3NtV3Z7kqPg5UcwEXmVsire7NaL3WMb2mtLaLbxH82jgBHQ/76l7OojHhh5J rBzo975VVn2Yj92aiiF9e4QPVkldTN7fSASVnd4+AUyqkU+uz+jEIKsN681OKNUFNSRD HarD+QtvPGas5G7xEpyHnABurCQrqYmoKxeCw4G4AbwObb9tBiGS1oGEjdG77/aC3X/M wL9UGZM1od3RvEX2HJWNtettC9qpi8wr7A1yQiiVzLHxAqjb1MIMiQaZgjYhTCSJ8h0+ /qjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906232; x=1719511032; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HgI5gEOuAZO9UYkmZKgqrzsmCGfdpvzU4+T+xEGqCGc=; b=qLaDBMQXNXHvma1DJ3WNbD3+rQys5b+VN1z6078l6EH8iIfOZSHYAc3DZgMkIAA7Yp 1gXQNOVAkh+iptgY4v52OR4gwj1irYncpuoyxATg/KYipdBUIoF6YQHAkcvmX1Enx001 4v3lgGqqVxAgsBzK2Af3LF9QfzKFqphzZSuNvwx43TyJmgiJWHOKBAW5YuWOPfiSWLjP 2efG2OEjxD0nQdrZ81gF4w4BCExQTz/mjhjxCDsP8Gn0hML9O00Z/lb5WXP+l25Py4Ai RsHaY8IIBRgg8GlOjsWZ5G7PPYHIWCKEsxa5C+psxwtEkhNNWCogsbMZD+yIqsBr1nzz BjLA== X-Forwarded-Encrypted: i=1; AJvYcCVthfaWAW2t9NKpSmG/8WT5o8I3rG18NaWnknfPNfYPsSa91mIcTe3y4fXrRVOqcCWorN+kpbUTWk4eVY3paWtpFncPoC/q6hvWUozLhg4O9hftq6xJaVi26s9y+ysoiciBLY0WxDukaBkqlA+fl5QRKyV0BZZwKH/QcU+hLz8ENWCczQRYHB8j2gT8CT+SZWRJIWEgdSt5bjrUPkfHDVHSYLwjqipLwFG8Mgy4rQ1IptynHdgNI7xQuJlekXxNfMqDxjuMYH+aj5h0gGgQFD380UE68QaQZzmLzKMWjs5pACHJ1EGAcm3XrVVDMm3hDgGzDfJUqqQbSGFQEf82/5jQBPjw5hrSLPpwH9/CoXmJhL9ZwcVrh/c2lZmAGbUmCBQvWKxKpNCagtYYYyro/vPAGUAjgoBkYDpO+zp+GcN+sv+W3E8v/+TBuwBFB79rP2lHqDNgDEt11dpAseLoELBXRKpt0WkjqO0gt117aOWZoZ2iJV7A8kzHeNG6G5+3ruUts4z/OYzChQv5oXmecIDkWj2h7xs55ssZuqSG13unf+M2YJjK1uIQdd//EhWC1nOj5s03GRiCJgbBufkcWzJJt7xxtWwGxOV3r2S4zzQFdiXOGZ/2z95sn4HEBkZk8MOa2eUxuElRt32DNWnnZMcfTpfZdR5sHHsiFJMzveWuxMjpB3IZ75/E55wDhYefToJNPpVYSRbHm0VU4J7eDsnKUruMfNSvtAs+/kt4dH9uzwy7AC96tfbWz7ghfA1mjp1V4vy6hg== X-Gm-Message-State: AOJu0YwlmbvP9FnD34/VHC7xRpiPfMI8dRbe6nth3LkPC0HwafJxa/Sd 5z0UyYnrn6vbvYC5hjlJiqEf1RcLAZvHcFxtzV73NrJ6xGE2gbvPctGBK1N4XH8= X-Google-Smtp-Source: AGHT+IELGiFFQYXDLuYwffpBy+2gvOLdiLXmpqp8gF/i2JmFW6wub2L8+md2wz99GOx5tRmisC4VJQ== X-Received: by 2002:a17:903:2445:b0:1f9:d282:7a28 with SMTP id d9443c01a7336-1f9d2829be3mr19305765ad.41.1718906231479; Thu, 20 Jun 2024 10:57:11 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9d0ec7a7asm15684145ad.251.2024.06.20.10.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:10 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, "David S. Miller" , "H. Peter Anvin" , "James E.J. Bottomley" , "K. Y. Srinivasan" , "Md. Haris Iqbal" , Akinobu Mita , Andrew Morton , Bjorn Andersson , Borislav Petkov , Chaitanya Kulkarni , Christian Brauner , Damien Le Moal , Dave Hansen , David Disseldorp , Edward Cree , Eric Dumazet , Fenghua Yu , Geert Uytterhoeven , Greg Kroah-Hartman , Gregory Greenman , Hans Verkuil , Hans de Goede , Hugh Dickins , Ingo Molnar , Jakub Kicinski , Jaroslav Kysela , Jason Gunthorpe , Jens Axboe , Jiri Pirko , Jiri Slaby , Kalle Valo , Karsten Graul , Karsten Keil , Kees Cook , Leon Romanovsky , Mark Rutland , Martin Habets , Mauro Carvalho Chehab , Michael Ellerman , Michal Simek , Nicholas Piggin , Oliver Neukum , Paolo Abeni , Paolo Bonzini , Peter Zijlstra , Ping-Ke Shih , Rich Felker , Rob Herring , Robin Murphy , Sean Christopherson , Shuai Xue , Stanislaw Gruszka , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Valentin Schneider , Vitaly Kuznetsov , Wenjia Zhang , Will Deacon , Yoshinori Sato , GR-QLogic-Storage-Upstream@marvell.com, alsa-devel@alsa-project.org, ath10k@lists.infradead.org, dmaengine@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-block@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-media@vger.kernel.org, linux-mips@vger.kernel.org, linux-net-drivers@amd.com, linux-pci@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-serial@vger.kernel.org, linux-sh@vger.kernel.org, linux-sound@vger.kernel.org, linux-usb@vger.kernel.org, linux-wireless@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, mpi3mr-linuxdrv.pdl@broadcom.com, netdev@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 01/40] lib/find: add atomic find_bit() primitives Date: Thu, 20 Jun 2024 10:56:24 -0700 Message-ID: <20240620175703.605111-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add helpers around test_and_{set,clear}_bit() to allow searching for clear or set bits and flipping them atomically. Using atomic search primitives allows to implement lockless bitmap handling where only individual bits are touched by concurrent processes, and where people have to protect their bitmaps to search for a free or set bit due to the lack of atomic searching routines. The typical locking routines may look like this: unsigned long alloc_bit() { unsigned long bit; spin_lock(bitmap_lock); bit =3D find_first_zero_bit(bitmap, nbits); if (bit < nbits) __set_bit(bit, bitmap); spin_unlock(bitmap_lock); return bit; } void free_bit(unsigned long bit) { spin_lock(bitmap_lock); __clear_bit(bit, bitmap); spin_unlock(bitmap_lock); } Now with atomic find_and_set_bit(), the above can be implemented lockless, directly by using it and atomic clear_bit(). Patches 36-40 do this in few places in the kernel where the transition is clear. There is likely more candidates for refactoring. The other important case is when people opencode atomic search or atomic traverse on the maps with the patterns looking like: for (idx =3D 0; idx < nbits; idx++) if (test_and_clear_bit(idx, bitmap)) do_something(idx); Or like this: do { bit =3D find_first_bit(bitmap, nbits); if (bit >=3D nbits) return nbits; } while (!test_and_clear_bit(bit, bitmap)); return bit; In both cases, the opencoded loop may be converted to a single function or iterator call. Correspondingly: for_each_test_and_clear_bit(idx, bitmap, nbits) do_something(idx); Or: return find_and_clear_bit(bitmap, nbits); Obviously, the less routine code people have to write themself, the less probability to make a mistake. The new API is not only a handy helpers - it also resolves a non-trivial issue of using non-atomic find_bit() together with atomic test_and_{set,clear)_bit(). The trick is that find_bit() implies that the bitmap is a regular non-volatile piece of memory, and compiler is allowed to use such optimization techniques like re-fetching memory instead of caching it. For example, find_first_bit() is implemented like: for (idx =3D 0; idx * BITS_PER_LONG < sz; idx++) { val =3D addr[idx]; if (val) { sz =3D min(idx * BITS_PER_LONG + __ffs(val), sz); break; } } On register-memory architectures, like x86, compiler may decide to access memory twice - first time to compare against 0, and second time to fetch its value to pass it to __ffs(). When running find_first_bit() on volatile memory, the memory may get changed in-between, and for instance, it may lead to passing 0 to __ffs(), which is undefined. This is a potentially dangerous call. find_and_clear_bit() as a wrapper around test_and_clear_bit() naturally treats underlying bitmap as a volatile memory and prevents compiler from such optimizations. Now that KCSAN is catching exactly this type of situations and warns on undercover memory modifications. We can use it to reveal improper usage of find_bit(), and convert it to atomic find_and_*_bit() as appropriate. In some cases concurrent operations with plain find_bit() are acceptable. For example: - two threads running find_*_bit(): safe wrt ffs(0) and returns correct value, because underlying bitmap is unchanged; - find_next_bit() in parallel with set or clear_bit(), when modifying a bit prior to the start bit to search: safe and correct; - find_first_bit() in parallel with set_bit(): safe, but may return wrong bit number; - find_first_zero_bit() in parallel with clear_bit(): same as above. In last 2 cases find_bit() may not return a correct bit number, but it may be OK if caller requires any (not exactly the first) set or clear bit, correspondingly. In such cases, KCSAN may be safely silenced with data_race(). But in most cases where KCSAN detects concurrency we should carefully review their code and likely protect critical sections or switch to atomic find_and_bit(), as appropriate. This patch adds the following atomic primitives: find_and_set_bit(addr, nbits); find_and_set_next_bit(addr, nbits, start); ... Here find_and_{set,clear} part refers to the corresponding test_and_{set,clear}_bit function. Suffixes like _wrap or _lock derive their semantics from corresponding find() or test() functions. For brevity, the naming omits the fact that we search for zero bit in find_and_set, and correspondingly search for set bit in find_and_clear functions. The patch also adds iterators with atomic semantics, like for_each_test_and_set_bit(). Here, the naming rule is to simply prefix corresponding atomic operation with 'for_each'. CC: Bart Van Assche CC: Sergey Shtylyov Signed-off-by: Yury Norov --- MAINTAINERS | 1 + include/linux/find.h | 4 - include/linux/find_atomic.h | 324 ++++++++++++++++++++++++++++++++++++ lib/find_bit.c | 86 ++++++++++ 4 files changed, 411 insertions(+), 4 deletions(-) create mode 100644 include/linux/find_atomic.h diff --git a/MAINTAINERS b/MAINTAINERS index b68c8b25bb93..54f37d4f33dd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3730,6 +3730,7 @@ F: include/linux/bitmap-str.h F: include/linux/bitmap.h F: include/linux/bits.h F: include/linux/cpumask.h +F: include/linux/find_atomic.h F: include/linux/find.h F: include/linux/nodemask.h F: include/vdso/bits.h diff --git a/include/linux/find.h b/include/linux/find.h index 5dfca4225fef..a855f82ab9ad 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -2,10 +2,6 @@ #ifndef __LINUX_FIND_H_ #define __LINUX_FIND_H_ =20 -#ifndef __LINUX_BITMAP_H -#error only can be included directly -#endif - #include =20 unsigned long _find_next_bit(const unsigned long *addr1, unsigned long nbi= ts, diff --git a/include/linux/find_atomic.h b/include/linux/find_atomic.h new file mode 100644 index 000000000000..a9e238f88d0b --- /dev/null +++ b/include/linux/find_atomic.h @@ -0,0 +1,324 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_FIND_ATOMIC_H_ +#define __LINUX_FIND_ATOMIC_H_ + +#include +#include + +unsigned long _find_and_set_bit(volatile unsigned long *addr, unsigned lon= g nbits); +unsigned long _find_and_set_next_bit(volatile unsigned long *addr, unsigne= d long nbits, + unsigned long start); +unsigned long _find_and_set_bit_lock(volatile unsigned long *addr, unsigne= d long nbits); +unsigned long _find_and_set_next_bit_lock(volatile unsigned long *addr, un= signed long nbits, + unsigned long start); +unsigned long _find_and_clear_bit(volatile unsigned long *addr, unsigned l= ong nbits); +unsigned long _find_and_clear_next_bit(volatile unsigned long *addr, unsig= ned long nbits, + unsigned long start); + +/** + * find_and_set_bit - Find a zero bit and set it atomically + * @addr: The address to base the search on + * @nbits: The bitmap size in bits + * + * This function is designed to operate in concurrent access environment. + * + * Because of concurrency and volatile nature of underlying bitmap, it's n= ot + * guaranteed that the found bit is the 1st bit in the bitmap. It's also n= ot + * guaranteed that if >=3D @nbits is returned, the bitmap is empty. + * + * The function does guarantee that if returned value is in range [0 .. @n= bits), + * the acquired bit belongs to the caller exclusively. + * + * Returns: found and set bit, or >=3D @nbits if no bits found + */ +static inline +unsigned long find_and_set_bit(volatile unsigned long *addr, unsigned long= nbits) +{ + if (small_const_nbits(nbits)) { + unsigned long val, ret; + + do { + val =3D *addr | ~GENMASK(nbits - 1, 0); + if (val =3D=3D ~0UL) + return nbits; + ret =3D ffz(val); + } while (test_and_set_bit(ret, addr)); + + return ret; + } + + return _find_and_set_bit(addr, nbits); +} + + +/** + * find_and_set_next_bit - Find a zero bit and set it, starting from @offs= et + * @addr: The address to base the search on + * @nbits: The bitmap nbits in bits + * @offset: The bitnumber to start searching at + * + * This function is designed to operate in concurrent access environment. + * + * Because of concurrency and volatile nature of underlying bitmap, it's n= ot + * guaranteed that the found bit is the 1st bit in the bitmap, starting fr= om + * @offset. It's also not guaranteed that if >=3D @nbits is returned, the = bitmap + * is empty. + * + * The function does guarantee that if returned value is in range [@offset= .. @nbits), + * the acquired bit belongs to the caller exclusively. + * + * Returns: found and set bit, or >=3D @nbits if no bits found + */ +static inline +unsigned long find_and_set_next_bit(volatile unsigned long *addr, + unsigned long nbits, unsigned long offset) +{ + if (small_const_nbits(nbits)) { + unsigned long val, ret; + + do { + val =3D *addr | ~GENMASK(nbits - 1, offset); + if (val =3D=3D ~0UL) + return nbits; + ret =3D ffz(val); + } while (test_and_set_bit(ret, addr)); + + return ret; + } + + return _find_and_set_next_bit(addr, nbits, offset); +} + +/** + * find_and_set_bit_wrap - find and set bit starting at @offset, wrapping = around zero + * @addr: The first address to base the search on + * @nbits: The bitmap size in bits + * @offset: The bitnumber to start searching at + * + * Returns: the bit number for the next clear bit, or first clear bit up t= o @offset, + * while atomically setting it. If no bits are found, returns >=3D @nbits. + */ +static inline +unsigned long find_and_set_bit_wrap(volatile unsigned long *addr, + unsigned long nbits, unsigned long offset) +{ + unsigned long bit =3D find_and_set_next_bit(addr, nbits, offset); + + if (bit < nbits || offset =3D=3D 0) + return bit; + + bit =3D find_and_set_bit(addr, offset); + return bit < offset ? bit : nbits; +} + +/** + * find_and_set_bit_lock - find a zero bit, then set it atomically with lo= ck + * @addr: The address to base the search on + * @nbits: The bitmap nbits in bits + * + * This function is designed to operate in concurrent access environment. + * + * Because of concurrency and volatile nature of underlying bitmap, it's n= ot + * guaranteed that the found bit is the 1st bit in the bitmap. It's also n= ot + * guaranteed that if >=3D @nbits is returned, the bitmap is empty. + * + * The function does guarantee that if returned value is in range [0 .. @n= bits), + * the acquired bit belongs to the caller exclusively. + * + * Returns: found and set bit, or >=3D @nbits if no bits found + */ +static inline +unsigned long find_and_set_bit_lock(volatile unsigned long *addr, unsigned= long nbits) +{ + if (small_const_nbits(nbits)) { + unsigned long val, ret; + + do { + val =3D *addr | ~GENMASK(nbits - 1, 0); + if (val =3D=3D ~0UL) + return nbits; + ret =3D ffz(val); + } while (test_and_set_bit_lock(ret, addr)); + + return ret; + } + + return _find_and_set_bit_lock(addr, nbits); +} + +/** + * find_and_set_next_bit_lock - find a zero bit and set it atomically with= lock + * @addr: The address to base the search on + * @nbits: The bitmap size in bits + * @offset: The bitnumber to start searching at + * + * This function is designed to operate in concurrent access environment. + * + * Because of concurrency and volatile nature of underlying bitmap, it's n= ot + * guaranteed that the found bit is the 1st bit in the range. It's also not + * guaranteed that if >=3D @nbits is returned, the bitmap is empty. + * + * The function does guarantee that if returned value is in range [@offset= .. @nbits), + * the acquired bit belongs to the caller exclusively. + * + * Returns: found and set bit, or >=3D @nbits if no bits found + */ +static inline +unsigned long find_and_set_next_bit_lock(volatile unsigned long *addr, + unsigned long nbits, unsigned long offset) +{ + if (small_const_nbits(nbits)) { + unsigned long val, ret; + + do { + val =3D *addr | ~GENMASK(nbits - 1, offset); + if (val =3D=3D ~0UL) + return nbits; + ret =3D ffz(val); + } while (test_and_set_bit_lock(ret, addr)); + + return ret; + } + + return _find_and_set_next_bit_lock(addr, nbits, offset); +} + +/** + * find_and_set_bit_wrap_lock - find zero bit starting at @ofset and set it + * with lock, and wrap around zero if nothing found + * @addr: The first address to base the search on + * @nbits: The bitmap size in bits + * @offset: The bitnumber to start searching at + * + * Returns: the bit number for the next set bit, or first set bit up to @o= ffset + * If no bits are set, returns >=3D @nbits. + */ +static inline +unsigned long find_and_set_bit_wrap_lock(volatile unsigned long *addr, + unsigned long nbits, unsigned long offset) +{ + unsigned long bit =3D find_and_set_next_bit_lock(addr, nbits, offset); + + if (bit < nbits || offset =3D=3D 0) + return bit; + + bit =3D find_and_set_bit_lock(addr, offset); + return bit < offset ? bit : nbits; +} + +/** + * find_and_clear_bit - Find a set bit and clear it atomically + * @addr: The address to base the search on + * @nbits: The bitmap nbits in bits + * + * This function is designed to operate in concurrent access environment. + * + * Because of concurrency and volatile nature of underlying bitmap, it's n= ot + * guaranteed that the found bit is the 1st bit in the bitmap. It's also n= ot + * guaranteed that if >=3D @nbits is returned, the bitmap is empty. + * + * The function does guarantee that if returned value is in range [0 .. @n= bits), + * the acquired bit belongs to the caller exclusively. + * + * Returns: found and cleared bit, or >=3D @nbits if no bits found + */ +static inline unsigned long find_and_clear_bit(volatile unsigned long *add= r, unsigned long nbits) +{ + if (small_const_nbits(nbits)) { + unsigned long val, ret; + + do { + val =3D *addr & GENMASK(nbits - 1, 0); + if (val =3D=3D 0) + return nbits; + ret =3D __ffs(val); + } while (!test_and_clear_bit(ret, addr)); + + return ret; + } + + return _find_and_clear_bit(addr, nbits); +} + +/** + * find_and_clear_next_bit - Find a set bit next after @offset, and clear = it atomically + * @addr: The address to base the search on + * @nbits: The bitmap nbits in bits + * @offset: bit offset at which to start searching + * + * This function is designed to operate in concurrent access environment. + * + * Because of concurrency and volatile nature of underlying bitmap, it's n= ot + * guaranteed that the found bit is the 1st bit in the range It's also not + * guaranteed that if >=3D @nbits is returned, there's no set bits after @= offset. + * + * The function does guarantee that if returned value is in range [@offset= .. @nbits), + * the acquired bit belongs to the caller exclusively. + * + * Returns: found and cleared bit, or >=3D @nbits if no bits found + */ +static inline +unsigned long find_and_clear_next_bit(volatile unsigned long *addr, + unsigned long nbits, unsigned long offset) +{ + if (small_const_nbits(nbits)) { + unsigned long val, ret; + + do { + val =3D *addr & GENMASK(nbits - 1, offset); + if (val =3D=3D 0) + return nbits; + ret =3D __ffs(val); + } while (!test_and_clear_bit(ret, addr)); + + return ret; + } + + return _find_and_clear_next_bit(addr, nbits, offset); +} + +/** + * __find_and_set_bit - Find a zero bit and set it non-atomically + * @addr: The address to base the search on + * @nbits: The bitmap size in bits + * + * A non-atomic version of find_and_set_bit() needed to help writing + * common-looking code where atomicity is provided externally. + * + * Returns: found and set bit, or >=3D @nbits if no bits found + */ +static inline +unsigned long __find_and_set_bit(unsigned long *addr, unsigned long nbits) +{ + unsigned long bit; + + bit =3D find_first_zero_bit(addr, nbits); + if (bit < nbits) + __set_bit(bit, addr); + + return bit; +} + +/* same as for_each_set_bit() but atomically clears each found bit */ +#define for_each_test_and_clear_bit(bit, addr, size) \ + for ((bit) =3D 0; \ + (bit) =3D find_and_clear_next_bit((addr), (size), (bit)), (bit) < (s= ize); \ + (bit)++) + +/* same as for_each_set_bit_from() but atomically clears each found bit */ +#define for_each_test_and_clear_bit_from(bit, addr, size) \ + for (; (bit) =3D find_and_clear_next_bit((addr), (size), (bit)), (bit) < = (size); (bit)++) + +/* same as for_each_clear_bit() but atomically sets each found bit */ +#define for_each_test_and_set_bit(bit, addr, size) \ + for ((bit) =3D 0; \ + (bit) =3D find_and_set_next_bit((addr), (size), (bit)), (bit) < (siz= e); \ + (bit)++) + +/* same as for_each_clear_bit_from() but atomically clears each found bit = */ +#define for_each_test_and_set_bit_from(bit, addr, size) \ + for (; \ + (bit) =3D find_and_set_next_bit((addr), (size), (bit)), (bit) < (siz= e); \ + (bit)++) + +#endif /* __LINUX_FIND_ATOMIC_H_ */ diff --git a/lib/find_bit.c b/lib/find_bit.c index 0836bb3d76c5..a322abd1e540 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -14,6 +14,7 @@ =20 #include #include +#include #include #include #include @@ -128,6 +129,91 @@ unsigned long _find_first_and_and_bit(const unsigned l= ong *addr1, } EXPORT_SYMBOL(_find_first_and_and_bit); =20 +unsigned long _find_and_set_bit(volatile unsigned long *addr, unsigned lon= g nbits) +{ + unsigned long bit; + + do { + bit =3D FIND_FIRST_BIT(~addr[idx], /* nop */, nbits); + if (bit >=3D nbits) + return nbits; + } while (test_and_set_bit(bit, addr)); + + return bit; +} +EXPORT_SYMBOL(_find_and_set_bit); + +unsigned long _find_and_set_next_bit(volatile unsigned long *addr, + unsigned long nbits, unsigned long start) +{ + unsigned long bit; + + do { + bit =3D FIND_NEXT_BIT(~addr[idx], /* nop */, nbits, start); + if (bit >=3D nbits) + return nbits; + } while (test_and_set_bit(bit, addr)); + + return bit; +} +EXPORT_SYMBOL(_find_and_set_next_bit); + +unsigned long _find_and_set_bit_lock(volatile unsigned long *addr, unsigne= d long nbits) +{ + unsigned long bit; + + do { + bit =3D FIND_FIRST_BIT(~addr[idx], /* nop */, nbits); + if (bit >=3D nbits) + return nbits; + } while (test_and_set_bit_lock(bit, addr)); + + return bit; +} +EXPORT_SYMBOL(_find_and_set_bit_lock); + +unsigned long _find_and_set_next_bit_lock(volatile unsigned long *addr, + unsigned long nbits, unsigned long start) +{ + unsigned long bit; + + do { + bit =3D FIND_NEXT_BIT(~addr[idx], /* nop */, nbits, start); + if (bit >=3D nbits) + return nbits; + } while (test_and_set_bit_lock(bit, addr)); + + return bit; +} +EXPORT_SYMBOL(_find_and_set_next_bit_lock); + +unsigned long _find_and_clear_bit(volatile unsigned long *addr, unsigned l= ong nbits) +{ + unsigned long bit; + + do { + bit =3D FIND_FIRST_BIT(addr[idx], /* nop */, nbits); + if (bit >=3D nbits) + return nbits; + } while (!test_and_clear_bit(bit, addr)); + + return bit; +} +EXPORT_SYMBOL(_find_and_clear_bit); + +unsigned long _find_and_clear_next_bit(volatile unsigned long *addr, + unsigned long nbits, unsigned long start) +{ + do { + start =3D FIND_NEXT_BIT(addr[idx], /* nop */, nbits, start); + if (start >=3D nbits) + return nbits; + } while (!test_and_clear_bit(start, addr)); + + return start; +} +EXPORT_SYMBOL(_find_and_clear_next_bit); + #ifndef find_first_zero_bit /* * Find the first cleared bit in a memory region. --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 7123B1B4C58; Thu, 20 Jun 2024 17:57:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906237; cv=none; b=FJ8phEsz78lRnitDHCh+w4eVHrzyGi3vpzRIvhrz06weKgk5cyYWuE3yQs1NitoS998K2+bYUik7yk1BIlPmPrveaCW3l55OwWvH74Mhtwem695h1yCxIFMwseUJKorXNQMvwHYX/XLWx10aR3QdRAtxqxhmG5bX/R5yKL3lLT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906237; c=relaxed/simple; bh=AaGeTjrw0FfF+0h9/U20FA8dwnbicgFR6M2oz4CBhwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=saYHHK/gETN5oulQHjzRo+QjFppqP/bhScEzFupoMpZXpjHlXC676vdwyHmVjGxpJtgOjtsy8M5LZuXp3wFO0OIw7BhSZX8I21rTvoTi/kcy32AijbckXhOYSWUctodNyeFkLKGwzb8GtGvvKtuFYwH4KR6+YcKnSlogJlfwvEo= 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=KKbhWgKz; arc=none smtp.client-ip=209.85.215.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KKbhWgKz" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-6e3ff7c4cc8so879911a12.3; Thu, 20 Jun 2024 10:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906235; x=1719511035; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=93DcC67mVeY/+nPj/RabbHCmpdvAxDoR+WvyjbP4Fv8=; b=KKbhWgKz9TSMkT6GJx+oHzkl14SBbVxhVprFE8KF/u/HwKkgFovEPas7JNigg1VVpd IzxkpMh6nT0UVYcmNhjwq9MIlDRt7g4yYmm1O8iWkPVeTFXREfOb3nd8oxVGrFb4hivT frnx7AjBvakMunPftb+HPJfaJzv7MEmRKL11bKx73fKKPvm19ZVUblrFVREqAa9HlPBz RnyS7gfOlRGCSNyKlrjaT9fU7aG15/2c0Sivad/bbqBvx9C6z5bFVhQxYqskkBgTBcvI dFbp2Vcg+7ym42AldglDeF/T0hQztGy2EkhncU7SuJCrN+Lx13DpCFbN8QA+JJYBhXJr ugWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906235; x=1719511035; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=93DcC67mVeY/+nPj/RabbHCmpdvAxDoR+WvyjbP4Fv8=; b=aUGjv/A8mdkdH7XtdU+XpiM18b9wp6RwlvA94ToqCLV3JXdwI8UxzOGZ4/Pe7s7Vrs tYS3qxbCw8BrH3DA2S+Uw7m2acxtI8VWt3UGstQHXMwOeHQ9Y4RvWyhpYVpsyuKWYwx0 7W/mqV+n6PjY85hFK1TnEc2oKbj3TIdgKI8rfdV4gJgO3hS5szd5Dg+Ximz0NMcdAxx8 UAnfIyKkRewgk17aTUR8LpSw7iz1fiL7Mw/WxemlVlJC6J+BrDrp6mL6Jx2KepoJqPVd okjrEEY9AjEj/rZPKkORGxp27RQgRjTeZ5twhRtfOVktktAOcg75oJRtMFKKsQE2q0zh jHXg== X-Forwarded-Encrypted: i=1; AJvYcCWV+K9ndBXcS6nR4BZCdr5FZ4oAm28DWAbaj9VRGgYwjY6fUR68oH1iagyeEJVBdUKps7X87/GebWzADXXo6w6OzrnClXfJY87eLd3E2m4pT50G23zy4yri8dtA7nQU9A+6fzUTW3obwUBw0PAcTCrWeeHtl7EzDoh9XWk8ex0M8SekmlNEb0AnlgrOZ+KB5f7X5O0ii7i/jAONdEMK32sofaIWhTVqmyeXzfAzVF+9mRHzR80cbpLfQ5ev/N00Z0Yh/ROyXB+WSIeEcZajeO/odnO4SWWQMRDyWpnm6m15o8WfhGJs02LAEV+id3dUTxYT1kKfCLWzdY78Sj+bDnXp5N8BS8WHc0aQ6MoHUYpupvGFtkVRAah9ekciSunxeEuQJTY7onBVQ9J9D3SM/ATLzj+SrLhAD+F7BCUXRY+QWkYmn0VipDEP14SL94St6JmJPYNJQg+ajN8AJ9Z1OeLqB9UzcIms6BiF1P0T89EYthNGaiBDxaNEhxlK8suAGKHDDuEg9dO1r+lS4uw5TxCJHimQRooivTK4/xIBon44uO9wSxYwe7OEQHtUj3qXOuEs7FWJ2YNUPdEyzaITVE6xf/eHRMTdP1hMXEYdpyurFHUFDU9hOd0VWmhnjn4CZ1Oc4mkuYsfc12fFH/EPvNRI7cq823/C2uORlIyZw8eN2s2iSCcEzsjOUgpqHAKslh23shccBpso9RelSLs9SjETXtwyljbfrjwL/oq4Ox9u80UTZJFJQ6ADDftE3kskwueQZJTPqQ== X-Gm-Message-State: AOJu0Yx5frqbE7XwDrj7MGKWoBtAdKKoiU8VtdHN2IEA/JB4LxxmDYel YuuoFvMDzov7GE7AMhbcIt4V2nRa0W4yqzZOH4x6UlAyn+vMhtKMV29e1XxwYF0= X-Google-Smtp-Source: AGHT+IF9ITZbJ7vVNEYTX8RCffN7BEtSM9imchEPcbZOZxImDJdvzQARxKbAqm1aXg+Hi0vjNW3ABQ== X-Received: by 2002:a17:902:f687:b0:1f6:fcd9:5b86 with SMTP id d9443c01a7336-1f9aa3ecca8mr64371665ad.12.1718906234591; Thu, 20 Jun 2024 10:57:14 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9d28ce155sm15196715ad.259.2024.06.20.10.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:14 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, "David S. Miller" , "H. Peter Anvin" , "James E.J. Bottomley" , "K. Y. Srinivasan" , "Md. Haris Iqbal" , Akinobu Mita , Andrew Morton , Bjorn Andersson , Borislav Petkov , Chaitanya Kulkarni , Christian Brauner , Damien Le Moal , Dave Hansen , David Disseldorp , Edward Cree , Eric Dumazet , Fenghua Yu , Geert Uytterhoeven , Greg Kroah-Hartman , Gregory Greenman , Hans Verkuil , Hans de Goede , Hugh Dickins , Ingo Molnar , Jakub Kicinski , Jaroslav Kysela , Jason Gunthorpe , Jens Axboe , Jiri Pirko , Jiri Slaby , Kalle Valo , Karsten Graul , Karsten Keil , Kees Cook , Leon Romanovsky , Mark Rutland , Martin Habets , Mauro Carvalho Chehab , Michael Ellerman , Michal Simek , Nicholas Piggin , Oliver Neukum , Paolo Abeni , Paolo Bonzini , Peter Zijlstra , Ping-Ke Shih , Rich Felker , Rob Herring , Robin Murphy , Sean Christopherson , Shuai Xue , Stanislaw Gruszka , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Valentin Schneider , Vitaly Kuznetsov , Wenjia Zhang , Will Deacon , Yoshinori Sato , GR-QLogic-Storage-Upstream@marvell.com, alsa-devel@alsa-project.org, ath10k@lists.infradead.org, dmaengine@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-block@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-media@vger.kernel.org, linux-mips@vger.kernel.org, linux-net-drivers@amd.com, linux-pci@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-serial@vger.kernel.org, linux-sh@vger.kernel.org, linux-sound@vger.kernel.org, linux-usb@vger.kernel.org, linux-wireless@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, mpi3mr-linuxdrv.pdl@broadcom.com, netdev@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 02/40] lib/find: add test for atomic find_bit() ops Date: Thu, 20 Jun 2024 10:56:25 -0700 Message-ID: <20240620175703.605111-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add basic functionality test for new API. Signed-off-by: Yury Norov --- lib/test_bitmap.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 65a75d58ed9e..405f79dd2266 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -6,6 +6,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 #include +#include #include #include #include @@ -221,6 +222,65 @@ static void __init test_zero_clear(void) expect_eq_pbl("", bmap, 1024); } =20 +static void __init test_find_and_bit(void) +{ + unsigned long w, w_part, bit, cnt =3D 0; + DECLARE_BITMAP(bmap, EXP1_IN_BITS); + + /* + * Test find_and_clear{_next}_bit() and corresponding + * iterators + */ + bitmap_copy(bmap, exp1, EXP1_IN_BITS); + w =3D bitmap_weight(bmap, EXP1_IN_BITS); + + for_each_test_and_clear_bit(bit, bmap, EXP1_IN_BITS) + cnt++; + + expect_eq_uint(w, cnt); + expect_eq_uint(0, bitmap_weight(bmap, EXP1_IN_BITS)); + + bitmap_copy(bmap, exp1, EXP1_IN_BITS); + w =3D bitmap_weight(bmap, EXP1_IN_BITS); + w_part =3D bitmap_weight(bmap, EXP1_IN_BITS / 3); + + cnt =3D 0; + bit =3D EXP1_IN_BITS / 3; + for_each_test_and_clear_bit_from(bit, bmap, EXP1_IN_BITS) + cnt++; + + expect_eq_uint(bitmap_weight(bmap, EXP1_IN_BITS), bitmap_weight(bmap, EXP= 1_IN_BITS / 3)); + expect_eq_uint(w_part, bitmap_weight(bmap, EXP1_IN_BITS)); + expect_eq_uint(w - w_part, cnt); + + /* + * Test find_and_set{_next}_bit() and corresponding + * iterators + */ + bitmap_copy(bmap, exp1, EXP1_IN_BITS); + w =3D bitmap_weight(bmap, EXP1_IN_BITS); + cnt =3D 0; + + for_each_test_and_set_bit(bit, bmap, EXP1_IN_BITS) + cnt++; + + expect_eq_uint(EXP1_IN_BITS - w, cnt); + expect_eq_uint(EXP1_IN_BITS, bitmap_weight(bmap, EXP1_IN_BITS)); + + bitmap_copy(bmap, exp1, EXP1_IN_BITS); + w =3D bitmap_weight(bmap, EXP1_IN_BITS); + w_part =3D bitmap_weight(bmap, EXP1_IN_BITS / 3); + cnt =3D 0; + + bit =3D EXP1_IN_BITS / 3; + for_each_test_and_set_bit_from(bit, bmap, EXP1_IN_BITS) + cnt++; + + expect_eq_uint(EXP1_IN_BITS - bitmap_weight(bmap, EXP1_IN_BITS), + EXP1_IN_BITS / 3 - bitmap_weight(bmap, EXP1_IN_BITS / 3)); + expect_eq_uint(EXP1_IN_BITS * 2 / 3 - (w - w_part), cnt); +} + static void __init test_find_nth_bit(void) { unsigned long b, bit, cnt =3D 0; @@ -1482,6 +1542,8 @@ static void __init selftest(void) test_for_each_clear_bitrange_from(); test_for_each_set_clump8(); test_for_each_set_bit_wrap(); + + test_find_and_bit(); } =20 KSTM_MODULE_LOADERS(test_bitmap); --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 1188D1BB6A6; Thu, 20 Jun 2024 17:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906239; cv=none; b=PdDPgUPiBzd11FJAFYvSNfbTJ11KraEv64Igh7suDgo/zDa8AotQ4PA+GZWjKCjp5o1paaCCLRqzEcCgWINW5c4MkfkcXuIIwx1CrsyQbNaYUNL6xQBdFLNqg4kIT68NO5Y392BBd3Dh2JRbBFBC02NlLd5Awt6t523mIjQVw6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906239; c=relaxed/simple; bh=IVOqRERikmBLXj/S4EhqDnNUn0svGtRW3/tF+qqU7rw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eWTidXXwn+dqHG1OEyJMO2Xx0VqY6x50e0QubUp/3r8H69MN9dvDj+mD95RdTUbISb6iYfmrP8FOQ1hRrQZy+ff4+B0r4kd2nHzxWShnLm4Po3DSq4vJeVt//kmp87w2LLaY9Nl6QHkMiN6cUcIQCX8AGSswgbCa6RMysM1saco= 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=CbyNgHUn; arc=none smtp.client-ip=209.85.210.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CbyNgHUn" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-706354409e1so1087930b3a.2; Thu, 20 Jun 2024 10:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906237; x=1719511037; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HhrUk1+mUN1F/EY1c0kk41tZKguvC2y3hVnxrlEDx7A=; b=CbyNgHUnnmxAeGqFpUvDlO/Xv4DSwaGYjDqTPsPpoVNg+ePvN0DNkLZlEj+WSsFn0E kX2EXvwwmd5Xj0WF8ZTL49c4md3LlLAyqu6nv9GQr4cnyG9KIK9/xpC4tPQ+dkOJURmf 1xTYtxAiaPibRv4nO5IUyBebHKwjtLckoyvA/OwXVDjgfDOCdcinFhezZlUit//llQN7 ntZMzRzKWHyQWTg/+JeNSmeTECeuc7W5wollqg3ZiHNjmm9v7MgQy0BL9r4NEZ4DxKV2 XA/YEyQFECEE4LzeGIDKOc28iKzJbkPCyfHjcIXuNaDaUQ14EevbE1/5PHZu0qq/5H7u /Lmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906237; x=1719511037; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HhrUk1+mUN1F/EY1c0kk41tZKguvC2y3hVnxrlEDx7A=; b=FRvA+w9sSEDdoXvWu5A10gqGEBZle3ImqalrjlwONoqMBAKHH2xmRnW7CiyCjJKbWJ 4ua1z2nR9YGRGfl0nxcsTHkUn8VnO0AEKDjkEbH/uzGcBhsa/rWL2l7rudS0bQz/+4lo 8kVcRH5yYpB9M7Enf4wW1MJnKL6KxomUQQYO1FWfy2nPm/6mYKYwDpi9HPLGgnI9Avd9 5+LXHeeREeECfdgOPF1oQXT3Q25D/YZT2znniv7YnpwJ/7vXPyWFr+ipGABPQkJ0u0vG Il2MMlilqviGpqsQqLKlwVCDsP79VgRgdae204Y2HTRLADxlyDZDvuynb/S3i7HqL8he +JVw== X-Forwarded-Encrypted: i=1; AJvYcCX4omB2ONhorDQQKIudg5r+rMK2KqiPOUvpyUovsPqvPDdwA3V1yOqR0MKT0dp6qH7A6iBO6fZisVnR8Eh1naNXDUBL8fJqz2RAngc= X-Gm-Message-State: AOJu0YyqbtGzI+v3xqPjQNOXIaYtrXY9QEad4+o0RcQOmmOFImup/e4J OZxC0oL7D32pWuc+9ldTstuEBH/XtfLXGqW3m/Ebc6RMIYGgNW+xPIFv+39p X-Google-Smtp-Source: AGHT+IHpmxkoFebUUOkKdZ9h5TVM/Y2ZZ8tmFfJa0z1asysx1Lt0lrjXjd81Wa3PpwLPa2TUwX38TQ== X-Received: by 2002:a05:6a20:2056:b0:1b4:772d:2892 with SMTP id adf61e73a8af0-1bcbb594fdbmr5780731637.32.1718906237195; Thu, 20 Jun 2024 10:57:17 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705cc91dcf8sm12602486b3a.27.2024.06.20.10.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:16 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Jens Axboe , linux-block@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 03/40] lib/sbitmap; optimize __sbitmap_get_word() by using find_and_set_bit() Date: Thu, 20 Jun 2024 10:56:26 -0700 Message-ID: <20240620175703.605111-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __sbitmap_get_word() opencodes either find_and_set_bit_wrap(), or find_and_set_next_bit(), depending on wrap parameter. Simplify it by using atomic find_bit() API. While here, simplify sbitmap_find_bit_in_word(), which calls it. CC: Jens Axboe Signed-off-by: Yury Norov Reviewed-by: Jan Kara --- lib/sbitmap.c | 47 ++++++++++------------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 1e453f825c05..3881996217c9 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -4,6 +4,7 @@ * Copyright (C) 2013-2014 Jens Axboe */ =20 +#include #include #include #include @@ -133,38 +134,13 @@ void sbitmap_resize(struct sbitmap *sb, unsigned int = depth) } EXPORT_SYMBOL_GPL(sbitmap_resize); =20 -static int __sbitmap_get_word(unsigned long *word, unsigned long depth, +static inline int __sbitmap_get_word(unsigned long *word, unsigned long de= pth, unsigned int hint, bool wrap) { - int nr; - - /* don't wrap if starting from 0 */ - wrap =3D wrap && hint; - - while (1) { - nr =3D find_next_zero_bit(word, depth, hint); - if (unlikely(nr >=3D depth)) { - /* - * We started with an offset, and we didn't reset the - * offset to 0 in a failure case, so start from 0 to - * exhaust the map. - */ - if (hint && wrap) { - hint =3D 0; - continue; - } - return -1; - } + if (wrap) + return find_and_set_bit_wrap_lock(word, depth, hint); =20 - if (!test_and_set_bit_lock(nr, word)) - break; - - hint =3D nr + 1; - if (hint >=3D depth - 1) - hint =3D 0; - } - - return nr; + return find_and_set_next_bit_lock(word, depth, hint); } =20 static int sbitmap_find_bit_in_word(struct sbitmap_word *map, @@ -175,15 +151,12 @@ static int sbitmap_find_bit_in_word(struct sbitmap_wo= rd *map, int nr; =20 do { - nr =3D __sbitmap_get_word(&map->word, depth, - alloc_hint, wrap); - if (nr !=3D -1) - break; - if (!sbitmap_deferred_clear(map)) - break; - } while (1); + nr =3D __sbitmap_get_word(&map->word, depth, alloc_hint, wrap); + if (nr < depth) + return nr; + } while (sbitmap_deferred_clear(map)); =20 - return nr; + return -1; } =20 static int sbitmap_find_bit(struct sbitmap *sb, --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 633EE1BBBE1 for ; Thu, 20 Jun 2024 17:57:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906241; cv=none; b=TjrkgHOZ2ak7rOfN3LitM6u8lAj1rgv+2SR62EnD3XSPhFI7Q0xGOWg7b1TwW3TbOkazpVBnrloWYgBJG05Le4mc0LHaqyp+iDStPTb3GH8qQJnSK5PsWDJ4pYtQ5NA2rLLU5rVv41UpkrE2aPC13TzAW4tGBCv7RcEPH9Mvqx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906241; c=relaxed/simple; bh=zlWE/BHnOM5LDq/uDURZ2MNHZjunij/1siJW9ZOxI00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZaSzK3D6QYiFWO/Q14L+kHlroo+4KDcNeYzWgSB2dEk80dQtR6Zomy9RaLTqpizIMTq5+xjmHj5h9gbce96b+tjYN06E1zO1hKckv34sQ+3uMz4sz4Ne2tgAbc5EPICkUBktQEqsQ4kX54IC9Vv5uuuFzw+iFiaZzFoTjkDu7Es= 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=Bw43jsS4; arc=none smtp.client-ip=209.85.210.178 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bw43jsS4" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-7062bf6d9a1so952144b3a.1 for ; Thu, 20 Jun 2024 10:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906240; x=1719511040; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6lqobSglYEzexPVkHLogTghmlkNBAO5YaO0aqGu8OxQ=; b=Bw43jsS4io1Z+u8D9AH8uvq2GxzmZiaxSFF4tOTegVxOCBPYrSKFSIXPu4Pt5dykx+ fYqqEFFHdcyy1VYiU3MUIyBQP2lhzTXChwhiRo+bZ5A+Qr6n3Xnkpy5CGC9lLJkWD1BG sVX2F8UI5jeWzirOsLFh9XNuY6+IsgTioWssrTUHyDY1ZdhAYLsT3C34mehP3UsuoxIS AYkoq9ALs7vfbRl6M/VrH/Q0mnsxPI0hgeU7Oe+VrmFvzuV2mA27nBJu1ODz3JNDZa4T Ky1+x41t9Blx7btkNRt+QM1icwGsUvEFjqDR+0vA/5dEgEgejirueNiJzblcc30NTNsH Nf3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906240; x=1719511040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6lqobSglYEzexPVkHLogTghmlkNBAO5YaO0aqGu8OxQ=; b=lgY/DtL5ByFTdUMRqanLSIVih3NUt9zkllxS+zeA/PTMSkdZpaAIs623szD76qyRq+ ECoI4/prPDs+raFaNFlG7Tl2wtWAeJzjk3yhittaxAPHOtuqqFbK+7ZYSjkz7HOxRlZd QvNtBKTr+v9ThI00pbz208WjJX5CBi+bZn+5fuOb8fosv5iNOp4gj0YAmH3d63tmjNF2 e8UhDZKI5x/uT0UKi4NxP8T/lUVCixKoPwNE5qx7H0R0Fj2E12VjunNlXlHFT6/Uume/ EXB4rqgOXIdoahqVf+sSiRHMaRBGRElI6L0+kjpRp/lnAiJMVWTpbjMoBQUZF48li8QE WHgQ== X-Gm-Message-State: AOJu0YwM9CfKphSgGh/hFAHmGNYs7xmmhOpSURUomt0HfsZOG61iPNFu 8to33PeaxvDAw9Sy0hyqzWw8J1iCL2SFSXDoMX+m6LbZT+xtlOJh4vo2qDpVNM8= X-Google-Smtp-Source: AGHT+IGJ118F6VC3AtyfokUQpT041EuGRx6X707mgLwtYJ0bL5vbzytScTF3N3LGUj1EU6oZpngWkw== X-Received: by 2002:a05:6a00:2e02:b0:705:bc88:612a with SMTP id d2e1a72fcca58-70629d690d3mr7357777b3a.1.1718906239678; Thu, 20 Jun 2024 10:57:19 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb71e66sm13067589b3a.176.2024.06.20.10.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:19 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Christian Brauner , David Howells , Siddh Raman Pant , Dave Airlie , David Disseldorp , Philipp Stanner , Nick Alcock Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 04/40] watch_queue: optimize post_one_notification() by using find_and_clear_bit() Date: Thu, 20 Jun 2024 10:56:27 -0700 Message-ID: <20240620175703.605111-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" post_one_notification() searches for a set bit in wqueue->notes_bitmap, and after some housekeeping work clears it, firing a BUG() if someone else cleared the bit in-between. We can allocate the bit atomically with an atomic find_and_clear_bit(), and remove the BUG() possibility entirely. Signed-off-by: Yury Norov --- kernel/watch_queue.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index 03b90d7d2175..387ee88af71d 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -9,6 +9,7 @@ =20 #define pr_fmt(fmt) "watchq: " fmt #include +#include #include #include #include @@ -112,7 +113,7 @@ static bool post_one_notification(struct watch_queue *w= queue, if (pipe_full(head, tail, pipe->ring_size)) goto lost; =20 - note =3D find_first_bit(wqueue->notes_bitmap, wqueue->nr_notes); + note =3D find_and_clear_bit(wqueue->notes_bitmap, wqueue->nr_notes); if (note >=3D wqueue->nr_notes) goto lost; =20 @@ -133,10 +134,6 @@ static bool post_one_notification(struct watch_queue *= wqueue, buf->flags =3D PIPE_BUF_FLAG_WHOLE; smp_store_release(&pipe->head, head + 1); /* vs pipe_read() */ =20 - if (!test_and_clear_bit(note, wqueue->notes_bitmap)) { - spin_unlock_irq(&pipe->rd_wait.lock); - BUG(); - } wake_up_interruptible_sync_poll_locked(&pipe->rd_wait, EPOLLIN | EPOLLRDN= ORM); done =3D true; =20 --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 94B731B47D9 for ; Thu, 20 Jun 2024 17:57:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906245; cv=none; b=kRbz9Gq/Qnw2iFsk5hw70KGrRTi1ZvueNez206c1hPrDM9hb0W13TlMF5ZTJTdtG1IdOm0CrOPqfwvXZ8flib/cnsMBFv/BrCdQziMeGzY7XTc4Fo7B/WwdIHBLj6ipPI3XN6dmyyUc/BLwq8t8OQWT13GQ7BipxLKCUmR/xQVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906245; c=relaxed/simple; bh=iFxwlIlYJmwx3d0DAafe4DTo8c0DRvIQvWI6JBsAmH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VC840l10T2TeO3tKrnLRaOSwKeZiCD1TFivT6lLmPQiwlDlNlz93nxg8hbiHhl+LD40CUdHJYUG5LRkJvTJhqcudEq3Wq4+UVI0CZD67TEGlGzFDGZvS6nWRwl6pxlOQMqdl3Y/TH3aMxsjwQSRxiW/Uh6bkikd7IOt4+gaUag4= 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=DLQPyUnw; arc=none smtp.client-ip=209.85.214.175 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DLQPyUnw" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1f9d9b57b90so5177655ad.0 for ; Thu, 20 Jun 2024 10:57:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906243; x=1719511043; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1FPc4+rs8YXE06jsQAfHrhhg6ai+ZxxKg14pnSGboBY=; b=DLQPyUnwRwTs03/sHtZECv4mGHGQqVVbF+tTWRYfFko/WUqHxtC01TdW+XCaMSnAXN f7SWDDFr00C+3P9L3+X7J4caoaNCQtAnjgf7NR/UJdtP44Cq8meNoRr4Cp9trLk/wKsc xidStn5/cU5xHCmirhKi+yxi374GL4hjRi0xK3acmX+USDN3RqJE0GEiVM96GwKlVaES qr2WUQUC91IC7WjJojX0g0dV0Mvclbgb4cEFqY6oVCKtkc/kJ1YJBnkVBnAl1iu6yO/X jsvaJKIn7bMUR8Vo9XwQCuwOIsfP0PypD1ZVvq+ZH9ssu3LkcWrdIm8fRCCAW1FEh9VN va2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906243; x=1719511043; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1FPc4+rs8YXE06jsQAfHrhhg6ai+ZxxKg14pnSGboBY=; b=RJWdnFqaVCZcCI3BGkysluooF5ShkZ6w83WZ6iJkXLGhoKZTYneZqj4C96xpM3LTpK lhJaQNFSnhLua1lVNN7IFTck1o5ndEuMlC0QvLnv5nf1nhljgDRzkM8BezEC9M/byBkj c+xUEYeVVs35RsEOgvu5E6TMpIQm4KxDXfKvMJnXIYVQIoS0jlVBOZnBB9Taaui5rTuq l/sxCNchvmZo2WCazStwx17myHqooVLjTKxzvMmyiyjHG4IS3hrNP+ztN4vHTyekFwJt Zq89dBdk/bY/5AyHhiXcI3Y1sUyQchViYfvmNzqTd2ztKeG7fMeXV0XC1YB9oVDa5vwp 2Kfw== X-Gm-Message-State: AOJu0Yzeu0Rw8AN+MrYa2uBmY9nxYtkmzV77v0fOOdo6h22vnXd/f4Fb kcIiqWJgrqel/71YvceUBvxm/Y2Cm+tF4n5wVwCeWjCstViaoVBNBKfPmGjBBGI= X-Google-Smtp-Source: AGHT+IEb+NM6rxCaMHA96INVWGzEGUheh9Av2Sh9BOmyvfITs/fmbdQOFOrzoApocqlSRwsejpxs/A== X-Received: by 2002:a17:903:32c8:b0:1f9:9768:ea61 with SMTP id d9443c01a7336-1f9aa3b0a03mr79468045ad.2.1718906242783; Thu, 20 Jun 2024 10:57:22 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855eeaaddsm140325445ad.122.2024.06.20.10.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:22 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Yury Norov , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Sergey Shtylyov , Mathieu Desnoyers Subject: [PATCH v4 05/40] sched: add cpumask_find_and_set() and use it in __mm_cid_get() Date: Thu, 20 Jun 2024 10:56:28 -0700 Message-ID: <20240620175703.605111-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __mm_cid_get() uses __mm_cid_try_get() helper to atomically acquire a bit in mm cid mask. Now that we have atomic find_and_set_bit(), we can easily extend it to cpumasks and use in the scheduler code. cpumask_find_and_set() considers cid mask as a volatile region of memory, as it actually is in this case. So, if it's changed while search is in progress, KCSAN wouldn't fire warning on it. CC: Peter Zijlstra Signed-off-by: Yury Norov Reviewed-by: Mathieu Desnoyers --- MAINTAINERS | 1 + include/linux/cpumask_atomic.h | 20 ++++++++++++++++++++ kernel/sched/sched.h | 15 ++++++--------- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 include/linux/cpumask_atomic.h diff --git a/MAINTAINERS b/MAINTAINERS index 54f37d4f33dd..7173c74896d8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3730,6 +3730,7 @@ F: include/linux/bitmap-str.h F: include/linux/bitmap.h F: include/linux/bits.h F: include/linux/cpumask.h +F: include/linux/cpumask_atomic.h F: include/linux/find_atomic.h F: include/linux/find.h F: include/linux/nodemask.h diff --git a/include/linux/cpumask_atomic.h b/include/linux/cpumask_atomic.h new file mode 100644 index 000000000000..1aaf9a63cbe6 --- /dev/null +++ b/include/linux/cpumask_atomic.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_CPUMASK_ATOMIC_H_ +#define __LINUX_CPUMASK_ATOMIC_H_ + +#include +#include + +/* + * cpumask_find_and_set - find the first unset cpu in a cpumask and + * set it atomically + * @srcp: the cpumask pointer + * + * Return: >=3D nr_cpu_ids if nothing is found. + */ +static inline unsigned int cpumask_find_and_set(volatile struct cpumask *s= rcp) +{ + return find_and_set_bit(cpumask_bits(srcp), small_cpumask_bits); +} + +#endif /* __LINUX_CPUMASK_ATOMIC_H_ */ diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index a831af102070..557896f8ccd7 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -3312,23 +3313,19 @@ static inline void mm_cid_put(struct mm_struct *mm) =20 static inline int __mm_cid_try_get(struct mm_struct *mm) { - struct cpumask *cpumask; - int cid; + struct cpumask *cpumask =3D mm_cidmask(mm); + int cid =3D nr_cpu_ids; =20 - cpumask =3D mm_cidmask(mm); /* * Retry finding first zero bit if the mask is temporarily * filled. This only happens during concurrent remote-clear * which owns a cid without holding a rq lock. */ - for (;;) { - cid =3D cpumask_first_zero(cpumask); - if (cid < nr_cpu_ids) - break; + while (cid >=3D nr_cpu_ids) { + cid =3D cpumask_find_and_set(cpumask); cpu_relax(); } - if (cpumask_test_and_set_cpu(cid, cpumask)) - return -1; + return cid; } =20 --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 7422E1BD029; Thu, 20 Jun 2024 17:57:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906247; cv=none; b=LdQuBoRguNNGtaP69X3d3kYE3N++luyvDuwXHe2L07eoPl3U1joo4JHRM2s/467imaJsLhzv/h7IgC8E0s/S76vAmgEN3uf1Wji59L7f8bRoIj+R6s5y6Danup/67lJbvEFTckSCOADNXIesIPjWuPArtho+ttcOP3u2YLFut2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906247; c=relaxed/simple; bh=I8E4t6KyeRkVK0XRtHQ/iGfj4wklBzc3eMAZGHg/dHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qU5SudiyuSHDY62JDf9fnO4CJiexRHzTaSW0CRIDh++x2Amf3NKzkvCErdd2EO0fBR9Rtxc+2dCO1Ip2TTnJD237TTbydzdm/kPP3V+CTrxBtn22RJ4fxtHlI6x9lFmqRNS0IsaUKROpHQ1xTrgVgchzkZRyLHd2SINSCBGrtS4= 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=XDMLBjzZ; arc=none smtp.client-ip=209.85.210.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XDMLBjzZ" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-704313fa830so1019065b3a.3; Thu, 20 Jun 2024 10:57:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906246; x=1719511046; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IYUrMJ63QpynCjnizoXrh5ONbtIqYlUBJ6H7w/nSvAY=; b=XDMLBjzZ8Sge7JK00GtL7l057jBIPzHXubhP5UyU4AjxxahLd0yyrtPpfFk6hKnDVF EsYEXfxwWcJ95vUUqWXYp/41KbVRxiX29+pm6Kbi1yAL4Mi4qX+sUawk1hCbmBlbmKA0 RFMqaumM4meyRNSM/LS+l8C2QOiI0D8Ppa8r/zDwrFNJdOiRiIFmwUuHCQrqiemR6Nbt Cq3CPQzJP2lOU3bNNvDZtm0XlCDdXS22gdMYy4wf/rsvFRg9ZOnNUIWA79r3A8Fs0NVH NQawEchgnkO0lhqRkSQpoB6Qrr9b707Qo9BoChIk+1iQsGiMBqgnG4pSSL2oOd2l2s0T LHqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906246; x=1719511046; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IYUrMJ63QpynCjnizoXrh5ONbtIqYlUBJ6H7w/nSvAY=; b=frhqFCBSGpBAkF56K/xnPtHYQPWZjhsAsK0IlIa6YSP848KFWJnxEIReyQ1IR+4cu9 st6nw4E0CioiI+Nj5MkbqhhByyWsg93ssv7HtdFQMPGkDl0NyrZA257FVa4VO13lBRRr gMl83pHsW3fdaxNAklM1qg68yMKR/KD9wtzqFJfxH9uGOgC5vPVcCEYx5rB0X5PA79nS NY8fhE5c1YPoQ56Y9vWtJNtEDCPcBdN3ti0czIQF8QMUYnYOk6nTfl7j2lLFPKbdjrMz UC8Mx+PZpANnGw2nU7kLcwCutJFoHlcQyR6bGJFJcnhJpdar2AWMKbDFynhBj0pTptV8 qfEg== X-Forwarded-Encrypted: i=1; AJvYcCWEiSOg+d266YxE1tTX4jpdRJYAU4HOnygdSPSQROwJ4vLXZ538G3vaoCTaT4p9xYyy2QR3W9U7IMnhWOE5eGfOowieY0ovKSWV6w== X-Gm-Message-State: AOJu0YwwFnfPgaNy7SwRLIP4cD5uwP6S0YmHn20ApzPbDqSn/FXJfyU+ 0nGnfMrwMsrpFcdJy7RT4MJ6Qan7yPrnLvv9GsAQTOId9n0OG5EN2chbsfFHiwg= X-Google-Smtp-Source: AGHT+IG0aUolJNs5TqVDOYzchwzf39ZB9KCQwKk1Wxr/VlXlAuIN0072V2NcOb8Lz9Wo4da6XcV69A== X-Received: by 2002:aa7:8b0f:0:b0:705:d9e3:6179 with SMTP id d2e1a72fcca58-7062bf98e16mr5100552b3a.26.1718906245736; Thu, 20 Jun 2024 10:57:25 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705cc967356sm12643957b3a.63.2024.06.20.10.57.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:25 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Thomas Bogendoerfer , linux-mips@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 06/40] mips: sgi-ip30: optimize heart_alloc_int() by using find_and_set_bit() Date: Thu, 20 Jun 2024 10:56:29 -0700 Message-ID: <20240620175703.605111-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" heart_alloc_int() opencodes find_and_set_bit(). Simplify it by using the dedicated function, and make a nice one-liner. Signed-off-by: Yury Norov --- arch/mips/sgi-ip30/ip30-irq.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/arch/mips/sgi-ip30/ip30-irq.c b/arch/mips/sgi-ip30/ip30-irq.c index 423c32cb66ed..a70e7af93643 100644 --- a/arch/mips/sgi-ip30/ip30-irq.c +++ b/arch/mips/sgi-ip30/ip30-irq.c @@ -2,6 +2,7 @@ /* * ip30-irq.c: Highlevel interrupt handling for IP30 architecture. */ +#include #include #include #include @@ -28,17 +29,9 @@ static DEFINE_PER_CPU(unsigned long, irq_enable_mask); =20 static inline int heart_alloc_int(void) { - int bit; + int bit =3D find_and_set_bit(heart_irq_map, HEART_NUM_IRQS); =20 -again: - bit =3D find_first_zero_bit(heart_irq_map, HEART_NUM_IRQS); - if (bit >=3D HEART_NUM_IRQS) - return -ENOSPC; - - if (test_and_set_bit(bit, heart_irq_map)) - goto again; - - return bit; + return bit < HEART_NUM_IRQS ? bit : -ENOSPC; } =20 static void ip30_error_irq(struct irq_desc *desc) --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 5FAE51BD4FF; Thu, 20 Jun 2024 17:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906250; cv=none; b=CWdDY97+Ja3uIVM1k9SemCpQeDLdFK8Psri4xhSbmRvjZ+QNq63gCKU70KbKlP52QQkfgGKvSlyyL7EPLUD8up6eh7DK0JKZeKDe3N65kxauO0XLxF+xDt7gXc5e3Bh9sV2OZPYHSjKkEzMJYyCOFgU9GeLlHTwCuxPxTC/sSnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906250; c=relaxed/simple; bh=T5HCBT7hE6rw7jOLllKCodQDT8hDNoNna7/UPL4o8E4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jeWH/AXrGuJBZiz6PRDZWRVdL2G2iXjpVwKRHFgrgFMaxmqmytyJHyp6JI0Z/Ub+CXmYI0Z2GoN5+mibs09fnj54UDYs9+kgVAPlqO5H7dnGPwwQ2CxaBWKrdUFxD6ylxfHO8H/dgsAQi1iSwfQhUKbxMs7h7DHyjKPnzysqYYs= 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=ghrW6QSi; arc=none smtp.client-ip=209.85.214.169 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ghrW6QSi" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f992388bbbso10601075ad.3; Thu, 20 Jun 2024 10:57:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906249; x=1719511049; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SVPa52iej7DfypFk891Jp8gHmdO7ancy2F0FLVrhULs=; b=ghrW6QSiVcTFkuuMhy3wm8wpmT3MYIFHpftOn5GF6apmEKE/lKfBDatQPc1mhnpmJF Qd6Ri5vCgY8NluWR9Gn1rQLmPEp6ITAqNCAoRGzVX+HehBSWKO6bjL//zvGNzL4XPbsv oddsGJWjL12O+GGYocWJffP1o4N3gnyaIPyKrX6jrbNmLiHJpn1S+6BOCZKeBBmc1jdM wYIL4xncGABED2J8ETuh42esGPrq6tDuRUkDzkKVwx4TygAyZF08Gycdr4HKrF/3mSsj 2tHkumZZIoB5du2OIWOkHmpXznaoHPJSi1cH45V+jeDdSWDHt34S9/ujx8lr044bOZC9 Jm4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906249; x=1719511049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SVPa52iej7DfypFk891Jp8gHmdO7ancy2F0FLVrhULs=; b=Cw86/myhN7YC0kWqbr/c30XQBlYhpCsPLVUukCkLIok43fMbpGXFclKKJVo+W7TDOQ 1jCJXDw7iSRQSnUsacbzMaGRnRj6Jy6r4oDWO6SBeaVMNBpYw+Af31+2rxe1JRjCsPnz NikTzgvbFBhafsEjMIFP9BdYto9v2GiJcw41Q7uzII7R3mZkf6NacaEEd0UCgdOMHoI7 X1WytKlGy6Xzj/7P+gI849I5vH1M96F2Gci5tBsd/5sGqw2isf0iXFJgHa1qVQ7fGRp0 K6mhAOtV4wg8E3vnOREGQUBRB8w9DqRtgrl1l/NiAoAEtgh7caeoH1FrDod6xgqwX/2H /L6Q== X-Forwarded-Encrypted: i=1; AJvYcCVvl/xhTP8FW9TBK0pjRlM0GQHGSRdF3PYMpKy5HUeETvhwGWrqQ2/zWYtzofBAkG7oxC2ePuXbO5W28yYmPDPghXf/QFa308LzYQ== X-Gm-Message-State: AOJu0YzXuMw+0F/z3briAzNR+YQ5xi4YpQv3t2blDFYM0eeUkeMpWMHk q1a77A2X00qFLMgPuuJwpr9u3YwsYfpiBDnXGGwEAZAKaaLoVCV3N9Cl1CCTG1o= X-Google-Smtp-Source: AGHT+IHCdI+iyTAhfn6J/fOToFnwrUzAO2Rfv2J8npjgxO3dQFprACFEqiP5ctWW4UyOi6jtP+LZKA== X-Received: by 2002:a17:902:f545:b0:1f6:f96c:2f06 with SMTP id d9443c01a7336-1f9aa473e32mr63554035ad.44.1718906248643; Thu, 20 Jun 2024 10:57:28 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e5b85bsm140398935ad.32.2024.06.20.10.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:28 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, "David S. Miller" , Rob Herring , Sam Ravnborg , Yury Norov , sparclinux@vger.kernel.org Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 07/40] sparc: optimize alloc_msi() by using find_and_set_bit() Date: Thu, 20 Jun 2024 10:56:30 -0700 Message-ID: <20240620175703.605111-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" alloc_msi() opencodes find_and_set_bit(). Simplify it by using the dedicated function, and make a nice one-liner. Signed-off-by: Yury Norov --- arch/sparc/kernel/pci_msi.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/sparc/kernel/pci_msi.c b/arch/sparc/kernel/pci_msi.c index acb2f83a1d5c..55ff78a8f37c 100644 --- a/arch/sparc/kernel/pci_msi.c +++ b/arch/sparc/kernel/pci_msi.c @@ -3,6 +3,7 @@ * * Copyright (C) 2007 David S. Miller (davem@davemloft.net) */ +#include #include #include #include @@ -96,14 +97,9 @@ static u32 pick_msiq(struct pci_pbm_info *pbm) =20 static int alloc_msi(struct pci_pbm_info *pbm) { - int i; - - for (i =3D 0; i < pbm->msi_num; i++) { - if (!test_and_set_bit(i, pbm->msi_bitmap)) - return i + pbm->msi_first; - } + int i =3D find_and_set_bit(pbm->msi_bitmap, pbm->msi_num); =20 - return -ENOENT; + return i < pbm->msi_num ? i + pbm->msi_first : -ENOENT; } =20 static void free_msi(struct pci_pbm_info *pbm, int msi_num) --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 4B9DB1B4C3B for ; Thu, 20 Jun 2024 17:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906253; cv=none; b=Qu5sRwoQc2KLFUYwXu1HhMy4yBVSQsWG6ThcyfPYnLs3J4TEvHUbiDPe5B6mam+/K64X90ikNvtrfuCdr35RfN+pMWzXPpzL5nxsMg1dshZJ6JMeDxsbHUaKihl8MMaYqJqPgVWsvCoiFMG1hqdbfJXEHFnzY0HUdBQVz9WU22w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906253; c=relaxed/simple; bh=1N1SZwR+ksGwCPMDZYiDQ+lz9Ae8zgclHhUvA9YDZ20=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DtXgYyjkBBcj69xisbMKGXGYOb6p3Bg5exRrk2qm447AytwDU3+JBCUN06hdRtSeOk5BX/XcoSWVzP08smCzHiMSheL/DWIG5phfzEpOO/xv9FSf1V7iw33r30NJ69vzv+p9E6N9BvZS051g36dkkKp1zYh6+r4Zw3f34csDcYE= 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=N6Ax8TWK; arc=none smtp.client-ip=209.85.216.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N6Ax8TWK" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2c80637d8adso437377a91.0 for ; Thu, 20 Jun 2024 10:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906251; x=1719511051; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6bzcYC+7QMJSAq6nbwz/pdTxPIFYLtbDE2ea+6aoErY=; b=N6Ax8TWK/5S7LFzNubmvjXIcFaltUm246RwutTt8uHNolawsptLejpXv1wJNVcH7hi KtU7lYy7vHO89A4F3nsYvoIQws8gZtFISVipwoEstwMIf9ZqeLx1RFbE+0GtejXiiO+K LhKmOhM2rJxJi8XazSM93P+6VQ5/sgkEFvqYWjMsYohuO3Ru1IMCBAhZ7AMPOso5dwDl e/csIfKmJn3PltsOYLUvZ+RmjZuExUbN0hu/UOsnsRbnCf8OBYXiXkCJGtQnifNWcFOb pIrdnchl1EmsqcUUSVWrjBc6DV3nXu2uum/e32jAth3tSFT3MeGDGljCYKNZmbj5R+OB 5eUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906251; x=1719511051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6bzcYC+7QMJSAq6nbwz/pdTxPIFYLtbDE2ea+6aoErY=; b=gHjqF/iQzF4fu6vwdPhvGpvf87Dm/HIxUiPHAb5UysLOUEjmPWTWd5UUv/HtkPApoM D2FZc+3OfwJblVA8M8CNYIqW1R+F4qd0yYQ9KnjwpHH0V3zrUTYF/43VLjFb5e/s6Q+H +wLoh6wheKitjf3tSPKG/INSatTnghnk9e5DL7TLOAdevmDe+yofRP1g7TsrvY4/PlPL PDsJBa/NlfHd1QhV3ZjlHezNoTvjqJZoXu1uzUr9C31Iw66C6duER98VCZmCUEJpk85x hTwPe5ngleB9V7TiHq/EenXsrl2gPk7Vt+ON7Te/XK2ufYoOqfTSsb9gA1fcaIkN1zNB NlUw== X-Gm-Message-State: AOJu0YwSS/o0sDcwL5I3rSpcFTXMnZpKPNQDPzLguy+nh2QYVParbgsl E5BhtJcfINA2s1eaFrkMWgGKdIAS5+eFRmKfFOjrNcq4phw674lpWx23IBR3OBg= X-Google-Smtp-Source: AGHT+IGzyYHmrHK4/S/CrwdNkwiA+pUDJ3yDivu3+UrGd8HpzK6oOgREUf8KUPo9rqfklDv5mSyQmQ== X-Received: by 2002:a17:90b:4d8a:b0:2c8:84b:8286 with SMTP id 98e67ed59e1d1-2c8084b834dmr1256023a91.37.1718906251564; Thu, 20 Jun 2024 10:57:31 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e53e0743sm2004328a91.15.2024.06.20.10.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:31 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 08/40] perf/arm: use atomic find_bit() API Date: Thu, 20 Jun 2024 10:56:31 -0700 Message-ID: <20240620175703.605111-9-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify subsystem by use atomic find_bit() or atomic API where applicable. CC: Will Deacon Signed-off-by: Yury Norov --- drivers/perf/arm-cci.c | 25 +++++++------------------ drivers/perf/arm-ccn.c | 11 +++-------- drivers/perf/arm_dmc620_pmu.c | 10 +++------- drivers/perf/arm_pmuv3.c | 9 +++------ 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c index c76bac668dea..4c5d23942352 100644 --- a/drivers/perf/arm-cci.c +++ b/drivers/perf/arm-cci.c @@ -4,6 +4,7 @@ // Author: Punit Agrawal , Suzuki Poulose =20 #include +#include #include #include #include @@ -318,12 +319,9 @@ static int cci400_get_event_idx(struct cci_pmu *cci_pm= u, return CCI400_PMU_CYCLE_CNTR_IDX; } =20 - for (idx =3D CCI400_PMU_CNTR0_IDX; idx <=3D CCI_PMU_CNTR_LAST(cci_pmu); += +idx) - if (!test_and_set_bit(idx, hw->used_mask)) - return idx; - - /* No counters available */ - return -EAGAIN; + idx =3D find_and_set_next_bit(hw->used_mask, CCI_PMU_CNTR_LAST(cci_pmu) += 1, + CCI400_PMU_CNTR0_IDX); + return idx < CCI_PMU_CNTR_LAST(cci_pmu) + 1 ? idx : -EAGAIN; } =20 static int cci400_validate_hw_event(struct cci_pmu *cci_pmu, unsigned long= hw_event) @@ -792,13 +790,8 @@ static int pmu_get_event_idx(struct cci_pmu_hw_events = *hw, struct perf_event *ev if (cci_pmu->model->get_event_idx) return cci_pmu->model->get_event_idx(cci_pmu, hw, cci_event); =20 - /* Generic code to find an unused idx from the mask */ - for (idx =3D 0; idx <=3D CCI_PMU_CNTR_LAST(cci_pmu); idx++) - if (!test_and_set_bit(idx, hw->used_mask)) - return idx; - - /* No counters available */ - return -EAGAIN; + idx =3D find_and_set_bit(hw->used_mask, CCI_PMU_CNTR_LAST(cci_pmu) + 1); + return idx < CCI_PMU_CNTR_LAST(cci_pmu) + 1 ? idx : -EAGAIN; } =20 static int pmu_map_event(struct perf_event *event) @@ -851,12 +844,8 @@ static void pmu_free_irq(struct cci_pmu *cci_pmu) { int i; =20 - for (i =3D 0; i < cci_pmu->nr_irqs; i++) { - if (!test_and_clear_bit(i, &cci_pmu->active_irqs)) - continue; - + for_each_test_and_clear_bit(i, &cci_pmu->active_irqs, cci_pmu->nr_irqs) free_irq(cci_pmu->irqs[i], cci_pmu); - } } =20 static u32 pmu_read_counter(struct perf_event *event) diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c index 86ef31ac7503..bd66d90dfda6 100644 --- a/drivers/perf/arm-ccn.c +++ b/drivers/perf/arm-ccn.c @@ -5,6 +5,7 @@ */ =20 #include +#include #include #include #include @@ -580,15 +581,9 @@ static const struct attribute_group *arm_ccn_pmu_attr_= groups[] =3D { =20 static int arm_ccn_pmu_alloc_bit(unsigned long *bitmap, unsigned long size) { - int bit; - - do { - bit =3D find_first_zero_bit(bitmap, size); - if (bit >=3D size) - return -EAGAIN; - } while (test_and_set_bit(bit, bitmap)); + int bit =3D find_and_set_bit(bitmap, size); =20 - return bit; + return bit < size ? bit : -EAGAIN; } =20 /* All RN-I and RN-D nodes have identical PMUs */ diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c index 7e5f1d4fca0f..f41cc2ee9564 100644 --- a/drivers/perf/arm_dmc620_pmu.c +++ b/drivers/perf/arm_dmc620_pmu.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -303,13 +304,8 @@ static int dmc620_get_event_idx(struct perf_event *eve= nt) end_idx =3D DMC620_PMU_MAX_COUNTERS; } =20 - for (idx =3D start_idx; idx < end_idx; ++idx) { - if (!test_and_set_bit(idx, dmc620_pmu->used_mask)) - return idx; - } - - /* The counters are all in use. */ - return -EAGAIN; + idx =3D find_and_set_next_bit(dmc620_pmu->used_mask, end_idx, start_idx); + return idx < end_idx ? idx : -EAGAIN; } =20 static inline diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c index 23fa6c5da82c..f3b20a3b1d9c 100644 --- a/drivers/perf/arm_pmuv3.c +++ b/drivers/perf/arm_pmuv3.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -903,13 +904,9 @@ static irqreturn_t armv8pmu_handle_irq(struct arm_pmu = *cpu_pmu) static int armv8pmu_get_single_idx(struct pmu_hw_events *cpuc, struct arm_pmu *cpu_pmu) { - int idx; + int idx =3D find_and_set_next_bit(cpuc->used_mask, cpu_pmu->num_events, A= RMV8_IDX_COUNTER0); =20 - for (idx =3D ARMV8_IDX_COUNTER0; idx < cpu_pmu->num_events; idx++) { - if (!test_and_set_bit(idx, cpuc->used_mask)) - return idx; - } - return -EAGAIN; + return idx < cpu_pmu->num_events ? idx : -EAGAIN; } =20 static int armv8pmu_get_chain_idx(struct pmu_hw_events *cpuc, --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 1DDEA1BD915 for ; Thu, 20 Jun 2024 17:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906256; cv=none; b=RkxlpJ87bwgSFaOciqKoOfdrNpkBuyzH2pUYpKJVhgw7bNfE/6NJzePkaeg9CTL+oa5HG95cKbW/27wvsYdivv+rUZAcAV7aUzNY3rWRCBBd48GMbkxkxHvRlTy1VybbuaCDTsGdDHTs88jCig7uQIBOYjoKIfuSE9MC7hx5Y1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906256; c=relaxed/simple; bh=IJH0Xr1pzPS2QRONxWqkkm6N53c8msn9QYo80VGvKXU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OKysLKrFIzbQFUfc/QCLTDD8cCI/x2XpSYciPc5rCax+PTGxdktdLDl0Zk11eVu78/cKaQunNJ/kfSY7eSHDLbsB3k1N3u6SECR7Drf3usNRuTw5a13sbdISJwnIi+vMTYx8+rvhXbIsvA4pUOlrup9cTuzlDKM/C0QJwb3/iWw= 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=MUwu9T40; arc=none smtp.client-ip=209.85.215.170 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MUwu9T40" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-6e41550ae5bso903926a12.3 for ; Thu, 20 Jun 2024 10:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906254; x=1719511054; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V5DGzLYbAUAdrqbJyW80kv/C/QU59EDA9QcwDgDhhzU=; b=MUwu9T40imIjXvxFeNDOMqpFLMD7DqnrIFwdIO87dT2BGC0rNjG9nrBKp3E0WHBULS IlYlVkxGELvGw+5SWCxK0+7e5a3XCCKtjD26h6O6hXmZR8UyHCKSXLx/MLud50ow6idi e5XAE7uGc8SsU3UFDrmDs7Rt2ftWVSSkTG+pco22wBCx5fPejDWtrPuNzwM/vAB6HW/2 INnx5MfIGOzZ0fYNMIk8Gw9vfJpD4cs6Y91LvjSXFmnDWmaZ9ppyKxQvoicQTYLkfI1n nL/ao5PkQFpYbUgf5STpVC8q/fjuP5ZZsgmeM34Kwm20cVlRzBgQDEATjx03/t5pnLBl upPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906254; x=1719511054; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V5DGzLYbAUAdrqbJyW80kv/C/QU59EDA9QcwDgDhhzU=; b=er3zW+n4JW8/FZzZVTshc2IfXeSFdSTZFURJt3U9u+U+1Cr9IrcK7Tr3CAHf80pzPm DXrarcTbK4JdhHlWbk+M1zLqqTDz6QP7w5XUx3G2i39j/O68DtDAlaMKnaHIXdRcvauI /chajvnfTZC9bOHEmf6yvnxqhLrdnduIqhGme1IJymRzISFAz+gRZxm78gXBDQr3EeVA 9PP760TPtgUqwPxX/KfmsLe2JAze1SnZf1q16CijIO0/p9GYbX+RvhpB/xOfMeWPPeX/ e78ILPeVi7ttH4hHwj63yQA8SfOnsDTOJKVjLsbZyTrTNC2lNL7/Dyw/0Q60SD5AFVxK VVxQ== X-Gm-Message-State: AOJu0YxzAcg3fFUwYQW00zCr2SbbBcRqAEXp0LzXaxsXTu9aEjOnWYTc M+R/P//hazln7Q14YW4vcIrHhl26P2YPFMxEK63vEOFffLjbCVqdsrOqlf1d1Cg= X-Google-Smtp-Source: AGHT+IEumLOfgHy9ptSYIb80BMzk95Th2CfOVKwPVPTL9GX5qt4vT11e0BpVTPi3+WCx/rlRYbxNTg== X-Received: by 2002:a17:90a:e60d:b0:2c4:a7af:4d79 with SMTP id 98e67ed59e1d1-2c7b5c75d03mr5990223a91.11.1718906254495; Thu, 20 Jun 2024 10:57:34 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e5af9b5dsm1989603a91.43.2024.06.20.10.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:34 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Shuai Xue , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 09/40] drivers/perf: optimize ali_drw_get_counter_idx() by using find_and_set_bit() Date: Thu, 20 Jun 2024 10:56:32 -0700 Message-ID: <20240620175703.605111-10-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function searches used_mask for a set bit in a for-loop bit by bit. Simplify it by using atomic find_and_set_bit(). Signed-off-by: Yury Norov Acked-by: Will Deacon --- drivers/perf/alibaba_uncore_drw_pmu.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/perf/alibaba_uncore_drw_pmu.c b/drivers/perf/alibaba_u= ncore_drw_pmu.c index 38a2947ae813..1516f2c3d58f 100644 --- a/drivers/perf/alibaba_uncore_drw_pmu.c +++ b/drivers/perf/alibaba_uncore_drw_pmu.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -266,15 +267,9 @@ static const struct attribute_group *ali_drw_pmu_attr_= groups[] =3D { static int ali_drw_get_counter_idx(struct perf_event *event) { struct ali_drw_pmu *drw_pmu =3D to_ali_drw_pmu(event->pmu); - int idx; + int idx =3D find_and_set_bit(drw_pmu->used_mask, ALI_DRW_PMU_COMMON_MAX_C= OUNTERS); =20 - for (idx =3D 0; idx < ALI_DRW_PMU_COMMON_MAX_COUNTERS; ++idx) { - if (!test_and_set_bit(idx, drw_pmu->used_mask)) - return idx; - } - - /* The counters are all in use. */ - return -EBUSY; + return idx < ALI_DRW_PMU_COMMON_MAX_COUNTERS ? idx : -EBUSY; } =20 static u64 ali_drw_pmu_read_counter(struct perf_event *event) --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 CFE521BE23F; Thu, 20 Jun 2024 17:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906259; cv=none; b=YvWy5ZD1oUhuxW4/xxUlbbVp8J4QGhGbIcFs8NXp5uEI7s0+qSafFQ4n8f4b+b3BZPPSKRDmbbPLke438mSqcPIQSsMXdJ/N+i42HMfWTQnbbY57SdQiTZ3iiU2RdN1OUSJ5N1K8VGTilwebqF7ZAb315VQkYsumMnhCPj4SXCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906259; c=relaxed/simple; bh=z4fUClb8dXuu+9jxRPnwJI/cA/pCMiUgLCw/o06uyx0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VeaeXwCBNs+AmV+3QgiTGNHEUMxIHJ7uureN6F2bcz66tI4eAUlvmYzFv7HRmraLXz7okCcrmJCbZkAXoFv+TwxPGwpgIUskSO7whD78T/TO0KqPY8RnbwF428vySx1VHgoj8y8imgPXwZfcHO8vNuvMthpy8zBBLnRoIZC+AEQ= 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=RW2+F/2z; arc=none smtp.client-ip=209.85.214.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RW2+F/2z" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f9aa039327so10177265ad.2; Thu, 20 Jun 2024 10:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906257; x=1719511057; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S217yThdoIjU6QeboD3InxZjcbGcSzSpB5H/7IT54JI=; b=RW2+F/2zWMGQqFszbWwyd3img/QWoXlD5hZNpcP4AlE7S8GcAo/Zu+fbnLrgL75OP3 sW6h7jSEp1Ja02h0b8YEo3PYYEwdMWjhHUyFyl16kUs5LU+vaykGzgCYIkd+Ie8vZJ21 zyYvUBj/RTmf2wDmDZx62ETIJkEh1Tmja0z8aHX+Yq/C+wszPPkmARTewHks+RGZv6/X zu0XXgokWU+6zVjWqRaspMcGvgONFFDwy9YXQ9tMXzC3Kyj3BCHyDQ8UnyDkBj9XdBYk 3lfaMZ78uXIzCF+sEvSWfNHCVIH9pf/Mzs2oCZOKC4h+gHcjNnkPmWlnf/gSb/XH8sEL wFiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906257; x=1719511057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S217yThdoIjU6QeboD3InxZjcbGcSzSpB5H/7IT54JI=; b=OgOJJ+5Eer9yHAoJZLmKk65ka7B75LtRr1WbXZPxkIRQNkMd9dvbVnjwyKJGLLkFE5 VWr7iMqLwx8bQkGbuiPEcX+5xob8bH3nEBwZzgWZFWvuqf5duAIMGeywvsyN6hxmNDSe PHpYLqx5I5K0RH1k5ydBn4yhHja6cU9bD0Ue/VS0JjCjK1D4NtaL2cSvOGApcwHwXNmI T709gqOq7gyucPds/L1fyfWIaH6HSvhYZ4YDgOtCTuGyvr1ALJTDz5ANAscs0T7Exwxh 1mAoijHaeOieNI27TL1L94v6BbCpPOqLZQTXa2ruLYQGbwxndLlewmaaV1K+GQgFa5qP o5Rg== X-Forwarded-Encrypted: i=1; AJvYcCV+aDMqmPmf8DRiZkrvONwCL8hjTqTi/Fq0FT6b6zilwlVZbfboNtxEc2D7z9YEgdw+NSZyGkgWG90Lb2f1q00JoCPsSpKHqTH/ X-Gm-Message-State: AOJu0YyS4nyfMJ/ALdURHt5xLRs+5FcL5OQcoUz0norqAKXF1VqMCEIp vBkdS9Zp1kzkixcCwIkxvrrY0kch9apgaCCDeeRqUERsRg3oG7IWZMWeVPmdmyw= X-Google-Smtp-Source: AGHT+IEsuBQgU5tFbCUFweOZuFt81ozFdug3U9h5V494KH6XT54Y5Mu4sLWTPUs8g0qHcojBfwlzTw== X-Received: by 2002:a17:902:ea01:b0:1f6:3445:3437 with SMTP id d9443c01a7336-1f9aa3de130mr63778435ad.27.1718906257091; Thu, 20 Jun 2024 10:57:37 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855f5e72asm140359505ad.308.2024.06.20.10.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:36 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Fenghua Yu , Dave Jiang , Vinod Koul , dmaengine@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 10/40] dmaengine: idxd: optimize perfmon_assign_event() Date: Thu, 20 Jun 2024 10:56:33 -0700 Message-ID: <20240620175703.605111-11-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function searches used_mask for a set bit in a for-loop bit by bit. Simplify it by using atomic find_and_set_bit(), and make a nice one-liner. Signed-off-by: Yury Norov Reviewed-by: Dave Jiang Acked-by: Vinod Koul Reviewed-by: Fenghua Yu --- drivers/dma/idxd/perfmon.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/dma/idxd/perfmon.c b/drivers/dma/idxd/perfmon.c index 5e94247e1ea7..063ee78fb132 100644 --- a/drivers/dma/idxd/perfmon.c +++ b/drivers/dma/idxd/perfmon.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2020 Intel Corporation. All rights rsvd. */ =20 +#include #include #include #include "idxd.h" @@ -134,13 +135,9 @@ static void perfmon_assign_hw_event(struct idxd_pmu *i= dxd_pmu, static int perfmon_assign_event(struct idxd_pmu *idxd_pmu, struct perf_event *event) { - int i; - - for (i =3D 0; i < IDXD_PMU_EVENT_MAX; i++) - if (!test_and_set_bit(i, idxd_pmu->used_mask)) - return i; + int i =3D find_and_set_bit(idxd_pmu->used_mask, IDXD_PMU_EVENT_MAX); =20 - return -EINVAL; + return i < IDXD_PMU_EVENT_MAX ? i : -EINVAL; } =20 /* --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 ACFB01BE840; Thu, 20 Jun 2024 17:57:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906262; cv=none; b=d9N5yWNgxYswk6Hi02Sc6OCXcAp4xXtWVZkuADBa5O3dWTwa/TDElebelKNUOLJ38CK+Ot4/RD68mZdTCR1qteyhMsxrx1K3tSRtnIXF27UPiRRpM3c5SXdnyCHU08MrEYy7C3W+JdQ2DrvX2OclsXv71ywCqrlz0SJa25Rcedg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906262; c=relaxed/simple; bh=oWm6wtDkPUXuudaVdlEMN+qr0+C3Zd/WIco5LGbYaIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l1XugCCgOsxr6W4HJYPok6PrTi3e2Qprc0O49Cr5dnhPw5xxox5SVXjLANTl4R+94jqMo/lkcbWN9tt3WB+58aw2JGzKtSX85d82Hi2P+QmOetKfO5GKApR8ohcquEO7JV2wLosP2qe2azNvw0U6pHLfmyXEifstR6kAF9DVQNI= 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=eRXaqcR5; arc=none smtp.client-ip=209.85.210.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eRXaqcR5" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-70631cd9e50so996929b3a.0; Thu, 20 Jun 2024 10:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906260; x=1719511060; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JyCbmEERBgdbr2L9cnI5uWj+Q286mUzZnK0ig6JQYFg=; b=eRXaqcR5hxFD/igTe/+gznaNKr0e6drSDBzoiknRHGsVwZ/u3fIswf0SEZieOx+gcj y5cSdi8j5Cu5QAMdsZJSn/awgVaV6k3lGOR3I9io2P/AC2zcgKzEV+LOpLANVhvj23v3 OtFS678cInEWEUwXlqo9/H/ZB4cso/VXTwdFsSzlZvArzWYiNRqnpwqgvy3IZzoq3wj5 oqVHNeWAs2r+UPs3ksm1JzwDJnEedwfKixRJ/dRMGVxW5NokTPjCfDBbY1aEtPh7kj1K HDCxwK+xvZskgdkbL9NnGOCUxeXDUnz3o9Jn8gz+fY2ozk/EgwOYSqw95RtiZ6r6KH52 eHrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906260; x=1719511060; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JyCbmEERBgdbr2L9cnI5uWj+Q286mUzZnK0ig6JQYFg=; b=qnliM5k1yKarEyzs5tsHiLwA7KpR4WwXBoPGA+TXK7vXMPvWX3KOwAtn29QeWQdBNC 4onNHjPRuZcqEjYupvohCTIFP0M7PIU8qaGMwFpuqlSXBUTSnzItMDw746i6IY9z4E9s jF0e5HBxy2j2yu+aetnc+ICC/dPEWN+ef4oGP4GWB9NsGxe0XkxqZJlWTTAOlxgn6LnS yGpL1Z7UsEcXP8KekB/ScmKkpDIvCurtmOblH7DmiTXS/xt2vWG7OdAnzlJSZBVVgND3 vMh0DjcdNiIW2EkYkslWTv8rVYrtK7B60NCbT4MLPKLPZ5j4cV8T+JLIhANnWFIMPrCh +2dw== X-Forwarded-Encrypted: i=1; AJvYcCXyE4YI7TkYJ2cuDZM/1Qi7pAYtDoYWxlR6B2n7sBNx72awKsqPeuUKZzua2yuNYqCI8SVf4XReVXnf6NIfjoVPkmyyK1fIr+ua9obaqEA= X-Gm-Message-State: AOJu0Yy2/GudJgIPyXCfx52RKwyD4kUp9V5jUwTM8Ii+uDzZBtgiNKXg gkoQynfCSR8H81XTmhT0HCiuFR0d8by6aAESu8PKCoIgZQRK2bfbuXRdUPwLDMc= X-Google-Smtp-Source: AGHT+IF6k794+bXj65/GLuqQFCenpTYt6QZL4TjH+FL/9upfIcGTU3RlCoM3IuIh09X+vOAPLBF0ZQ== X-Received: by 2002:a05:6a00:2f49:b0:706:2acd:405 with SMTP id d2e1a72fcca58-7062acd0449mr5420295b3a.31.1718906259963; Thu, 20 Jun 2024 10:57:39 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb3d65csm12619770b3a.102.2024.06.20.10.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:39 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Kalle Valo , Jeff Johnson , ath10k@lists.infradead.org, linux-wireless@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 11/40] ath10k: optimize ath10k_snoc_napi_poll() Date: Thu, 20 Jun 2024 10:56:34 -0700 Message-ID: <20240620175703.605111-12-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ath10k_snoc_napi_poll() traverses pending_ce_irqs bitmap bit by bit. Simplify it by using for_each_test_and_clear_bit() iterator. Signed-off-by: Yury Norov --- drivers/net/wireless/ath/ath10k/snoc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/snoc.c b/drivers/net/wireless/= ath/ath10k/snoc.c index 8530550cf5df..d63608e34785 100644 --- a/drivers/net/wireless/ath/ath10k/snoc.c +++ b/drivers/net/wireless/ath/ath10k/snoc.c @@ -5,6 +5,7 @@ =20 #include #include +#include #include #include #include @@ -1237,11 +1238,10 @@ static int ath10k_snoc_napi_poll(struct napi_struct= *ctx, int budget) return done; } =20 - for (ce_id =3D 0; ce_id < CE_COUNT; ce_id++) - if (test_and_clear_bit(ce_id, ar_snoc->pending_ce_irqs)) { - ath10k_ce_per_engine_service(ar, ce_id); - ath10k_ce_enable_interrupt(ar, ce_id); - } + for_each_test_and_clear_bit(ce_id, ar_snoc->pending_ce_irqs, CE_COUNT) { + ath10k_ce_per_engine_service(ar, ce_id); + ath10k_ce_enable_interrupt(ar, ce_id); + } =20 done =3D ath10k_htt_txrx_compl_task(ar, budget); =20 --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 6AFBC1BE86B; Thu, 20 Jun 2024 17:57:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906264; cv=none; b=OpH2UUf3W6AA0PnHYFvkKgk3VferXxjb4TRSgHrAaJ05fFk1eVwrF/1Brxp2N1NQ+qtjUkRdvVsaPDYUpM4jXa0g2yiO7mforGnhMSjlvTw9IdiCo83X8vmHxYoSvv//JYbiMoR5uaqxHIn5qIa46c9fxhRg1q53vPZutpbwWmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906264; c=relaxed/simple; bh=Kq0Le/AzG6nhFQ+X/jkGw++00vhHiyLHVZOAh/AXVkQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T6aJHpvfrPTlexzKzd2CNQODM/bPuLYbQGXbNyy4pdvMInLcoN0lUC5GmBCfrcfz3bI/wt39Bya0kKq1RpLZBBwFunB+VFuG1Yf903PzZJvSD9Fh0nFtmEwYFDeSLQa6Z8BgFMQ39ovMAJ1aZ+DqRdjntBawgyb30Pf+RX8bSJc= 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=jTKbvNiQ; arc=none smtp.client-ip=209.85.214.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jTKbvNiQ" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1f9de13d6baso4397325ad.2; Thu, 20 Jun 2024 10:57:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906263; x=1719511063; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AoRopA5ztbgBJRJEKQhgRyu/McLJD9vC3MN+d4zw/zY=; b=jTKbvNiQWVes0vDEyyG7Shb/nyfrhRKxbMpNfF8B8b/f0f9Aqa0VC8ZUskzSe1BPL+ ryoDVXOPPqiNr6jLZfX9kO6WD7hyE9enr/15IaMJgy7dNJUtdTBOvJZUEATjHV8t3KhQ htZ7c8N0On6YyDDIThnOF2AZbAumvdP/MJTwZaV6VBpvbtR1qA8TXBEN2Q/g/UlKF6l5 dFVGV+/3cb61ncD6DQzJo8A/DPOLj93NDp7/rbeqLFx4+Vj070wHSC/+xttzIEkdHeN0 INk5OUB5zm+Ky+7nNKvRZcOwd5WWukXUlz7r0zE4XXWPNapkB7qOPMDYtwq5EVyzk1FL 78kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906263; x=1719511063; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AoRopA5ztbgBJRJEKQhgRyu/McLJD9vC3MN+d4zw/zY=; b=n8lyzdvaVfLDeu1utbSDARPIi6PdzVc+i3UGUcyrsugaKFaVIKNCyoIn8AuqWxD8GD feYDm2OQQtQ2cOI71qJnuYZqyMg0s4QbBzmvc4qiw6Ye2Q6dI2wdasainhVv1zfp19TH ADJanZ7BKCffPnpcWV+R/jCdJR+BjP4QWHQtpnKdKIvDoSuGLkHZOG8OBq0vnd6FJLTc qYNmWYYL9lNJ3INGTWC9Rll4ZqUIIzCusmNwi7WoTmXopMr+2TJuFcb8kqiHI5SCmsCF YJXLRSopQnEq0V/C5cePZGntFVsWQLIPsnF74TnY2s4HkKpMGpt+HXlIRynLWVsdJnw2 2qbA== X-Forwarded-Encrypted: i=1; AJvYcCUCFKQBH8+38o+UYcgQzRI37Gvai1cpSHUJBT+vDxK7FxVO78GnzRtESRvmMq4Ppn8XHKVvdycaXbdgPZBDBb9y1vxr56cAXWHjwI/H0VE= X-Gm-Message-State: AOJu0YyH6GniuyTuDAYYEvEDgdwrOqj9g7YgliMm4AMq0Xen3b416bhv TIYnUXTDvF8OJMeRdoDrZCouP0N2pfBLD4PElLpmOLOc12hHGRQPlp8seYzL8a8= X-Google-Smtp-Source: AGHT+IFHXkrW2RCg31fg2jAnnLV16IOTYwG6YWnnpIOxreHYDd/8dS8YUOFYNhDpd1HKZjOhC4X4hA== X-Received: by 2002:a17:902:d508:b0:1f9:d1f7:3fe5 with SMTP id d9443c01a7336-1f9d1f76f10mr22446525ad.34.1718906262729; Thu, 20 Jun 2024 10:57:42 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9d6b45389sm13541245ad.216.2024.06.20.10.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:42 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Ping-Ke Shih , Kalle Valo , linux-wireless@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 12/40] wifi: rtw88: optimize the driver by using atomic iterator Date: Thu, 20 Jun 2024 10:56:35 -0700 Message-ID: <20240620175703.605111-13-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" rtw_pci_tx_kick_off() and rtw89_pci_tx_kick_off_pending() traverse bitmaps bit by bit. Simplify it by using atomic for_each_test_and_clear_bit() iterator. Signed-off-by: Yury Norov --- drivers/net/wireless/realtek/rtw88/pci.c | 6 +++--- drivers/net/wireless/realtek/rtw89/pci.c | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireles= s/realtek/rtw88/pci.c index 30232f7e3ec5..28c0f4c99cf8 100644 --- a/drivers/net/wireless/realtek/rtw88/pci.c +++ b/drivers/net/wireless/realtek/rtw88/pci.c @@ -2,6 +2,7 @@ /* Copyright(c) 2018-2019 Realtek Corporation */ =20 +#include #include #include #include "main.h" @@ -790,9 +791,8 @@ static void rtw_pci_tx_kick_off(struct rtw_dev *rtwdev) struct rtw_pci *rtwpci =3D (struct rtw_pci *)rtwdev->priv; enum rtw_tx_queue_type queue; =20 - for (queue =3D 0; queue < RTK_MAX_TX_QUEUE_NUM; queue++) - if (test_and_clear_bit(queue, rtwpci->tx_queued)) - rtw_pci_tx_kick_off_queue(rtwdev, queue); + for_each_test_and_clear_bit(queue, rtwpci->tx_queued, RTK_MAX_TX_QUEUE_NU= M) + rtw_pci_tx_kick_off_queue(rtwdev, queue); } =20 static int rtw_pci_tx_write_data(struct rtw_dev *rtwdev, diff --git a/drivers/net/wireless/realtek/rtw89/pci.c b/drivers/net/wireles= s/realtek/rtw89/pci.c index 03bbcf9b6737..deb06cab5974 100644 --- a/drivers/net/wireless/realtek/rtw89/pci.c +++ b/drivers/net/wireless/realtek/rtw89/pci.c @@ -2,6 +2,7 @@ /* Copyright(c) 2020 Realtek Corporation */ =20 +#include #include =20 #include "mac.h" @@ -1234,10 +1235,7 @@ static void rtw89_pci_tx_kick_off_pending(struct rtw= 89_dev *rtwdev) struct rtw89_pci_tx_ring *tx_ring; int txch; =20 - for (txch =3D 0; txch < RTW89_TXCH_NUM; txch++) { - if (!test_and_clear_bit(txch, rtwpci->kick_map)) - continue; - + for_each_test_and_clear_bit(txch, rtwpci->kick_map, RTW89_TXCH_NUM) { tx_ring =3D &rtwpci->tx_rings[txch]; __rtw89_pci_tx_kick_off(rtwdev, tx_ring); } --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 934921BF30B; Thu, 20 Jun 2024 17:57:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906267; cv=none; b=fJpkiqwvhWg/4qW58S51Dy0lyisFEZeNAcQlfB9T6Wz4eZ3iB1fRe2QshR89GFFJK69Q0rebPRH9fTfBWWv/AVF3U1ld60vJt37RhqdEqqSX/vBlxYmNhk1k2Waw4fyLHJZ3f7tIIQIa/38zSRp21RFNpLvX1vlHmq8LxgLerBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906267; c=relaxed/simple; bh=4urYLJw0UpvAK2blqcUY9JMaZPzQLSOYCfTIDKdM0wk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I3SbdjmQ36N9pTG//C4G+U4f5/xV2HbFUsbZjovJh/bZ0a8mEE742djv4FDbeiv+MMRenixhTJ1A1yzXN9HcAzxxHRzdGO0HGpCJsHFOAvI8gH8lOQNK2nmPbPB+l9pUbl/d6a1rV+kW7u+bxGcq2FZpPJtnZmf5kRz/+jjaJmU= 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=UqmRxU5q; arc=none smtp.client-ip=209.85.215.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UqmRxU5q" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-70b2421471aso912993a12.0; Thu, 20 Jun 2024 10:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906266; x=1719511066; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t63yqlV4wLLuWcSezXBxdfBk1sgIeDP3Cs2mWXS4mPM=; b=UqmRxU5q008n8Hk/SZhgqSyMGikfKTeSfXfCO35p/hkRT1vs4T+HtpSmhpGyDIsMyz Wm1k/eys49cNlMuoFrQjcMSKFD1kB1VDevOYxR6ulPUIOIuxjpHO6ROO7uH8bPLAVZRZ m4FlK20xDGxCbgL60HLs6yPVClP6bkJCFpSlW5XdPujwwhmA4QUVhkydD7OgnTqrGM6u JqEb3LolGMsUhngBKblL0TSAiO3gScBhyH3OHw9RXhL1flr6YxSOxsXPWlj2A4c0sZ/5 fsUfoB9wLiZC5O/N81yKricAtPNecDPwgqK2uBdN9m2X6fZcvjgBzkdc6xxEU9cE92TZ UbAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906266; x=1719511066; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t63yqlV4wLLuWcSezXBxdfBk1sgIeDP3Cs2mWXS4mPM=; b=VGOFXT/wytJTtIckbsjZ6PdmcJQysI4PJN4Ll3VtHWljomdYp4+nMNZS7j60JiiYQe tzTFEs6DWW7aUc/oZWAon3k0YH7blVlJVnXadhsjnLmf9jITJX9J3yH0u7NoYxlAzPC1 nZLom0dGE7QXB35oC1pYKnNKfn9jOlWvuoejx4Fah6oO+b75S63VVxXtwCJJUxJqpyzD VVW5QdLFGtbgvaoLegfleRHNo1XFSpS9beD4kN4JcaN35OEVyVWnuyQ2/7/3XbqD1d19 WZEMs2u8S+7UfNQifqcncbMcV9Wldm5TZPlk/s1drJtLAi/DTy7quNNjTf0/vaJ94sHO IGEw== X-Forwarded-Encrypted: i=1; AJvYcCXGaQKfpaVnUAiOaZjMnydkWuRx/PNTrFcbYQnXhA/8cnt7FE8FiRVpdbfOTDhA8jursQdHNdtswYdXKrPfvtVjE7Te X-Gm-Message-State: AOJu0YwU+jduzWIZu79ff7r3PZFcdLw6G0DOmCMOJEPvR+h9+6kOIHHp A7an1v1+dczhtaSrA+hFJ6mYO7d6E8SpCyr8UIWd9sptMJU67CSxnIH5nGWEE3g= X-Google-Smtp-Source: AGHT+IFx76sQ02XBcANL8DcVNfxhLC0tLCAwAsMFhiQVAC5yOXkmJulbSByKVrlRFBXWR+fdSTy4Gw== X-Received: by 2002:a17:902:db0e:b0:1f7:124:b820 with SMTP id d9443c01a7336-1f9aa45eaf1mr62717175ad.50.1718906265990; Thu, 20 Jun 2024 10:57:45 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9d0c8341csm15936625ad.162.2024.06.20.10.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:45 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 13/40] KVM: x86: hyper-v: optimize and cleanup kvm_hv_process_stimers() Date: Thu, 20 Jun 2024 10:56:36 -0700 Message-ID: <20240620175703.605111-14-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function traverses stimer_pending_bitmap in a for-loop bit by bit. Simplify it by using atomic for_each_test_and_clear_bit(). Because there are only 4 bits, using for_each_test_and_clear_bit() will generate inline code, so no excessive bloating with the new API. While here, refactor the logic by decreasing indentation level. CC: Sean Christopherson Signed-off-by: Yury Norov Reviewed-by: Vitaly Kuznetsov Acked-by: Sean Christopherson --- arch/x86/kvm/hyperv.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 8a47f8541eab..96acbcf603f5 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -28,6 +28,7 @@ #include "xen.h" =20 #include +#include #include #include #include @@ -870,27 +871,27 @@ void kvm_hv_process_stimers(struct kvm_vcpu *vcpu) if (!hv_vcpu) return; =20 - for (i =3D 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++) - if (test_and_clear_bit(i, hv_vcpu->stimer_pending_bitmap)) { - stimer =3D &hv_vcpu->stimer[i]; - if (stimer->config.enable) { - exp_time =3D stimer->exp_time; - - if (exp_time) { - time_now =3D - get_time_ref_counter(vcpu->kvm); - if (time_now >=3D exp_time) - stimer_expiration(stimer); - } - - if ((stimer->config.enable) && - stimer->count) { - if (!stimer->msg_pending) - stimer_start(stimer); - } else - stimer_cleanup(stimer); - } + for_each_test_and_clear_bit(i, hv_vcpu->stimer_pending_bitmap, + ARRAY_SIZE(hv_vcpu->stimer)) { + stimer =3D &hv_vcpu->stimer[i]; + if (!stimer->config.enable) + continue; + + exp_time =3D stimer->exp_time; + + if (exp_time) { + time_now =3D get_time_ref_counter(vcpu->kvm); + if (time_now >=3D exp_time) + stimer_expiration(stimer); } + + if (stimer->config.enable && stimer->count) { + if (!stimer->msg_pending) + stimer_start(stimer); + } else { + stimer_cleanup(stimer); + } + } } =20 void kvm_hv_vcpu_uninit(struct kvm_vcpu *vcpu) --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 CCD051BF32D; Thu, 20 Jun 2024 17:57:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906271; cv=none; b=VawZVzNUnDZroT4cPLSwEnO6Y07CMrqxkxrgL1ivB6Vl2jWhPjzMswD9BJhvS5VLooaA73myia/S2KbMMzF13qOt97SkghNuJt5kJQJe9BYCDuRs3GiN4DTvmO0vBGRzZlBZWkodh/WM+sHaIC1Rufs1vxxCWAoySlO8Xtq1Ty4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906271; c=relaxed/simple; bh=XG2GU2+zFp405uZad/oPORvyyKH9S5jaQ4HWX9leIiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e15OaC6HtrEaW3QgA147Hp9EqWydEZ17nNc0HG167Mv8f5kwdeFOhRysqDafBxl6Wr6O+ByLclOvmjKkrQsOzlataXbRL3bxmFdsYbAFO4v7Nl1xCxcQwjyemHWwaiOsuaXvmF3pIaVIcjgXviyRHP5Gz6m/e231lmpC2nuh04c= 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=hVupu5/H; arc=none smtp.client-ip=209.85.216.52 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hVupu5/H" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2c7b3c513f9so1044678a91.3; Thu, 20 Jun 2024 10:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906269; x=1719511069; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Dh6DBCUzBIXsYTBDCp5GIVtLCP64sJqenVlYmZsGDjI=; b=hVupu5/H5+dZneVBgBWN4KCPLGzYbfc6+CEbUbh0rNl9ajM2oNoots6DCrchcKm7mr VDFEcXh4pqAsxRpcqdcunlL9V02dKuBwtKmuWwLRt5d0RCX4UMFjZ7zL2ajQZKl7R3Ks zkbrbL41U+sL+FraDGlNuWjFNbFVY2d59Rbvv30iRzD4Y2gWoTJNcPgUaJnagYio8rbC J/fQyMVbWOmu1MYbJuYQJyj9rOb3QfIgvM4pK4Lt3ssdQrkjWUVSxOaCdrvwXeQhTucr Ajit/NsdNIR1oVVdAn3TYZvF92lAJmjk0V2R7T+KSl4Lb6qlint5m8d1IZFpuryzF0a3 sJhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906269; x=1719511069; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dh6DBCUzBIXsYTBDCp5GIVtLCP64sJqenVlYmZsGDjI=; b=FjfvfT6swsg30ptzVgygZqko0kwWjukO2+7lbpcDTEteRCanntocZZIAgsXCrCeBEp GMz7vefABQYYg0itcK9suBZQKS6YJ5YJKfIOeNBUDJTnLtYIM1GhOcH2hVNGuPutyZna ydIsv2r1vbZMv2Dlc4GO5pXpASfmayF1+E7n8D2KVsA8R6loIKNPeJcoUVRGTzLob6n0 lZLLMbD3Ka6nmmViuDiUe442Mk0rA9kLpRNbwNAjjP0qkx5P7orz8/R03aS82t35a6w4 xZkYOugBtDSy82tudfeRunraDisRqXXClqhtoVoK6JI6vjlLLc+JY+5HCQF0q33HUnNn 1ZWw== X-Forwarded-Encrypted: i=1; AJvYcCVksFpp5i3t8egpWEroYU2QOGq/1kO3uPiQuc46+wyfcyFclwM9gGqb22be1aNB+rm+0ei9YJoHhAAdveBuQgmh/xIIVwBO02BdIE+htx75ycj0PkzqI3+26VsrFT86lALPbF78d5Vw X-Gm-Message-State: AOJu0Yz5TETUKK4RYpvtel4hO2LdWPXHRasus1/JLVc7d1Jd6zrT5qaR l+Ye95o/1Bjqf/0DA1qiigQ2ks3P6uvrQTAt3oNrBgP5+pg0j5NH+BFytqUzN0o= X-Google-Smtp-Source: AGHT+IG83Pia9Bm6gkce/miVZL5B0kwBeKxwmNQd+rjCKpzPOZ8JsfwHh5KI+bHzYlygVmWjL4TSuQ== X-Received: by 2002:a17:90a:d58a:b0:2c7:c6a1:42d9 with SMTP id 98e67ed59e1d1-2c7c6a144d7mr4361713a91.49.1718906269090; Thu, 20 Jun 2024 10:57:49 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e58d041dsm1993578a91.38.2024.06.20.10.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:48 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov , Michael Kelley Subject: [PATCH v4 14/40] PCI: hv: Optimize hv_get_dom_num() by using find_and_set_bit() Date: Thu, 20 Jun 2024 10:56:37 -0700 Message-ID: <20240620175703.605111-15-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function traverses bitmap with for_each_clear_bit() just to allocate a bit atomically. Simplify it by using dedicated find_and_set_bit(). Signed-off-by: Yury Norov Reviewed-by: Michael Kelley Acked-by: Wei Liu Acked-by: Bjorn Helgaas --- drivers/pci/controller/pci-hyperv.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/p= ci-hyperv.c index 5992280e8110..d8a3ca9a7378 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -37,6 +37,7 @@ * the PCI back-end driver in Hyper-V. */ =20 +#include #include #include #include @@ -3599,12 +3600,9 @@ static u16 hv_get_dom_num(u16 dom) if (test_and_set_bit(dom, hvpci_dom_map) =3D=3D 0) return dom; =20 - for_each_clear_bit(i, hvpci_dom_map, HVPCI_DOM_MAP_SIZE) { - if (test_and_set_bit(i, hvpci_dom_map) =3D=3D 0) - return i; - } + i =3D find_and_set_bit(hvpci_dom_map, HVPCI_DOM_MAP_SIZE); =20 - return HVPCI_DOM_INVALID; + return i < HVPCI_DOM_MAP_SIZE ? i : HVPCI_DOM_INVALID; } =20 /** --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 A61481C0044; Thu, 20 Jun 2024 17:57:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906274; cv=none; b=EiUydBIjhUzUSGIdVbrYDMBwtjnq3PZ+2p2i98HjYOo/jpY1SnEuxp5DkQEp+IpbTH1TXjjt1t3NtkGTIJBhY/O9O54ytzHFyiNvNP/ZTXtUvHrokDVFfv2HjC1PNiS8wl2n9KebrZm7wv6rPdyMN5j+xAX1YGHo12J5wF1wxMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906274; c=relaxed/simple; bh=pqtOnbnky5xRYHpCY2gs4oz50L4qhYf4MNiIl6TOKwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P20jkhwBQMFZx0q1PriSOX8N72XyTB2hxi77rwbfK0Uoly1iLGD0ws9dPzV9p/killjtWYKSq1v0wTXpkWd8n49IlYqNvIcGTlad86VILnilWa6vYUtmJjYlak3fIXq3RuJGiDuNsJtg9Q1X4eRKDl0cPW+fSk/J7F0wPtiXPbg= 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=O1jMxBXj; arc=none smtp.client-ip=209.85.210.169 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O1jMxBXj" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-705b9a89e08so1073741b3a.1; Thu, 20 Jun 2024 10:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906272; x=1719511072; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ns854O7sPQQdjBV1LbOoY/vyRfsFM848PqiWwxxwo8Q=; b=O1jMxBXjVu0N5+tWWL30ewrTny4DzaseEqvxCLu2Nc50n2Bwh6+gy3eoxN8ivLaNSX EvwN/XaOeYwQx8QpNBrsWp4C/WN7GBdwYQ/Vn78UQY/hzYnfmcTkvPymiuWma1zCAAUQ R9l77JzK8pSQEBaeU913tIG2Tr5QI3PC+fuDWdNqC8MnCPUoXHxZ5vJAbof2qq9zRXUQ ryppYDBUNfhNipgNzy9Xw6gqEE9bFAFn86/dmpU0Bg5ilJ71MNlpzAEGQCKv1tpGLQm2 WnknKA/+/9ujGyHxmNlX1msLvoHwJoLxY5Dpew1/01VUhPxLmVmR6AG+a3nYXXXqlB04 +OVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906272; x=1719511072; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ns854O7sPQQdjBV1LbOoY/vyRfsFM848PqiWwxxwo8Q=; b=J3xwNirKAgk4ZMY2/WzU4GKvFpgG/wa38CxBYGzO1am7y1Om7Ds/mAXXj5vL6NjxJE LExG4FVYxs55+CrYJHjpVltsVVEsKCgeleVoEc9F4sN5Q33cN1azHTiIo4lbCpJXcBC/ MQHlVO8rOqTujkf0CQnqltaHd3IlZj6X0nVqnRpohd/D0n8KUivg2O68m6oG4XbmeEnn PzXgsS/uv8m/CrgFMTuHqKJUdpRo/xT5oyVhEAzWNuYdLgIVzYrcH1zHPD6J4eZkPcnA KATkpF7HTQbLqDiGx38x/BzCh4uAPZx40bPEg4jN2p8rK2UY+zdtqWuyIHn6jepH+OuH qFBg== X-Forwarded-Encrypted: i=1; AJvYcCWYojj9pMILWknuQpXZivtGWh0FDEM9jqjT2OA4oy590qZnyRG/PLxfoy1dZr3uuruK9+wWjHa3Eeqoc/m5vF4YQKjgMZ3wA0n3Bw== X-Gm-Message-State: AOJu0Yw+rNepwRzrue/+//2UGT1wvYZLdrgFRVP8XT2iMGyIe9p7ZQjn crOf2IeNLeCnQbfxDUsFBs7pcF+B0XuSnPLgk6JPNAEMTzi2fvvrFVL5WbXkW60= X-Google-Smtp-Source: AGHT+IFQDBD85AA/e7ZhBS6C/4LWgeRZuwweRJrrA1tTXXTcy4Qlg68OlOPMF2Nl1kWKC++a1RbKnw== X-Received: by 2002:a05:6a20:3b93:b0:1b7:d5d5:415b with SMTP id adf61e73a8af0-1bcbb6982femr5756881637.57.1718906272053; Thu, 20 Jun 2024 10:57:52 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb6b4fasm12608970b3a.150.2024.06.20.10.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:51 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Sathya Prakash Veerichetty , Kashyap Desai , Sumit Saxena , Sreekanth Reddy , "James E.J. Bottomley" , "Martin K. Petersen" , Nilesh Javali , Manish Rangankar , GR-QLogic-Storage-Upstream@marvell.com, mpi3mr-linuxdrv.pdl@broadcom.com, linux-scsi@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 15/40] scsi: core: optimize scsi_evt_emit() by using an atomic iterator Date: Thu, 20 Jun 2024 10:56:38 -0700 Message-ID: <20240620175703.605111-16-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A plain loop in scsi_evt_thread() opencodes optimized atomic bit traversing macro. Simplify it by using the dedicated iterator. CC: Bart Van Assche Signed-off-by: Yury Norov --- drivers/scsi/scsi_lib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index ec39acc986d6..72bebe5247e7 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -2588,14 +2589,13 @@ static void scsi_evt_emit(struct scsi_device *sdev,= struct scsi_event *evt) void scsi_evt_thread(struct work_struct *work) { struct scsi_device *sdev; - enum scsi_device_event evt_type; + enum scsi_device_event evt_type =3D SDEV_EVT_FIRST; LIST_HEAD(event_list); =20 sdev =3D container_of(work, struct scsi_device, event_work); =20 - for (evt_type =3D SDEV_EVT_FIRST; evt_type <=3D SDEV_EVT_LAST; evt_type++) - if (test_and_clear_bit(evt_type, sdev->pending_events)) - sdev_evt_send_simple(sdev, evt_type, GFP_KERNEL); + for_each_test_and_clear_bit_from(evt_type, sdev->pending_events, SDEV_EVT= _LAST + 1) + sdev_evt_send_simple(sdev, evt_type, GFP_KERNEL); =20 while (1) { struct scsi_event *evt; --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 7FC221C004A; Thu, 20 Jun 2024 17:57:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906276; cv=none; b=jqvn+EZjKzajz/ZLH+2m7ARIO3ZLdaTs2C7sA9ArwSWp5IeuDdtDK3kwPybn4NFDVp85SBTavJ/3SoTVSOg1WOH0X7TD3anUaW/UXpkGIP0+64KrGXmQYtffkVtYHvVWdkCvQEYmvnYbPjHdEnYjRXk43UPtYVIxW1fUTBYeQTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906276; c=relaxed/simple; bh=VYKqh/NkznC9CObWrWdbjElllM8wu6NtGW8jRbGEu1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qAsgiH9pWatjfArkMPTl0tOhDz62soZ3C0EsPPt8lQxRfvJlnnrXOuzrtggpBwrZ/Wj9nDCF19NG+itouOaLlH7TdRUAj6xAqQyb5cZyy3abHyAtatWOgGaiZxPCdCO/i/dKmNBCKBLjinMe7A9RrE2KKGsfLHS/di+aGbeOpio= 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=CN8aEbr7; arc=none smtp.client-ip=209.85.216.51 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CN8aEbr7" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2c2dee9d9cfso1010579a91.3; Thu, 20 Jun 2024 10:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906275; x=1719511075; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8gLFCykJTwTUyj41nXgH0cr48eAqtsmwHylJ+z5USpc=; b=CN8aEbr7JOpbChEUsh8Z4WRFqaJBOzmngQqDdE6+TgwkZV9HCs9Ro/p3qd7gkhQ8hT gQlrozxxJ2bmwEWOPXOWRILrsgPtHFMUelHNmz/LaMsg4bqU0utI9Lu31za0F24Cr8U1 3WeLjf5GV2XGJGobsHX+kwH58/VbNbi/G9IDC5hRBWm8cH2QAX0eheQ6kzO60Z/IzhyJ FYlSWpwOiQJ1JVm+OtfzZXjHrDQJW9zhq1Do5jiZRRMGZ4DbKQ+r8wwLsnhGaVBcHRSi iGllA+mmrQHCpQDdFnRbbq8yJDsW+GznQqjmQBBAUnQSA0OPprjvyDGW18F+RkwLW/oV 7qig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906275; x=1719511075; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8gLFCykJTwTUyj41nXgH0cr48eAqtsmwHylJ+z5USpc=; b=cLWvrDm+XvSeq6iOmRxkOjJ/1mQNI6/6ztMkIu45I6QsJdPT8omKxF2y8Wa8M07rJW JLjkwR1mi4MK+6AlNmlJYvlAgOGhg8RS4I0UZPS6/bcQIBPvR1YpbwG1kWlgveeedPGn Md+4TAD0xWP0EQsjfvGgFkLJR10UZUIzxIroQBtGSnqLZV+9z8r9ORxviSR3zqaQTSNY 9eQSl3aTguRIioghagYbs05REk8+aGWri7lqxRLt55gAhpzAlauhv3ociHzpfEZu53my kX2mrJKUczN9YJhNZ/eDMRizOYTnDVBKmEo5u5FkS9CVlqwMYI1KPL94t3Mp0A+Cmc8N B/Vw== X-Forwarded-Encrypted: i=1; AJvYcCVU8T7ol06G7OKunj++sE7KK4jGrSDB2tpoCFF1tWqyp6vO7UtHxVVf7DrgxLoqGQswDC+ZFL2Jm15fhK6NCi2SUMOhIXI1GZgxCw== X-Gm-Message-State: AOJu0YyIAtaEejUvaPt3w0AxFi/sODWXK+gaDmyOjx7oSCfhb/XUb9UC D+x9BQT4zYZXE/xfL/WtSw9In5Mz1ga908TIjjzCFeam+YCpyQioN4vZKLG5nb8= X-Google-Smtp-Source: AGHT+IEs3xkwMF/QaqEF7eP2EEue34uat1uHueDoae/eLjPzmkBpQNQnWmyoCgGGoO7izL2d+Mf08A== X-Received: by 2002:a17:90b:4c43:b0:2c8:647:1600 with SMTP id 98e67ed59e1d1-2c80647165emr1512425a91.9.1718906274840; Thu, 20 Jun 2024 10:57:54 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e53ea477sm2023501a91.17.2024.06.20.10.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:54 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Sathya Prakash Veerichetty , Kashyap Desai , Sumit Saxena , Sreekanth Reddy , "James E.J. Bottomley" , "Martin K. Petersen" , Nilesh Javali , Manish Rangankar , GR-QLogic-Storage-Upstream@marvell.com, mpi3mr-linuxdrv.pdl@broadcom.com, linux-scsi@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 16/40] scsi: mpi3mr: optimize the driver by using find_and_set_bit() Date: Thu, 20 Jun 2024 10:56:39 -0700 Message-ID: <20240620175703.605111-17-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mpi3mr_dev_rmhs_send_tm() and mpi3mr_send_event_ack() opencode find_and_set_bit(). Simplify them by using dedicated function. CC: Bart Van Assche Signed-off-by: Yury Norov --- drivers/scsi/mpi3mr/mpi3mr_os.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_o= s.c index bce639a6cca1..8ad1521dd0b3 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -7,6 +7,7 @@ * */ =20 +#include #include "mpi3mr.h" #include =20 @@ -2292,13 +2293,9 @@ static void mpi3mr_dev_rmhs_send_tm(struct mpi3mr_io= c *mrioc, u16 handle, if (drv_cmd) goto issue_cmd; do { - cmd_idx =3D find_first_zero_bit(mrioc->devrem_bitmap, - MPI3MR_NUM_DEVRMCMD); - if (cmd_idx < MPI3MR_NUM_DEVRMCMD) { - if (!test_and_set_bit(cmd_idx, mrioc->devrem_bitmap)) - break; - cmd_idx =3D MPI3MR_NUM_DEVRMCMD; - } + cmd_idx =3D find_and_set_bit(mrioc->devrem_bitmap, MPI3MR_NUM_DEVRMCMD); + if (cmd_idx < MPI3MR_NUM_DEVRMCMD) + break; } while (retrycount--); =20 if (cmd_idx >=3D MPI3MR_NUM_DEVRMCMD) { @@ -2433,14 +2430,9 @@ static void mpi3mr_send_event_ack(struct mpi3mr_ioc = *mrioc, u8 event, "sending event ack in the top half for event(0x%02x), event_ctx(0x%08= x)\n", event, event_ctx); do { - cmd_idx =3D find_first_zero_bit(mrioc->evtack_cmds_bitmap, - MPI3MR_NUM_EVTACKCMD); - if (cmd_idx < MPI3MR_NUM_EVTACKCMD) { - if (!test_and_set_bit(cmd_idx, - mrioc->evtack_cmds_bitmap)) - break; - cmd_idx =3D MPI3MR_NUM_EVTACKCMD; - } + cmd_idx =3D find_and_set_bit(mrioc->evtack_cmds_bitmap, MPI3MR_NUM_EVTAC= KCMD); + if (cmd_idx < MPI3MR_NUM_EVTACKCMD) + break; } while (retrycount--); =20 if (cmd_idx >=3D MPI3MR_NUM_EVTACKCMD) { --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 A24DA1C007E; Thu, 20 Jun 2024 17:57:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906279; cv=none; b=rJXMwiavEGLrNR5XPWLrWxBMEQ4ck5iimJHiSTV9YKFstZeVorwltw+Dg0J6wW58OGP5eZOUJbzHIRNwNNVo8KUboioBCmcO6wwN6IJxjMPA8RofcyG5c1KkrA4Zj8hU4yDFcr3dY6DL49fKa4uy0dcjp8H0s3ScnFJ9HQoKabE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906279; c=relaxed/simple; bh=FZM6CosxQTAEV5PQ+/KRibOjH9YQS1OMFOTTqUFKpt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c3oiB6K01w4kVVpykEAqRvOK5xgqAF5+uoM55C06nGXFG41Kt/uSx2Sgn9yKRewHVGQD5danNOdfcGuX480051LhLxoQ7yA9geDJmhc0+jGJair1ehs66WKe1jPV7aX80CY5wYGpf95ZP0k5NdBberd/qNvUyJpGAhzPTiCMBHE= 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=c7UlnWPU; arc=none smtp.client-ip=209.85.210.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c7UlnWPU" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7041e39a5beso983263b3a.3; Thu, 20 Jun 2024 10:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906278; x=1719511078; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jBNHO7SGyRYGtIlT3hp756CkWMYdfL+ybrdFx5N+b+g=; b=c7UlnWPUUeUtVJwNjx5kaf5cEPYr8gJT/g6NqoxuM2c8u99lOEM7WG946Gmskbsixe ET3g/tjhaRsHUgUTXKZs9j/joP73X4itynY146LlhwPyg0+LSquleQy5t6PaLOxtJWej 1kchOVnLY85P2W2EOiYOD9Uku3EvaDNtES7wQWoS7sSGn70Dl9Omk86BwdgIIe6pOT4T RxY8ywVw0F76TUrExceypvNASojCuWxPH2NYV9qzM3nrMZ810vAHWMrYqv+q1saNAJDG mKHw876SetKlhauXdG1+VfIyCKyNzV4KrqsOTrnGB3aScpVHnkhXjcufYy54ElKDH/DM 9PpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906278; x=1719511078; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jBNHO7SGyRYGtIlT3hp756CkWMYdfL+ybrdFx5N+b+g=; b=i2B7aQ2weAwynSUoCNN7YXTcMU5Ofn+hDZkh+J+zCRZzEY7sRCUq+OhANb/SzXxnOE y+G1TLWqfGaUr+Yfn6sJ+vIC852ENSjJm2tKgBPv7QyGCOmE6xlZ3OyjO450sXCGi6Tp RDZ/SbRgMdwiX1MPJwn5v6drEUwxTfnuaJ7zDQlCBSTzSoCxFU/rO3VIQNVrJTFLxxgY W3jHzR+cKCOvyQ/X5pAYni0BczdN7c/MPVsEgDS5t/4+q8+HpVdZ37fstrl6sP/NbeOj 86gaIespaql+Mz8Y5fv9uh7FE+nfRvQUWBOauDIpbY9HQRVlaKvRx6R1rg7nukHRxxE5 CW1A== X-Forwarded-Encrypted: i=1; AJvYcCXzy5klCf48bSgj1DFSs9kihsjUnUfiPg8JS1P7HapQbvMJH0S5nBUrljyu1osodXcGgb4MN420V9DQfHMEI1IxFu7412E1k/pL5A== X-Gm-Message-State: AOJu0YxnekfiQOsxHeLfImEok8UecXoWHD7Hmguo3XEiK95lVTgEBo2M u8k50saptDA/I6XVAwCQQZMODnKyjNnAYM330giPZDRyy2Gp+G/QvMeCB192gJI= X-Google-Smtp-Source: AGHT+IEkRJptF+yJLHlQoKp30dUDbXDqMnSMJA9iS2RvxoRFsvlFT1i8S85A1astV7Xk0uWHBXz5XA== X-Received: by 2002:a05:6a20:c120:b0:1b6:dffa:d6e4 with SMTP id adf61e73a8af0-1bcbb451678mr5750153637.4.1718906277953; Thu, 20 Jun 2024 10:57:57 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb92c89sm12586864b3a.213.2024.06.20.10.57.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:57 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Sathya Prakash Veerichetty , Kashyap Desai , Sumit Saxena , Sreekanth Reddy , "James E.J. Bottomley" , "Martin K. Petersen" , Nilesh Javali , Manish Rangankar , GR-QLogic-Storage-Upstream@marvell.com, mpi3mr-linuxdrv.pdl@broadcom.com, linux-scsi@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 17/40] scsi: qedi: optimize qedi_get_task_idx() by using find_and_set_bit() Date: Thu, 20 Jun 2024 10:56:40 -0700 Message-ID: <20240620175703.605111-18-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" qedi_get_task_idx() opencodes find_and_set_bit(). Simplify it and make the whole function a simiple almost one-liner. CC: Bart Van Assche Signed-off-by: Yury Norov --- drivers/scsi/qedi/qedi_main.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c index cd0180b1f5b9..a6e63a6c25fe 100644 --- a/drivers/scsi/qedi/qedi_main.c +++ b/drivers/scsi/qedi/qedi_main.c @@ -5,6 +5,7 @@ */ =20 #include +#include #include #include #include @@ -1824,20 +1825,13 @@ int qedi_get_task_idx(struct qedi_ctx *qedi) { s16 tmp_idx; =20 -again: - tmp_idx =3D find_first_zero_bit(qedi->task_idx_map, - MAX_ISCSI_TASK_ENTRIES); + tmp_idx =3D find_and_set_bit(qedi->task_idx_map, MAX_ISCSI_TASK_ENTRIES); =20 if (tmp_idx >=3D MAX_ISCSI_TASK_ENTRIES) { QEDI_ERR(&qedi->dbg_ctx, "FW task context pool is full.\n"); tmp_idx =3D -1; - goto err_idx; } =20 - if (test_and_set_bit(tmp_idx, qedi->task_idx_map)) - goto again; - -err_idx: return tmp_idx; } =20 --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 3B0EB1C0DED for ; Thu, 20 Jun 2024 17:58:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906282; cv=none; b=NkUVJXCv4y+2x0t+1ssofwxH3wMTRbHbERMmSKMq2ox7mGiQvncwY2GtfAfFsGZzAZYx7uxnMX8B4DjXYjJHP0rG8yvFH3g6iVgulwBZNIxApCVweEJXd8wtvWp8EZUCyrIhqa2WjDRExe6D8h8K1B2Wr+YO5W95KCYItQUZKkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906282; c=relaxed/simple; bh=CvUGneMbBEz1yZXc0tmhKn1m4dEY/czL5W1N3gs4WcA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tAxytrvi3+ilnI+xl4l2qfeIzKkq6UpZSjV0GmkCZNdwIupDTuo9TWci3hqnR9jPEYW7JPQxL9071zzg9qJUnJxeCM+TV/FmrUUgDbPwgXENpaznNVXhPw8WKWd4qwMHwRM2YgmY2H9gYsIM55LfLKlXlOvO2sGr6NYNaWW8sP0= 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=dJ6Gl21+; arc=none smtp.client-ip=209.85.214.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dJ6Gl21+" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f9b364faddso10597805ad.3 for ; Thu, 20 Jun 2024 10:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906280; x=1719511080; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gJqqXRh/eOzPQsK99Bb/yzPgqho23i5/Ws9ra3QtPAE=; b=dJ6Gl21+0wH00d6JQcnBxXFXKmuV4DFYgxvewtSSzCaAkCI2W2V+Sv0O+pu6zt2hpC Lp87kcGrONgZAPQlg0aDNqgqlKz6p4ndDRQ2UC4k6JWYofAi0XP/uBL/V8iLLX/Afsuw u7wlkJ/xZYu/wGnQuvyugBhDFkkGX2tMpan6w7g7NY2nJ8EhiTLt6TVswbuWjZ6vs+Rs Bh7sbLpctQMvb6x1ZnT1jqvK2QTqWiy04uYErsjIyn47M6UgfPpO7BF50M8VgZ4kENuq /wq/XBg6/U46KTynkUb5lxS/IdZCgLWnJHLXQkNfWSp0bWf2Vhd78UoVvg2rPNv3xqWT 3VEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906280; x=1719511080; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gJqqXRh/eOzPQsK99Bb/yzPgqho23i5/Ws9ra3QtPAE=; b=W4pAsImt59syVRzGK+pOMueySwaqCiPIvFg2R1twQwz6g6b57fKWinfdDYlVlYd7zc nnscdHST1sYtoy568GJijFBpwt+AneOvlQ8UDNpqIQDqxgREQJPVwUX5Z980Zat2czL7 i8tPPdChQiQbc4JGLis59dcMlKgFjGpE0HF+9X8HeGUrmQUZt6Jz0LcYp5pL5G0bVHCc EX7l48VgfWCqSVwucBxc7xsxkCTeDaU7MRW7O07DjkVlzF33cqkbaOXzE8R2lTyQLv0V AGrap+A3G/U05z3Yj29EXat0/yVeZ34dSnX5oyKeXtpLO0icJH86x0onwjySE3NzSIRB e80g== X-Gm-Message-State: AOJu0YyPc1v+/UOoykYwZoTW5+Q+1IvVtK/zxrsrrAsnO0Vabm14A4uX pd1GAl9kO/zBM/YYChjo8nba/X23wB7st06VL3ElX0vZn/e520zBoubmQ1W0pJo= X-Google-Smtp-Source: AGHT+IF4qTXDJh2dmu7C8j7KbrNKpNe1traR1hBaJSEqONmhCH9MELk4yXOVD6L7Rof1XKmaGu/wKA== X-Received: by 2002:a17:903:1211:b0:1f8:3c9e:3ba8 with SMTP id d9443c01a7336-1f9aa3b50b0mr70367035ad.10.1718906280486; Thu, 20 Jun 2024 10:58:00 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855f339fbsm139710805ad.262.2024.06.20.10.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:00 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Michael Ellerman , Nicholas Piggin , Christophe Leroy , Colin Ian King , linuxppc-dev@lists.ozlabs.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 18/40] powerpc: optimize arch code by using atomic find_bit() API Date: Thu, 20 Jun 2024 10:56:41 -0700 Message-ID: <20240620175703.605111-19-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use find_and_{set,clear}_bit() where appropriate and simplify the logic. Signed-off-by: Yury Norov --- arch/powerpc/mm/book3s32/mmu_context.c | 11 +++--- arch/powerpc/platforms/pasemi/dma_lib.c | 46 ++++++---------------- arch/powerpc/platforms/powernv/pci-sriov.c | 13 ++---- 3 files changed, 20 insertions(+), 50 deletions(-) diff --git a/arch/powerpc/mm/book3s32/mmu_context.c b/arch/powerpc/mm/book3= s32/mmu_context.c index 1922f9a6b058..ece7b55b6cdb 100644 --- a/arch/powerpc/mm/book3s32/mmu_context.c +++ b/arch/powerpc/mm/book3s32/mmu_context.c @@ -17,6 +17,7 @@ * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds */ =20 +#include #include #include #include @@ -50,13 +51,11 @@ static unsigned long context_map[LAST_CONTEXT / BITS_PE= R_LONG + 1]; =20 unsigned long __init_new_context(void) { - unsigned long ctx =3D next_mmu_context; + unsigned long ctx; =20 - while (test_and_set_bit(ctx, context_map)) { - ctx =3D find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx); - if (ctx > LAST_CONTEXT) - ctx =3D 0; - } + ctx =3D find_and_set_next_bit(context_map, LAST_CONTEXT + 1, next_mmu_con= text); + if (ctx > LAST_CONTEXT) + ctx =3D 0; next_mmu_context =3D (ctx + 1) & LAST_CONTEXT; =20 return ctx; diff --git a/arch/powerpc/platforms/pasemi/dma_lib.c b/arch/powerpc/platfor= ms/pasemi/dma_lib.c index 1be1f18f6f09..db008902e5f3 100644 --- a/arch/powerpc/platforms/pasemi/dma_lib.c +++ b/arch/powerpc/platforms/pasemi/dma_lib.c @@ -5,6 +5,7 @@ * Common functions for DMA access on PA Semi PWRficient */ =20 +#include #include #include #include @@ -118,14 +119,9 @@ static int pasemi_alloc_tx_chan(enum pasemi_dmachan_ty= pe type) limit =3D MAX_TXCH; break; } -retry: - bit =3D find_next_bit(txch_free, MAX_TXCH, start); - if (bit >=3D limit) - return -ENOSPC; - if (!test_and_clear_bit(bit, txch_free)) - goto retry; - - return bit; + + bit =3D find_and_clear_next_bit(txch_free, MAX_TXCH, start); + return bit < limit ? bit : -ENOSPC; } =20 static void pasemi_free_tx_chan(int chan) @@ -136,15 +132,9 @@ static void pasemi_free_tx_chan(int chan) =20 static int pasemi_alloc_rx_chan(void) { - int bit; -retry: - bit =3D find_first_bit(rxch_free, MAX_RXCH); - if (bit >=3D MAX_TXCH) - return -ENOSPC; - if (!test_and_clear_bit(bit, rxch_free)) - goto retry; - - return bit; + int bit =3D find_and_clear_bit(rxch_free, MAX_RXCH); + + return bit < MAX_TXCH ? bit : -ENOSPC; } =20 static void pasemi_free_rx_chan(int chan) @@ -374,16 +364,9 @@ EXPORT_SYMBOL(pasemi_dma_free_buf); */ int pasemi_dma_alloc_flag(void) { - int bit; + int bit =3D find_and_clear_bit(flags_free, MAX_FLAGS); =20 -retry: - bit =3D find_first_bit(flags_free, MAX_FLAGS); - if (bit >=3D MAX_FLAGS) - return -ENOSPC; - if (!test_and_clear_bit(bit, flags_free)) - goto retry; - - return bit; + return bit < MAX_FLAGS ? bit : -ENOSPC; } EXPORT_SYMBOL(pasemi_dma_alloc_flag); =20 @@ -439,16 +422,9 @@ EXPORT_SYMBOL(pasemi_dma_clear_flag); */ int pasemi_dma_alloc_fun(void) { - int bit; - -retry: - bit =3D find_first_bit(fun_free, MAX_FLAGS); - if (bit >=3D MAX_FLAGS) - return -ENOSPC; - if (!test_and_clear_bit(bit, fun_free)) - goto retry; + int bit =3D find_and_clear_bit(fun_free, MAX_FLAGS); =20 - return bit; + return bit < MAX_FLAGS ? bit : -ENOSPC; } EXPORT_SYMBOL(pasemi_dma_alloc_fun); =20 diff --git a/arch/powerpc/platforms/powernv/pci-sriov.c b/arch/powerpc/plat= forms/powernv/pci-sriov.c index cc7b1dd54ac6..e33e57c559f7 100644 --- a/arch/powerpc/platforms/powernv/pci-sriov.c +++ b/arch/powerpc/platforms/powernv/pci-sriov.c @@ -3,6 +3,7 @@ #include #include #include +#include #include =20 #include @@ -397,18 +398,12 @@ static int64_t pnv_ioda_map_m64_single(struct pnv_phb= *phb, =20 static int pnv_pci_alloc_m64_bar(struct pnv_phb *phb, struct pnv_iov_data = *iov) { - int win; + int win =3D find_and_set_bit(&phb->ioda.m64_bar_alloc, phb->ioda.m64_bar_= idx + 1); =20 - do { - win =3D find_next_zero_bit(&phb->ioda.m64_bar_alloc, - phb->ioda.m64_bar_idx + 1, 0); - - if (win >=3D phb->ioda.m64_bar_idx + 1) - return -1; - } while (test_and_set_bit(win, &phb->ioda.m64_bar_alloc)); + if (win >=3D phb->ioda.m64_bar_idx + 1) + return -1; =20 set_bit(win, iov->used_m64_bar_mask); - return win; } =20 --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 131ED1C231E; Thu, 20 Jun 2024 17:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906285; cv=none; b=u2UY/IQRVmK8DHdctBlXHdiyLzDRlKKmB81qBS3tN0lW7mEN3BrvKp6FHPJoSeqy1D3tD1L6dnYAYRtvR1LdIdUrPvuUspEoBpYKIZgg6F5S7Ch8J91nqPRaKNECF6nO/bv2z7OlJ/2CsOk2/pi9rf4qGpBGSSktqjOSJ/MJdUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906285; c=relaxed/simple; bh=G8SsYV8VKhk+1kr8G6gSzRlXENvMiu+vYX15iq0TH0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PLChtDLWWHgwWu1QLR7jWpR/z68QZD3uCg7NR7FEDp2ivPp9U48uGI9VytDdZ2I133KZopKKMXTflGeKidk4WShJ0XNpW7+ARQireikVth6ZJQFnFfD0Zeda8pIP7x6wN2bqDhV4bXB848AaL0OlyFVwPbFYLhkqt9LUlexY6u8= 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=IHuR/vw0; arc=none smtp.client-ip=209.85.210.170 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IHuR/vw0" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-70601bcfddcso1160854b3a.3; Thu, 20 Jun 2024 10:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906283; x=1719511083; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=voUtFDbfyXxYSLuhMxY/5Es179PR05W0y6qbv62GFHo=; b=IHuR/vw0Yr3ip4W2ecHazBSDXEDQf67luVGyRA1rThf/BH5Pcp7+7bMg/G5S1dT8p8 m/FU2PAqZ1iP8Iz9KaS3jBrELAvI1ElNLi8BDG3RHPXFYp4kH6c5YV6z1NBmeDCQyHVb qTRGK3Ow8gL30dSVq2vT3b+DHVFmQtWWMuYP9vogVPH9jZnk7h3vqZ/2UKu5J5K9FOrT KeFdMb3vyJ1W1w3GDR/51Guz8nAQFkGqepQDBgSUlvcROOlydyOQWwcBJbYaIHW/CXqC aRvok4dLGPGkT48z+4sawxUoXM5hTNizqMN8IQYxCAec9w1MYzVeJ7keJ2HSwsJGZoSl CI9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906283; x=1719511083; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=voUtFDbfyXxYSLuhMxY/5Es179PR05W0y6qbv62GFHo=; b=HU7uT9rK1XX0fjEmrhS0URDigtaRQbyFz0A0WBooptDVYThD/6qD3jYnjGvf/pDXA1 YHNA7p72Oe57JU2hWQxDKujsgncUbJvtP0R9yagrNmU9wVjj9qznWZezOisrnr1Hg59K K9aXLOuDrovlPD0wCGvxDsLLtm1VxYJ7+6Og+oJsCmnZcbA4BriprXHLB8mGV5IJcAEp mOKWU2nLoddfC5f5D6NHq7dhdjDXVDzvQ5ZOYN27q/tApQQs7/172G0CrgM9zLusgKzf i1u++gcEdTKuUCECdMTfUfNRQ1G/VR2ZUcnHbtOaDWGO51k1PB/rIvIq2TOnV3hJ2Vw9 v3Fw== X-Forwarded-Encrypted: i=1; AJvYcCUgzj8cnlrVrUgXKhY0TYOykavtbGpXFSbBwX3hUUXCngewcrPWD2hrAqnilXJTmXyN8Z7L1C6XAL3Qkcb/dDb/YCddp9i46SNlW+Er/g== X-Gm-Message-State: AOJu0YzZnMIp6RMgkgYppQKNCaxOrxu88DfvZUwF2ic2xLC2gQeRBtr0 S0qT0K6ee8Fi6DakRu9Ovdq54vrD0WyTNpllJsKQ7P/idoqaMaGqqeVtTyvZnns= X-Google-Smtp-Source: AGHT+IFuFY8WsrUaBevsclcxusM/Sc7ZvIAfPxrnCGbXlGrdTSyKJ0ahnS/qbGoRPvPpSuP7Wt6hDQ== X-Received: by 2002:a05:6a00:4d07:b0:706:3514:2d6c with SMTP id d2e1a72fcca58-70635142dd9mr3899791b3a.29.1718906283409; Thu, 20 Jun 2024 10:58:03 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb6adb5sm12628100b3a.155.2024.06.20.10.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:02 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Will Deacon , Robin Murphy , Joerg Roedel , Andy Gross , Bjorn Andersson , Konrad Dybcio , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 19/40] iommu: optimize subsystem by using atomic find_bit() API Date: Thu, 20 Jun 2024 10:56:42 -0700 Message-ID: <20240620175703.605111-20-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify __arm_smmu_alloc_bitmap() and msm_iommu_alloc_ctx() by using a dedicated API, and make them nice one-liner wrappers. While here, refactor msm_iommu_attach_dev() and msm_iommu_alloc_ctx() so that error codes don't mismatch. Signed-off-by: Yury Norov --- drivers/iommu/arm/arm-smmu/arm-smmu.h | 11 +++-------- drivers/iommu/msm_iommu.c | 19 +++++-------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-= smmu/arm-smmu.h index 4765c6945c34..c74d0300b64b 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -455,15 +456,9 @@ struct arm_smmu_impl { =20 static inline int __arm_smmu_alloc_bitmap(unsigned long *map, int start, i= nt end) { - int idx; + int idx =3D find_and_set_next_bit(map, end, start); =20 - do { - idx =3D find_next_zero_bit(map, end, start); - if (idx =3D=3D end) - return -ENOSPC; - } while (test_and_set_bit(idx, map)); - - return idx; + return idx < end ? idx : -ENOSPC; } =20 static inline void __iomem *arm_smmu_page(struct arm_smmu_device *smmu, in= t n) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 989e0869d805..4299e6a5b2ec 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -185,17 +186,9 @@ static const struct iommu_flush_ops msm_iommu_flush_op= s =3D { .tlb_add_page =3D __flush_iotlb_page, }; =20 -static int msm_iommu_alloc_ctx(unsigned long *map, int start, int end) +static int msm_iommu_alloc_ctx(struct msm_iommu_dev *iommu) { - int idx; - - do { - idx =3D find_next_zero_bit(map, end, start); - if (idx =3D=3D end) - return -ENOSPC; - } while (test_and_set_bit(idx, map)); - - return idx; + return find_and_set_bit(iommu->context_map, iommu->ncb); } =20 static void msm_iommu_free_ctx(unsigned long *map, int idx) @@ -418,10 +411,8 @@ static int msm_iommu_attach_dev(struct iommu_domain *d= omain, struct device *dev) ret =3D -EEXIST; goto fail; } - master->num =3D - msm_iommu_alloc_ctx(iommu->context_map, - 0, iommu->ncb); - if (IS_ERR_VALUE(master->num)) { + master->num =3D msm_iommu_alloc_ctx(iommu); + if (master->num >=3D iommu->ncb) { ret =3D -ENODEV; goto fail; } --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 E83CD1C689B; Thu, 20 Jun 2024 17:58:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906288; cv=none; b=VbByJxYfXpVoxy3txFkb7d7hyivi/fG5N58cccLyhzt+dstQ3dOYhs+Gu/XkSDnQhFoojU5J24aOrXUMfKaJ4kt1gPvi4Waz73jQG3ZZWfSBM+xYNLyc9NzSeF8QibTuDad7TVsEWFpWCDaDrlsY+cKhHLMOaNzSYAmpqPC+fuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906288; c=relaxed/simple; bh=rbpkUlmlOme1ikdxKqZBWeti6AjXTa90yhLh7ntoYNQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YjvnAhWj00yYCdT2ylyQpEPFsyUZilTFspcE7C2oxzBYrPvQ4E4kc0yl9uFMWKS1eWKwvu2KxxlEKr9KA2GJnYfWnxIaynp19Y7P8m9ltoQmxnLfWlkPiXgtwSauoJFT1j3S5IvT8kmSXenAcP+4uZMOlbaBihaUpSxkms/8Lx0= 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=RTnd2+Ww; arc=none smtp.client-ip=209.85.214.181 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RTnd2+Ww" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f44b45d6abso9824665ad.0; Thu, 20 Jun 2024 10:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906286; x=1719511086; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SFjixNs7es/to5XyEjk1SDKnVmCrXPTnsKlxKMUnV5E=; b=RTnd2+Ww4D8I3qYAX+wiRl47Ig/lyjyAHqWZ2Sd3TlnxQHuGzxZx6ngzqlFhmhGQt6 N9mk/PUfHTWE2rbV+grMl03x2h9BB9mM02ZyZG+HixVzU/BNZwOZnhbd03IJPSHmLLQ8 kvFcQxOurvVzGnXVx6i8HWlgs7VsB96LvPkE9dy394+mJccSeJ6jw9aYDjszWWhwabpB Uik/C7EJIx0YYLcK1KYgihn6IJMn/K+YtLcf1ciKmBiFGRW3vEG0QSRgQ3ax+7dUJ4pk /lQUesoG/4o7RA9YxhOfqXn84q6N15woGm4JKJhY8YP/3KpuZ8fIwO0EvjT01J3A3X0p RZlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906286; x=1719511086; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SFjixNs7es/to5XyEjk1SDKnVmCrXPTnsKlxKMUnV5E=; b=s0ivuSK4n9XW1EhAto3B0BTdEOK3a36qBpH4TOerExHogQQhSERDxoGRbXypAkiTNh PTvtuaI2kfjfAHuCJRj2j0mzWgyb8a44Yog/WZvNvQOX6+4V2pG2H5Mcq84l+yrK5pOe uC/4U3H7qRAS51DBxnvKptyTqw5esyXJMMHSeiPfUCQo0nRxFkEkWRRChZxjPQ9KrMjG 8g+qu+QKSkUUbxvwQi0mset7TGGbRE6nC4uEiI6qJB7thlt3FK75SJTJj6JWDYWeRLR9 ReqZw4Ioon3nzLFUy2bxKakZb0EctbONEN9F8ioAsbliMp5meogSJaULHMPpTC+UbxWO PgEg== X-Forwarded-Encrypted: i=1; AJvYcCWOuo7/0GjkmXHeYeQd3OA+j8SXl6xeNyxkwzU2Aiw6fkLDwPMhZa+AKZsh5hLC5D4C6O4IKbCgfgrWEsI9y0HMJ7BjrRzTK+qOHCk= X-Gm-Message-State: AOJu0YyDj6hy4ZC7+5BHePtDL+IlEHn8YffqdQ7dOGeCdL9560mbRkMS PFnlZS3sELecJ6MeQQX/d0VDhGdMT48flq4R7E4kY+2H//nXJ9jmMFXaElfo6p0= X-Google-Smtp-Source: AGHT+IF/POMq9aLYdhYAN8mGl+02ev+tjcxf5SZfsiQcx3hYPUqBs5YJM468bSW3OlFox/Lm2qYWhA== X-Received: by 2002:a17:903:2c6:b0:1f4:977e:bf with SMTP id d9443c01a7336-1f9aa3c1bf6mr80297755ad.19.1718906286292; Thu, 20 Jun 2024 10:58:06 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e55c96sm139667235ad.61.2024.06.20.10.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:05 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov , Hans Verkuil Subject: [PATCH v4 20/40] media: radio-shark: optimize the driver by using atomic find_bit() API Date: Thu, 20 Jun 2024 10:56:43 -0700 Message-ID: <20240620175703.605111-21-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Despite that it's only 2- or 3-bit maps, convert for-loop followed by test_bit() to for_each_test_and_clear_bit() as it makes the code cleaner. Signed-off-by: Yury Norov Acked-by: Hans Verkuil --- drivers/media/radio/radio-shark.c | 6 ++---- drivers/media/radio/radio-shark2.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-= shark.c index 127a3be0e0f0..c7e5c08d034a 100644 --- a/drivers/media/radio/radio-shark.c +++ b/drivers/media/radio/radio-shark.c @@ -21,6 +21,7 @@ * GNU General Public License for more details. */ =20 +#include #include #include #include @@ -158,10 +159,7 @@ static void shark_led_work(struct work_struct *work) container_of(work, struct shark_device, led_work); int i, res, brightness, actual_len; =20 - for (i =3D 0; i < 3; i++) { - if (!test_and_clear_bit(i, &shark->brightness_new)) - continue; - + for_each_test_and_clear_bit(i, &shark->brightness_new, 3) { brightness =3D atomic_read(&shark->brightness[i]); memset(shark->transfer_buffer, 0, TB_LEN); if (i !=3D RED_LED) { diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio= -shark2.c index e3e6aa87fe08..d897a3e6fcb0 100644 --- a/drivers/media/radio/radio-shark2.c +++ b/drivers/media/radio/radio-shark2.c @@ -21,6 +21,7 @@ * GNU General Public License for more details. */ =20 +#include #include #include #include @@ -145,10 +146,7 @@ static void shark_led_work(struct work_struct *work) container_of(work, struct shark_device, led_work); int i, res, brightness, actual_len; =20 - for (i =3D 0; i < 2; i++) { - if (!test_and_clear_bit(i, &shark->brightness_new)) - continue; - + for_each_test_and_clear_bit(i, &shark->brightness_new, 2) { brightness =3D atomic_read(&shark->brightness[i]); memset(shark->transfer_buffer, 0, TB_LEN); shark->transfer_buffer[0] =3D 0x83 + i; --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 8AA531C68BF; Thu, 20 Jun 2024 17:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906290; cv=none; b=NkG6ahXI7qdXlnafBDMWBquDhfBbKoVZl8gfC0o1lB/NVTWGIxuPceYByF5VYlmxPPy+PW3nlYA2FaqBlhD3p/yRy94IEf0qXiW78DoxCAKq/UF1MIzk455GNgezjQBCumZ7t2yVIb3bjpeAOHTBc4NVdUyxC7ZaMjj8++w1qXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906290; c=relaxed/simple; bh=ScoEmgZi6HPVHvIh/FX/S5wdvye/fu3oKSGTZiZ4FUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HIU8vCE3Lh3K7ntOpBjbCxNv0mcdt0i1ABuQ0VbyLIc3pZIiHGFJWFz9s10VBj1nXgpb5vq/FGfm098rK2UuRy76JuNWHm1icDRY9bW1qdOPPgeD1x78eMCBpLsox0+Wv2Yjd3d6IU/K/6fspLQuWwBaSU+Ec9juUa+OU3u3mMY= 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=mMLvHFWs; arc=none smtp.client-ip=209.85.214.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mMLvHFWs" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f65a3abd01so9825955ad.3; Thu, 20 Jun 2024 10:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906289; x=1719511089; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aM5r6drJAolG+e7iKS0TLJF6ZMjGSQBElC3QUFVYkk4=; b=mMLvHFWssZem5d0HFmhbgpMfzJUBZrcE7ha8z7HkCcgAZARCbQYYXPyGrL1DwT+f1Q ewR2CK8Ibc4PptJCYpeK6YqoBSnqVla7yG4mzIeg+8R2d8N+5bicC4Dx5FdO5abSRRNT SPSlbMLVgpDUrW+BW2yUW6voaqpPGRNp97DQ8rXFj6XOCPWVBofJvdOTn1Ra0Cj7qBS7 cQTAKhF1pva7UMcFofDPofBahbk6DEmBusTIONl0ykSdGGLkyvWuDHNOsqzAIwkeTu80 T7F6hJGI1Ge79x+nfBUkzdAwkUIyed/zSIOtBa3GUhHTo1JPcfzC/PJiSH5NVPEwLpjY vHTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906289; x=1719511089; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aM5r6drJAolG+e7iKS0TLJF6ZMjGSQBElC3QUFVYkk4=; b=kS/eH4dKv24G2TsSJpgPWJ2bqxWwBqGqr4lsXRrKgJ39+GpSM0vpyo0jFj6aBzUVL3 7QrvoFJzKcNCZ4ZYVUcW6J/vy6dgZjUfrQIm0w8//LtlD09ulVs3fcUs57prbLII6a1s NWHyJ9c8QTKij0UOSFkcozv91+uuIw1WbA0gCRr6EPvlgmkwbaq6vtOHnGa0QW/2lY7v wdd6/NBKJ64SaKbA8vOhvIv2kUvgBVPg3lCm8B7nQrWoNAQ6/gK+2gekp0qmpwvCy0MG Y06MLXd5lfJo0JlwCbZzGR/mkkneXy7b4wwCsVYm8FM0lTCikj7R37pOoSxDgBLUu2OR UZ4w== X-Forwarded-Encrypted: i=1; AJvYcCXIe6kGrcpG9O7Jppf3NI1toOXwR6TXaLovyNPw6hFDVafOwtKDutkNrPVS9X370qXVlEYit/hzGOVwJgFeePGJ83G2aarn X-Gm-Message-State: AOJu0YxTt9JUIG40ATzSvgK1tabTEgEJgPrDUAcpGiQCoIDzQ5pcvnA5 BRz9v9J2JOljFD0H9MCA8Ow3G2YnippB5HXaRxsLZemfRo0q8Aa+pck6le9JxtM= X-Google-Smtp-Source: AGHT+IGTpIdO1uV11a9fnQTFo6rZEqj4PAGNZxvz9A2Y8Nk1O+96gr6SMXGZm1d2oyKBSv0djR+7OA== X-Received: by 2002:a17:903:2349:b0:1f8:69ed:cfd5 with SMTP id d9443c01a7336-1f9aa3b09ebmr73525515ad.10.1718906288971; Thu, 20 Jun 2024 10:58:08 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9c20c7e30sm24175035ad.221.2024.06.20.10.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:08 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-net-drivers@amd.com Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 21/40] sfc: optimize the driver by using atomic find_bit() API Date: Thu, 20 Jun 2024 10:56:44 -0700 Message-ID: <20240620175703.605111-22-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SFC code traverses rps_slot_map and rxq_retry_mask bit by bit. Simplify it by using dedicated atomic find_bit() functions, as they skip already clear bits. Signed-off-by: Yury Norov Reviewed-by: Edward Cree --- drivers/net/ethernet/sfc/rx_common.c | 5 ++--- drivers/net/ethernet/sfc/siena/rx_common.c | 5 ++--- drivers/net/ethernet/sfc/siena/siena_sriov.c | 15 +++++++-------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/sfc/rx_common.c b/drivers/net/ethernet/sf= c/rx_common.c index dcd901eccfc8..370a2d20ccfb 100644 --- a/drivers/net/ethernet/sfc/rx_common.c +++ b/drivers/net/ethernet/sfc/rx_common.c @@ -9,6 +9,7 @@ */ =20 #include "net_driver.h" +#include #include #include #include @@ -953,9 +954,7 @@ int efx_filter_rfs(struct net_device *net_dev, const st= ruct sk_buff *skb, int rc; =20 /* find a free slot */ - for (slot_idx =3D 0; slot_idx < EFX_RPS_MAX_IN_FLIGHT; slot_idx++) - if (!test_and_set_bit(slot_idx, &efx->rps_slot_map)) - break; + slot_idx =3D find_and_set_bit(&efx->rps_slot_map, EFX_RPS_MAX_IN_FLIGHT); if (slot_idx >=3D EFX_RPS_MAX_IN_FLIGHT) return -EBUSY; =20 diff --git a/drivers/net/ethernet/sfc/siena/rx_common.c b/drivers/net/ether= net/sfc/siena/rx_common.c index 219fb358a646..fc1d4d02beb6 100644 --- a/drivers/net/ethernet/sfc/siena/rx_common.c +++ b/drivers/net/ethernet/sfc/siena/rx_common.c @@ -9,6 +9,7 @@ */ =20 #include "net_driver.h" +#include #include #include #include @@ -959,9 +960,7 @@ int efx_siena_filter_rfs(struct net_device *net_dev, co= nst struct sk_buff *skb, int rc; =20 /* find a free slot */ - for (slot_idx =3D 0; slot_idx < EFX_RPS_MAX_IN_FLIGHT; slot_idx++) - if (!test_and_set_bit(slot_idx, &efx->rps_slot_map)) - break; + slot_idx =3D find_and_set_bit(&efx->rps_slot_map, EFX_RPS_MAX_IN_FLIGHT); if (slot_idx >=3D EFX_RPS_MAX_IN_FLIGHT) return -EBUSY; =20 diff --git a/drivers/net/ethernet/sfc/siena/siena_sriov.c b/drivers/net/eth= ernet/sfc/siena/siena_sriov.c index 8353c15dc233..f643413f9c20 100644 --- a/drivers/net/ethernet/sfc/siena/siena_sriov.c +++ b/drivers/net/ethernet/sfc/siena/siena_sriov.c @@ -3,6 +3,7 @@ * Driver for Solarflare network controllers and boards * Copyright 2010-2012 Solarflare Communications Inc. */ +#include #include #include #include "net_driver.h" @@ -722,14 +723,12 @@ static int efx_vfdi_fini_all_queues(struct siena_vf *= vf) efx_vfdi_flush_wake(vf), timeout); rxqs_count =3D 0; - for (index =3D 0; index < count; ++index) { - if (test_and_clear_bit(index, vf->rxq_retry_mask)) { - atomic_dec(&vf->rxq_retry_count); - MCDI_SET_ARRAY_DWORD( - inbuf, FLUSH_RX_QUEUES_IN_QID_OFST, - rxqs_count, vf_offset + index); - rxqs_count++; - } + for_each_test_and_clear_bit(index, vf->rxq_retry_mask, count) { + atomic_dec(&vf->rxq_retry_count); + MCDI_SET_ARRAY_DWORD( + inbuf, FLUSH_RX_QUEUES_IN_QID_OFST, + rxqs_count, vf_offset + index); + rxqs_count++; } } =20 --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 4C7BF1C8FC2; Thu, 20 Jun 2024 17:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906293; cv=none; b=Ogn7gefBpvloN5p+3JvAjcRoIjDAzqVkE1HTxD5bOogckt73P2GGXYoPJ1gdIAGjiJ5R/c6D9R1aU6kEzhP+MxV3NAquX95Kpkumr1AXpZ2CFLaQpisdkgawpce1WIOk5ncRDyws97qJSqnLiETJbvBjTPDl6VWQ7aW0JsBBq1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906293; c=relaxed/simple; bh=uWAIPWK/y5sntscGmoFoKf1TBYYoJ8omzWsjZLwiJ/A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AMsT9j0AA23Ul7nmlIXG0W8yV/H4uzPchlIwcyoNgwXVzDeohjTouePGlTyJp27h9UWoXTrQEAyEOIrpKh8oS1SsjBmXepvIIp0hx6P5cZ7qWo2KAHmCOI05Tsh+9DBwsz7VuFCcbaf21wSfXldOLd2J1OGwGmX5aDP8WpB/bX8= 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=WAhWVB/Z; arc=none smtp.client-ip=209.85.214.175 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WAhWVB/Z" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1f47f07acd3so9491225ad.0; Thu, 20 Jun 2024 10:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906292; x=1719511092; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B5EYjko3sqn/5zVhVGKhFedN1WIYjrNTNEVk8UsUCrQ=; b=WAhWVB/ZT6IY+ZWG8oL8+CIyjjKosAXvkrRyugjSHoH1BHk9YtZEZPsiLilvQr6w2Z XwtHjwY5w0b+2ZscCIXtImQOOj0CYFaudCB+XjlUSoHsb7UQ+H716thQ5H1Bv7fEtACb c5JxMkb4eDYpe6BYge/8TFBYxnylb3+j7JF4iTbkkOcgPsO+og3dPBOkrQYlMKEpeedD WopWSIRPxWy12EgnY2PJ2mc7zwIh16JjDE6QibYDvcw8IW3lwe8mVk/VBC4YPzdMVopP yVNwwhWAVmrwe4ML1DMt2bmFCFgK8YbxcrWR0LeYaboT5tuuwJdmtSTOnKZMMS8bfWyn PXjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906292; x=1719511092; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B5EYjko3sqn/5zVhVGKhFedN1WIYjrNTNEVk8UsUCrQ=; b=fMqLPm5BGaSLmNIDeG3czmU807P+0eyDol8VJBBdRJltVbK9JwU71qjwuEDqJkPGu3 rz+SzQpVV/vlR17KydOjuQsWgvbS0QswGqL0pFrsM6hTGJauepPgfG1jP8SyR5hMdVcd tNW0MOiMc/gV8WPiBBgonNaKczqn0GCNbKONWhVyhci+vTUa6ppGLfqs4d54ClIpijQ1 bWl4sOWpoebl0AQI3yJCVT4tO2kKQfD1OW6YIsksKgfOIBMzytCopfH0kr4a8udbJfvO eKI+aAIh7zbHEzvj3+yCwS4KS4lAlbI5pQNUQWjC5jzY27d0Klp/QHIt/+EDx0WfGziZ 6aNg== X-Forwarded-Encrypted: i=1; AJvYcCV9gviVYfGj3S646ETF3OPGGg0rJKiQ53HnPogER/QyOrTrHOQemMddo2jdfMct7s+KBtj7ANghzrCcHDm94f3Z0tIQ6iiWxONySjVe X-Gm-Message-State: AOJu0Ywx9cu+A2B5PbAF17NVFZBpIsJUVwaxNbIHgMMU4h93fd9ds1f8 3/egk1xfO8qiy1SXjNohmXNgDELI8sssRNmh5KIOwVNWXDFJUlPpvO/0vCROS6w= X-Google-Smtp-Source: AGHT+IGNZgfeQC5tH36QJE9gcJwoghUtuEwxnBd7Pq0D1sgVZTvkF9LD2b5agbKQAwWjRSTyP3W0ow== X-Received: by 2002:a17:902:e88a:b0:1f7:4021:508a with SMTP id d9443c01a7336-1f9aa3e8931mr78300105ad.33.1718906291691; Thu, 20 Jun 2024 10:58:11 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f85bf28552sm136016905ad.132.2024.06.20.10.58.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:11 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 22/40] tty: nozomi: optimize interrupt_handler() Date: Thu, 20 Jun 2024 10:56:45 -0700 Message-ID: <20240620175703.605111-23-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the exit path of interrupt_handler(), dc->flip map is traversed bit by bit to find and clear set bits and call tty_flip_buffer_push() for corresponding ports. Simplify it by using for_each_test_and_clear_bit(), as it skips already clear bits. Signed-off-by: Yury Norov --- drivers/tty/nozomi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c index e28a921c1637..2fe063190867 100644 --- a/drivers/tty/nozomi.c +++ b/drivers/tty/nozomi.c @@ -28,6 +28,7 @@ /* Enable this to have a lot of debug printouts */ #define DEBUG =20 +#include #include #include #include @@ -1201,9 +1202,8 @@ static irqreturn_t interrupt_handler(int irq, void *d= ev_id) exit_handler: spin_unlock(&dc->spin_mutex); =20 - for (a =3D 0; a < NOZOMI_MAX_PORTS; a++) - if (test_and_clear_bit(a, &dc->flip)) - tty_flip_buffer_push(&dc->port[a].port); + for_each_test_and_clear_bit(a, &dc->flip, NOZOMI_MAX_PORTS) + tty_flip_buffer_push(&dc->port[a].port); =20 return IRQ_HANDLED; none: --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 81E651C9EA3; Thu, 20 Jun 2024 17:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906296; cv=none; b=AJz7sxfLS9m+ZGrVlM9JDEbiZw3yDIHnRiQN0NEL+xww4/MqOG9NXozwEREhx6A+9B4m9U6UhdodAkS4yY7422SQCvNZ2ngVEpZADH12CWhYHzERpsYTMsI9W58En6XXQ4PyEXLNtuW3+JQUEjW+f//zOY5bLrQvTQPruOzHPuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906296; c=relaxed/simple; bh=KdbeHfsgkowpARY2YPlVsmqqW/kJIUxTm29Tdz3OOA0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pR4Bxj1THNVvdCpEVRm2wkqxOTUPh67aNJofFOSdMsLpfJIp4DG41wMUFI2YC9fTTZ7dpVruCvKuq4VzAylKjWEm/8u8ytXBNMtiYBJ6ZrXpeCO6nyDlxb5flaaSZzLBTYZerKSPQ2kS/XWZwdlC0AIgjOS1yKQnvWCeJC453uU= 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=ZBVFz+TK; arc=none smtp.client-ip=209.85.210.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZBVFz+TK" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7041e39a5beso983536b3a.3; Thu, 20 Jun 2024 10:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906295; x=1719511095; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X3AS9JVo8Hs/Ti3mNv2gE0HU0UAaWpI1VlkoQQK++VU=; b=ZBVFz+TKCMu/ZNUGyZgkeYz7BF2GY99DH+ew+oY29ZTzSudv9CTbrbkXE2QUADVoCj 9JuiHMxaUWVmzUIC0tDiULah63aKRdOLeHGLcvq/99stzfi1+o7B5s55HaqKpnqgvf8w 6zD2d5cR8HcRewR0Gmo8/ZJhFx82qzYSJMD8uvrVy2bbJb14dLPgZsG56Eu1H3CCPdEC 9wwktf3fbXD9F4swDyo5bkbhfXlbe5hAu7+32nerBrPtXDwE6yG1oSRZ86pZ071hVOAF PWXY771grJZriqpL81+VBS57ISK1ouJSDy1AuXOgd0vCnH/icqHj630rRvS+7Fp69/ZH bm8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906295; x=1719511095; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X3AS9JVo8Hs/Ti3mNv2gE0HU0UAaWpI1VlkoQQK++VU=; b=ryOD4z3/pG4zvn1kqKFjGgz1gam3GocHeZ8I+L7r3t+ZhdiEvt88uUDPY5h5yRvB2K 1LwFPv93po/FBdwQ+esa6dXVgiNvhplPUQA7Hq5SsrPpGLElZAzql6HG8FlZczmMUjnY Q5WnSR5s1c84EgJpDudk2DTWoJOrExIZk/YWryoDyapr+w2Bf/CJICvdU0PDozXa/L+Q GfiRgrBzZjgcSPNJmzD7eIurJGU92lKUXOL8bSv1CdSDxvE2U6ptidOpGO0lyxbB5vW6 Mq/bD4xUWGZCq9a2MasmDn4D2yS7BFemxgZTwl3Aeb0BGKaQjD1PCuG32SwOuBUH9L7l WrAA== X-Forwarded-Encrypted: i=1; AJvYcCUMPOOG1sIqitwJy0fz2mRQZ84vu7Ub00SqQjqlhEyUjhznUA+8on7fvt2F+I9NIfq7TjqMotL605dbfKCph0YmR02atUsNxh7Z X-Gm-Message-State: AOJu0Yy6fuVoZaj6DBkG8+Xt/4cSTG1jnYL3cyhiEoS5TXY+hK701XZ3 1Dnut4I0wyAlL6A4guP3aUlcL+CNxgbHKqn6ObPWFzkKP8OGJyN2qynVFxyUP/Q= X-Google-Smtp-Source: AGHT+IFyDwE+Jz3Bn1/3b5AVproXEgZap0y3BwG6IwB5VEhHDqAtrR7HyxflDE7GXDdoxY3T8nE9cg== X-Received: by 2002:a05:6a20:29d:b0:1b5:2fbb:2d78 with SMTP id adf61e73a8af0-1bcbb656593mr5458467637.48.1718906294899; Thu, 20 Jun 2024 10:58:14 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb4c621sm12637089b3a.115.2024.06.20.10.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:14 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Oliver Neukum , Greg Kroah-Hartman , linux-usb@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 23/40] usb: cdc-acm: optimize acm_softint() Date: Thu, 20 Jun 2024 10:56:46 -0700 Message-ID: <20240620175703.605111-24-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" acm_softint() uses for-loop to traverse urbs_in_error_delay bitmap bit by bit to find and clear set bits. Simplify it by using for_each_test_and_clear_bit(), because it doesn't test already clear bits. Signed-off-by: Yury Norov Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 0e7439dba8fe..f8940f0d7ad8 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -18,6 +18,7 @@ #undef DEBUG #undef VERBOSE_DEBUG =20 +#include #include #include #include @@ -613,9 +614,8 @@ static void acm_softint(struct work_struct *work) } =20 if (test_and_clear_bit(ACM_ERROR_DELAY, &acm->flags)) { - for (i =3D 0; i < acm->rx_buflimit; i++) - if (test_and_clear_bit(i, &acm->urbs_in_error_delay)) - acm_submit_read_urb(acm, i, GFP_KERNEL); + for_each_test_and_clear_bit(i, &acm->urbs_in_error_delay, acm->rx_buflim= it) + acm_submit_read_urb(acm, i, GFP_KERNEL); } =20 if (test_and_clear_bit(EVENT_TTY_WAKEUP, &acm->flags)) --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 93EE31C9EC3; Thu, 20 Jun 2024 17:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906299; cv=none; b=i0/+JyG1mRq6yf+PnMuilfQuKx45EoFm6I6+ZpAJGTYL+ssWbwyEFruGcTCySZfeeQ/2ULsUpOcY1AN2tLokirT2xUW1niHwZSfs/HWQ9WxaQKTNn4/Q8Y/TMzVtBiE8TG1C18G9tzaKw0jB8EXxEfVerI+Cen04VWjrCnX8d+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906299; c=relaxed/simple; bh=EEnf5xzi7eXOhkKDYzRKsCmReB+rHy33vbj/1r6jsqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OjtGivw0aov+S/td7GSoPcBPCInKp6INRoVQn0Xxa9OR6eFPp+hSwR4uhzsu8ilj55TF0b3QwVGss6gWH9mWITPIFKNFmsOWDAzuDoBoQYY+Zmdo+bcIionDN7o7knbYWRPptpONM8b8o4tgyPJlwreQY/kdSwUtineqw8JYRR8= 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=fJW2RHhY; arc=none smtp.client-ip=209.85.210.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fJW2RHhY" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-7061365d2f3so941691b3a.3; Thu, 20 Jun 2024 10:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906298; x=1719511098; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EllZQDb/fqD8EGwJT0CuH2LSmY08c8ja9Mytx23g1KM=; b=fJW2RHhYQu8j9VzlQBTJNiee2IE2SLdof1Aw7zwr69AS6Hv09/UHjcdevwEW6iFE15 sqpJYHqJt8/1E3Hwo/HzeC1KzXfchUjZhedpJUJu1CZnc92HgliMVd/Rbe7bGYeGrirI XkMUL+Yka8uEOQnWUA13T2/99UrG8wbd9QTq7rb66AgjIWmyAIGsLqR0oVDrpenuMflI Bn/oUTb7g9d/NQVqhgLZ8wp+ORkWG/9fcpDOadxhGLv3w0qqQSCX64qdLPvTHP15f5Ua aRdxt4BGLlgNX3syfDSN16KM8A1hOejTv05K/WM5h6jYMnSyDL67RXevfsrKJRsRPGdC ATDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906298; x=1719511098; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EllZQDb/fqD8EGwJT0CuH2LSmY08c8ja9Mytx23g1KM=; b=DkFVZG+Pe4KNDRSbq4u2T4zw/JJ9yJ/8gW/eYNR69KS8szoDhufMpUgxWH5GuN1Zsy vdO2h0cPbX4bpqsPrX+MwFlYHM2Cq8qpjZl/6H2HFdNHJ7gwF42S10Ps9KWOHr5DY3Vz zaa824mpi4SVIhOKSMYeM6mJ87tt/+SdgXAk5HRMQJTRmWeSvJO7IowdZHj2fmeUTNH1 J+ty8Duow3YBQmrLJ4fO1W13Oo1+y4Eh8mZMiStDRJxMU+i38j8M3+hhl+jnUODq0M39 q9qtWxYYG36jrPPBziL7P7IV6lJaiZ75dqWsFWNyyr//hOaJXXucB/dCmw/CLKtQKgAo zESg== X-Forwarded-Encrypted: i=1; AJvYcCVZXSKcBY1WWrSlDNTd1Me1EixHLmJgoejOn9eirFYID4FZ9Vk7YUne1Evm0eInD7yoknraZX+SNiXK2objf2xraIxig8GdEAam8A== X-Gm-Message-State: AOJu0Yz35JKIezrNq49VusPTgS3ehTRj7S0DgGiMBdO8vqB6UofuBEUv IVIoVGMIAQVlwzME5rr4SndH/5hapFgZR9sh5A70kUkb2GH9Mkaoba/xFAZon1Q= X-Google-Smtp-Source: AGHT+IEkrpt1MRFKLlVi7ulyys1DlHO0ZCczRH9xxekWr4vHxde7wTkq55+80B0FxrWnRZBVoG0B4w== X-Received: by 2002:a05:6a20:4881:b0:1b0:1a02:4136 with SMTP id adf61e73a8af0-1bcbb386b43mr5771824637.8.1718906297955; Thu, 20 Jun 2024 10:58:17 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e53e2846sm1989195a91.24.2024.06.20.10.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:17 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 24/40] RDMA/rtrs: optimize __rtrs_get_permit() by using find_and_set_bit_lock() Date: Thu, 20 Jun 2024 10:56:47 -0700 Message-ID: <20240620175703.605111-25-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function opencodes find_and_set_bit_lock() with a while-loop polling on test_and_set_bit_lock(). Use the dedicated function instead. Signed-off-by: Yury Norov Reviewed-by: Jack Wang --- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ul= p/rtrs/rtrs-clt.c index 88106cf5ce55..52b7728f6c63 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c @@ -10,6 +10,7 @@ #undef pr_fmt #define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt =20 +#include #include #include #include @@ -72,18 +73,9 @@ __rtrs_get_permit(struct rtrs_clt_sess *clt, enum rtrs_c= lt_con_type con_type) struct rtrs_permit *permit; int bit; =20 - /* - * Adapted from null_blk get_tag(). Callers from different cpus may - * grab the same bit, since find_first_zero_bit is not atomic. - * But then the test_and_set_bit_lock will fail for all the - * callers but one, so that they will loop again. - * This way an explicit spinlock is not required. - */ - do { - bit =3D find_first_zero_bit(clt->permits_map, max_depth); - if (bit >=3D max_depth) - return NULL; - } while (test_and_set_bit_lock(bit, clt->permits_map)); + bit =3D find_and_set_bit_lock(clt->permits_map, max_depth); + if (bit >=3D max_depth) + return NULL; =20 permit =3D get_permit(clt, bit); WARN_ON(permit->mem_id !=3D bit); --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 482671C9EDA; Thu, 20 Jun 2024 17:58:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906302; cv=none; b=WEkVXSS0O6J4JbImOWi4c03DedfYYuHtQFcDTipGp6qn1V84kUvRoc7kVZspimoFGrdV5CEhndPgCpb4C9npDQmqSWSQve0XUvEh54Q6qEDrUIIbg6GIsLhGvwDVjG+SW9Z1XlV9wSSIRRvPkFtRPDUH/2gw/jvPlYEdqteNakk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906302; c=relaxed/simple; bh=K4IWdyliZkmZhKKSV+eGfL58Im2XzxDJDCPSFOZ4NNI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lXG2mF28Dk9BBopB7AVgMSBsxUN/K/JpPpm6KAHsGnjjEOzv9oS/HU8LkWe+RE9Im8bLcxw/De89A1R2+IZQMEIzjdgzMpp7Lrzr4f1zsJWxpItf6wPyoL4+vUmrU1ayNaoBVYnqa/fKkVxGAxSYCaHG/eu1vSYn8y4lUrwwLyk= 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=EqRe5MAa; arc=none smtp.client-ip=209.85.215.181 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EqRe5MAa" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-711b1512aeaso940415a12.3; Thu, 20 Jun 2024 10:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906301; x=1719511101; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lti5kgcPeWhIYDqzEsD33v78UGifs1rdopCyxCRLYNo=; b=EqRe5MAaHm1RKGWNTbNGuIXjFJJZCh9XYH9QoC00WbkQwvh8ZDyDqTUa1SRJNhmd5U HOaxOLn9M4HqXWgJG0a4Wr7p7bWnkeeqt5NF3pplLwOW653UKkQVF82UDyFUKi//FnN6 4AojZw0PMDdSScD1/iLic10nrlO1wLs6OWfZEZL+17Uw7Ffjb3ys15ga4d8YbOi5vFku M0vJw6+h3M8ks/nRVxnBHRZjtktyck9NxLB2L6zN4y/2Eg/QiBArb0+JYK46J2EP/dJz 9WFHWW5zOUjpuU6Yy1InJVZKcBVlnrwaM06ITWld7lEWgdXQhhI6HKtFb01BxUpU3Qga VVWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906301; x=1719511101; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lti5kgcPeWhIYDqzEsD33v78UGifs1rdopCyxCRLYNo=; b=HvESYKySeC0dkYTla3ElZASb0SImvB3DaFWxeJ6mouzPoGfGXTgzuS+4M2Z6sxN4u5 xC0QWPvKQ/wSa4oQ+NDm5kOPiqpH0JY3zATWt8g6uYSQj5+1Lituakkh8Vdnd+L8gY8P /m9C0ui8PAGFzDpHOtJDbgbPO9qfNveup0XcDt6bv2sGgYqmcSfjjP1Nfj0YE9zmetXJ N5OEE5ghhw7VAuVED7Q2OrclWjg0OS52xAQCifyu8dEVQbGOWFEtt5hRSUJYrG+bz2p/ a8oUIvzBfvp2d60eVHuy7S9bhVCmIPsCsdlkJX6PqUSU1ehfCOYyXLwfKdx3Kgo0K7lM GGpA== X-Forwarded-Encrypted: i=1; AJvYcCWmoaQeki63ZBsowMiPPl2rH48zbfVRatIBnsESKd3Y3L4jU6tChjIfxW2DHJIPcbESRhRpKNF88nsZXFtkaMyyLMZTw1mb X-Gm-Message-State: AOJu0Yza2sGmSmljWo4RGxqALHNpxIdtQQhE+ERLp9EBKfXF8UuXawU7 B2roZ5r3rCckASixZXnmE+BkTfE7Ck7Jd5bpIqijb09rPpYKaB3VX4b7xWFQC54= X-Google-Smtp-Source: AGHT+IFht8NxOCyg7z9RpFIr1DfT39gsfSL0btobRHEcyEuZAVDhEroB+sko5XU5BgaZjpnZPlp6Jg== X-Received: by 2002:a17:90a:4ca6:b0:2c8:647:216 with SMTP id 98e67ed59e1d1-2c8064709bdmr1546880a91.20.1718906300684; Thu, 20 Jun 2024 10:58:20 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e56d5d31sm1996388a91.27.2024.06.20.10.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:20 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Karsten Keil , netdev@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 25/40] mISDN: optimize get_free_devid() Date: Thu, 20 Jun 2024 10:56:48 -0700 Message-ID: <20240620175703.605111-26-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" get_free_devid() traverses each bit in device_ids in an open-coded loop. Simplify it by using the dedicated find_and_set_bit(). It makes the whole function a nice one-liner. And because MAX_DEVICE_ID is a small constant-time value (63), on 64-bit platforms find_and_set_bit() call will be optimized to: test_and_set_bit(ffs()); Signed-off-by: Yury Norov --- drivers/isdn/mISDN/core.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/isdn/mISDN/core.c b/drivers/isdn/mISDN/core.c index ab8513a7acd5..d499b193529a 100644 --- a/drivers/isdn/mISDN/core.c +++ b/drivers/isdn/mISDN/core.c @@ -3,6 +3,7 @@ * Copyright 2008 by Karsten Keil */ =20 +#include #include #include #include @@ -197,14 +198,9 @@ get_mdevice_count(void) static int get_free_devid(void) { - u_int i; + int i =3D find_and_set_bit((u_long *)&device_ids, MAX_DEVICE_ID + 1); =20 - for (i =3D 0; i <=3D MAX_DEVICE_ID; i++) - if (!test_and_set_bit(i, (u_long *)&device_ids)) - break; - if (i > MAX_DEVICE_ID) - return -EBUSY; - return i; + return i <=3D MAX_DEVICE_ID ? i : -EBUSY; } =20 int --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 16AD51CCCA5; Thu, 20 Jun 2024 17:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906306; cv=none; b=Jiv6ZMxUMQHZO56erfKSCitcqnobr5Xtphw36L3fhL/fzhHM2jp/6T3VmdYzyWSkZkJrda1oYqijHw1QLNoWHv7GpP2g1RS/4P/TqqTiRnuc9PcsHY0JuSZQbLcDlyMBxfBMiyZZczJ8ykOVFqLNVqx671cu9q2vcXhw01/X36c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906306; c=relaxed/simple; bh=JZiYOORmljoK1sw2ane9GWAOBNpWFrHsg6e0OWJ8vSI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t3+OpDNxvhlse8w6M6ItVukiFyBm1GVud4FILQ45j8qPTQguMhW7ZYAuMMwaJaKHDwFbK+bMLgwIauC1+fmp1cXy+NGIk9upAM1q5GLFXrDNqtMl7Txd00BAc5bSUM3i25AaQy2pIyaPlduGOaHys7ulxw8+0o0nCVNlLSUS6zw= 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=Q7tf5tcQ; arc=none smtp.client-ip=209.85.214.179 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q7tf5tcQ" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1f99fe4dc5aso10187265ad.0; Thu, 20 Jun 2024 10:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906303; x=1719511103; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ML3sp6993QhuntHDiwMgBg5++AU4tTHxgPTWBrSRxD4=; b=Q7tf5tcQdUK5OwNm3iP6c/cOYh+E6F12X6Gf7qGvh9OYF4/XrLJM84inLbVIg+OdSX 89SX6RwCZEzVjLevRLmx8LRMSzsVtmX+Ne4AdcsoYjIBl9ZJzhzoKVp1aUx40Ehlf1wm h6pV4691kzAsmp5s2YEeh4y9sn0LRcgBXhKepxtGPnN0lmza/AsRZKOdxSgPXnPUYr2K s1rLdrmHTv+3pEFsqR7P1pFo38BKXeK+p0S+dnFklkWjMbXcxIR13mMnLQS/X6DLvlOk xyKyzcT0TKzsrkOnUXmkOrUsTkgsIjFkkw4iRA6ULusGW/IQi8Qls4uKEj8NYwicujCU aweg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906303; x=1719511103; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ML3sp6993QhuntHDiwMgBg5++AU4tTHxgPTWBrSRxD4=; b=URNvW+8R0iOXQCezgzQT8uZPKtDJjLRhYrYWQBiTCw87qL1CCqpLADDCWjw6BSE42G iH3JdupvyVJBV8/1EqSfn/Q/thiZm0KUrVFoufKOv7AYxfgQFXCb+ShVrlhyX0UpTKIh NlcgLB0eQAYjCtR4q9cQ0xYEhukXZR+tsiNX3HASI+GG3343IrWMjSl/dOjcrityRLh4 XfgwbKJoEPDInquozllB1F9OlSnwpv7SiS1G+l88eQqtszQR6jO1Ykswtj1MOtSGwCXB TL9pK4XpBeg5iJZO6k6Dq6eHq+ohjNWpTNwrMrp0yvn/BvQIfYz3gnGYbxmA8VBSvM/z Erlw== X-Forwarded-Encrypted: i=1; AJvYcCUoNGf7L2LzKEQPiTB51EcpeuW7pnXwWG59+d7NAN6+nbG08IWqOpIysWdY990KIsHpSMnK0z/IGU+7ZP0kV+4vPGNRcCmdBYJ7wh8= X-Gm-Message-State: AOJu0YwtItbCBdbJKbujhs82kTjZRHsjiygGgmSZj9xxelIZNcipTUPv gvts/Pwu2oByT8jyFcomRhEtfR42l7BC2brAiKkBF9mOXnHqXtrLQiZhmTtuMF0= X-Google-Smtp-Source: AGHT+IFBQBMGehB+oQoKQYHD/qYtBbqhxOtOkxopDaJNky+s/Sb/aQTrReWOcCKSQ26MccV2yDTi7g== X-Received: by 2002:a17:902:cf11:b0:1f3:1061:60fe with SMTP id d9443c01a7336-1f9aa3d24f7mr77142485ad.18.1718906303339; Thu, 20 Jun 2024 10:58:23 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9c81f48e3sm19719915ad.230.2024.06.20.10.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:22 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Yury Norov , linux-media@vger.kernel.org Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov , Hans Verkuil Subject: [PATCH v4 26/40] media: em28xx: cx231xx: optimize drivers by using find_and_set_bit() Date: Thu, 20 Jun 2024 10:56:49 -0700 Message-ID: <20240620175703.605111-27-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Functions in the media/usb drivers opencode find_and_set_bit(). Simplify them by using the function. Signed-off-by: Yury Norov Acked-by: Hans Verkuil --- drivers/media/usb/cx231xx/cx231xx-cards.c | 17 +++++----- drivers/media/usb/em28xx/em28xx-cards.c | 38 ++++++++++------------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/= cx231xx/cx231xx-cards.c index 92efe6c1f47b..8bdfbc4454f1 100644 --- a/drivers/media/usb/cx231xx/cx231xx-cards.c +++ b/drivers/media/usb/cx231xx/cx231xx-cards.c @@ -9,6 +9,7 @@ */ =20 #include "cx231xx.h" +#include #include #include #include @@ -1708,16 +1709,12 @@ static int cx231xx_usb_probe(struct usb_interface *= interface, return -ENODEV; =20 /* Check to see next free device and mark as used */ - do { - nr =3D find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS); - if (nr >=3D CX231XX_MAXBOARDS) { - /* No free device slots */ - dev_err(d, - "Supports only %i devices.\n", - CX231XX_MAXBOARDS); - return -ENOMEM; - } - } while (test_and_set_bit(nr, &cx231xx_devused)); + nr =3D find_and_set_bit(&cx231xx_devused, CX231XX_MAXBOARDS); + if (nr >=3D CX231XX_MAXBOARDS) { + /* No free device slots */ + dev_err(d, "Supports only %i devices.\n", CX231XX_MAXBOARDS); + return -ENOMEM; + } =20 udev =3D usb_get_dev(interface_to_usbdev(interface)); =20 diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em= 28xx/em28xx-cards.c index bae76023cf71..59e6d7f894ad 100644 --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c @@ -11,6 +11,7 @@ =20 #include "em28xx.h" =20 +#include #include #include #include @@ -3684,17 +3685,14 @@ static int em28xx_duplicate_dev(struct em28xx *dev) return -ENOMEM; } /* Check to see next free device and mark as used */ - do { - nr =3D find_first_zero_bit(em28xx_devused, EM28XX_MAXBOARDS); - if (nr >=3D EM28XX_MAXBOARDS) { - /* No free device slots */ - dev_warn(&dev->intf->dev, ": Supports only %i em28xx boards.\n", - EM28XX_MAXBOARDS); - kfree(sec_dev); - dev->dev_next =3D NULL; - return -ENOMEM; - } - } while (test_and_set_bit(nr, em28xx_devused)); + nr =3D find_and_set_bit(em28xx_devused, EM28XX_MAXBOARDS); + if (nr >=3D EM28XX_MAXBOARDS) { + /* No free device slots */ + dev_warn(&dev->intf->dev, ": Supports only %i em28xx boards.\n", EM28XX_= MAXBOARDS); + kfree(sec_dev); + dev->dev_next =3D NULL; + return -ENOMEM; + } sec_dev->devno =3D nr; snprintf(sec_dev->name, 28, "em28xx #%d", nr); sec_dev->dev_next =3D NULL; @@ -3827,17 +3825,13 @@ static int em28xx_usb_probe(struct usb_interface *i= ntf, udev =3D usb_get_dev(interface_to_usbdev(intf)); =20 /* Check to see next free device and mark as used */ - do { - nr =3D find_first_zero_bit(em28xx_devused, EM28XX_MAXBOARDS); - if (nr >=3D EM28XX_MAXBOARDS) { - /* No free device slots */ - dev_err(&intf->dev, - "Driver supports up to %i em28xx boards.\n", - EM28XX_MAXBOARDS); - retval =3D -ENOMEM; - goto err_no_slot; - } - } while (test_and_set_bit(nr, em28xx_devused)); + nr =3D find_and_set_bit(em28xx_devused, EM28XX_MAXBOARDS); + if (nr >=3D EM28XX_MAXBOARDS) { + /* No free device slots */ + dev_err(&intf->dev, "Driver supports up to %i em28xx boards.\n", EM28XX_= MAXBOARDS); + retval =3D -ENOMEM; + goto err_no_slot; + } =20 /* Don't register audio interfaces */ if (intf->altsetting[0].desc.bInterfaceClass =3D=3D USB_CLASS_AUDIO) { --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 A37A91CCCB8; Thu, 20 Jun 2024 17:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906308; cv=none; b=fYjixBD1fBMqu5Rj2x71Z0I/tbccGAr4TEZXyYqum8VauIkarrvYHa2zACfx2a22WxGdsrfsrkJHkKd7lX0fNrufRfYvN0bqAtG4sGp4rhJkbu7u8v3RxeKZDFulxTc5daxlSmUx6//QdzKFjYWoTKdCiRJoS1os1fGNboxqClw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906308; c=relaxed/simple; bh=MMONOtKUaLQgb2KMTa49gZOqkZLyA88DR8AvElxOfHw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LWd50kujfpVL/UUU4xdnVIVHUlS3ZWFPdKq+G4Ty3nxDjp/02jW7B+GeDGbwLFWH5w0Y8/G2znPv9skWAFNZYhEuXFtOd92WLfz7DX2LtAE+KERG28/yVYctvOOlDjOYm3CYzAbhEhsm3NTp6/hfheAOoavnLkTxAr6UcrJ2PnU= 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=MUyKx6y+; arc=none smtp.client-ip=209.85.214.176 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MUyKx6y+" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1f9e5fb4845so42285ad.0; Thu, 20 Jun 2024 10:58:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906306; x=1719511106; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4VirWasie1qW9f1ZDCT7HBbnQgPTV5Nl+uIgo4Ud+Ow=; b=MUyKx6y+yg3yfzqY1Vq6O8XXjsXOsgvLbND/QgSzh7xhCYBWAouf8aVDhfwa5Df6ow AitCEmkOUGfwfdEZHH8fRDlLoKmp6aGd1XjqzTmQMcQKMMtBffwXl2x98NjEX5eHlUUE b87qXUwsvyT+hoE0iFkdDbM3cPQ2bF6o0+CYEdNWtM6QfwZklHDUiD18qoIbO7GxTVKZ 5nJ0dJO3BGi6x5BAPEcVwQ1HdSR8C9ln6NFCQeUIKdpH0UOqVqVwMXT407ygTfxsQEHY 0psFBQDVfVCCom6ILSsbJk7HiTozJALltXVQYxV/S7sLrhlJ3WGvT6Sw5XiyNHYvw7gM OuyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906306; x=1719511106; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4VirWasie1qW9f1ZDCT7HBbnQgPTV5Nl+uIgo4Ud+Ow=; b=G8nkmPovV52rQyuThsIRyAO2P4mY7rrVgvMITZkVyTIfdLGV39P2TZl1rGujm9zkhK 6UBjgRT52bDUisW2c4GI6o7XF8hMXIrema9I/n48PcqWV3uN6HdaoiV08TGizRTyK2rG 70ISuOAnEy4ovRxk5ojdy8UEb7bFqutaZ1EMwdXJwQp661g6QzqyhkTp6NFRX18y66Cd rfzvI9BCssWSzLd+VjG2DmR/2hP+XpUCzhbxHbMfUwMT8xA/Sg/0GYxVfc9IKvKl4+zz Z7FJqSZZqb2vz5zlHBFuOxsYWVbB6tRSp7SwUmAirXlxING8b2HM3FsjHM3wtDHQsaDU uUlg== X-Forwarded-Encrypted: i=1; AJvYcCVoGC+72kDVXKEzwxxgjF4YhoKGzZQvjv4EXIqumcOrAx81tH2p0vh4JL+HrhaXueEp+9e2PnTeUEUlMWVRrT3vgkcRGZML X-Gm-Message-State: AOJu0Yyud7JL4+KqIksXXm9Q8NV8wNEBA25s7/YOBgDYv2z++9F/3kex LHvVBJqNO0hAqhrcR0tnNy5X9VIUDKUyUg6QlBOU7KtYBek2ErpxixfpzqECqHA= X-Google-Smtp-Source: AGHT+IGsYwTXJlieKXLf9Y84hPa5gN6g1kURBsnd/RiHetV5GGng3zA8q1keb8ZyZsxbKZxqnzjz2A== X-Received: by 2002:a17:902:d2d1:b0:1f9:a602:5e1f with SMTP id d9443c01a7336-1f9a8d5f164mr93863805ad.19.1718906305998; Thu, 20 Jun 2024 10:58:25 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9986d3130sm56082585ad.80.2024.06.20.10.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:25 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 27/40] ethernet: rocker: optimize ofdpa_port_internal_vlan_id_get() Date: Thu, 20 Jun 2024 10:56:50 -0700 Message-ID: <20240620175703.605111-28-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Optimize ofdpa_port_internal_vlan_id_get() by using find_and_set_bit(), instead of polling every bit from bitmap in a for-loop. Signed-off-by: Yury Norov --- drivers/net/ethernet/rocker/rocker_ofdpa.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ether= net/rocker/rocker_ofdpa.c index 826990459fa4..d8fe018001b9 100644 --- a/drivers/net/ethernet/rocker/rocker_ofdpa.c +++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c @@ -6,6 +6,7 @@ * Copyright (c) 2014-2016 Jiri Pirko */ =20 +#include #include #include #include @@ -2249,14 +2250,11 @@ static __be16 ofdpa_port_internal_vlan_id_get(struc= t ofdpa_port *ofdpa_port, found =3D entry; hash_add(ofdpa->internal_vlan_tbl, &found->entry, found->ifindex); =20 - for (i =3D 0; i < OFDPA_N_INTERNAL_VLANS; i++) { - if (test_and_set_bit(i, ofdpa->internal_vlan_bitmap)) - continue; + i =3D find_and_set_bit(ofdpa->internal_vlan_bitmap, OFDPA_N_INTERNAL_VLAN= S); + if (i < OFDPA_N_INTERNAL_VLANS) found->vlan_id =3D htons(OFDPA_INTERNAL_VLAN_ID_BASE + i); - goto found; - } - - netdev_err(ofdpa_port->dev, "Out of internal VLAN IDs\n"); + else + netdev_err(ofdpa_port->dev, "Out of internal VLAN IDs\n"); =20 found: found->ref_count++; --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 683BF1CD5AB; Thu, 20 Jun 2024 17:58:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906310; cv=none; b=KqHRuaU1nwYh8+A8Rt0o37bqbzskEn20uE0Ox5LGQrLmWTel59q+Cqx9mTKUe+0NXZj1uHwzHx78BYWpymeBmEVpFyPndnHi8AEEplL65gZxG7O55qZB1Sfl5+7gK0mjX3Tx+LyPWCWzandpX/hirR+xq78akI6bx+Mv7idoAjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906310; c=relaxed/simple; bh=xIXzaqvD3dZKkTf9zQCESfh4yAmpcoxDwwO6XLudC9c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NL5rZ8HMrGHBHcIuUzTVyS/X73grcO/7ZMha832cf8tlwyXGzkm+39Enojm+MSy8klm7COro0cmyzQEBzoyl4FT/7PeDeuDmpIWmpQO0io36mdDwmwt8yoZmlBsRcwhWbMIr+a/VXhXuR/XsbtlDCkgx8+RxHFanN3xLTYGmEgU= 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=lBuUtVI0; arc=none smtp.client-ip=209.85.210.170 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lBuUtVI0" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-70627716174so1068189b3a.3; Thu, 20 Jun 2024 10:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906309; x=1719511109; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jPbSDSWVNJkYRt5U6fddE9YLEW5XzX+KySLxZvUgJ0U=; b=lBuUtVI0R1aOZIO+NIJGFrtPwPg26jCxUpklMMfcJ7v/8GsydH3SPCXvAnmRDI+gfv yJN4UvI33PSF2EtyqPfRs/EYajsKVmjckOKDxvpd+HknyF/dCvEIXLcRUPeFDw4PXCsY +MGmrU1OUo6W9DmTQOea3clbuNWB1OwVkRAOirLppuDUgWNjQrzf1ixQkeNSIEl4p6RR ix7EKFe+d/aJnJwMMZgtNQSHrlgZPj4Gr4ta79WirtW1hYbGBAR6SkHtDdNwak/Y35HR NxhqYRKflWJqBEbQ++fcFtMZt+LX3Sztr54YMRmo0Tx4VWvaZV8bP//+s1SE7MZ7tFne Tf5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906309; x=1719511109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jPbSDSWVNJkYRt5U6fddE9YLEW5XzX+KySLxZvUgJ0U=; b=cimvZZB5ZvcoeSGtLgv7vOZJSw38F7VfmI4Ku1O8Be2Ce3SR6DjMh/h8U1+pMOTGa+ n97dAXcCezCePb8/n+w0I18R666JnHEV8BtquwW0Pvl5TKwSvS+6A3vqT5hl/iqDStqC RqrXGmnZrbfGVaRUXeusnD4eX1+jPtehjeNmO1gaDe/AHU11wf4Ekrhal/fhoLC0Ju4o ZfSIrFBLgKO419nmuRMDPdQPGF1/481nri/hCxNM6exLU1GQQORxBhFDb8Pv8TX7pOq0 58XpzhZ5THrqcoqXqBvTKyrZQywIAz/ZhmyAaBNV/QefMNn+nGAyAui1jL4+3V3xN3vn +l7w== X-Forwarded-Encrypted: i=1; AJvYcCW+ZcQdIFQLFMZnyf+ZAkEC2NOptANNRDGhbc3LkQNmastnF7AXjTzMZsEnfsKkT4G7CeKuFQDVy/+QkOT8pZpvag/WeYj592+fXIdlbni6yU1moRcG2R/hSRmbZ5FNHL/ujYzP7twr X-Gm-Message-State: AOJu0Yw0z4JtyblKBeNDPxtUyQNuNc+Ivx4LQv4jqwWTAUdg0ioVc9g2 FPmBtZsNX5A3Rsfq9Y8wiaO+z2xEJCKWaSQHzHs7yXZcwkvVMcRFBWXDGYoP/mg= X-Google-Smtp-Source: AGHT+IHvf0bW8VCqpbS7PR3F8xoHNnAblcUThJfvAknOeOXH59R5Hyux42nvZ1qRNcQS9/OO7fDUNA== X-Received: by 2002:a05:6a21:78a3:b0:1b8:6ed5:a89 with SMTP id adf61e73a8af0-1bcbb640cb4mr7628578637.46.1718906308833; Thu, 20 Jun 2024 10:58:28 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6fedf2a74dcsm11326669a12.46.2024.06.20.10.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:28 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Karsten Keil , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Yury Norov , netdev@vger.kernel.org, linux-bluetooth@vger.kernel.org Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 28/40] bluetooth: optimize cmtp_alloc_block_id() Date: Thu, 20 Jun 2024 10:56:51 -0700 Message-ID: <20240620175703.605111-29-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of polling every bit in blockids, use a dedicated find_and_set_bit(), and make the function a simple one-liner. Signed-off-by: Yury Norov --- net/bluetooth/cmtp/core.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c index 90d130588a3e..06732cf2661b 100644 --- a/net/bluetooth/cmtp/core.c +++ b/net/bluetooth/cmtp/core.c @@ -22,6 +22,7 @@ =20 #include =20 +#include #include #include #include @@ -88,15 +89,9 @@ static void __cmtp_copy_session(struct cmtp_session *ses= sion, struct cmtp_connin =20 static inline int cmtp_alloc_block_id(struct cmtp_session *session) { - int i, id =3D -1; + int id =3D find_and_set_bit(&session->blockids, 16); =20 - for (i =3D 0; i < 16; i++) - if (!test_and_set_bit(i, &session->blockids)) { - id =3D i; - break; - } - - return id; + return id < 16 ? id : -1; } =20 static inline void cmtp_free_block_id(struct cmtp_session *session, int id) --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 F15001CD5DB; Thu, 20 Jun 2024 17:58:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906313; cv=none; b=artVaZnoj72LraHMrp77m00V164AejW+fATzN373fYJK9/kUyZ5IEYIlw53vW/N0cqLaIXmbXURGq64AwwzuQGmgWVpp1G1WUcUnqnG1DdMbxY95RZc8M7SZfgr3kiq47XnI2hqLXg0uOuZx+6bDUKXl35t8R2gGISQAE3pA2sE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906313; c=relaxed/simple; bh=yUj0Y+PW1ytJyi+j5TbtjzOTkmnNG3+T5JTavbIkNlI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o0VUtlM5vfAWz15a77QYeZntFp1dmrQeK2FsNntMr4JYS3ZSbFOLzQ/Jz3ayTVPfNiqt9vzABkXGpI1QrwFSnSwEPoqgE0TEhRh91sPXTkD1biOUQgk+soeBXPiSFIErLXAe1QH05Z3fQb9JNjoEP0Z8L8Zb9BlHFlYYJnWsN6Y= 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=UodKF5VX; arc=none smtp.client-ip=209.85.216.49 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UodKF5VX" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2c80657e4a3so397726a91.0; Thu, 20 Jun 2024 10:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906311; x=1719511111; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W4ZNVeHwDlQoCLSBSWGAz09EiaWGr7H7R1MAc+9TBMI=; b=UodKF5VXGDYf+97aUtqqtVv+qRYvkgHw1FgT6MpVk1RmNNj98QJEpBra0u5mkuaMxy WYF9rEo2ARMuTOyLxpzi26OkRT7fL8mV+gfs6RMjzyJ8Rb2q8rFC6V+Yz8xhkeCBeaFr H4jyP9xncoXC9onCxcsmt+3C/X5NAYLG4E8Q//vXIVSMR378V8F/GdwAYKtgPtmv3GuW WkTJ4rgRy88q/AOltw9xpIIuYFa1sjGfMdbm8By8knWXfEP/3XqKApoJHii1Zwsbc6pF 2eFtvcStKDT2CN5eUF3QwCiBiEJl0sywVfRCNHpp0HwgMVZ07xVENhzkgT7pOO4ppac6 ENkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906311; x=1719511111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W4ZNVeHwDlQoCLSBSWGAz09EiaWGr7H7R1MAc+9TBMI=; b=EuYQHgsE2Tn6sW2eWbpC3ZOVYKlNsdNz30PavFXQ9/aIh73X9GwV5Jk4g8MTjPlfN2 PwQneYZP345JuoDHVXpyThI1O8GwMDAOGNdM0j/1cZB4zyo+DohZ4BiQYx5ReUYt/NiB asslckQEn+0MIIfU0Trfzv5XJHQxClTciLbmpDrp+xO2315SdLWUFDwYRLOcjUi+o+aC DBc8ApkjOGnBSm3ejydozXzxfxYAVbyn+c9n/aWIZWVL+8sbRR5tIP68LmwSH0/KDSGI 3kh3jtX9EMllB0GfrFx59EuAP5fwRYpwcjRzIuIcJa+4118KqQqrLN+qKQal0H4yN1Jt Owcg== X-Forwarded-Encrypted: i=1; AJvYcCW5kFNHRYJ96W3ehttdbw4jVbob1HUSXPrnxLA8PUbOkP/DoLlUb9tKQsw0BofkldcXfjqo2psyesvxKWJ4SpJdn+Z3nwNUaX/T5Ni/kTW/fsN+RjhPuQCynBVF1HHplE93hg== X-Gm-Message-State: AOJu0YzfTiMcBQujzq4Fw6QLYJ5mxj4DuFdkbgnSQ5hXQrStKihRPES4 kqlJxp8CAQNbSCAxs6r1E+dq4A4NZelVTZi66p3P6PCC23TAXQalW9W8OZykUfc= X-Google-Smtp-Source: AGHT+IGQvEz1XDyV8hqESSgXyRr9H2vNsDwapE+wi9Cj5ayf2ki62AI5CWw/I1Sfogv5UmABjnUlEw== X-Received: by 2002:a17:90b:3688:b0:2c4:e000:f811 with SMTP id 98e67ed59e1d1-2c7b5d98300mr5635707a91.49.1718906311353; Thu, 20 Jun 2024 10:58:31 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e58d3f93sm1998031a91.45.2024.06.20.10.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:31 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Karsten Graul , Wenjia Zhang , Jan Karcher , "D. Wythe" , Tony Lu , Wen Gu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-s390@vger.kernel.org, netdev@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov , Alexandra Winter Subject: [PATCH v4 29/40] net: smc: optimize smc_wr_tx_get_free_slot_index() Date: Thu, 20 Jun 2024 10:56:52 -0700 Message-ID: <20240620175703.605111-30-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify the function by using find_and_set_bit() and make it a simple almost one-liner. While here, drop explicit initialization of *idx, because it's already initialized by the caller in case of ENOLINK, or set properly with ->wr_tx_mask, if nothing is found, in case of EBUSY. CC: Tony Lu Signed-off-by: Yury Norov Reviewed-by: Alexandra Winter Reviewed-by: Wen Gu --- net/smc/smc_wr.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c index 0021065a600a..941c2434a021 100644 --- a/net/smc/smc_wr.c +++ b/net/smc/smc_wr.c @@ -23,6 +23,7 @@ */ =20 #include +#include #include #include #include @@ -170,15 +171,11 @@ void smc_wr_tx_cq_handler(struct ib_cq *ib_cq, void *= cq_context) =20 static inline int smc_wr_tx_get_free_slot_index(struct smc_link *link, u32= *idx) { - *idx =3D link->wr_tx_cnt; if (!smc_link_sendable(link)) return -ENOLINK; - for_each_clear_bit(*idx, link->wr_tx_mask, link->wr_tx_cnt) { - if (!test_and_set_bit(*idx, link->wr_tx_mask)) - return 0; - } - *idx =3D link->wr_tx_cnt; - return -EBUSY; + + *idx =3D find_and_set_bit(link->wr_tx_mask, link->wr_tx_cnt); + return *idx < link->wr_tx_cnt ? 0 : -EBUSY; } =20 /** --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 ABB0D1CE09E; Thu, 20 Jun 2024 17:58:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906316; cv=none; b=OpISsrcwPPhvW8PNlBvF/qQWwTFFKj5IF1XLeXZKwkcKF41KY0cChcTEbbf7cZAF4orbMTIi6HeVoLVxGpa/IZVKXU468mRqiQOCt0shoSZwBE8PF9XcqvUEuOsMt/qt/8QINybDTbJMoWnOZD1sWY2gxm0+uKPD32zvq/Gm2sE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906316; c=relaxed/simple; bh=RuFo+rj7IH+rMOczKL4ih3dsBtps5oyKpsIg/YRyQz0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bd5g8LIHnIEtqxyYpMcSZ9oOu0jgan7gZzVANzuvtN5phuc7lmkh6YyAzCgANUfOikZBx2jvYDyObG86LPF+f6Zcnuj2/WA4xIIX38kuo45n51D9TQPCCpKRLh9YH2G2AtdSbEeYOTo6P2cFdk88PMHs4THq9WnEKdSIxgz/WuQ= 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=bUnQp5nq; arc=none smtp.client-ip=209.85.210.175 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bUnQp5nq" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-7062bf6d9a1so953086b3a.1; Thu, 20 Jun 2024 10:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906314; x=1719511114; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FW85PghmUwc3BgHXRaYJ+DzXpmwYGv3Aew2YdRltNsw=; b=bUnQp5nqJIWUAOvQEkxHkXrxZC1VmKvFsJT5jnzaDAuwKWqNVV7zXc4xyZgPovG15R 5dKtdAHRMW6XU1BZPAIZoDvDDKgwoA6mebkKystDnPygppmxvMqr5WhQl51mjc+sNEs0 htJ2eRoIOq8hYdY3lu921s5D+VByM1Gwkxs9IYOqyGZhVQ8fOWVFgVmt0bp5k+r44+fT w2XGl/S0owQoSfCnTRbOUok/o0AIeoHF0iHsJ7He4150hKky6SmOh0ZoHL7uwN/vgbkh JPQTmf3dWak9WkMTOqFBF35oSKdrdFJP75TIWzRyb1/z2WVhiZ4aZWZ19hYJppGLs2z+ JtcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906314; x=1719511114; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FW85PghmUwc3BgHXRaYJ+DzXpmwYGv3Aew2YdRltNsw=; b=AyBnD3IIozEEDeTCiaFSVcfGGo39IkO8qc6paxkNYCPTorkoaY4ePT1iWT84TUrSef b/KbSPxM/IYb//UosSdBcujoRCeEeTlZgBvdUiMFTF0O6rJpfYoNQzBcxEbBIicTx84W bhLo1xEuaL+OepF067/2H7j5bc8G71mQszdZhZKv3HoGAVmD2ICo3/P/Z1uqxWIbyUuo YQq455jj3wk8cmlw5aVjz1pIdTZPP0c8VK87jDyKyiymQTQKOMAEuKwEHi+qXDmcLJoQ 5oIMsSsakKO1rgLAuB0Ajq0M0si2/h3FOdhjJVfeHfjlSMMbH/9cdF8qQIsfB2lyH9vH FsYg== X-Forwarded-Encrypted: i=1; AJvYcCVcnxvPMCr7GrSD8awRZNLT3Z5EG4Q5ZVkJnj9zDi/6DMJp6nvH49nwmXAXv36I29deNxTYCQ3h7PyQ6aB5q2LvQMZUbJ/qAXqBBuk= X-Gm-Message-State: AOJu0YzFYtdbm4HwoiQM1eoXRdnjI3Vhw7ZngY/1S/oqKCT01Giox8Ep ffV78eoBwTAefmtWMZ1WI6W34k6o++NEUMiwJb0q88QSwQm7AfVwayoTaUzWeiM= X-Google-Smtp-Source: AGHT+IEoH3Qng23SGIOniQLh/mfoKH0d8yH2qow3ztjr66B8CysNLSQkypEK4r+/80Kz1cmwQvxiZw== X-Received: by 2002:a05:6a20:7291:b0:1b5:cf26:ecfd with SMTP id adf61e73a8af0-1bcbb426fb3mr7450803637.24.1718906314118; Thu, 20 Jun 2024 10:58:34 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6fee2d34cc2sm11211938a12.64.2024.06.20.10.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:33 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Jaroslav Kysela , Takashi Iwai , Daniel Mack , Cezary Rojewski , Kai Vehmanen , Yury Norov , Kees Cook , linux-sound@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov , Takashi Iwai Subject: [PATCH v4 30/40] ALSA: use atomic find_bit() functions where applicable Date: Thu, 20 Jun 2024 10:56:53 -0700 Message-ID: <20240620175703.605111-31-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ALSA code tests each bit in bitmaps in a for-loop. Switch it to using dedicated atomic find_bit() API. Signed-off-by: Yury Norov Acked-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 8 ++++---- sound/usb/caiaq/audio.c | 14 ++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 325e8f0b99a8..7201afa82990 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -7,6 +7,7 @@ =20 #include #include +#include #include #include #include @@ -3263,10 +3264,9 @@ static int get_empty_pcm_device(struct hda_bus *bus,= unsigned int type) =20 #ifdef CONFIG_SND_DYNAMIC_MINORS /* non-fixed slots starting from 10 */ - for (i =3D 10; i < 32; i++) { - if (!test_and_set_bit(i, bus->pcm_dev_bits)) - return i; - } + i =3D find_and_set_next_bit(bus->pcm_dev_bits, 32, 10); + if (i < 32) + return i; #endif =20 dev_warn(bus->card->dev, "Too many %s devices\n", diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c index 4981753652a7..93ecd5cfcb7d 100644 --- a/sound/usb/caiaq/audio.c +++ b/sound/usb/caiaq/audio.c @@ -4,6 +4,7 @@ */ =20 #include +#include #include #include #include @@ -610,7 +611,7 @@ static void read_completed(struct urb *urb) struct snd_usb_caiaq_cb_info *info =3D urb->context; struct snd_usb_caiaqdev *cdev; struct device *dev; - struct urb *out =3D NULL; + struct urb *out; int i, frame, len, send_it =3D 0, outframe =3D 0; unsigned long flags; size_t offset =3D 0; @@ -625,17 +626,14 @@ static void read_completed(struct urb *urb) return; =20 /* find an unused output urb that is unused */ - for (i =3D 0; i < N_URBS; i++) - if (test_and_set_bit(i, &cdev->outurb_active_mask) =3D=3D 0) { - out =3D cdev->data_urbs_out[i]; - break; - } - - if (!out) { + i =3D find_and_set_bit(&cdev->outurb_active_mask, N_URBS); + if (i >=3D N_URBS) { dev_err(dev, "Unable to find an output urb to use\n"); goto requeue; } =20 + out =3D cdev->data_urbs_out[i]; + /* read the recently received packet and send back one which has * the same layout */ for (frame =3D 0; frame < FRAMES_PER_URB; frame++) { --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 CB3DD1CE0AC for ; Thu, 20 Jun 2024 17:58:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906319; cv=none; b=cESe2ySE4on080E9dqwUVfUyvOkeUPm0+5LNoc49s+HdOH7NjrlOeGdBO0BrS/JY6uoIsObiodz96U+PgYPE6DM04l+ii3e+pYyPfZ59rToNyat17Hyab23o1PsnPb71NeITjKVm+AAnYMue8m0lJcKW1CYuUCxsqZgnKMY6t1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906319; c=relaxed/simple; bh=qDgzpvKMzB33HuJtkLcNWCvXNPeJ2JXa19MfPLKu4GA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=STvJMXMFfzrcueApUKgvAs5yp/n6nsxRK+rQwX0cIGCEnQl+0fJisEorr6eGQ2j0RcdNEuAgijhK4e76mnU9ApGfNF9BYHTjloUrjALSjuTTRmmayv2szUqvTqWJgPGL62TmPoXjHH5veJIetxwg395ZTBS0dWehOp4i+ws2sMg= 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=dMz0MKJW; arc=none smtp.client-ip=209.85.210.169 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dMz0MKJW" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70623ec42c2so958526b3a.0 for ; Thu, 20 Jun 2024 10:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906317; x=1719511117; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5UeGLEmgFCwB7SfnnVFN7CY07bSxQRD2zzo6uHvh98Y=; b=dMz0MKJWC7pw+IARzAWJI7MjHg7MRSha1zXy7e8SiKNE7EOpaDtudJZL0r6PbbhuX4 TAyYj3KKCRpPRx4fBmrQOucfkvcygV/WTROxo3gc2wl4LisRChz9BJPS1Pb43WOdqsTu roRATb4kV5pB0pt9LbVR2fZZqNMTG9eIxIfQyL/uPALE1fBcQ5kgGSfxEyrN2RuQLYSc UOqu+M9ZTCu4VjDzZFpJNhHfMgib2sU+7djzBTNs8goXhmshTQ7aqkfUGw2TX0UddDMQ Wm0K0Hm4+md++uEuXD+aPiAnCI7vWwgwGKL9IcRjyeKCw4kY7TYS/2vnc5L/nnUEH6pt 4tUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906317; x=1719511117; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5UeGLEmgFCwB7SfnnVFN7CY07bSxQRD2zzo6uHvh98Y=; b=hBNenJC7NPfcEci5YRzR01jEJ+G6fDZ/z+Z66K7EhpUD/7qv96w3Gj7PIH20DxTYgU aLbTBP5MYGtBpcU13XxUeGbaOxWL7e+6KvPN0g6yV4FvKUjSxMsHT8SX/PJneAhXASs1 cL+8n5PtvRUuuv/MSwkdsDwR++YSE8JnXjopVeF81UeUgC1XW0qmeD6oruu+QYInrscc OnLKM9VEKc2Xpj/9dMM3hipHeG9fw6cgbtpyCXYKSBmSr5VxeJ6K0RFYkMrAPyy7yMkB i9MSSqzJ7YjAgfMxjasD4WwX4NG1PJkkBmMcsLbv0M7LmmrGojGCbTQA62QRVONufGlJ 3f8A== X-Gm-Message-State: AOJu0YyijWHryUfeyLg88spLPVjsW52vmSuP15E9mpptkb4eGb7XQgBk KSjCJU12V1W+kPkTIXbmHOjVk2H8CaP8Ndmy5IHnM49wdv90k0I/wyKHUQSkg+s= X-Google-Smtp-Source: AGHT+IF2582ElUzYGc8sFWyeezew6KYJJtZelHSbtcwZADymS9B/iS/gSLgFlcKPRR5Z3cyEALz5Xw== X-Received: by 2002:a05:6a20:a51b:b0:1ac:3b81:2b5a with SMTP id adf61e73a8af0-1bcba15b47bmr7898847637.8.1718906317030; Thu, 20 Jun 2024 10:58:37 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705e5fbe103sm9526573b3a.72.2024.06.20.10.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:36 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Geert Uytterhoeven , Hugh Dickins , Andrew Morton , Yury Norov , linux-m68k@lists.linux-m68k.org Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov , Greg Ungerer Subject: [PATCH v4 31/40] m68k: optimize get_mmu_context() Date: Thu, 20 Jun 2024 10:56:54 -0700 Message-ID: <20240620175703.605111-32-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" get_mmu_context() opencodes atomic find_and_set_bit_wrap(). Simplify it by using find_and_set_bit_wrap(). CC: Geert Uytterhoeven Signed-off-by: Yury Norov Acked-by: Greg Ungerer --- arch/m68k/include/asm/mmu_context.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/m68k/include/asm/mmu_context.h b/arch/m68k/include/asm/mm= u_context.h index 141bbdfad960..2e61063aa621 100644 --- a/arch/m68k/include/asm/mmu_context.h +++ b/arch/m68k/include/asm/mmu_context.h @@ -3,6 +3,7 @@ #define __M68K_MMU_CONTEXT_H =20 #include +#include #include =20 #ifdef CONFIG_MMU @@ -35,12 +36,11 @@ static inline void get_mmu_context(struct mm_struct *mm) atomic_inc(&nr_free_contexts); steal_context(); } - ctx =3D next_mmu_context; - while (test_and_set_bit(ctx, context_map)) { - ctx =3D find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx); - if (ctx > LAST_CONTEXT) - ctx =3D 0; - } + + do { + ctx =3D find_and_set_bit_wrap(context_map, LAST_CONTEXT + 1, next_mmu_co= ntext); + } while (ctx > LAST_CONTEXT); + next_mmu_context =3D (ctx + 1) & LAST_CONTEXT; mm->context =3D ctx; context_mm[ctx] =3D mm; --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 4839D1CE9FA for ; Thu, 20 Jun 2024 17:58:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906321; cv=none; b=XUrjSv16Sm3JB93wEhI1wqrEw1I9aqm4DbN5rL16MYIdqof968ONn8C81Z634HCSAIXzRzcWxa3jXD6H1YJAY9sQAgAgqPebjXz8WPhPEc6ubGV01Grd3h9yQ8dfcx8aGKBdK1q8YEsQA5lFuyq9Ww2hFD2Q59900dRz0o/LHeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906321; c=relaxed/simple; bh=/JBXGQMRau5wgpYf7SSlSW4t8HpQ8h/PbonGYBClZP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m0OGZ9WE/rlxXbTPVVT14qytF12Huvse9IYLgrv5LyK/MdNzLQCAw2vRoygtYcFQo7TpNr8QQYjkt1BWTkZwLnG68sryP0+3hih/BmjBtmt47ouuOYWKpEsxEJ3jxpEBMG/srn3jOBx0CdUJUJUdQrRsGbo6yuzFBfdhVoamAPE= 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=cxlWiXVl; arc=none smtp.client-ip=209.85.210.175 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cxlWiXVl" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-70436048c25so1202320b3a.0 for ; Thu, 20 Jun 2024 10:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906319; x=1719511119; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PBsNta2Mqn95L/6yjm5XyoZC72SdhB72JzDL0b/aOFc=; b=cxlWiXVl+b0GQO4flulpwxN/2DqwpsWSznsHrxlEojUeu4VTH2oQBPTh6e5v3QHYJA /ibB4sR+JbFuh+nIVBdqejedGQI6RpLnDZ7gZQzda2uQcsbr85ZfviT1iCqM6bgtxoCZ ZtCLot0n4z0jIrpRV5trS4ryly87Fns2osxjM+341PafOCElsnnQGrJkV1EbMVQuf9+Q 39nbplWiCCPT7Fo3nrnahY2H72enaTA9qCqoG+B0q2z94uEdYcZY41+gYsl9KzJk7edU 3T++n7msQ5dnQXaTPR0oS4o/3rza/RVNUrQxbob66ex3YD+9r/0yAG3+XPbO9x1mJEZL n5sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906319; x=1719511119; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PBsNta2Mqn95L/6yjm5XyoZC72SdhB72JzDL0b/aOFc=; b=uSfM2lkj5BAU9AckFwo16hBS3ilnEmeYhpBqZ/P2aVJXROL5+7KWzILbaClllTc/od tsuwwfePXTipcBLx2LAE8OyqydWFkE2CRLyO5QpFlB4Kd2zi27NnPImunIDUFpfrs1z4 JS6NkhVOe32Meev6V52ulnHn3ebW5LTglHR8lxYuRPNGV3mrvqu/idXWIVMA/LodYJur 3GvhEmK2qKYV/SKbXxVueCWv7BrCGGpALdSdY81+dP1aWr+tJNOP7XG0l8uWqaUx8tPy oEB2Cl+EluB08Y29Dd0aGIRBYrgWCegXOAYXdRYMtdQQuTe0cA51V2HzBPmBQt69aNyJ 7PmA== X-Gm-Message-State: AOJu0YxhyU9DJPFbwTYCQ9z17KwEg4Z6vMt6fmlalf2Tw5dxy/sY2uvz PIJHO64BNxO7KpsEAM538fpX0H4YAQ4UFSIq98awT1Pw/YvwGP58PnQPLo5cSy8= X-Google-Smtp-Source: AGHT+IEZAZcqG95Z4B86VBJvTYjBRxBlyXTqG2gWLuzcon07F6oQ2VyYd3V1qJeznfngffLajTsd/Q== X-Received: by 2002:a05:6a20:3399:b0:1b5:5ee0:378a with SMTP id adf61e73a8af0-1bcbb5a3936mr5878131637.36.1718906319680; Thu, 20 Jun 2024 10:58:39 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-70f885e9dd3sm3972155a12.79.2024.06.20.10.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:39 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Michal Simek , Yury Norov Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 32/40] microblaze: optimize get_mmu_context() Date: Thu, 20 Jun 2024 10:56:55 -0700 Message-ID: <20240620175703.605111-33-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify get_mmu_context() by using find_and_set_bit_wrap(). Signed-off-by: Yury Norov --- arch/microblaze/include/asm/mmu_context_mm.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/microblaze/include/asm/mmu_context_mm.h b/arch/microblaze= /include/asm/mmu_context_mm.h index c2c77f708455..d4d1e80b3b66 100644 --- a/arch/microblaze/include/asm/mmu_context_mm.h +++ b/arch/microblaze/include/asm/mmu_context_mm.h @@ -9,6 +9,7 @@ #define _ASM_MICROBLAZE_MMU_CONTEXT_H =20 #include +#include #include #include =20 @@ -82,12 +83,11 @@ static inline void get_mmu_context(struct mm_struct *mm) return; while (atomic_dec_if_positive(&nr_free_contexts) < 0) steal_context(); - ctx =3D next_mmu_context; - while (test_and_set_bit(ctx, context_map)) { - ctx =3D find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx); - if (ctx > LAST_CONTEXT) - ctx =3D 0; - } + + do { + ctx =3D find_and_set_bit_wrap(context_map, LAST_CONTEXT + 1, next_mmu_co= ntext); + } while (ctx > LAST_CONTEXT); + next_mmu_context =3D (ctx + 1) & LAST_CONTEXT; mm->context =3D ctx; context_mm[ctx] =3D mm; --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 1504B1CEA13; Thu, 20 Jun 2024 17:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906324; cv=none; b=AnfecTO0SV4/TkrTgTXzTsdKExcqxnXMvYNnj8t7eDaJ0HaqCY5QJkvMJDPAheNGeIlVnvOnlgCrXw864uVnx9wMegFXB06L88dvH5Fkirxm66pewb9wri1inGp4XA+1Z4zrH3w98gGll1q0+H0M1YgurWrrP6zE4fhXX07GgMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906324; c=relaxed/simple; bh=EE6kuxbo5QGE7L7+DMLqP/XTIbnT3wTeY7rcKK6IYpw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iCylmWhbvG8thQ5nRFC+Cn19sK4wQJ8F8fZKPRmleV11UO0Q2dY9OvRJwgGAFtavGJDS9bh8ahgkOkSVhDii5ycnixvsOZ4SdjEFQeIeZMp6LVhCdGNrQIkVQSnrvGFt42yYkUz5rgBoT3aoNhIipZLwiQUPvYdcspX7QMgPkSg= 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=Y9UVvmWs; arc=none smtp.client-ip=209.85.214.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y9UVvmWs" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1f9d9b57b90so5187435ad.0; Thu, 20 Jun 2024 10:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906322; x=1719511122; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/RrpOxxSwU6dhPGdg1a14uJwTPLPcla8GvMqVb4mdfc=; b=Y9UVvmWsyFhQcamnLC5CRk43XiZfPCq+QpeAsMtYOTLtQi99vMODJaos7uHq+qr8Jb 3K58mOxQADlUh1enWELoS7tW8pYu5BFheBdFgYnQi0UP7UCiV9bSBYiJEFjzAYQrcAre AQzz2bmG3GdxiDn5YmwJXRBA1sf+6lO35Y855Q18+sqpsM6G2yHliSVETkgY5XTZJ24v bWLPkl4g39mp3PveDZHsUkh8nP2bnp5wxTAamT6/WES5sDAoApG0HoZBtJxnvTP9Uk+4 ByoYXraPnlv5gWOY92AfYxavEirl2TpVGM5wR5RCQW3EDx5Q3YZYwpEhBRIlo+oSQK5X qLtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906322; x=1719511122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/RrpOxxSwU6dhPGdg1a14uJwTPLPcla8GvMqVb4mdfc=; b=D4BtWZXY4mnYlNx5iWYbMLjGv+PclqdCVoqhw1ljmnlULfDYsrtKAlDao23LFyOB04 VrFTlHmkJ9gS201/DRnvJZ0y/sWZ6ZPLeAXITieX090H7T4OxTTNCP7MCdrKYly0UhVP uECcYBTm+9huKtaN6izEGA5p1VvjeknmMWR3X/QZWNWzwgKaQcPVb99zxHpbUp0M8lX8 C78kJaAeFi9BeevLbMt1lrvCu32L7qgaKFxVvcGFBXittpZ8N6gYvTVW3iyZAXEAMMwF Ts+VKUEN1k/63Tm5OfuV49Mb/QsGhuymGWEC90LrJt4zNphE4Nke3bzr38NY+q8pYnoR Ja1w== X-Forwarded-Encrypted: i=1; AJvYcCUmvebutdO1GGMCJRwKrY2145XcywipD10nYGCO/iuikbq9MHjUm5HRSeBbPXDeS8kQwYF8Md+VIb0gS5w/LZ8PLvq/uL3bj88= X-Gm-Message-State: AOJu0YyIpvbtcyP5KOdJAkTyRInvgC2cCBZcEKSM5SDp7qT6qg2+YRrc xSX5DrxMas7jkWj4Gb0GkNmpQ6fZ+D7wc7jwCruOiPpNon4I7Dt0vU0hcX9x4Zg= X-Google-Smtp-Source: AGHT+IFwR4KUsUwz3DVzTLlDW/Tyw/BDO/CoRLBHVeFWOs1T2umlbZqTuQWZCRaEx6Uoyiqs/GQXHg== X-Received: by 2002:a17:902:db05:b0:1f6:e11e:640e with SMTP id d9443c01a7336-1f9aa3b07c1mr68642755ad.4.1718906322284; Thu, 20 Jun 2024 10:58:42 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f98841f6bfsm61533625ad.195.2024.06.20.10.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:41 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Geert Uytterhoeven , Yury Norov , linux-sh@vger.kernel.org Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 33/40] sh: mach-x3proto: optimize ilsel_enable() Date: Thu, 20 Jun 2024 10:56:56 -0700 Message-ID: <20240620175703.605111-34-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify ilsel_enable() by using find_and_set_bit(). Geert also pointed the bug in the old implementation: I don't think the old code worked as intended: the first time no free bit is found, bit would have been ILSEL_LEVELS, and test_and_set_bit() would have returned false, thus terminating the loop, and continuing with an out-of-range bit value? Hence to work correctly, bit ILSEL_LEVELS of ilsel_level_map should have been initialized to one? Or am I missing something? The new code does not have that issue. CC: John Paul Adrian Glaubitz Signed-off-by: Yury Norov Reviewed-by: Geert Uytterhoeven --- arch/sh/boards/mach-x3proto/ilsel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/sh/boards/mach-x3proto/ilsel.c b/arch/sh/boards/mach-x3pr= oto/ilsel.c index f0d5eb41521a..35b585e154f0 100644 --- a/arch/sh/boards/mach-x3proto/ilsel.c +++ b/arch/sh/boards/mach-x3proto/ilsel.c @@ -8,6 +8,7 @@ */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 +#include #include #include #include @@ -99,8 +100,8 @@ int ilsel_enable(ilsel_source_t set) } =20 do { - bit =3D find_first_zero_bit(&ilsel_level_map, ILSEL_LEVELS); - } while (test_and_set_bit(bit, &ilsel_level_map)); + bit =3D find_and_set_bit(&ilsel_level_map, ILSEL_LEVELS); + } while (bit >=3D ILSEL_LEVELS); =20 __ilsel_enable(set, bit); =20 --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 B285A1CF3CC; Thu, 20 Jun 2024 17:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906327; cv=none; b=SqfLvwd/P2sSBzAw6ulV3hFcCAjeNN3n85GxfDjFfM6ERNTyWdcnN26XNq/fvSnPpEvN4KKkgJE+IbB0FssIl56Jz79VdDBOJeG6H5gYgfYUwFXQZNFjugDkG1KPp5kikKKeGMummwBKIWEc/U8rnjiFJbxUnWiNlgVaj+x2KwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906327; c=relaxed/simple; bh=9VKEeJ2Bp6V9P0lgAXpETIbdOrUySYRDJ0KU4G9h1Ms=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mMEDoiS61B9SMww9uI4dCQmbUvVoBLJ3H9fydcocjQGByQkcynC9miMoqyYlwI8fNuheYgpVb5F4LTjivNCtnclGkFfccFN82iRImotxzNeyKtJ7t0y9XcyBByzqw3+pPNWV03Wv/5OZMHAopg5Cw1GOYlJv31kysRG8Nib2yuY= 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=C6JVWD60; arc=none smtp.client-ip=209.85.210.182 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C6JVWD60" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-70635466708so1164614b3a.1; Thu, 20 Jun 2024 10:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906325; x=1719511125; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QDKUwH++JfbwJqOinFdI5jqclRMQl0q8xEbU2EXAI2M=; b=C6JVWD601Os/HscPNlyGaztA/eeiPlWbKxPoioONwFNHRIQNVIRjgU+JPzZKMx/NIc e9l75IKK3kQOFedyktCQMOzzfT00/2Bh3X5mZOFIBT0trs9caJ7Qo2dCnJRpZDUD3Mtn damjcwNbHMdF9JCcLK7VvUu+s8jQde+sy4h++kpKU5Gabj1Y6Z4DCfbIIcXTHCvLuvf8 aycleffGJWTZsGLI/OU7zXmFQPOtnK5Mtr3pxockDvD5W3ow8kb/Opy/WRfYdFpi1FeO QzRPKbU/FFsJdpWUGbNVrSl33T1cn2niE6yAzbDuuxVjSvgn0LjSSF8ceFrA7TTjKZgD oFJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906325; x=1719511125; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QDKUwH++JfbwJqOinFdI5jqclRMQl0q8xEbU2EXAI2M=; b=wTU8pZsEVOfTac+/+5jZXGLh5QIziiQaRN/zVVBC7K8Xhwa0jLvCDY3yyIVC2JKBqD TZaapBnsKmBZErfOO8SbZ3Ia+IpVjFUiQx5gOQvz/nkcx/Edbq647S7skBNQYupCMJrF Ypb7dHtk0B7QLcZkKCpowdM/cZ4kwLZ9StE1/K/PwS8BHk7wB7t/rOyr2sestfugNVCo lJgpiYetz+z/Cg7lqGF1fWwh/4PbBj8Sb0m/va9l2HwcnmV8fv/VgNNkEDqGoQxyYoBb /777S6gGthHYmHjdciPNrgCR9o5qAJbFkA0driN8JVFX5/R4H00b8bMdhQTwNKfTYZpk q8HA== X-Forwarded-Encrypted: i=1; AJvYcCWMnGyDL4asTQ5fSxv3K3omzlqNMICi9O3bp0uwu6cT+ne6DQmcCrMVxiKwmlFLv6vOkmymV8EZDhKv0dgBfGvcYq1kkBcr66JuIA== X-Gm-Message-State: AOJu0YyiXzuQD25xLIZ4xF+jbkJKcnQ15oniseaU2QGhnMD/FWcqXtKR qzP3FpRISsn6xSSuEs4R5qVp0X8v0Hcw3r9rL/tXO2sfK2rdAXYjqx0x9wNbql4= X-Google-Smtp-Source: AGHT+IGQBqThGaLy+ssIXPNfXK0T9Cj9jN1FEARMt7HY6rnbCm2HHwjb8BD1YqPuoPyBGgsGk3h3kw== X-Received: by 2002:a05:6a00:124f:b0:706:3ba3:a192 with SMTP id d2e1a72fcca58-7063ba3a6c5mr4518454b3a.22.1718906324947; Thu, 20 Jun 2024 10:58:44 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705cc920a4bsm12630837b3a.21.2024.06.20.10.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:44 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Thomas Bogendoerfer , Yury Norov , Florian Fainelli , linux-mips@vger.kernel.org Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 34/40] MIPS: sgi-ip27: optimize alloc_level() Date: Thu, 20 Jun 2024 10:56:57 -0700 Message-ID: <20240620175703.605111-35-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify alloc_level by using a dedicated atomic find() API, and make it a nice one-liner wrappers. Signed-off-by: Yury Norov --- arch/mips/sgi-ip27/ip27-irq.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/arch/mips/sgi-ip27/ip27-irq.c b/arch/mips/sgi-ip27/ip27-irq.c index 00e63e9ef61d..fc29252860a3 100644 --- a/arch/mips/sgi-ip27/ip27-irq.c +++ b/arch/mips/sgi-ip27/ip27-irq.c @@ -13,6 +13,7 @@ #include #include #include +#include #include =20 #include @@ -36,17 +37,9 @@ static DEFINE_PER_CPU(unsigned long [2], irq_enable_mask= ); =20 static inline int alloc_level(void) { - int level; + int level =3D find_and_set_bit(hub_irq_map, IP27_HUB_IRQ_COUNT); =20 -again: - level =3D find_first_zero_bit(hub_irq_map, IP27_HUB_IRQ_COUNT); - if (level >=3D IP27_HUB_IRQ_COUNT) - return -ENOSPC; - - if (test_and_set_bit(level, hub_irq_map)) - goto again; - - return level; + return level < IP27_HUB_IRQ_COUNT ? level : -ENOSPC; } =20 static void enable_hub_irq(struct irq_data *d) --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 5E5D11CF3D8; Thu, 20 Jun 2024 17:58:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906329; cv=none; b=ZDzOLuzfkUFAttgGSLLJQKyuyDt+uW7CKxrnaC8zOZfTBW5sff/IlYyl4bbSoRbl1ispDVCpGOn4kAJYoWvMkXJj0uqV49ejapInO7xC0PkN0RwEJsEZ90j5eR/VLZwkrYrhO9pOZm32EXtoZu8rj3qEI6u7SAtpSIMTzHidfx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906329; c=relaxed/simple; bh=7jDPXKVK1Gn1Q5IAcYSYnvMH/NIfDHCFFGZUZqyUDvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FgR++Sft1L01yyCJJ8hWv9sgsMeXIUONHZ2DpT3yzj1B0RPt6puiAGv9QOqdyNKkQhXx5Aok8/vZM9uI1LPCh1TlU3j5eTlSWnFPydj5a5DgDyPEufjybHsF0Iz9dlg8jQoDgB5hXKc0b+1Ijvi0tA7HLfnlqov2RPK/korSQxI= 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=Q21tjXbx; arc=none smtp.client-ip=209.85.210.174 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q21tjXbx" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7064afd7011so434354b3a.1; Thu, 20 Jun 2024 10:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906328; x=1719511128; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/4Ir80xSiYngcpPXBHnGnxBUcMhzo8e4IRrRAzmZKk0=; b=Q21tjXbx0tcwXHB9x+zYv1Ac0/ZlxInXWoAhn7Wn3y9V3FxLbAZ9NqitElD/XFlTSY wjgOMw8LRPQFskxwgdFcowj5rqXPGPRaR8oXxJdozPB+iI1/svSSn7D9cuG2vYibgAxW 0zVER3Zar73O7KQ3iKqjQfxJnL+fvZh5kCan3YY5+Ah211vXJx4g4kYCjtd7tO8TZ1ja EZaDA0jGJOvVFr8sdHtfLe/sfATG/oWp8PS9+ARyci7zu2e6cJyx7+JnqjayhJgp65dn VWeC/va/vrF0UGVpc8KQ5eYWEKtsAnlra8pykl3NPbeSsTAyKDRhqfGoCpf516ioRRvX EwSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906328; x=1719511128; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/4Ir80xSiYngcpPXBHnGnxBUcMhzo8e4IRrRAzmZKk0=; b=nbyMeaOEUfyPibfgAMmvrwcgeuLUr4aMKZdEMkIx3+uUT/KlJb91I0xVyt2JJjPLJG wfgDxO+FE2Z0NpfpdtgFnieeEWSzxq07PC7/guUTXdpkdnDKhFYXgmknxO0l2ZMepnMX 03nq9t0S/zZNM8fK6DPnQwwq2yolyt8snGK5fTFxxRO8VYVDlxQDLLxNkTGJWK/5QFnA obbvzip4t8NMLYuWWmL3Xvhp6dILiRUZub0OwFlkbjtg3mDxL35rwFYtTHWEmMriCstr 6tq9CTD2QutClHIXa5KnmesUrBwdy+lqDkFJqlhpUcPH8Utd/3VJs4mgf8ahz79mWD0Q iEqA== X-Forwarded-Encrypted: i=1; AJvYcCWIua7lAosSW1gr8Tl2RVh079B6uujRTOaLKlxiV3MAFVVsBBKEAQQBN1YHY3YDVgVKK+4TLOopv/kcljasGzafO7uZbpwrPQQPoLXx1IaZ1A== X-Gm-Message-State: AOJu0YzSCgxgpSONWqm8tKP2OfriBLnBXvzp912oB3w/dg9URNyvqsz9 4GUTy3UVxBHxH/epC12/pWu6zkzgHGcW3R0Xtx4xNvLJH8aepIdTrxdqJBQtLRs= X-Google-Smtp-Source: AGHT+IGeZnFwtFK9/vOKkpOdDMAbvJAuNbjW/POTw87WB/bESSwhGo/tx9inSGzZgD+dxEVltZsAkw== X-Received: by 2002:a62:b50e:0:b0:706:3454:7d8b with SMTP id d2e1a72fcca58-70634547fd4mr4788083b3a.16.1718906327659; Thu, 20 Jun 2024 10:58:47 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb6c1c7sm12676888b3a.167.2024.06.20.10.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:47 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-perf-users@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 35/40] uprobes: optimize xol_take_insn_slot() Date: Thu, 20 Jun 2024 10:56:58 -0700 Message-ID: <20240620175703.605111-36-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function opencodes atomic find_bit() operation. Switch to using a dedicated function. Signed-off-by: Yury Norov --- kernel/events/uprobes.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 2c83ba776fc7..30654c41f0b2 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -9,6 +9,7 @@ * Copyright (C) 2011-2012 Red Hat, Inc., Peter Zijlstra */ =20 +#include #include #include #include /* read_mapping_page */ @@ -1581,17 +1582,13 @@ static unsigned long xol_take_insn_slot(struct xol_= area *area) unsigned long slot_addr; int slot_nr; =20 - do { - slot_nr =3D find_first_zero_bit(area->bitmap, UINSNS_PER_PAGE); - if (slot_nr < UINSNS_PER_PAGE) { - if (!test_and_set_bit(slot_nr, area->bitmap)) - break; + while (1) { + slot_nr =3D find_and_set_bit(area->bitmap, UINSNS_PER_PAGE); + if (slot_nr < UINSNS_PER_PAGE) + break; =20 - slot_nr =3D UINSNS_PER_PAGE; - continue; - } wait_event(area->wq, (atomic_read(&area->slot_count) < UINSNS_PER_PAGE)); - } while (slot_nr >=3D UINSNS_PER_PAGE); + } =20 slot_addr =3D area->vaddr + (slot_nr * UPROBE_XOL_SLOT_BYTES); atomic_inc(&area->slot_count); --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 F26D11CFD69; Thu, 20 Jun 2024 17:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906332; cv=none; b=PCHk+HB3prAbWetC6+M0qEBEXBEBc5wGh3UalDBabLGluz9hZDl7o3Y3zY1xfvp9sAnUd/7syK73sqj04cJlIp+9IC9IvKIG7dtSSNRu2pNwR69N5Qjji0yD0oa9yIal+wsShLzy81kD9m9TEb4GwdRoFwxzjhDNTuGYVDAvvuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906332; c=relaxed/simple; bh=JtxyDAJmwTseDc70rSPwJFLuifJTU6XLGZKMlZ49AeI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNSZGDggHeuk3mnGyLyMYvlsMcszSW7VpxzLqmzF/lzBpNDLZ9XBThcYytq9JTDMZQystC4+iKSTffT25oEcsMdjs+0emYWh26IpcA7F6L8T8KhVTOt9ALM56Kcwxd8bt9Fli04cucQrOSyiId4RR9YtCIkMknJUxxgmb+qqETM= 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=PGH7yXlF; arc=none smtp.client-ip=209.85.215.169 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PGH7yXlF" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-707040e3017so848802a12.3; Thu, 20 Jun 2024 10:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906330; x=1719511130; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A1P/SC3CnW8VwRQdxuFYJOk3VzBL5R50SJhCR1VLaP4=; b=PGH7yXlFlJDTnty4owPptnNHe+umUxWtkr+BLCQiHnnQ0RRcUFPhQAvHw8VPrlcgbK RvCaW0y+LhjS5W8EDgD8pXrMvWD0vNEVrYHBHFETWMbi1GIwG6r20Kazdaw64g3lS+nE RBLfFngZS1bWDgd2GisjdNvUWVHa8dAiZrIhP3hVSlaV6AZGE7VjMaXTnVeF5o6ftkzS 1ZUQjQCHaoW0hLRoBDBk0oTrel+h+DmPCC2AQh5gJ0XpvDdSt61JeczEeCNjYXRySg+k Jzoa0PwStq+z1IGT4apIA7ufuQqNH/JGLMEezJztD9dg/HTcEV6m8hR2CZ5S81mh7NIq IxAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906330; x=1719511130; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A1P/SC3CnW8VwRQdxuFYJOk3VzBL5R50SJhCR1VLaP4=; b=tGOgqS3eWoa1Wn4I1wXFvz3sEadJ6TiVxTZG6HS4uzl4WmW+NxoHP/kDlWB+z1pUNs sN2qS3Ir3ufG5nqTm0Z+OJZYb021X1FOIkP21l9F9/TK0/8buSeP/xX9WZbC6zqEbB2r zMbtK8p9wfoNlidHDYRXf+eH6vvr1xPc6FCbYIgvCSbHspriiFCGox2lyoIwHT0iw0YZ zP5e/gOgEQsbNByX8MkmiInBWB4S8BGckWq4dI3A4DFpF0mneIreP9szpy6BmEZaK+N8 9YNvfy1/kVVW0fHKSqZSobia5qkzH95ctr1mLEPn0Zdk+Y5CX8uZqZl9k6bI0CYUw4i6 ufcQ== X-Forwarded-Encrypted: i=1; AJvYcCXxTkkWqaXDdMwA3wQqKWfCqpGWbV9+DrLHLPCJiPINKCP5cH1Kful/mTfbNMkHiowTn1zZKwJsvoyq7wc75R01O4f+YISvEAsj7Q== X-Gm-Message-State: AOJu0YzGef4T/z08mzX+lG7ESTFhJc+8rspd6sX/FFQAI9kSh31hmCjR VfcO96sukxM9Pz+E4YKElfjHmodV2s7gTx4KnrxnkY2XKCNkS9lY/3+ZjvFghH0= X-Google-Smtp-Source: AGHT+IGWXsSjB74ZkY33xSGV66MpkL8BGYuPS62vzS9X76Uki4Qr6bCcEMzRCDBxT7/iFMdNX6o18w== X-Received: by 2002:a17:902:dac7:b0:1f7:90e:6d3e with SMTP id d9443c01a7336-1f9aa47878dmr72023545ad.67.1718906330373; Thu, 20 Jun 2024 10:58:50 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9941d957fsm56566125ad.273.2024.06.20.10.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:49 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 36/40] scsi: sr: drop locking around SR index bitmap Date: Thu, 20 Jun 2024 10:56:59 -0700 Message-ID: <20240620175703.605111-37-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The driver accesses the sr_index_bits bitmaps to set/clear individual bits only. Now that we have an atomic bit search helper, we can drop the sr_index_lock that protects the sr_index_bits, and make all this routine lockless. While there, use DECLARE_BITMAP() to declare sr_index_bits. Signed-off-by: Yury Norov --- drivers/scsi/sr.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 7ab000942b97..3b4e04ed8b4a 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -33,6 +33,7 @@ * check resource allocation in sr_init and some cleanups */ =20 +#include #include #include #include @@ -103,8 +104,7 @@ static struct scsi_driver sr_template =3D { .done =3D sr_done, }; =20 -static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG]; -static DEFINE_SPINLOCK(sr_index_lock); +static DECLARE_BITMAP(sr_index_bits, SR_DISKS); =20 static struct lock_class_key sr_bio_compl_lkclass; =20 @@ -566,10 +566,7 @@ static void sr_free_disk(struct gendisk *disk) { struct scsi_cd *cd =3D disk->private_data; =20 - spin_lock(&sr_index_lock); clear_bit(MINOR(disk_devt(disk)), sr_index_bits); - spin_unlock(&sr_index_lock); - unregister_cdrom(&cd->cdi); mutex_destroy(&cd->lock); kfree(cd); @@ -628,15 +625,11 @@ static int sr_probe(struct device *dev) goto fail_free; mutex_init(&cd->lock); =20 - spin_lock(&sr_index_lock); - minor =3D find_first_zero_bit(sr_index_bits, SR_DISKS); + minor =3D find_and_set_bit(sr_index_bits, SR_DISKS); if (minor =3D=3D SR_DISKS) { - spin_unlock(&sr_index_lock); error =3D -EBUSY; goto fail_put; } - __set_bit(minor, sr_index_bits); - spin_unlock(&sr_index_lock); =20 disk->major =3D SCSI_CDROM_MAJOR; disk->first_minor =3D minor; @@ -700,9 +693,7 @@ static int sr_probe(struct device *dev) unregister_cdrom: unregister_cdrom(&cd->cdi); fail_minor: - spin_lock(&sr_index_lock); clear_bit(minor, sr_index_bits); - spin_unlock(&sr_index_lock); fail_put: put_disk(disk); mutex_destroy(&cd->lock); --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 8A2261D0524; Thu, 20 Jun 2024 17:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906334; cv=none; b=OazWtCS14e+oVvfU/Ut2vWyzzizUaWXB047+es8oDE5aLACWwJpjSoGvxPwRdyh/IK1zUic/VEvkWk8sfcLtyLUyaI0eGuUQoghf+WsYqaVTrnS/a/eLO9GS5cC+IM+IH+PS+Z8pwwbGTZolnmyfBL1oKjg1q7IEtZq2TsYVMoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906334; c=relaxed/simple; bh=iFsifJx1wMiIIUWuh/ayjg/iUbqKnwO1KoeqNmj0MPo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tgjwOGRzA1h7Srlc+or0ON+BS9qxvSb5rYpkU+AEBPurK+NvwyreBYUa4eErJ3XB9ACShS7Qam8XON+3ozzT3fUqyy+b0Y8155in1msV8y+s1gjpyL2vq7wBfq3QjlaafJaTNoJUqJJc00Hb+jAJBdt/TXJTNuXzgzHvHREJBM0= 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=j/4JY3q2; arc=none smtp.client-ip=209.85.214.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j/4JY3q2" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1f4a5344ec7so8743805ad.1; Thu, 20 Jun 2024 10:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906333; x=1719511133; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hj1QfKPBw8fFwUqArOqXUFjt0dwMTc6OO+45pzeQpo8=; b=j/4JY3q2qlsOdoJeRcVTj5iKP5KuR9U365iHvOhM57fFUV9yH7QJhNt2bjdLRiVgjw dzNcfhHl6lvlnEE4WEoimXRbFRPYNFbBtAvYzMqkgRWxBk/It0isVE4T2V6gF9yi9DQN 99pUylWzxvsFSpjR8GUzZlApLOJ7q/M+r1gT0qwh1KPnuDn/ewwzYRb3ATApEXD1exp0 mlYq3yEBIkwvQXtFVEmEwauf3GtOek4aYqmxBCTm0DYTlHwGq/uvyAaY7QbUXDe5mzgb mR0DYFBQCkHaPcWEd44nMY+Wp4+01UlaxZPUN7XixE7ZBaoRovoU3dMuwd4+LbWIUlZO wArw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906333; x=1719511133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hj1QfKPBw8fFwUqArOqXUFjt0dwMTc6OO+45pzeQpo8=; b=UZWqdl9uz0GoVF3lmQ1MR53EExWlLi2ExMaViUQjo33jCBtkIoXsuZU417AM3Picz0 exDkH0ATMN4iE9Oy/l0rgn8kSpP17PlllTn2hNa4+NAZUzunWxKzfPP/fycr4TolEwoG HR73ADPZTMzyszKnNK7Vd+7CXbylFAaBspQrxwAz7LKbBZTuxf62gYHv2uVpDHa+wvpS Co/oAYTIyemfkkt2Rc1eXmmX5nwoX1s7m1c8zPlKqwQKc1SbZImNZHr0CuhGrajeRiA2 rt6PpUnmU1rGLV9/MDBMpF7l/vItyoVAy70cqlhBAzw9I00iAQnMYWmBE01JkP+E2QUY JCyg== X-Forwarded-Encrypted: i=1; AJvYcCW5DxLvCNQEMNB6JYK0aVQeJsGLJKwSI2rtF8FrGXxz6WQf+mhMFGPgarrHMWxvIyTE2dD49pxXoYsIKd1vuQNLIObH X-Gm-Message-State: AOJu0YzLs90tys57502gK3TJVdP60AEJdi4+uxClG2tbV6PMxgmtuEsA Z7A1IHLzXA04JHPYA2ahqAOdzSQ5H9nXFBAdFUMEYXvqSRRrMxYd33FwUN8KNHM= X-Google-Smtp-Source: AGHT+IHv7hZ0hu3tHqs8vQg7dykPKbTq19sg2MZwzPshyGp9XYLFVMvIGQ9OcLfhnMnfvSTxeFX6Ow== X-Received: by 2002:a17:902:d510:b0:1f6:ee7b:6ecf with SMTP id d9443c01a7336-1f98b28f021mr132320805ad.34.1718906333014; Thu, 20 Jun 2024 10:58:53 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9c92ac748sm19063135ad.187.2024.06.20.10.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:52 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Naveen N. Rao" , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 37/40] KVM: PPC: Book3s HV: drop locking around kvmppc_uvmem_bitmap Date: Thu, 20 Jun 2024 10:57:00 -0700 Message-ID: <20240620175703.605111-38-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The driver operates on individual bits of the kvmppc_uvmem_bitmap. Now that we have an atomic search API for bitmaps, we can rely on it and drop locking around the bitmap entirely. Signed-off-by: Yury Norov --- arch/powerpc/kvm/book3s_hv_uvmem.c | 33 ++++++++++-------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_h= v_uvmem.c index 92f33115144b..93d09137cb23 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -86,6 +86,7 @@ * page-sizes, we need to break this assumption. */ =20 +#include #include #include #include @@ -99,7 +100,6 @@ =20 static struct dev_pagemap kvmppc_uvmem_pgmap; static unsigned long *kvmppc_uvmem_bitmap; -static DEFINE_SPINLOCK(kvmppc_uvmem_bitmap_lock); =20 /* * States of a GFN @@ -697,23 +697,20 @@ static struct page *kvmppc_uvmem_get_page(unsigned lo= ng gpa, struct kvm *kvm) struct page *dpage =3D NULL; unsigned long bit, uvmem_pfn; struct kvmppc_uvmem_page_pvt *pvt; - unsigned long pfn_last, pfn_first; + unsigned long num_pfns, pfn_first; =20 pfn_first =3D kvmppc_uvmem_pgmap.range.start >> PAGE_SHIFT; - pfn_last =3D pfn_first + - (range_len(&kvmppc_uvmem_pgmap.range) >> PAGE_SHIFT); + num_pfns =3D range_len(&kvmppc_uvmem_pgmap.range) >> PAGE_SHIFT; =20 - spin_lock(&kvmppc_uvmem_bitmap_lock); - bit =3D find_first_zero_bit(kvmppc_uvmem_bitmap, - pfn_last - pfn_first); - if (bit >=3D (pfn_last - pfn_first)) - goto out; - bitmap_set(kvmppc_uvmem_bitmap, bit, 1); - spin_unlock(&kvmppc_uvmem_bitmap_lock); + bit =3D find_and_set_bit(kvmppc_uvmem_bitmap, num_pfns); + if (bit >=3D num_pfns) + return NULL; =20 pvt =3D kzalloc(sizeof(*pvt), GFP_KERNEL); - if (!pvt) - goto out_clear; + if (!pvt) { + clear_bit(bit, kvmppc_uvmem_bitmap); + return NULL; + } =20 uvmem_pfn =3D bit + pfn_first; kvmppc_gfn_secure_uvmem_pfn(gpa >> PAGE_SHIFT, uvmem_pfn, kvm); @@ -725,12 +722,6 @@ static struct page *kvmppc_uvmem_get_page(unsigned lon= g gpa, struct kvm *kvm) dpage->zone_device_data =3D pvt; zone_device_page_init(dpage); return dpage; -out_clear: - spin_lock(&kvmppc_uvmem_bitmap_lock); - bitmap_clear(kvmppc_uvmem_bitmap, bit, 1); -out: - spin_unlock(&kvmppc_uvmem_bitmap_lock); - return NULL; } =20 /* @@ -1021,9 +1012,7 @@ static void kvmppc_uvmem_page_free(struct page *page) (kvmppc_uvmem_pgmap.range.start >> PAGE_SHIFT); struct kvmppc_uvmem_page_pvt *pvt; =20 - spin_lock(&kvmppc_uvmem_bitmap_lock); - bitmap_clear(kvmppc_uvmem_bitmap, pfn, 1); - spin_unlock(&kvmppc_uvmem_bitmap_lock); + clear_bit(pfn, kvmppc_uvmem_bitmap); =20 pvt =3D page->zone_device_data; page->zone_device_data =3D NULL; --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 BF9861BA899; Thu, 20 Jun 2024 17:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906338; cv=none; b=Dc8Tla66NiZShYo3jO94oDGiCBj2A3hJXkc5xoTNDKmtiFOxF0XmJi7ijagWXZXPCHyLanvidyqyY3MPakG7alFlrKPs8g2rWU+d67SQrvAZdihNEuQ/VRqtHTLo+xOdrVGam9ddn1QwE+NykdLrxJk5n9xXJ0M+bvp7W4QwJAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906338; c=relaxed/simple; bh=ywt5jQ7AnfZyxoNrW7FHAEolpYpDtzMcqsRhreJJnKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tbqe6TOxm5luTdJduiv/USd+K5Xgx82rsdD18ejVhPq/Bcv46EKRARJx/UvmLYvSmL1zZEs8YgH2JmTYeMAGp388MmejwXYhFz5wFHCTDFdyj/t5XeRGjz7MXx3jI73knoOLojCqdygsioErNz/HQXXO51bvzxp4P5a0keoEduw= 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=dEus66wz; arc=none smtp.client-ip=209.85.214.174 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dEus66wz" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1f9de13d6baso4405965ad.2; Thu, 20 Jun 2024 10:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906336; x=1719511136; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GsYMR7W/oLrUdYReWrdeZFpoa0VAudVSEYOx4NZUcFc=; b=dEus66wzbWLc6RKjs0qC7OoUuC5V6/s/atRec+t6lUIXOFRzMd8T/eqcN81nPbsjDY mIRVwZiKVCaElOkuzU8ptFn1SLvpxrs0ld5rmZLAC5MfsT5CwPTpGqG2lzGaIYz0Q8HE WUMkBghlOH4JinHau8u7O0Ngoa8IGdJpFewZ4/zbT8ALhvW0K3bqkbKwB+AcOK3YTDnp rs+UmyxUkWpe+MS6WwWRlFa3N/wBsPtXJtcvVkLPvuEHE0pJke7YiTmHoLkBGQ5FT5pN buqbL9TILLHJWoTs2gCFkvfsXls4w/bnWvgN+DJWWkjflPUfQZ5yhI7cawuKCD27SQbn D+Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906336; x=1719511136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GsYMR7W/oLrUdYReWrdeZFpoa0VAudVSEYOx4NZUcFc=; b=XpLnJUFZ12lyS/evw3swl/z0EoaYLIAQe9Uq1uem/XrCFIcg2WzCkpYy0Hp+5WXRyC 4H6nm+kuTu/F51C+WFjV7NTiU0/r9XFCbOoGya+WCDNhQtLm4OBREsPDYjSAGM6VEGNR WO5vqcEEYbAe8YjrWNvvjgVWvccs30hm/V/vk4w82G3Unbj1WV6Nj2LW6jP2o+kxe+H9 MtUUOHtP5oA0LbixVUMwkjDPhAIxkA5XnZt8cqKoiNi4TMnN+yXcXkG26Hu3mYeQ453A hB4/tHlTTkJ72++CSONZZAXqpg0li0V4j9qzuY8oIwKQPw2RGCwXTH6I0GDxRz8gGOch tqAA== X-Forwarded-Encrypted: i=1; AJvYcCW/SGolH4yNufbE03jgZV53WU708Czwqn5hgTBMZ0tzpmPZewSX7KlUGGzKJGaRuDdhVncbJBFvXFThEN0jgbj+g4MKQ+NC X-Gm-Message-State: AOJu0YwOiPruEIGEnCX+at4LGQhwrmGAl9FiZhmKdE7TGmHEGi3+W5Qk bjt4sacaxVYxk6lOP+dSTYAE0QstB3Ml5GrNTnvPSqYOfO0XOcHmMd0dOQ5egyE= X-Google-Smtp-Source: AGHT+IEcVgYYT890Ph3UgqxZ7WCGlaQv51dFbcwu7r/mkJrr17cMFG1OvZ8xQ71txPYDVC9RQU4wXg== X-Received: by 2002:a17:902:f64c:b0:1f7:38a2:f1e6 with SMTP id d9443c01a7336-1f9aa473e72mr69121615ad.43.1718906336023; Thu, 20 Jun 2024 10:58:56 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9b5b7a994sm35821215ad.177.2024.06.20.10.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:55 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Michael Chan , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 38/40] wifi: mac80211: drop locking around ntp_fltr_bmap Date: Thu, 20 Jun 2024 10:57:01 -0700 Message-ID: <20240620175703.605111-39-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The driver operates on individual bits of the bitmap. Now that we have atomic find_and_set_bit() helper, we can move the map manipulation out of ntp_fltr_lock-protected area. Signed-off-by: Yury Norov --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethern= et/broadcom/bnxt/bnxt.c index c437ca1c0fd3..5f4c3449570d 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -5616,17 +5617,16 @@ static int bnxt_init_l2_filter(struct bnxt *bp, str= uct bnxt_l2_filter *fltr, struct bnxt_l2_key *key, u32 idx) { struct hlist_head *head; + int bit_id; =20 ether_addr_copy(fltr->l2_key.dst_mac_addr, key->dst_mac_addr); fltr->l2_key.vlan =3D key->vlan; fltr->base.type =3D BNXT_FLTR_TYPE_L2; if (fltr->base.flags) { - int bit_id; - - bit_id =3D bitmap_find_free_region(bp->ntp_fltr_bmap, - bp->max_fltr, 0); - if (bit_id < 0) + bit_id =3D find_and_set_bit(bp->ntp_fltr_bmap, bp->max_fltr); + if (bit_id >=3D bp->max_fltr) return -ENOMEM; + fltr->base.sw_id =3D (u16)bit_id; bp->ntp_fltr_count++; } @@ -14396,13 +14396,11 @@ int bnxt_insert_ntp_filter(struct bnxt *bp, struc= t bnxt_ntuple_filter *fltr, struct hlist_head *head; int bit_id; =20 - spin_lock_bh(&bp->ntp_fltr_lock); - bit_id =3D bitmap_find_free_region(bp->ntp_fltr_bmap, bp->max_fltr, 0); - if (bit_id < 0) { - spin_unlock_bh(&bp->ntp_fltr_lock); + bit_id =3D find_and_set_bit(bp->ntp_fltr_bmap, bp->max_fltr); + if (bit_id >=3D bp->max_fltr) return -ENOMEM; - } =20 + spin_lock_bh(&bp->ntp_fltr_lock); fltr->base.sw_id =3D (u16)bit_id; fltr->base.type =3D BNXT_FLTR_TYPE_NTUPLE; fltr->base.flags |=3D BNXT_ACT_RING_DST; --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 66C961D0F4F for ; Thu, 20 Jun 2024 17:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906340; cv=none; b=F+sBc1IgvCMq1I5/c8muZJzUQZZy8uHxkdeeZY6tLaRRFOFglPEXWsbKqztfpt42eVrZsUGrXiYpQ4dpFIG3f3ZYdQECmsAL0AATNVoyn2M6aylAjVHrxenejFMjiojboKUAI5ssO93FKs0wjoBWcrQB8w0hr1K/QdJ1lyU4Kbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906340; c=relaxed/simple; bh=43PCcVjF9LLFxFCfleFm+1u6w23B3SV5aS208ZW0XBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HBIEhJDguYFnWdclQdavgyaCwypCtapKBi83oz3Z6Ls/bkMBGiZp53hJgxFdSR/r3gaxxpGHLxZwL1Zo+VOW0ppYfYGYA2Yv0R0f6gsPXVER4VgZyP7SIUIkIJJdcqWP8b4QaCaIhe8HaZbrtf8sMe2G/yy10icqZOIxIKj6wlI= 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=Gj9vD1Sj; arc=none smtp.client-ip=209.85.215.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gj9vD1Sj" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-6eab07ae82bso830769a12.3 for ; Thu, 20 Jun 2024 10:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906339; x=1719511139; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2ipwGbR+ze0Ay3Tr6YsAi2mpOH1rdNvZeMvAJD4j/30=; b=Gj9vD1SjxHxZ+TirGvC0rVtBrKM6JbbeWL69QgCnI6sW8p6uEwo5tWtu4UmoHWeeI7 EE7Kn34oVvKwx3OZ47TTv4Poc/P4dCgzZLpKuPmWBGer3UG1t8iGgPOWPaphUou/o1jx ouD1zbpmS3PG7CawAmLx/LvE67yoEhgCb+xfr3RRNgKJjB70IPRnaUpN+aIwUU7RBtJe C63Nt+nIg8Acm5uvUOE5fOa8FW+o11L/OI3xe2sO66lU5j8nAL9ZN8KUDFpMwCeYNY0S L3G6r61YO/n85ifEnOu8PEbS/c/rWy7O7AreCWY+HdTObOSZQB+NGogUTGO5S5OESsBL 8VDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906339; x=1719511139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ipwGbR+ze0Ay3Tr6YsAi2mpOH1rdNvZeMvAJD4j/30=; b=DWw3kXrvE5G7fjVUBK/LQs057Nh1kN388cDkPonMM489Xul5oicfQdEzwNRtMUrGQ1 /hmUyHHMrSvoAo9EMNEYNf+J9+XPUHdJvy1gc0adhqEQ/JmQ4/efLOQxbhLPWUyOQVo8 XbJAdITbp2mi2pb5Fx+MpQM3P1rajwsKsX4RQAuTRzCGYVYHYs2JbbPSfQ6Vrdck3nGL rdp0EmBMI7lkMaWmtWArQvI7Ubahl7UVCAPIudNLUEnOiCO/hj9UErYFoR75T0kyMPvb T0bachnOiwGosXoQK/JINk4P5reYtN1P0ax+NRgI5N1MrO8vRQkdWoNJEA6jAJN357Mg JTnA== X-Gm-Message-State: AOJu0Yx54c0uAlP1E80Ie+iofd2aKHUSxsG4T5a+mzhC1GVl87UxmHQ2 hnquTyhqrgCeJyE+p/iiQ6FJkpHOblR9qQHzMXp1w0KiXBdx1pjspBcMZYK3DVw= X-Google-Smtp-Source: AGHT+IEfVgCYhizW2aBSpfFWamrwpAlGma5UzQVQzhVAXMNPxrw0Ml+8Pulc0jdTKXgia5DGvnGynA== X-Received: by 2002:a17:90b:e89:b0:2c7:b17c:dfc3 with SMTP id 98e67ed59e1d1-2c7b5b569aemr5726138a91.15.1718906338696; Thu, 20 Jun 2024 10:58:58 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e55e1846sm2010484a91.28.2024.06.20.10.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:58 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Jassi Brar Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 39/40] mailbox: bcm-flexrm: simplify locking scheme Date: Thu, 20 Jun 2024 10:57:02 -0700 Message-ID: <20240620175703.605111-40-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use atomic find_and_set_bit() and drop locking around ring->requests_bmap. Signed-off-by: Yury Norov --- drivers/mailbox/bcm-flexrm-mailbox.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c b/drivers/mailbox/bcm-fle= xrm-mailbox.c index b1abc2a0c971..7aca533a1068 100644 --- a/drivers/mailbox/bcm-flexrm-mailbox.c +++ b/drivers/mailbox/bcm-flexrm-mailbox.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -989,21 +990,17 @@ static int flexrm_new_request(struct flexrm_ring *rin= g, msg->error =3D 0; =20 /* If no requests possible then save data pointer and goto done. */ - spin_lock_irqsave(&ring->lock, flags); - reqid =3D bitmap_find_free_region(ring->requests_bmap, - RING_MAX_REQ_COUNT, 0); - spin_unlock_irqrestore(&ring->lock, flags); - if (reqid < 0) + reqid =3D find_and_set_bit(ring->requests_bmap, RING_MAX_REQ_COUNT); + if (reqid >=3D RING_MAX_REQ_COUNT) return -ENOSPC; + ring->requests[reqid] =3D msg; =20 /* Do DMA mappings for the message */ ret =3D flexrm_dma_map(ring->mbox->dev, msg); if (ret < 0) { ring->requests[reqid] =3D NULL; - spin_lock_irqsave(&ring->lock, flags); - bitmap_release_region(ring->requests_bmap, reqid, 0); - spin_unlock_irqrestore(&ring->lock, flags); + clear_bit(reqid, ring->requests_bmap); return ret; } =20 @@ -1063,9 +1060,7 @@ static int flexrm_new_request(struct flexrm_ring *rin= g, if (exit_cleanup) { flexrm_dma_unmap(ring->mbox->dev, msg); ring->requests[reqid] =3D NULL; - spin_lock_irqsave(&ring->lock, flags); - bitmap_release_region(ring->requests_bmap, reqid, 0); - spin_unlock_irqrestore(&ring->lock, flags); + clear_bit(reqid, ring->requests_bmap); } =20 return ret; @@ -1130,9 +1125,7 @@ static int flexrm_process_completions(struct flexrm_r= ing *ring) =20 /* Release reqid for recycling */ ring->requests[reqid] =3D NULL; - spin_lock_irqsave(&ring->lock, flags); - bitmap_release_region(ring->requests_bmap, reqid, 0); - spin_unlock_irqrestore(&ring->lock, flags); + clear_bit(reqid, ring->requests_bmap); =20 /* Unmap DMA mappings */ flexrm_dma_unmap(ring->mbox->dev, msg); --=20 2.43.0 From nobody Tue Dec 16 10:50:45 2025 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 AC4C71D18E4 for ; Thu, 20 Jun 2024 17:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906344; cv=none; b=QrAMzKg2bPUwnnExoKNbJFBav4Mf7qoJcI9mvIoV2JhNx8/5rOnHMz81OtBU+6iLbGHgI6dE9Rgk+Tc41k6sIp8RPQcMBELiXvTKADk4n4zOOr3rzkJVke3axau58dGO9lknfZXuqt4+av3/ImoK2hpB+SfpnngIJs4GAb14kyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718906344; c=relaxed/simple; bh=4Us/VrK+pFb5LnKE8hNzRDXM2DGUvjJ7JpoDeE9B24Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ABNxQIL+NCh3Du5s9rSTN4HZeKLi8BjPfDdL+AqG6KdDsaSw9dJShcOFwj/LRBFV/U6CeD0FOzlPM/KWtN+kfZcgoAxXJl2vYSmlIXp9JQeJtml0+ryCmk3le6tEL2QbzSprATb/ewwzLG3um71bl7/P9w53wptdSuLNYcfdE9o= 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=WecGNaMs; arc=none smtp.client-ip=209.85.210.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WecGNaMs" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7062bf6d9a1so953471b3a.1 for ; Thu, 20 Jun 2024 10:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906342; x=1719511142; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q+W8qrsNzjA5KvK9XemaQbK3hnneV0OURa4QuE2WY6E=; b=WecGNaMs58p1PKf9iEuYwVwc4iu0qZnvp2oP0FNrrQg7gyCLA6+2mXVlzgig857hKd rnt00pN1ENFWg/9EhXYBtswurInkU6H0hdCT8j1cxhB0nW2R485LkRqlRBuyufsAI/ur UgshH3MxgTFKED5lolaXeYkNC7uC/xqIt7scBxktSLQaHnQGzUc6qDwXMaNwqEH+ryHm nJMlPwK+hOHbhGQiHSKc+8ZbFdpP4ePYJsvolzOtq6Xsek+S0OrD3tfetEKZaqcs5PDd Qprdc7D6g25BWU3jyvfVtjA/8J5x27N6G5pZS+gFNyF7QWxkA5+M6dFtcT5lLmvHcTIm pXKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906342; x=1719511142; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q+W8qrsNzjA5KvK9XemaQbK3hnneV0OURa4QuE2WY6E=; b=n7wuuilwaMd91sDk44pQcS7j/2Bd8vko4QXg+z2ORg6zigs4F66LQLkPvdCQaFoQD0 9gjuZLllx/ADthGh/qHvkokCtICpN4cPcFLs5KoEXTtujAqzno4OVYFwZdCGKCtlEaMo rgT4dkiNQkAd+Z9C8XpK9TMVjZJtIPRlUwPDb2lYoBbsccoPoYgFTwd553xVCpqU5WWq AJjfqLYZQUShVoNLiZ90hoTvP9ZJ+y8TVwBPfDm18XMbZ/Zbk5AN6KUdKPETLrhJVZQy +lR4IfrOKbYclKLY+RFzb9Myo3RToZJ6JaJkzgbj6HKx+mFy67qU/1K4EtUJXiufpOtl I/Hg== X-Gm-Message-State: AOJu0YwvJ6sMOIMCruZ+25E7uyffNP5RzcXaIpnJO1tSTI3OwASWjuvE /Dj5j4mImN5wCTmdyr8aOVeXha9hykT+ceXTN3aP3R25iqhxrZ7QmX574mQJ8IQ= X-Google-Smtp-Source: AGHT+IEbaEr10aoZqMNXkMGuZ5af7kUmWBhANe7UmWWwHg5OCvBD+k/5bSXXGBLZOHAs+1L/wt8fOA== X-Received: by 2002:aa7:820d:0:b0:704:3491:d74e with SMTP id d2e1a72fcca58-70629cce5b3mr5236265b3a.22.1718906341930; Thu, 20 Jun 2024 10:59:01 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb4c621sm12637684b3a.115.2024.06.20.10.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:59:01 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Naveen N. Rao" , Yury Norov , linuxppc-dev@lists.ozlabs.org Cc: Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 40/40] powerpc/xive: drop locking around IRQ map Date: Thu, 20 Jun 2024 10:57:03 -0700 Message-ID: <20240620175703.605111-41-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The code operates on individual bits of the bitmap, and leveraging atomic find ops we can drop locking scheme around the map. Signed-off-by: Yury Norov --- arch/powerpc/sysdev/xive/spapr.c | 34 ++++++-------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/sp= apr.c index e45419264391..2b3b8ad75b42 100644 --- a/arch/powerpc/sysdev/xive/spapr.c +++ b/arch/powerpc/sysdev/xive/spapr.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,6 @@ struct xive_irq_bitmap { unsigned long *bitmap; unsigned int base; unsigned int count; - spinlock_t lock; struct list_head list; }; =20 @@ -55,7 +55,6 @@ static int __init xive_irq_bitmap_add(int base, int count) if (!xibm) return -ENOMEM; =20 - spin_lock_init(&xibm->lock); xibm->base =3D base; xibm->count =3D count; xibm->bitmap =3D bitmap_zalloc(xibm->count, GFP_KERNEL); @@ -81,47 +80,26 @@ static void xive_irq_bitmap_remove_all(void) } } =20 -static int __xive_irq_bitmap_alloc(struct xive_irq_bitmap *xibm) -{ - int irq; - - irq =3D find_first_zero_bit(xibm->bitmap, xibm->count); - if (irq !=3D xibm->count) { - set_bit(irq, xibm->bitmap); - irq +=3D xibm->base; - } else { - irq =3D -ENOMEM; - } - - return irq; -} - static int xive_irq_bitmap_alloc(void) { struct xive_irq_bitmap *xibm; - unsigned long flags; - int irq =3D -ENOENT; =20 list_for_each_entry(xibm, &xive_irq_bitmaps, list) { - spin_lock_irqsave(&xibm->lock, flags); - irq =3D __xive_irq_bitmap_alloc(xibm); - spin_unlock_irqrestore(&xibm->lock, flags); - if (irq >=3D 0) - break; + int irq =3D find_and_set_bit(xibm->bitmap, xibm->count); + + if (irq < xibm->count) + return irq + xibm->base; } - return irq; + return -ENOENT; } =20 static void xive_irq_bitmap_free(int irq) { - unsigned long flags; struct xive_irq_bitmap *xibm; =20 list_for_each_entry(xibm, &xive_irq_bitmaps, list) { if ((irq >=3D xibm->base) && (irq < xibm->base + xibm->count)) { - spin_lock_irqsave(&xibm->lock, flags); clear_bit(irq - xibm->base, xibm->bitmap); - spin_unlock_irqrestore(&xibm->lock, flags); break; } } --=20 2.43.0