From nobody Mon Apr 6 14:56:54 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F110C433FE for ; Mon, 3 Oct 2022 15:34:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbiJCPez (ORCPT ); Mon, 3 Oct 2022 11:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbiJCPet (ORCPT ); Mon, 3 Oct 2022 11:34:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E887ABC1F for ; Mon, 3 Oct 2022 08:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664811286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eqsEWenkkxG3d+8eGwddnf9BdMPGOTzm3zE5yD9Z50g=; b=F7q0vM1IHMXtcZoZgor2Q6jk8L8z4SvW4UgbCzLbMo+SOneUoIBmKdUxKumEipi5ZBIqOp SckaFy3Fz6TgXvStojoSaXEJ3wk/AXeXyOB/Uj7ClTBYgJ2LvBHPJCK9DPHyk485+K9VF2 OvmSTXZHDjJj3ZoMCNUgIwDMEay/6qc= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-204-8m_4FXIZM66AvSNZ0HIAqQ-1; Mon, 03 Oct 2022 11:34:45 -0400 X-MC-Unique: 8m_4FXIZM66AvSNZ0HIAqQ-1 Received: by mail-wm1-f69.google.com with SMTP id v5-20020a1cac05000000b003b884c5b09eso2745921wme.2 for ; Mon, 03 Oct 2022 08:34:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=eqsEWenkkxG3d+8eGwddnf9BdMPGOTzm3zE5yD9Z50g=; b=ZGc4oi8+XJ6gF+GCYMYw6sOv1f08MUs53nKN99yzWibguwcqD6lYqZUNRI8Q6FKEXj w5PGwsnWkd/JgUEbvrUDqRzn3TcXsnL3gdkV9PxilrsRFfnPByoyHV1j5EOZ1/kLeVSc LnvQ2uZ0a3mODIZ+Tuy6bYVOx081sLai0gtKlA9SZlYwJgeUrpqbU8Ilixj5md1/UbQ2 oVDMTBykYSbsDTdRxYMDHJwBvzjOVtUIgqL4MbYEjUkHQXCVO2iXZEuX0MVTuGDdea81 IOO0SdPWm+q4LIOAI3nOAQFsVFslS/Zc+DcfHqorv6hU+I3+bCIR9j6tEZvrkZc9MyDa HeAA== X-Gm-Message-State: ACrzQf3l0bnk07gDbAWPnk0w/0V4hPFq/CakQFSw+LR5QLqCKLiRWUXU IZ74rO0SVegiTfbD7xxgQcUamq7LbTv3iWiP3P0tvfKF0ToVBu6qgeVkzJi6eqM93eZZPUsDc16 oRzvRWVnJ+VPQj+DC2IF6F0T6 X-Received: by 2002:a05:600c:3511:b0:3b4:bb85:f1e3 with SMTP id h17-20020a05600c351100b003b4bb85f1e3mr7402326wmq.0.1664811282665; Mon, 03 Oct 2022 08:34:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6N/tiZtv+buwIsgJCAUILRSHo8cXt2iCO72yhosTjOIvYDphNYg9irITQGmr5FDL9l4PDtEg== X-Received: by 2002:a05:600c:3511:b0:3b4:bb85:f1e3 with SMTP id h17-20020a05600c351100b003b4bb85f1e3mr7402314wmq.0.1664811282459; Mon, 03 Oct 2022 08:34:42 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id o9-20020a05600c510900b003a5c244fc13sm18343151wms.2.2022.10.03.08.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 08:34:41 -0700 (PDT) From: Valentin Schneider To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Jens Axboe , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Subject: [PATCH bitmap-for-next 1/5] blk_mq: Fix cpumask_check() warning in blk_mq_hctx_next_cpu() Date: Mon, 3 Oct 2022 16:34:16 +0100 Message-Id: <20221003153420.285896-2-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221003153420.285896-1-vschneid@redhat.com> References: <20221003153420.285896-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A recent commit made cpumask_next*() trigger a warning when passed n =3D nr_cpu_ids - 1. This means extra care must be taken when feeding CPU numbers back into cpumask_next*(). The warning occurs nearly every boot on QEMU: [ 5.398453] WARNING: CPU: 3 PID: 162 at include/linux/cpumask.h:110 __bl= k_mq_delay_run_hw_queue+0x16b/0x180 [ 5.399317] Modules linked in: [ 5.399646] CPU: 3 PID: 162 Comm: ssh-keygen Tainted: G = N 6.0.0-rc4-00004-g93003cb24006 #55 [ 5.400135] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS = rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014 [ 5.405430] Call Trace: [ 5.406152] [ 5.406452] blk_mq_sched_insert_requests+0x67/0x150 [ 5.406759] blk_mq_flush_plug_list+0xd0/0x280 [ 5.406987] ? bit_wait+0x60/0x60 [ 5.407317] __blk_flush_plug+0xdb/0x120 [ 5.407561] ? bit_wait+0x60/0x60 [ 5.407765] io_schedule_prepare+0x38/0x40 [ 5.407974] io_schedule+0x6/0x40 [ 5.408283] bit_wait_io+0x8/0x60 [ 5.408485] __wait_on_bit+0x72/0x90 [ 5.408668] out_of_line_wait_on_bit+0x8c/0xb0 [ 5.408879] ? swake_up_one+0x30/0x30 [ 5.409158] ext4_read_bh+0x7a/0x80 [ 5.409381] ext4_get_branch+0xc0/0x130 [ 5.409583] ext4_ind_map_blocks+0x1ac/0xb30 [ 5.409844] ? __es_remove_extent+0x61/0x6d0 [ 5.410128] ? blk_account_io_merge_bio+0x67/0xd0 [ 5.410416] ? percpu_counter_add_batch+0x59/0xb0 [ 5.410720] ? percpu_counter_add_batch+0x59/0xb0 [ 5.410949] ? _raw_read_unlock+0x13/0x30 [ 5.411323] ext4_map_blocks+0xc2/0x590 [ 5.411609] ? xa_load+0x7c/0xa0 [ 5.411859] ext4_mpage_readpages+0x4a2/0xaa0 [ 5.412192] read_pages+0x69/0x2b0 [ 5.412477] ? folio_add_lru+0x4f/0x70 [ 5.412696] page_cache_ra_unbounded+0x11d/0x170 [ 5.412960] filemap_get_pages+0x109/0x5d0 [ 5.413340] ? __vma_adjust+0x348/0x930 [ 5.413576] filemap_read+0xb7/0x380 [ 5.413805] ? vma_merge+0x2e9/0x330 [ 5.414067] ? vma_set_page_prot+0x43/0x80 [ 5.414309] ? __inode_security_revalidate+0x5e/0x80 [ 5.414581] ? selinux_file_permission+0x107/0x130 [ 5.414889] vfs_read+0x205/0x2e0 [ 5.415162] ksys_read+0x54/0xd0 [ 5.415348] do_syscall_64+0x3a/0x90 [ 5.415584] entry_SYSCALL_64_after_hwframe+0x63/0xcd Fixes: 78e5a3399421 ("cpumask: fix checking valid cpu range") Suggested-by: Yury Norov Signed-off-by: Valentin Schneider --- block/blk-mq.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index c96c8c4f751b..30ae51eda95e 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2046,8 +2046,13 @@ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx= *hctx) =20 if (--hctx->next_cpu_batch <=3D 0) { select_cpu: - next_cpu =3D cpumask_next_and(next_cpu, hctx->cpumask, - cpu_online_mask); + if (next_cpu =3D=3D nr_cpu_ids - 1) + next_cpu =3D nr_cpu_ids; + else + next_cpu =3D cpumask_next_and(next_cpu, + hctx->cpumask, + cpu_online_mask); + if (next_cpu >=3D nr_cpu_ids) next_cpu =3D blk_mq_first_mapped_cpu(hctx); hctx->next_cpu_batch =3D BLK_MQ_CPU_WORK_BATCH; --=20 2.31.1 From nobody Mon Apr 6 14:56:54 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 826CBC4332F for ; Mon, 3 Oct 2022 15:35:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230219AbiJCPfG (ORCPT ); Mon, 3 Oct 2022 11:35:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbiJCPey (ORCPT ); Mon, 3 Oct 2022 11:34:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D5A4E020 for ; Mon, 3 Oct 2022 08:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664811287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=arpFl93eCu4VRK8HZxr5R+cc0l1GALQ+UU+vo8Q36Tc=; b=JcX+OBnfktZj5QZHobNgxeMVyWlRMNgBGSaAw//uRHf82s/eaAXlPvWt+r9wKmHzfHBdLM vEseG8XLSu6/kb1Oj3gESVPKzTeIK5ArWq8CD+kbcTS47ta3itK0jZOdfVZJuC0fCqfnKi vt56pYHfhqnA+D0nQdKocYKtGjK3u2I= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-657-z6gv90XhMuCbqh7QkZG01A-1; Mon, 03 Oct 2022 11:34:46 -0400 X-MC-Unique: z6gv90XhMuCbqh7QkZG01A-1 Received: by mail-wr1-f70.google.com with SMTP id p7-20020adfba87000000b0022cc6f805b1so3150407wrg.21 for ; Mon, 03 Oct 2022 08:34:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=arpFl93eCu4VRK8HZxr5R+cc0l1GALQ+UU+vo8Q36Tc=; b=27fhtwSkZA2YwSKb2AQwI7+J+dBTuAYKrxt6f9st6m4c9V56a6LOUPjejxadnyM5ga fCVCm++qZ8dUPUAlEune1EpnIB3ZqnUleQZoxFufY4QflvaC8XuEzhpxNeyIPkfIhvAr raj0QkheS7bDS1Eg9Q8ZMbT5DXl+zNjM64u2trRKMcXX2LfB/Y4MA1J/nhZB/uNKy0xg +aTo3vP6tulqVGWaRYBIoMjSRjsRNtOaENgAZQyTPulTvsK+O58K1gUu5r6BVDmeT0L6 973U8gbzBNrcolEqV+6sJ69elkOJ+HlBIM/e1+yl7fWrdK2RVE5jark84mg9AIwo0c88 k5Ag== X-Gm-Message-State: ACrzQf0vejVpQBOvWsjm/vedUtra/DCVqV/7stBvEGfdZdl3KJrh8sWj QimCueVATOGPEbmSHcH2Uis0+OTXG5xyyQXD5FgoS1JF9RcnJdrrZ+xF/kLXCOzl4YxnhEeWBKw 821H0PXfMMA1ONvJWTO1W0wVR X-Received: by 2002:a05:600c:4fd1:b0:3b4:c00d:230a with SMTP id o17-20020a05600c4fd100b003b4c00d230amr7086582wmq.62.1664811285123; Mon, 03 Oct 2022 08:34:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5HFAm+wSvaJDfxQ4UcUyn6T4neRKzOgQk7Nth3fuyLRYFQZj5JvPP9+Ll3a76uaMR7QmiqBA== X-Received: by 2002:a05:600c:4fd1:b0:3b4:c00d:230a with SMTP id o17-20020a05600c4fd100b003b4c00d230amr7086570wmq.62.1664811284906; Mon, 03 Oct 2022 08:34:44 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id o9-20020a05600c510900b003a5c244fc13sm18343151wms.2.2022.10.03.08.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 08:34:43 -0700 (PDT) From: Valentin Schneider To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , 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 Subject: [PATCH bitmap-for-next 2/5] lib/find_bit: Introduce find_next_andnot_bit() Date: Mon, 3 Oct 2022 16:34:17 +0100 Message-Id: <20221003153420.285896-3-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221003153420.285896-1-vschneid@redhat.com> References: <20221003153420.285896-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In preparation of introducing for_each_cpu_andnot(), add a variant of find_next_bit() that negate the bits in @addr2 when ANDing them with the bits in @addr1. Signed-off-by: Valentin Schneider --- include/linux/find.h | 33 +++++++++++++++++++++++++++++++++ lib/find_bit.c | 9 +++++++++ 2 files changed, 42 insertions(+) diff --git a/include/linux/find.h b/include/linux/find.h index 0cdfab9734a6..2235af19e7e1 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -12,6 +12,8 @@ unsigned long _find_next_bit(const unsigned long *addr1, = unsigned long nbits, unsigned long start); unsigned long _find_next_and_bit(const unsigned long *addr1, const unsigne= d long *addr2, unsigned long nbits, unsigned long start); +unsigned long _find_next_andnot_bit(const unsigned long *addr1, const unsi= gned long *addr2, + unsigned long nbits, unsigned long start); unsigned long _find_next_zero_bit(const unsigned long *addr, unsigned long= nbits, unsigned long start); extern unsigned long _find_first_bit(const unsigned long *addr, unsigned l= ong size); @@ -91,6 +93,37 @@ unsigned long find_next_and_bit(const unsigned long *add= r1, } #endif =20 +#ifndef find_next_andnot_bit +/** + * find_next_andnot_bit - find the next set bit in *addr1 excluding all th= e bits + * in *addr2 + * @addr1: The first address to base the search on + * @addr2: The second address to base the search on + * @size: The bitmap size in bits + * @offset: The bitnumber to start searching at + * + * Returns the bit number for the next set bit + * If no bits are set, returns @size. + */ +static inline +unsigned long find_next_andnot_bit(const unsigned long *addr1, + const unsigned long *addr2, unsigned long size, + unsigned long offset) +{ + if (small_const_nbits(size)) { + unsigned long val; + + if (unlikely(offset >=3D size)) + return size; + + val =3D *addr1 & ~*addr2 & GENMASK(size - 1, offset); + return val ? __ffs(val) : size; + } + + return _find_next_andnot_bit(addr1, addr2, size, offset); +} +#endif + #ifndef find_next_zero_bit /** * find_next_zero_bit - find the next cleared bit in a memory region diff --git a/lib/find_bit.c b/lib/find_bit.c index 25609974cbe4..18bc0a7ac8ee 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -164,6 +164,15 @@ unsigned long _find_next_and_bit(const unsigned long *= addr1, const unsigned long EXPORT_SYMBOL(_find_next_and_bit); #endif =20 +#ifndef find_next_andnot_bit +unsigned long _find_next_andnot_bit(const unsigned long *addr1, const unsi= gned long *addr2, + unsigned long nbits, unsigned long start) +{ + return FIND_NEXT_BIT(addr1[idx] & ~addr2[idx], /* nop */, nbits, start); +} +EXPORT_SYMBOL(_find_next_andnot_bit); +#endif + #ifndef find_next_zero_bit unsigned long _find_next_zero_bit(const unsigned long *addr, unsigned long= nbits, unsigned long start) --=20 2.31.1 From nobody Mon Apr 6 14:56:54 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94F52C433FE for ; Mon, 3 Oct 2022 15:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230021AbiJCPfQ (ORCPT ); Mon, 3 Oct 2022 11:35:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbiJCPey (ORCPT ); Mon, 3 Oct 2022 11:34:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0910BBC35 for ; Mon, 3 Oct 2022 08:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664811290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ojCbGuFmiyLgdgSBf4HLyZfSJMuzgvdBj8Ilq3qJPwM=; b=HfA7hYfnFFIB3OUM6kLv0B7gibd2sEURwo6klT73ljS4AHRwc083BnfwwRsWVJg5SJNJ0G it/O9vojV2HpukBfZhS4FbHe4ZEKIliU8HDhRwNb9WxdBInmqZ7Z8n2CbnDOCz7J5qTgPo adi1XL8KsVJuG1LnHqyTBmgmICxh6uo= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-608-L7Xe-_VwOUipKcBL-JFn-g-1; Mon, 03 Oct 2022 11:34:49 -0400 X-MC-Unique: L7Xe-_VwOUipKcBL-JFn-g-1 Received: by mail-wr1-f72.google.com with SMTP id k30-20020adfb35e000000b0022e04708c18so1873467wrd.22 for ; Mon, 03 Oct 2022 08:34:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=ojCbGuFmiyLgdgSBf4HLyZfSJMuzgvdBj8Ilq3qJPwM=; b=1+o+NmhYHBFWENx+Z0PMR6hBGdNIuorfSaTpk3hoe4lk3Bg36wJrBzqVFUulQPjq4t HYNOIZTM5Q5JrYbfoZHKLa60od/ZKU6iw1zWyWzDXL2JQ9nCa8K9r0AG1uoYVM+YWF28 xVmTnGB716nXZ6HH73Vll/I2VM+i0L/vyz3P4CTJA+R/XZCAGSCiP9X5D644DwWDFHoM VaQ1B99uA50ttt6h4yDww/HEogwiIWb6Qw2JIONL1bTI8hDMx7wqt2w5DWkjnLICb7nz Vq+ofuhG49CTpfBa5sgUAAOZS5c66iuhzx7ZG3Kq+38Otf4JriVJ0iSMvag8a/qE4y/5 h2bw== X-Gm-Message-State: ACrzQf3qVMVtSseEVwU+hpIIAGrT7s9rfFvqUfZB2jJEQ5ZgVf3I4JrB MZnxaS5cqdDo9BGUsbe4rERVjgKfBo0sQXnqHB2pE9zdVoIFjkkbhttCXG1UjXV+BVBTdBc9oUE akLfF1C0LZnlpP3K57MVMOXFf X-Received: by 2002:a05:600c:3d0c:b0:3b4:c481:c63b with SMTP id bh12-20020a05600c3d0c00b003b4c481c63bmr6941544wmb.147.1664811286767; Mon, 03 Oct 2022 08:34:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DC0p2uhrZdvpPbhbvwisJCgZSihR5TsChXOyUBUKDJL+xI/cPY6MLHDizyk+JnQ7+AazWyw== X-Received: by 2002:a05:600c:3d0c:b0:3b4:c481:c63b with SMTP id bh12-20020a05600c3d0c00b003b4c481c63bmr6941528wmb.147.1664811286530; Mon, 03 Oct 2022 08:34:46 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id o9-20020a05600c510900b003a5c244fc13sm18343151wms.2.2022.10.03.08.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 08:34:45 -0700 (PDT) From: Valentin Schneider To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , 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 Subject: [PATCH bitmap-for-next 3/5] cpumask: Introduce for_each_cpu_andnot() Date: Mon, 3 Oct 2022 16:34:18 +0100 Message-Id: <20221003153420.285896-4-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221003153420.285896-1-vschneid@redhat.com> References: <20221003153420.285896-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" for_each_cpu_and() is very convenient as it saves having to allocate a temporary cpumask to store the result of cpumask_and(). The same issue applies to cpumask_andnot() which doesn't actually need temporary storage for iteration purposes. Following what has been done for for_each_cpu_and(), introduce for_each_cpu_andnot(). Signed-off-by: Valentin Schneider --- include/linux/cpumask.h | 18 ++++++++++++++++++ include/linux/find.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 286804bfe3b7..2f065ad97541 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -306,6 +306,24 @@ unsigned int __pure cpumask_next_wrap(int n, const str= uct cpumask *mask, int sta #define for_each_cpu_and(cpu, mask1, mask2) \ for_each_and_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpumas= k_bits) =20 +/** + * for_each_cpu_andnot - iterate over every cpu present in one mask, exclu= ding + * those present in another. + * @cpu: the (optionally unsigned) integer iterator + * @mask1: the first cpumask pointer + * @mask2: the second cpumask pointer + * + * This saves a temporary CPU mask in many places. It is equivalent to: + * struct cpumask tmp; + * cpumask_andnot(&tmp, &mask1, &mask2); + * for_each_cpu(cpu, &tmp) + * ... + * + * After the loop, cpu is >=3D nr_cpu_ids. + */ +#define for_each_cpu_andnot(cpu, mask1, mask2) \ + for_each_andnot_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpu= mask_bits) + /** * cpumask_any_but - return a "random" in a cpumask, but not this one. * @mask: the cpumask to search diff --git a/include/linux/find.h b/include/linux/find.h index 2235af19e7e1..ccaf61a0f5fd 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -498,6 +498,11 @@ unsigned long find_next_bit_le(const void *addr, unsig= ned (bit) =3D find_next_and_bit((addr1), (addr2), (size), (bit)), (bit) = < (size);\ (bit)++) =20 +#define for_each_andnot_bit(bit, addr1, addr2, size) \ + for ((bit) =3D 0; \ + (bit) =3D find_next_andnot_bit((addr1), (addr2), (size), (bit)), (bi= t) < (size);\ + (bit)++) + /* same as for_each_set_bit() but use bit as value to start with */ #define for_each_set_bit_from(bit, addr, size) \ for (; (bit) =3D find_next_bit((addr), (size), (bit)), (bit) < (size); (b= it)++) --=20 2.31.1 From nobody Mon Apr 6 14:56:54 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BD08C433F5 for ; Mon, 3 Oct 2022 15:35:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230201AbiJCPfL (ORCPT ); Mon, 3 Oct 2022 11:35:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230087AbiJCPey (ORCPT ); Mon, 3 Oct 2022 11:34:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0917BBF4C for ; Mon, 3 Oct 2022 08:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664811290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vikRyGRx44R+pUt2VG/nhewaVPQwv7B4yL3TDMhKXBE=; b=FtBxqa/4roFjcquQezFuJgJZ5L/hAIDiF4Atwe94QkXyidYJ9fkevMX2C6Mlx5zDlDYWeZ W6AnVzMqNYxk/A8fKede5QsEbL7bC35wMJ7dFLFRY91K85ZQcDuiYdEgpBL0oSQhguVP9h n74VGn+58jYKRoVoJta4ausjzcolExE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-622--qI3bnORNl-FSTp-GLGv8Q-1; Mon, 03 Oct 2022 11:34:49 -0400 X-MC-Unique: -qI3bnORNl-FSTp-GLGv8Q-1 Received: by mail-wm1-f69.google.com with SMTP id f25-20020a7bc8d9000000b003b4768dcd9cso3001882wml.9 for ; Mon, 03 Oct 2022 08:34:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=vikRyGRx44R+pUt2VG/nhewaVPQwv7B4yL3TDMhKXBE=; b=wEvgQ9xGF4HBJviUdie/mEVlpAoK0fTlicYn21O6tUssZNIIDS/6V43xWbS78g1qZ1 upx7vgdJWIds1HCMNKkI1c5FohgCemGbJdw/K82021Myl35QFFbQa3aCcsoO0o7LY7di d/uj0g4TCLH5ol/dQDvMPoVNzn6myOBWTW2xx/VZ3LbeVtphaxiMqyYjDNWeJwv5zuQw tfu3Yx2rNUrXgBZh3CdZYPh+sUYAMRlgujCmB/bnm2dWAqerA9EOJ2QTNij51NTcpRnN FBqDj7+R42F2tKCZjpExGUqGkMLHB0OszmGQw09jIaO47361oFjzh2hmCCEtU2ofPxvp uviw== X-Gm-Message-State: ACrzQf1YlGeh6tBcReLNrxKraZnewfdWEeYPbY0+6brQSmFlWvIp1oFO iZgKfN1eEMScAsctzQ2Lm4AC9mFIqVxvwiPQPjXP7d3oekau9ebNgi5y7Ml9doy09b6QFCLWBLt QzeatxD7VUZvVeBnOumJ8k4Em X-Received: by 2002:adf:eb83:0:b0:22c:f295:19a5 with SMTP id t3-20020adfeb83000000b0022cf29519a5mr10121221wrn.457.1664811288674; Mon, 03 Oct 2022 08:34:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6AxGBSuoH8QT0vvHb78KjtqGJutdJ99UqNDldM3189qAbHyo5YXUfrzbcxW+MhznI3xOosZw== X-Received: by 2002:adf:eb83:0:b0:22c:f295:19a5 with SMTP id t3-20020adfeb83000000b0022cf29519a5mr10121206wrn.457.1664811288506; Mon, 03 Oct 2022 08:34:48 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id o9-20020a05600c510900b003a5c244fc13sm18343151wms.2.2022.10.03.08.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 08:34:47 -0700 (PDT) From: Valentin Schneider To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Jens Axboe , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Subject: [PATCH bitmap-for-next 4/5] lib/test_cpumask: Add for_each_cpu_and(not) tests Date: Mon, 3 Oct 2022 16:34:19 +0100 Message-Id: <20221003153420.285896-5-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221003153420.285896-1-vschneid@redhat.com> References: <20221003153420.285896-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Following the recent introduction of for_each_andnot(), add some tests to ensure for_each_cpu_and(not) results in the same as iterating over the result of cpumask_and(not)(). Suggested-by: Yury Norov Signed-off-by: Valentin Schneider --- lib/cpumask_kunit.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/cpumask_kunit.c b/lib/cpumask_kunit.c index ecbeec72221e..d1fc6ece21f3 100644 --- a/lib/cpumask_kunit.c +++ b/lib/cpumask_kunit.c @@ -33,6 +33,19 @@ KUNIT_EXPECT_EQ_MSG((test), nr_cpu_ids - mask_weight, iter, MASK_MSG(mas= k)); \ } while (0) =20 +#define EXPECT_FOR_EACH_CPU_OP_EQ(test, op, mask1, mask2) \ + do { \ + const cpumask_t *m1 =3D (mask1); \ + const cpumask_t *m2 =3D (mask2); \ + int weight; \ + int cpu, iter =3D 0; \ + cpumask_##op(&mask_tmp, m1, m2); \ + weight =3D cpumask_weight(&mask_tmp); \ + for_each_cpu_##op(cpu, mask1, mask2) \ + iter++; \ + KUNIT_EXPECT_EQ((test), weight, iter); \ + } while (0) + #define EXPECT_FOR_EACH_CPU_WRAP_EQ(test, mask) \ do { \ const cpumask_t *m =3D (mask); \ @@ -54,6 +67,7 @@ =20 static cpumask_t mask_empty; static cpumask_t mask_all; +static cpumask_t mask_tmp; =20 static void test_cpumask_weight(struct kunit *test) { @@ -101,10 +115,15 @@ static void test_cpumask_iterators(struct kunit *test) EXPECT_FOR_EACH_CPU_EQ(test, &mask_empty); EXPECT_FOR_EACH_CPU_NOT_EQ(test, &mask_empty); EXPECT_FOR_EACH_CPU_WRAP_EQ(test, &mask_empty); + EXPECT_FOR_EACH_CPU_OP_EQ(test, and, &mask_empty, &mask_empty); + EXPECT_FOR_EACH_CPU_OP_EQ(test, and, cpu_possible_mask, &mask_empty); + EXPECT_FOR_EACH_CPU_OP_EQ(test, andnot, &mask_empty, &mask_empty); =20 EXPECT_FOR_EACH_CPU_EQ(test, cpu_possible_mask); EXPECT_FOR_EACH_CPU_NOT_EQ(test, cpu_possible_mask); EXPECT_FOR_EACH_CPU_WRAP_EQ(test, cpu_possible_mask); + EXPECT_FOR_EACH_CPU_OP_EQ(test, and, cpu_possible_mask, cpu_possible_mask= ); + EXPECT_FOR_EACH_CPU_OP_EQ(test, andnot, cpu_possible_mask, &mask_empty); } =20 static void test_cpumask_iterators_builtin(struct kunit *test) --=20 2.31.1 From nobody Mon Apr 6 14:56:54 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ADE9C433F5 for ; Mon, 3 Oct 2022 15:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230256AbiJCPfV (ORCPT ); Mon, 3 Oct 2022 11:35:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230173AbiJCPfC (ORCPT ); Mon, 3 Oct 2022 11:35:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24C3B13FAD for ; Mon, 3 Oct 2022 08:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664811293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9qKy0mrwb1ZaeVcnoJdtpT0vU2IyZpITeq2cNcv3elU=; b=QI25XqqnZfwn7ABQTyB2IwXViyPF3u2viiiAvNC398Tr7O/ATip4pH2ZYtrpsas8Exaoio 9i/xvcEJno+Hoi0dCe9A3igsu49yc6Y4WHbUaj54PVlM3goCTjihspOazx8GfabPvUM43j jgib16ylh9nmjBRWuWtYJYruoz/8Bds= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-492-zFZmoeNEOm-qa0eVyk3b3A-1; Mon, 03 Oct 2022 11:34:52 -0400 X-MC-Unique: zFZmoeNEOm-qa0eVyk3b3A-1 Received: by mail-wm1-f69.google.com with SMTP id y15-20020a1c4b0f000000b003b47578405aso3001918wma.5 for ; Mon, 03 Oct 2022 08:34:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=9qKy0mrwb1ZaeVcnoJdtpT0vU2IyZpITeq2cNcv3elU=; b=3UiYYtNZoL7GZthSKmaLgeHeDjRjygeeTcl2emN2zmUfiWDCY24xnJzkSQdPLTTvF1 TTtN20rw9Ua/FIZoQ49xaPW0jhi39NEKMICQUTcxiAdmYwnrWVMVeULZ0QhxICn2blrw yZylKVBkhmnx0CFF/w3X3vKzED/8BcYFsRipIkHqO54NDE5dxLuwPU1BBbhf2YPoFKYW 8q5ifTp4Bku0/Cll2kP/oF6FUBBUMH9ETA06xu/g6N2pXnodd8c0ZVpRLb3y6zg5XJNs 2j9UkMFtWpXv5n/gx/fz3Z7fUp74CLe4nfDdFzuQYiboLvCG8yrqN2TLIxhaRFw1+BRR F67g== X-Gm-Message-State: ACrzQf3ovnZQQZ5IjP4Kbm+FBVuPR5rsIDGCUC/+nOfM3ZKuMq4D4YDy NEKCmSHpWVNAn6evFaiwSeN7YdTYkJ7aJkkmOdgMCyQzPGHQF4Fesuc1V9vf3tLZGXLuobHcCUR ov9jTDYQisxT293f6faP7V5dh X-Received: by 2002:a5d:588c:0:b0:22b:24d4:d896 with SMTP id n12-20020a5d588c000000b0022b24d4d896mr13440190wrf.611.1664811291126; Mon, 03 Oct 2022 08:34:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7dK79kXgKpUAVjxCPuM7ftmnrqJfkV/6uJjTLHWR/lVxoHiO15CtzuAB4IFYHSYe+goWsQ7g== X-Received: by 2002:a5d:588c:0:b0:22b:24d4:d896 with SMTP id n12-20020a5d588c000000b0022b24d4d896mr13440171wrf.611.1664811290913; Mon, 03 Oct 2022 08:34:50 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id o9-20020a05600c510900b003a5c244fc13sm18343151wms.2.2022.10.03.08.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 08:34:50 -0700 (PDT) From: Valentin Schneider To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Jens Axboe , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Subject: [PATCH bitmap-for-next 5/5] sched/core: Merge cpumask_andnot()+for_each_cpu() into for_each_cpu_andnot() Date: Mon, 3 Oct 2022 16:34:20 +0100 Message-Id: <20221003153420.285896-6-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221003153420.285896-1-vschneid@redhat.com> References: <20221003153420.285896-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This removes the second use of the sched_core_mask temporary mask. Suggested-by: Yury Norov Signed-off-by: Valentin Schneider --- kernel/sched/core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index ee28253c9ac0..b4c3112b0095 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -360,10 +360,7 @@ static void __sched_core_flip(bool enabled) /* * Toggle the offline CPUs. */ - cpumask_copy(&sched_core_mask, cpu_possible_mask); - cpumask_andnot(&sched_core_mask, &sched_core_mask, cpu_online_mask); - - for_each_cpu(cpu, &sched_core_mask) + for_each_cpu_andnot(cpu, cpu_possible_mask, cpu_online_mask) cpu_rq(cpu)->core_enabled =3D enabled; =20 cpus_read_unlock(); --=20 2.31.1