From nobody Mon Apr 6 21:11:05 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 BF7D6C433F5 for ; Thu, 6 Oct 2022 12:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230480AbiJFMWS (ORCPT ); Thu, 6 Oct 2022 08:22:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230413AbiJFMWP (ORCPT ); Thu, 6 Oct 2022 08:22:15 -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 149EA9C23F for ; Thu, 6 Oct 2022 05:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665058934; 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=f4FcB3FE0QSiF1o1I/AAbf5Q+pSSTlAAyOWClq2LzM8=; b=NhrXCDv6DfF2FRnMzT3KToh6mGY54g4n0iBnkg49D/qtuGNGao0Ajh2KEp+T8gxj8gjOzn NwTWz64kEz8yIhhaCXjDPFU253ckF5K8/BHP98/IffIp2Uulj6hr5JwOqOeI1/Mo0pVMjc xUITro9IokH0eTMGD2WX6abO12SdJ3Q= 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-298-X8ubmx5yOwWjBRnjo2Bh9g-1; Thu, 06 Oct 2022 08:22:12 -0400 X-MC-Unique: X8ubmx5yOwWjBRnjo2Bh9g-1 Received: by mail-wr1-f70.google.com with SMTP id n8-20020adf8b08000000b0022e4d3dc8d2so463564wra.7 for ; Thu, 06 Oct 2022 05:22:12 -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:message-id:reply-to; bh=f4FcB3FE0QSiF1o1I/AAbf5Q+pSSTlAAyOWClq2LzM8=; b=5thOFXUar1hmae7SytoLreD3MYNmuN6LMqRaV3r6RLsowMP9SB1CdpeKQOmQuY7NmP dTvK+z+8+rfQ85q1LKelar/PX7W9b6Dka8hJiqdqELJoaXmXjRmZO5aFwUAnKOsmdWDI vhq2xlyOYL2Hn1tr2uOgezKTiVWuYe0EmI93zR0u19O/L0kOx5u+Cblezj921Jzk8iqz xoOD1pFncu7mGTYr8Rhkr+WDZnoUd7OVJyvEHY3EVYO9hSGOgGUvFxQlQpqcMvW5NzRH KkfxsRBjMfvaay4nWUVOCHi555oQkS+81SvLuPf1OBT653shMj74L2Py8Q0cnIsBeST9 BPqQ== X-Gm-Message-State: ACrzQf3K8vvfVI7XAMxeCGz8y+9bhMTYOn47qblZ8eYvgCZTfOAAoj2f f2RqtENult0NxlH9I0rpN/vTaAkksb8ipdW8S52GO7GZoHMPrKQhu7pSEIDwk4zOqg8e6A73msX n5UyEG1y6VDy7Yd14LapSpTBR X-Received: by 2002:adf:ec83:0:b0:22e:51e2:7fc7 with SMTP id z3-20020adfec83000000b0022e51e27fc7mr2889037wrn.229.1665058931880; Thu, 06 Oct 2022 05:22:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5gzmhI49Qj0vN4kOxPftSNmbMO1JiOhVBd+9Ah9pQSqVNkyp/EMjaNKytALAzdnMHBZZV+Vw== X-Received: by 2002:adf:ec83:0:b0:22e:51e2:7fc7 with SMTP id z3-20020adfec83000000b0022e51e27fc7mr2889031wrn.229.1665058931748; Thu, 06 Oct 2022 05:22:11 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id p16-20020a05600c359000b003bdd2add8fcsm5004841wmq.24.2022.10.06.05.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 05:22:10 -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 Subject: [RFC PATCH bitmap-for-next 1/4] lib/cpumask: Generate cpumask_next_wrap() body with a macro Date: Thu, 6 Oct 2022 13:21:09 +0100 Message-Id: <20221006122112.663119-2-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221006122112.663119-1-vschneid@redhat.com> References: <20221006122112.663119-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 cpumask_next_and_wrap(), gather the would-be-boiler-plate logic into a macro, as was done in e79864f3164c ("lib/find_bit: optimize find_next_bit() functions") Signed-off-by: Valentin Schneider --- lib/cpumask.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/cpumask.c b/lib/cpumask.c index c7c392514fd3..6e576485c84f 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -7,8 +7,27 @@ #include #include =20 +#define CPUMASK_NEXT_WRAP(FETCH_NEXT, n, start, wrap) \ +({ \ + unsigned int next; \ + \ +again: \ + next =3D (FETCH_NEXT); \ + \ + if (wrap && n < start && next >=3D start) { \ + next =3D nr_cpumask_bits; \ + } else if (next >=3D nr_cpumask_bits) { \ + wrap =3D true; \ + n =3D -1; \ + goto again; \ + } \ + \ + next; \ +}) + /** - * cpumask_next_wrap - helper to implement for_each_cpu_wrap + * cpumask_next_wrap - Get the next CPU in a mask, starting from a given + * position and wrapping around to visit all CPUs. * @n: the cpu prior to the place to search * @mask: the cpumask pointer * @start: the start point of the iteration @@ -21,21 +40,7 @@ */ unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int star= t, bool wrap) { - unsigned int next; - -again: - next =3D cpumask_next(n, mask); - - if (wrap && n < start && next >=3D start) { - return nr_cpumask_bits; - - } else if (next >=3D nr_cpumask_bits) { - wrap =3D true; - n =3D -1; - goto again; - } - - return next; + return CPUMASK_NEXT_WRAP(cpumask_next(n, mask), n, start, wrap); } EXPORT_SYMBOL(cpumask_next_wrap); =20 --=20 2.31.1 From nobody Mon Apr 6 21:11:05 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 0E2F9C433FE for ; Thu, 6 Oct 2022 12:22:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231174AbiJFMWW (ORCPT ); Thu, 6 Oct 2022 08:22:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbiJFMWR (ORCPT ); Thu, 6 Oct 2022 08:22:17 -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 1C9B69C2D0 for ; Thu, 6 Oct 2022 05:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665058936; 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=curPJ2N237W59qX/Eld5VxS77RbwV2c9wPIACxuEK8E=; b=YJP8Xt/4w9NFu15RQ7bhGSPSAJhsyQdVJT0Xe/hT4Hb3OFC2XH566HJcSfmrw1FXzh118R TCnak8ZjjCjCMOjlo8suxLoEQD7uvE4WrYM40gY+xuY8XkfKNu+/esrP6iyS5nNPvnWt6A KFzZ39D/f297E0593wRcruAGndIWJ4k= 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-316-gpY6XO9_MiutGtFSsbvpEw-1; Thu, 06 Oct 2022 08:22:14 -0400 X-MC-Unique: gpY6XO9_MiutGtFSsbvpEw-1 Received: by mail-wr1-f70.google.com with SMTP id d22-20020adfa356000000b0022e224b21c0so466493wrb.9 for ; Thu, 06 Oct 2022 05:22:14 -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:message-id:reply-to; bh=curPJ2N237W59qX/Eld5VxS77RbwV2c9wPIACxuEK8E=; b=7VPx/SFIWIkCYPxCEf4KFRLsMT4tVK+Ska6mCcGbcrYE3OMucWX5Hbr69aPhMjWzc7 /44QaqxDi7kIc5QWpZb81Yz9egzGN30hmdfPgKUus14z6OFQQRvg8kIeBbbJWjwJAitJ fujB9i/oG7P62RpL1aVW2tJUtV03+wxJEjWW3ynHb2wN3KSj4ySOatck5BGMPjL/q0s9 j6ncNWfq9ptn36JoEopCYpqqQdRPawPy8Tz3mM1/GI04NvV7MUYLCWJ8gAWqGuePxd3q 3gafGCy3JyO6xn4+myxYIWsNKuPFgWd6qrMgWYL7XTlaaAk3DBc0h/hZ6ygCgf4Rglg+ dG2Q== X-Gm-Message-State: ACrzQf2tEzhnorqP8LrASdi0FfZr9c+6NGqxiuf46exaVHqVW8k1asBR Ofv4w9VINq2pLCXWavildjq+FropLAhduiv2MlSrLanOmU0K2UE+SToTUgxHX/LIfpG5cGKl7Yl ApkkLjSeNGktmnkrLT9FYN8cZ X-Received: by 2002:a05:6000:982:b0:229:79e5:6a96 with SMTP id by2-20020a056000098200b0022979e56a96mr2935627wrb.469.1665058933635; Thu, 06 Oct 2022 05:22:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6cBRqvDWKL6nogwn4jWqQOUP5QiNmUXGk3gstAcZf9U2hKbplHB+q+pomjYcPJEtgFuQ/ajw== X-Received: by 2002:a05:6000:982:b0:229:79e5:6a96 with SMTP id by2-20020a056000098200b0022979e56a96mr2935618wrb.469.1665058933480; Thu, 06 Oct 2022 05:22:13 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id p16-20020a05600c359000b003bdd2add8fcsm5004841wmq.24.2022.10.06.05.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 05:22:12 -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 Subject: [RFC PATCH bitmap-for-next 2/4] lib/cpumask: Fix cpumask_check() warning in cpumask_next_wrap*() Date: Thu, 6 Oct 2022 13:21:10 +0100 Message-Id: <20221006122112.663119-3-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221006122112.663119-1-vschneid@redhat.com> References: <20221006122112.663119-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" Invoking cpumask_next*() with n=3D=3Dnr_cpu_ids-1 triggers a warning as the= re are (obviously) no more valid CPU ids after that. This is however undesired for the cpumask_next_wrap*() family which needs to wrap around reaching this condition. Don't invoke cpumask_next*() when n=3D=3Dnr_cpu_ids, go for the wrapping (if any) instead. NOTE: this only fixes the NR_CPUS>1 variants. Signed-off-by: Valentin Schneider --- lib/cpumask.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cpumask.c b/lib/cpumask.c index 6e576485c84f..f8174fa3d752 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -12,11 +12,11 @@ unsigned int next; \ \ again: \ - next =3D (FETCH_NEXT); \ + next =3D n =3D=3D nr_cpu_ids - 1 ? nr_cpu_ids : (FETCH_NEXT); \ \ if (wrap && n < start && next >=3D start) { \ - next =3D nr_cpumask_bits; \ - } else if (next >=3D nr_cpumask_bits) { \ + next =3D nr_cpu_ids; \ + } else if (next >=3D nr_cpu_ids) { \ wrap =3D true; \ n =3D -1; \ goto again; \ --=20 2.31.1 From nobody Mon Apr 6 21:11:05 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 DB537C433F5 for ; Thu, 6 Oct 2022 12:22:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230477AbiJFMW0 (ORCPT ); Thu, 6 Oct 2022 08:22:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231147AbiJFMWV (ORCPT ); Thu, 6 Oct 2022 08:22:21 -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 D4F8E9E0C3 for ; Thu, 6 Oct 2022 05:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665058938; 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=Sd3ek9lr0+3lr0pFZrCWvq5bzuM9iwLSGj27oiriJtw=; b=U78xo8ieNCU/HbEM2WA7cHovrxqyIg4XrJHDSmOg/aE10Al7G6JOXyyREJUJclrjxjDW4V 8rJ9lBZqoWggDqVszw8OqE4vvK4NPqf2ZY41VUklcJoSIYGK7Re9o6xyQtgII9Hb9M1TQB SHg7KWGtB3XsapCur2cLU3IW3Iqfsi8= 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-462-p2JCQ44zPWKUra7Sji7BVQ-1; Thu, 06 Oct 2022 08:22:16 -0400 X-MC-Unique: p2JCQ44zPWKUra7Sji7BVQ-1 Received: by mail-wm1-f69.google.com with SMTP id l1-20020a7bc341000000b003bfe1273d6cso502708wmj.4 for ; Thu, 06 Oct 2022 05:22:16 -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:message-id:reply-to; bh=Sd3ek9lr0+3lr0pFZrCWvq5bzuM9iwLSGj27oiriJtw=; b=OhT2FuJfbvpovVif0bpmWgf2w+49fJVDD3RUpKkzG2+PeBNJqkE9GFO+zYntZPGAC6 /uK83TUdT0thqIs+YLgOF8d7qhua2iPPHdoDBb3XOoUzbT985ewQpAS9RQ1f6E5y2ssP EGrMuWPrKYOfIIZWyr55PE7fisY2qJQ1md7ff4ZOzzKak3h+OFLWVg/nDySTWX3+bHE9 iesmhr/KQBv0peirqKAqNNHuGvSjkEFQZJ443DbFlqyS+xFHpgWA1pTg51V+8vElWPYs ugZaMQZEj/YR6K7EgkPMjhTnHr/mXGL39FRswNl5DJUfAw8LAwn3vAVBng+fK39BrEwR YFbQ== X-Gm-Message-State: ACrzQf3c11oiKI77TtnKPZ59VkptFHFeFnZmHzpSkjuVCfi+zVZe7vWz 5yblsHTOuTJie6ug63otsE6faULXgDIFAQty3NECF6bppTz3Sb3rTyIKq0b+H2d1U6FtOV490HZ v1HuyYvMM/d4CQVZnjE0KH/bh X-Received: by 2002:a05:6000:1d8d:b0:22e:6371:65b6 with SMTP id bk13-20020a0560001d8d00b0022e637165b6mr3047106wrb.657.1665058935156; Thu, 06 Oct 2022 05:22:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CgZbASqqSidmHgofT701/lhaYz5Pr8fVsGmau+bso0aHUIBuOg2UB+JmzaIBsI+vIRTA21w== X-Received: by 2002:a05:6000:1d8d:b0:22e:6371:65b6 with SMTP id bk13-20020a0560001d8d00b0022e637165b6mr3047091wrb.657.1665058934983; Thu, 06 Oct 2022 05:22:14 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id p16-20020a05600c359000b003bdd2add8fcsm5004841wmq.24.2022.10.06.05.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 05:22:13 -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 Subject: [RFC PATCH bitmap-for-next 3/4] lib/cpumask: Introduce cpumask_next_and_wrap() Date: Thu, 6 Oct 2022 13:21:11 +0100 Message-Id: <20221006122112.663119-4-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221006122112.663119-1-vschneid@redhat.com> References: <20221006122112.663119-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 leverages the newly-introduced CPUMASK_NEXT_WRAP() macro. Signed-off-by: Valentin Schneider --- include/linux/cpumask.h | 22 ++++++++++++++++++++++ lib/cpumask.c | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 286804bfe3b7..e0b674263e57 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -272,8 +272,30 @@ unsigned int cpumask_next_wrap(int n, const struct cpu= mask *mask, int start, boo =20 return cpumask_first(mask); } +static inline unsigned int cpumask_next_and_wrap(int n, + const struct cpumask *mask1, + const struct cpumask *mask2, + int start, bool wrap) +{ + cpumask_check(start); + /* n is a prior cpu */ + cpumask_check(n + 1); + + /* + * Return the first available CPU when wrapping, or when starting before = cpu0, + * since there is only one valid option. + */ + if (wrap && n >=3D 0) + return nr_cpumask_bits; + + return cpumask_first_and(mask1, mask2); +} #else unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, i= nt start, bool wrap); +unsigned int __pure cpumask_next_and_wrap(int n, + const struct cpumask *mask1, + const struct cpumask *mask2, + int start, bool wrap); #endif =20 /** diff --git a/lib/cpumask.c b/lib/cpumask.c index f8174fa3d752..c689348df0bf 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -44,6 +44,29 @@ unsigned int cpumask_next_wrap(int n, const struct cpuma= sk *mask, int start, boo } EXPORT_SYMBOL(cpumask_next_wrap); =20 +/** + * cpumask_next_and_wrap - Get the next CPU in a mask, starting from a giv= en + * position and wrapping around to visit all CPUs. + * @n: the cpu prior to the place to search + * @mask1: the first cpumask pointer + * @mask2: the second cpumask pointer + * @start: the start point of the iteration + * @wrap: assume @n crossing @start terminates the iteration + * + * Returns >=3D nr_cpu_ids on completion + * + * Note: the @wrap argument is required for the start condition when + * we cannot assume @start is set in @mask. + */ +unsigned int cpumask_next_and_wrap(int n, + const struct cpumask *mask1, + const struct cpumask *mask2, + int start, bool wrap) +{ + return CPUMASK_NEXT_WRAP(cpumask_next_and(n, mask1, mask2), n, start, wra= p); +} +EXPORT_SYMBOL(cpumask_next_and_wrap); + /* These are not inline because of header tangles. */ #ifdef CONFIG_CPUMASK_OFFSTACK /** --=20 2.31.1 From nobody Mon Apr 6 21:11:05 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 3F94AC433F5 for ; Thu, 6 Oct 2022 12:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231335AbiJFMWd (ORCPT ); Thu, 6 Oct 2022 08:22:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbiJFMWX (ORCPT ); Thu, 6 Oct 2022 08:22:23 -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 122779E0D2 for ; Thu, 6 Oct 2022 05:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665058939; 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=VyLNJ3Q8dO/0vKh1HIe/nO5H/c5qCfiPxqiFfqkNSWk=; b=A1ePRC5HKMowZ0/giYexFf3tx/ZdLi2yFa7PNcdlwPGl7N+57LAqp0BD4mgDXuKXbKSqFi yza5H335XZ+iyMrhSH52Rzfue+lMlyaOu5Ek+qoHzO4oc5VML/dsV++vI2Vau+me2AD/mB fr73Oa2duTn9Rl70UWJcBISXjWIGoGg= 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-481-gozsNrFrNJqAEfZRQZIqoA-1; Thu, 06 Oct 2022 08:22:18 -0400 X-MC-Unique: gozsNrFrNJqAEfZRQZIqoA-1 Received: by mail-wm1-f71.google.com with SMTP id v191-20020a1cacc8000000b003bdf7b78dccso954602wme.3 for ; Thu, 06 Oct 2022 05:22:17 -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:message-id:reply-to; bh=VyLNJ3Q8dO/0vKh1HIe/nO5H/c5qCfiPxqiFfqkNSWk=; b=QsxHdj8jQGkxsoK8qeKzYXBbsAUYDK+TxvFQnwU9rTLpdVD/tbqDnET9RZQvVVHzDk zaP15JP+p4CCHz66uynBXM9YGrGjd1lH1YV1cil558qzEIcbXGh/1VtSv5udshSI3J2l iJSN+znLhIUpQnKdanaqJF+Rj5sBuvq4O7ueErbA33rWGd++iGp0ehMIFuNWYPSulP+v HOHTiJ/AHWit8Hia8DSV8B3UqJON/AP2/H/ycYHDhLiiM+BttgafGE/HrGEtg2jrzNYS chV9KlNLU9zvcBkMiOCyI9/sew3hNk4QvpxOChuN9DnVvbF3AJ+9UvrrsuSzTjtBY+1y HJng== X-Gm-Message-State: ACrzQf2ZXEeEe1kCmt8q+IVamCd7hfqJQaP1+OA+V5PIwebYU5Qd3K0L iXzhBIZpRhvCiGGv93vVVwM2tAKi0cYI3E0DiG24z6jWq8ypE520QSDm/QK3JMkK3tLHw57KVWU /fBMmIqog8281SimCQSrvrK2v X-Received: by 2002:a7b:cb56:0:b0:3b3:4ad8:9e31 with SMTP id v22-20020a7bcb56000000b003b34ad89e31mr3011936wmj.87.1665058936811; Thu, 06 Oct 2022 05:22:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qWsAUUYKzD5ctEpWK6L/j4O461FW/w/5nPtaXdKtNtdlZORmxI4PlTdF8RnFxVcoKWbiuLg== X-Received: by 2002:a7b:cb56:0:b0:3b3:4ad8:9e31 with SMTP id v22-20020a7bcb56000000b003b34ad89e31mr3011921wmj.87.1665058936626; Thu, 06 Oct 2022 05:22:16 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id p16-20020a05600c359000b003bdd2add8fcsm5004841wmq.24.2022.10.06.05.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 05:22:15 -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 Subject: [RFC PATCH bitmap-for-next 4/4] blk_mq: Fix cpumask_check() warning in blk_mq_hctx_next_cpu() Date: Thu, 6 Oct 2022 13:21:12 +0100 Message-Id: <20221006122112.663119-5-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221006122112.663119-1-vschneid@redhat.com> References: <20221006122112.663119-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" blk_mq_hctx_next_cpu() implements a form of cpumask_next_and_wrap() using cpumask_next_and_cpu() and blk_mq_first_mapped_cpu(): [ 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 [...] This triggers a warning when next_cpu =3D=3D nr_cpu_ids - 1, so rewrite it using cpumask_next_and_wrap() directly. The backwards-going goto can be removed, as the cpumask_next*() operation already ANDs hctx->cpumask and cpu_online_mask, which implies checking for an online CPU. No change in behaviour intended. Suggested-by: Yury Norov Signed-off-by: Valentin Schneider --- block/blk-mq.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index c96c8c4f751b..1520794dd9ea 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2038,42 +2038,29 @@ static inline int blk_mq_first_mapped_cpu(struct bl= k_mq_hw_ctx *hctx) */ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx) { - bool tried =3D false; int next_cpu =3D hctx->next_cpu; =20 if (hctx->queue->nr_hw_queues =3D=3D 1) return WORK_CPU_UNBOUND; =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 nr_cpu_ids) - next_cpu =3D blk_mq_first_mapped_cpu(hctx); + if (--hctx->next_cpu_batch > 0 && cpu_online(next_cpu)) + return next_cpu; + + next_cpu =3D cpumask_next_and_wrap(next_cpu, hctx->cpumask, cpu_online_ma= sk, next_cpu, false); + if (next_cpu < nr_cpu_ids) { hctx->next_cpu_batch =3D BLK_MQ_CPU_WORK_BATCH; + hctx->next_cpu =3D next_cpu; + return next_cpu; } =20 /* - * Do unbound schedule if we can't find a online CPU for this hctx, - * and it should only happen in the path of handling CPU DEAD. + * No other online CPU in hctx->cpumask. + * + * Make sure to re-select CPU next time once after CPUs + * in hctx->cpumask become online again. */ - if (!cpu_online(next_cpu)) { - if (!tried) { - tried =3D true; - goto select_cpu; - } - - /* - * Make sure to re-select CPU next time once after CPUs - * in hctx->cpumask become online again. - */ - hctx->next_cpu =3D next_cpu; - hctx->next_cpu_batch =3D 1; - return WORK_CPU_UNBOUND; - } - - hctx->next_cpu =3D next_cpu; - return next_cpu; + hctx->next_cpu_batch =3D 1; + return WORK_CPU_UNBOUND; } =20 /** --=20 2.31.1