From patchwork Mon Oct 3 15:34:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12997632 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 4D236C433F5 for ; Mon, 3 Oct 2022 15:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230273AbiJCPfa (ORCPT ); Mon, 3 Oct 2022 11:35:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230154AbiJCPfG (ORCPT ); Mon, 3 Oct 2022 11:35:06 -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 25A9725EB3 for ; Mon, 3 Oct 2022 08:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664811302; 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=a/2OH7n3+yqVlt+qmH3UHKNaCoEIDNV9r74fB+ENQacdkudiwuw6aTPKXG1WvQinVr18LA uIApPhvrEQz1yaCxNhjPmg01eRfa7dF5sJAXDngngSgPbK1TlMtIzo1hYVNvE2ccqE+uKj g1Sbr4sYNPfNKRtHVno0BaUN+COe7/M= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-219-IXFwcWaTMASzKzXaOzXnqQ-1; Mon, 03 Oct 2022 11:34:50 -0400 X-MC-Unique: IXFwcWaTMASzKzXaOzXnqQ-1 Received: by mail-wm1-f72.google.com with SMTP id h133-20020a1c218b000000b003b3263d477eso6443854wmh.8 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=oWOqPdzz+AOyEfIa1cY7i8I3ux/rXzCxmRQdz32dUHelzgz8nGglPp/kqIatAfhIb2 5g+2MjXxF72vzB+wNEhuICeKlex4jRc9MGZtyQBLKjJcTGUo+2h1sDUdlo5bPHX8LskY QhVruH39j3qudN/nBWsl7x1dcgDXaL7wiJUWUW3SP2HVz3J1aHCJA68RP7qpXHrAgSwb KqNZSdSW/1WtcbtGJI3eDTp4eg8PR4q6nPQBdkY5kJlZyVRrAIQe20zr/NBEkAFxcGBe ksRXiTMS7lYzHDIRVm4zDsUxtF7pCLnNHjGuOCKTVlBRx4ikEW4Hu0sSz7ZHWZvrPt17 Pjiw== X-Gm-Message-State: ACrzQf3yJfZoVbOrblsK0dpJJWpvzH9ozGIgERK/KCAvG9AsX9TUEYjH XvflG5iysmWuoz157oxRGgGB7XUzMWhKqa8DdPRx60ieadEJbm5R6nXqltIe7yY7oxWf1qaegBq LpeI3Bjx8W7Hcm87gfnbEHBor686EX4hEWaABq6p5NfLx08YsViwG9w7X+M+2qGYaZisv9btcSn w= X-Received: by 2002:a05:600c:3511:b0:3b4:bb85:f1e3 with SMTP id h17-20020a05600c351100b003b4bb85f1e3mr7402342wmq.0.1664811282760; 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 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org A recent commit made cpumask_next*() trigger a warning when passed n = 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 __blk_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) if (--hctx->next_cpu_batch <= 0) { select_cpu: - next_cpu = cpumask_next_and(next_cpu, hctx->cpumask, - cpu_online_mask); + if (next_cpu == nr_cpu_ids - 1) + next_cpu = nr_cpu_ids; + else + next_cpu = cpumask_next_and(next_cpu, + hctx->cpumask, + cpu_online_mask); + if (next_cpu >= nr_cpu_ids) next_cpu = blk_mq_first_mapped_cpu(hctx); hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH; From patchwork Mon Oct 3 15:34:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12997627 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 48939C433F5 for ; Mon, 3 Oct 2022 15:35:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbiJCPfD (ORCPT ); Mon, 3 Oct 2022 11:35:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbiJCPey (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 0D7A4E0BC for ; Mon, 3 Oct 2022 08:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664811289; 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=E8L46M8xFNyjN2Qr9c4c8hrLyy9f636dN/BUWTcfZFKdqj2FwLYul2BFpnjmjALYDArRA2 ecdu/MihLUjHwBwNeLC4YZ7wmm4NNS8K6V7pcejASXDYlWy+F3KoBV6ney6wicghbJSkFb xMJvon6BCPs2EP9bDYstGeal7kcaCYk= 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-118-wfCtX7bPM5OzAWLat16njg-1; Mon, 03 Oct 2022 11:34:48 -0400 X-MC-Unique: wfCtX7bPM5OzAWLat16njg-1 Received: by mail-wr1-f70.google.com with SMTP id d22-20020adfa356000000b0022e224b21c0so1531498wrb.9 for ; Mon, 03 Oct 2022 08:34:48 -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=qQNcrch/A6QcY9MwylRNPOJKKuen7WsGZACc+TJUAUBY2AnE1Ilmw3aJlk+NsIOfAC T8zzdTA44A9NvFMgmMdNXCJwwEa7eFmFf1wi75lx47Y9SA4XPPlRE+uUv2II7CcBKz+c 60+Vdbf5P/IMjd4n7Pj+k8cevDzENCjH5YVZXYuDfVZKZUNxltnRh/dS5YT3XxKigqq+ JGTh727Qbfkvn6zs/PUek8RaZExAz1eX5YnFz5oV8kiX3oRNNCKzDwcSXFV+twS4GauU /P3XJXxm2KAnJ/+vAkRAFTfNjnD/T7lQX8gr2kkZAO/EhPvbmjex5kP7h68TJedpw7X6 3Sxw== X-Gm-Message-State: ACrzQf2VYYZAzKGY7hHyhBqndjhBk/u/LKYdrQ+UwcXFayCnWgyPvmv8 DWv/H7zlitH9pKSyPhlCC4Gi0BqGJYHOf47xPeBQNAs3H60dgLvocmLqGlrlYy+welfJQ1AfbZE kx0VZL6d4H2wrpj46+7pHv2WWJXCL2Y0oZbzBjYI7jH9Xssl66TqlNCqTl3fqa1ya11FMPp8I5i E= X-Received: by 2002:a05:600c:4fd1:b0:3b4:c00d:230a with SMTP id o17-20020a05600c4fd100b003b4c00d230amr7086599wmq.62.1664811285194; 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 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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 unsigned long *addr2, unsigned long nbits, unsigned long start); +unsigned long _find_next_andnot_bit(const unsigned long *addr1, const unsigned 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 long size); @@ -91,6 +93,37 @@ unsigned long find_next_and_bit(const unsigned long *addr1, } #endif +#ifndef find_next_andnot_bit +/** + * find_next_andnot_bit - find the next set bit in *addr1 excluding all the 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 >= size)) + return size; + + val = *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 +#ifndef find_next_andnot_bit +unsigned long _find_next_andnot_bit(const unsigned long *addr1, const unsigned 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) From patchwork Mon Oct 3 15:34:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12997628 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 21608C433FE for ; Mon, 3 Oct 2022 15:35:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230206AbiJCPfE (ORCPT ); Mon, 3 Oct 2022 11:35:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbiJCPey (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 0D887E0D7 for ; Mon, 3 Oct 2022 08:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664811289; 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=f0ng6bSQCAhh0vf/xhbANNUJ9eS4A0JArZE9VRV0lcgMWxcEm/hdJGPMGfqKST6VN6UwO2 njI6yI3/2fGPw1X1MX+N908d+tmKaN2iSQPokBTIh3DSgJnSzjszVjmRc5mnmZ82u7EcPy DtBGxMhHjPTdbHOm+u4kchVr6smhvK4= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-379-bp19qoVrM9WGUHIMhhozcQ-1; Mon, 03 Oct 2022 11:34:48 -0400 X-MC-Unique: bp19qoVrM9WGUHIMhhozcQ-1 Received: by mail-wr1-f71.google.com with SMTP id d22-20020adfa356000000b0022e224b21c0so1531524wrb.9 for ; Mon, 03 Oct 2022 08:34:48 -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=H2Kk+trJ+SwmkjkV3aZm6H5gXHI3qF9qE8uM7fgCDif51ZR6T83xxkOc8f6fbIacon CebyTo5CzONbm2tXqgLhHyZh0iHkVpV9/nDECuJk/i0oJJVXlPKA0e8FCGHXqUASC16c eBmE0EI+sZfc6gJh7zDoRZh+ocmylIS4fuJV2vsNHaEa17D5tJTcR4cMiYQHavwgZvu0 Sbshj/BLka2yI4ka7RTEXT4efVVKxBHeO/enxTkguCJ5PE/B4LvTLvihjfmON8jU32p/ +9kt2aq5lLnhig4jyXvAlx+5cL5WhuW6mNbjiO+bLSsBrf9w9U+9dYqFiOyqfKxf+71j lmXw== X-Gm-Message-State: ACrzQf32QKN7LPisxkGyNeV5Y5K9b+vaa2/89GxN1+H8e3wrZ1BGlsGa 1CBW+HJrM8ObpXhxKj4bq3JXX7+pMnaNKxJfCm3uW0y6oqwbaLX0dWLeN3+adot7nxOs3FSrUoB l6xLECiyK5AGTzRRnQN8isTfFuXrvHeVCjl43aFcintBzCwNm0PL+Q6lbLMrLe4NL8+gHdpJwXA c= X-Received: by 2002:a05:600c:3d0c:b0:3b4:c481:c63b with SMTP id bh12-20020a05600c3d0c00b003b4c481c63bmr6941554wmb.147.1664811286863; 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 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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 struct cpumask *mask, int sta #define for_each_cpu_and(cpu, mask1, mask2) \ for_each_and_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpumask_bits) +/** + * for_each_cpu_andnot - iterate over every cpu present in one mask, excluding + * 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 >= nr_cpu_ids. + */ +#define for_each_cpu_andnot(cpu, mask1, mask2) \ + for_each_andnot_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpumask_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, unsigned (bit) = find_next_and_bit((addr1), (addr2), (size), (bit)), (bit) < (size);\ (bit)++) +#define for_each_andnot_bit(bit, addr1, addr2, size) \ + for ((bit) = 0; \ + (bit) = find_next_andnot_bit((addr1), (addr2), (size), (bit)), (bit) < (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) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++) From patchwork Mon Oct 3 15:34:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12997629 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 A92A2C433F5 for ; Mon, 3 Oct 2022 15:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbiJCPfF (ORCPT ); Mon, 3 Oct 2022 11:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbiJCPfA (ORCPT ); Mon, 3 Oct 2022 11:35:00 -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 9D77DFD06 for ; Mon, 3 Oct 2022 08:34:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664811291; 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=DR4qGZbbRuMkhMlPVByMnA+uamgVMf3Vcdcp81DiCW1Z+Ek/1PzmEVg2gqBRKO9MkNEmZT p93//iOTEw4Mqhk1db2LD5+DR9I3iA5DH3nIvp+uCFbw1SK2QER9AJl/fre0UofbkQ7N5C 2HFThS4dka70OQRpgsc3EWIyuMUz6lU= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-22-VpjnbryQNpaaGOlZ6uMR1Q-1; Mon, 03 Oct 2022 11:34:50 -0400 X-MC-Unique: VpjnbryQNpaaGOlZ6uMR1Q-1 Received: by mail-wm1-f71.google.com with SMTP id y20-20020a05600c365400b003b4d4ae666fso3001209wmq.4 for ; Mon, 03 Oct 2022 08:34:50 -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=J5KQob6XIuGpzqD+sTAbBRlxP22J3n6xxM6kQgjoDGPhgV88O781il4QWfkMSEZ25t BtTziECo4LbuuEMlSWZt/ylG1ZbyiSbJ1hKBWKJC0CTGR0142BAqNA81WVnBCaUGGMhH uqlDl4mcP6CgwGSkQkhQg70RJw6g0d8z5Icl1kuyYbIwkAgwtLjaoKz0RLd7J/L17Y70 q0P2ypzDveTIZuCWpDyhJGTmyzIUuhCS24ZWvu2svjqC05MweOy+HSaQBSttG7J4IKgf SCLWVwbyXVOitCGO0DaID7r0YBCpurs2x7W0CHgc3gX7faV/4oAqkWLfo/AQ1aIOmWBY z+zw== X-Gm-Message-State: ACrzQf1JuRxQByTCf6hfmiaA4wVJavsnzxwj6U19TdJ66oFeB8C4iSyZ z7lSZ1PztjqxtY9d4ynwyA7QcjcJ0T9xgL9HOlDIBC5EyvvOz0rF8QadS2h1UNiUdyneU1BmyMW aOo/tC/YmeAHb0yNzdenafDqTC6ezqw7NWNKUvGcsKItbb1uLAvjKBqX0x0nEhc/KNXbLITvf7R k= X-Received: by 2002:adf:eb83:0:b0:22c:f295:19a5 with SMTP id t3-20020adfeb83000000b0022cf29519a5mr10121233wrn.457.1664811288706; 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 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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(mask)); \ } while (0) +#define EXPECT_FOR_EACH_CPU_OP_EQ(test, op, mask1, mask2) \ + do { \ + const cpumask_t *m1 = (mask1); \ + const cpumask_t *m2 = (mask2); \ + int weight; \ + int cpu, iter = 0; \ + cpumask_##op(&mask_tmp, m1, m2); \ + weight = 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 = (mask); \ @@ -54,6 +67,7 @@ static cpumask_t mask_empty; static cpumask_t mask_all; +static cpumask_t mask_tmp; 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); 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); } static void test_cpumask_iterators_builtin(struct kunit *test) From patchwork Mon Oct 3 15:34:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12997631 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 4BDBEC433FE for ; Mon, 3 Oct 2022 15:35:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229862AbiJCPfJ (ORCPT ); Mon, 3 Oct 2022 11:35:09 -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 S230170AbiJCPfC (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.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB14615729 for ; Mon, 3 Oct 2022 08:34:54 -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-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-113-KEkOcCM2PdifNFHJk09eNw-1; Mon, 03 Oct 2022 11:34:52 -0400 X-MC-Unique: KEkOcCM2PdifNFHJk09eNw-1 Received: by mail-wr1-f72.google.com with SMTP id s5-20020adf9785000000b0022e1af0e7e8so1584987wrb.11 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=UXC037ch7s5/9PBYQQ2MmJiIwJjEDFBXTLxlq52wKFs7a5ldnYuQ0daYHko8VgScnY +UpFkRmQ+TFpKMgyLESNFLL9s187YumHh4qqKBIDCDgS/4YYeNfM/ayr5D34jEj9G+NW gT2LikMQ4qMFN+jHZMeRSJRgVLdyTpImFlUZPlTZXxriQ6/9NbJVWFpP8fFAr/hcElLk uDRTSNzaQGmIz2F/OSCuAR593gQWIu7XCNkGjGebErJK/ydJdPalKEp6iHR3LthPLzXl 6nfCP50wyiLv3ZiDZCPeWs7NnrFrD9p2EGPIfqwgdJZevTdtT4N9QIRCZWW2MLp1EDAS csFw== X-Gm-Message-State: ACrzQf3t4DRok2VyrJ/QdrJ3Kqd8kqwMUMi4tP+Mk4FevhDZ1iQqOVxU gQqTIhLYulaLUYoYgaUiybJbTbvxkoRXlbj506BvtQGEV+Oumcxr5Zw6XDSAvkEnGcExg/necci H3EhK+z3Jr++QKWTyx7+XXhgdCbUlu8hS+tPTAgfx+OetfA9PWIBmwC4A8Owx3YNpRsw1htfPjN o= X-Received: by 2002:a5d:588c:0:b0:22b:24d4:d896 with SMTP id n12-20020a5d588c000000b0022b24d4d896mr13440200wrf.611.1664811291163; 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 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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 = enabled; cpus_read_unlock();