Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4376100rdb; Mon, 11 Dec 2023 18:30:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/Y0iqxbWRGSEquxax7dfMXuHZ8Wy3TRPgVIWhxjBn0syyxPMVXzwF3yLt3At/hxY1hBv9 X-Received: by 2002:a05:6e02:20c5:b0:35d:693a:432a with SMTP id 5-20020a056e0220c500b0035d693a432amr8705671ilq.3.1702348200378; Mon, 11 Dec 2023 18:30:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702348200; cv=none; d=google.com; s=arc-20160816; b=i4l72Ua1/+eaJbt51tvxtIMZla2EibiUd/WSfDHCwExfuyleRmnpQGP9E+XRC+1BlX tuYOKtrNAFlgDwqPmGHP0EoTkoalZEZVLF8wy/H7/jy/nlH4yuHXxNccv7wzkyfNkM9x 9wCJ6TIpDvS5cqM2K3ojVqu5uRQ7cEGYNpvwjf8Jojb0vE6nP8mlyW+2UMcfzERX+8oX vQlmLQ2YXBIdNTvq9HZ+285i2MK4z02guWhkIIzA1F3lAG1Eq7AKlRp6ogAPBZsp7Pf9 gyxJvQRn/flNysqGTRuV0iSGMt8eccaOrhOpfMWHBzz5aafwcDGuHMygh8XP1MXxVZxt 0Y9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2naZtSkEf1NcPMGJshyYFtrlJjtShUpPX2HAHwMhtPE=; fh=hv3iqpMdHO6W1M6pRceemuYd1xn4mjvHm+q4POPI+5A=; b=XSrpPVEK+B9iXGGq1IJPfgGkbmSYAjKERpS1eDIkpq4CwUxTj4A2b5KkyMbPm89Sx/ cPy75uuZOwo6y4fJGvaPGfAPorx/BaIiEjjgXEns0teZVMGQRMAzMpmFAjkHHeS2V8+c wqhj3O7N6M2UEu83iQCov7oOx2aFtbUCDrk72uxl3aPVBiva/BXG4g0m5Sbl11+tXFlL ZLArMYXbsPWCUb2GjJvjWUW1/mYzLGn7V9PP16SMDwUW/UHBDMu2V0aQ0dMyjqCDJVd8 AYiNvQg/tTHKVyoiTXopZ9sM8eDK/T1ocxkU+fV4Di3VIiLsCkjh7fxwPSu49oCrWd4D D9rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ci6rj3Le; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id jc1-20020a17090325c100b001cc0cd0772dsi6878852plb.86.2023.12.11.18.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:30:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ci6rj3Le; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 6E05680D2932; Mon, 11 Dec 2023 18:29:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345899AbjLLC3M (ORCPT + 99 others); Mon, 11 Dec 2023 21:29:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345788AbjLLC2p (ORCPT ); Mon, 11 Dec 2023 21:28:45 -0500 Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9629112A; Mon, 11 Dec 2023 18:28:30 -0800 (PST) Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-5e196c128fcso7854147b3.1; Mon, 11 Dec 2023 18:28:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702348109; x=1702952909; 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=2naZtSkEf1NcPMGJshyYFtrlJjtShUpPX2HAHwMhtPE=; b=Ci6rj3LeDWNP6MoXDX8OdHwssAKHiA07o9+ThUiV9mRJ2ptrlnOOvizX9gFhIu5cM0 BogueEGjBDU4xlPVfPPKRbK5h0cvkhDRK8IWomtbF5rowcNrfsS+53wBecVaOEGwzwmX kGMOejEn2+CZXJqClQarnt9x/5TVta8PhiSgaHJGwOgAL6vLbbR3Rwjyps3rgFlQrGCu mBGOJEt6tNHfq9ZTT2CLkk73UwEPSa+JZq/KeVKuom0sIHaI63W5QRgsyeZB7mlzS1Wc bc4+a3gOzURBNi0r0qZb2qNbeDvLo+cnAajXF9ea0LOOyKEA7G4raEBBKvkDYxHIeq12 mfcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702348109; x=1702952909; 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=2naZtSkEf1NcPMGJshyYFtrlJjtShUpPX2HAHwMhtPE=; b=Ev5hvb5GpU8kqSMlxq35m5Fz1ACYLooq5a+f89dvp8yob7iProO9NHqfWK7yMuBT/u s6NWw3JxHV4+LbZY6oik2TCaw9z4JcXKtoWTSTBj7Zez+rALE1+Y8UM+tWqLi9H9bXrJ VD5hFxRSqF8HBjje2Ql9IYO6CuFKvVj8AtRyaz4dcSZOs7fhn4DUtaBjHxSr33R3k1i6 nU5UHMFbyTGa4AOaEkn/GLFESPsHpxTy8sVOMOgGB15cZ6XSCgBjVhzw8Gj5WUOfHeL2 otdXLkMu/hDpwrEye3UcQ6X6HG1w4/TFIwLPT9v+Rerme4v/3BI/Lfh1LOCncpZTUViI 6Xrg== X-Gm-Message-State: AOJu0Yxj2QX7SBeEPaEMFrzdtGTlpnU0Lkq4n+vqISyeIsxjD/6V+GCq siyEaZ3vcbq+ELYqgDDg9lpRS//J0EThpg== X-Received: by 2002:a81:8395:0:b0:5ca:4db5:6962 with SMTP id t143-20020a818395000000b005ca4db56962mr4232765ywf.46.1702348109282; Mon, 11 Dec 2023 18:28:29 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id u13-20020a81a50d000000b005cc8b377fe9sm3395826ywg.121.2023.12.11.18.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:28:28 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, Jens Axboe , Damien Le Moal , Chaitanya Kulkarni , Ming Lei , Johannes Thumshirn , Chengming Zhou , Nitesh Shetty , Akinobu Mita , Shin'ichiro Kawasaki , Yury Norov , linux-block@vger.kernel.org Cc: Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov , Bart Van Assche , Sergey Shtylyov Subject: [PATCH v3 24/35] block: null_blk: replace get_tag() with a generic find_and_set_bit_lock() Date: Mon, 11 Dec 2023 18:27:38 -0800 Message-Id: <20231212022749.625238-25-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212022749.625238-1-yury.norov@gmail.com> References: <20231212022749.625238-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 11 Dec 2023 18:29:54 -0800 (PST) get_tag() opencodes find_and_set_bit(). Simplify the code by getting rid of it. Signed-off-by: Yury Norov Reviewed-by: Chengming Zhou Reviewed-by: Jan Kara --- drivers/block/null_blk/main.c | 41 +++++++++++------------------------ 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 3021d58ca51c..671dbb9ab928 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -760,19 +760,6 @@ static void put_tag(struct nullb_queue *nq, unsigned int tag) wake_up(&nq->wait); } -static unsigned int get_tag(struct nullb_queue *nq) -{ - unsigned int tag; - - do { - tag = find_first_zero_bit(nq->tag_map, nq->queue_depth); - if (tag >= nq->queue_depth) - return -1U; - } while (test_and_set_bit_lock(tag, nq->tag_map)); - - return tag; -} - static void free_cmd(struct nullb_cmd *cmd) { put_tag(cmd->nq, cmd->tag); @@ -782,24 +769,22 @@ static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer); static struct nullb_cmd *__alloc_cmd(struct nullb_queue *nq) { + unsigned int tag = find_and_set_bit_lock(nq->tag_map, nq->queue_depth); struct nullb_cmd *cmd; - unsigned int tag; - - tag = get_tag(nq); - if (tag != -1U) { - cmd = &nq->cmds[tag]; - cmd->tag = tag; - cmd->error = BLK_STS_OK; - cmd->nq = nq; - if (nq->dev->irqmode == NULL_IRQ_TIMER) { - hrtimer_init(&cmd->timer, CLOCK_MONOTONIC, - HRTIMER_MODE_REL); - cmd->timer.function = null_cmd_timer_expired; - } - return cmd; + + if (tag >= nq->queue_depth) + return NULL; + + cmd = &nq->cmds[tag]; + cmd->tag = tag; + cmd->error = BLK_STS_OK; + cmd->nq = nq; + if (nq->dev->irqmode == NULL_IRQ_TIMER) { + hrtimer_init(&cmd->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + cmd->timer.function = null_cmd_timer_expired; } - return NULL; + return cmd; } static struct nullb_cmd *alloc_cmd(struct nullb_queue *nq, struct bio *bio) -- 2.40.1