Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4375897rdb; Mon, 11 Dec 2023 18:29:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2AadqBPVaZC8obxMOORtGYlHUMWgvnee6zN8C9SENsys89FSuxBJpOCrxPreUNN7fvGid X-Received: by 2002:a05:6808:1706:b0:3b8:b063:6baf with SMTP id bc6-20020a056808170600b003b8b0636bafmr6391801oib.94.1702348169869; Mon, 11 Dec 2023 18:29:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702348169; cv=none; d=google.com; s=arc-20160816; b=06ocklL5VzqEG/la5RINmFZ4DSx9Rw5fEab8/yijlh804/de0anybZ1AueYfLvjZaA WASkVUqiQ+Hg8FQwuHn92oitPOGBKilTIXauMnepR4daRlAWMRzqwLCLCTMc2C9c+Mq4 PKdABFB7dHdnIkFm8OO8faxVTsGpi4mCFa71y5MDnmFKsh0vzYFh7M0OG0dphGSK5h5L ApDT9W6cikW3iu4OZ5iLUdwOCNBqo1t6hxiMg7n7oI6ZR3hT7Hj7leNp6GzRq1ZXMO2D jXru9jWJGLW/BDm1VZX3GQ7YTOr9IEr/iJ+mukCxUE6OM92dkTPWn/kyq89onkVAM7bz nEEA== 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=xXHhxsG3/UhGgqamsfrlyZxDKNFN6ooaZwOKCcSTfsQ=; fh=0dBgNiZKqgWnjuNzsVOVoNRd51CGUnw9xRLtiM40R1Q=; b=kquooJbxU8DJBySFqQdz6BXzCXCSq0Kf5Jda5QoiWybPT7Fm2rWMd0sZpnitLnRWbP RoejRZO689TVcn36Oo94OHvB1xNv1/jJn6oSZYliCHTlh6rM/rlSEdyNfkey6ypxbXxV oDk9IU6FFT650N7JDCOOinV+OjN3c3hkFL2npYTwbYL2Ir/pMAW+6wAJoLoFbf/kVyQm BUyit+7wGk7zPhimyCJxaxMjZVlIffrvOKzfa3N6dbKTNcFVXXHrTWzNI3ItcgNg0uEe hkVwXtXxbBWNFJM6MAsg1TgVCNO/qIFe4+zvzU+O9ZsQZOZWRHi2DS4YKTWNmhB4YFV1 Vd0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jp2Nz9P4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z25-20020a656659000000b005ab7b51ab5bsi6749074pgv.110.2023.12.11.18.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:29:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jp2Nz9P4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id DB4A6804E710; Mon, 11 Dec 2023 18:29:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345920AbjLLC3P (ORCPT + 99 others); Mon, 11 Dec 2023 21:29:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345792AbjLLC2p (ORCPT ); Mon, 11 Dec 2023 21:28:45 -0500 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8326A135; Mon, 11 Dec 2023 18:28:32 -0800 (PST) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5df49931b4eso28081517b3.0; Mon, 11 Dec 2023 18:28:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702348110; x=1702952910; 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=xXHhxsG3/UhGgqamsfrlyZxDKNFN6ooaZwOKCcSTfsQ=; b=jp2Nz9P49zWcrnTotdEWzMcMYlaNUW3Iqrj1F4Lr1niQgy2JKLY9kFqZzAultqMUBr ZHokKXNSda1Q3xriJREOyA+qW3LPfwA2OE5TZoxSvnaoeuE8aR6wqXpqAQI6RxmkTvAF pYqiaCGXQ29IIBsZ8uxxkFeR0pvbrN4YxbS7sHUvnIWuk6w6Rq3cqijp9lBLvJsBVLiZ aa5qTtj+pIPkA0w0c6OmhTaqanANwIlM3O2gH2xh/GpEyxBSsvTZAjfu0B+4jQbaiwc+ t4WwcLk3ZKsIHV4pZnlQLuvb63G1o2ULmxkIizGDNA0zTJ1hH3TowJs4XewqcPHKNjFp ChzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702348110; x=1702952910; 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=xXHhxsG3/UhGgqamsfrlyZxDKNFN6ooaZwOKCcSTfsQ=; b=xIfUdLzkmGrnaYCvmOS/23hjKA4tqcA1DJ2OTdrgTRs+LrL2Jxr7pISgJAbaHulsHt kn7gsSXKlwwNAb94Fpk6SznMIQbctlMYsVrXOpBpNhjuzZO9PNr3s9qpbiY1yvmfVXwW /F2KT0JV5PI5fQMLVXcF95MdXO4FHn7j67kpgPL8OsrMR7CaNTaQ5G2pZ6Uwn6hui4wZ VqAj1E5uMdUUr6yAK3B0V/VSWx4KSYJ8XgSzG1uk4ZP8+0HRmZ/JIjPKgpBD4Z5buzTW 7AABXKwPN4m1o7FEEuIl/7ldFY3LCScptH5Ahk3YLIYljwGlYzgGUFsA916hYmNue8ib siTw== X-Gm-Message-State: AOJu0YxE4uyH4ODJqaMG/IgDQCjH4fagOZpxS02HeEoDJ0qja259LjR2 uQcUpJq27oz9vPuMViMOO+x16KfAgb+hrA== X-Received: by 2002:a05:690c:4505:b0:5e1:9f39:b084 with SMTP id gt5-20020a05690c450500b005e19f39b084mr762715ywb.2.1702348110591; Mon, 11 Dec 2023 18:28:30 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id j72-20020a81924b000000b005d716572128sm3471268ywg.17.2023.12.11.18.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:28:30 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org Cc: Yury Norov , Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov , Bart Van Assche , Sergey Shtylyov Subject: [PATCH v3 25/35] RDMA/rtrs: optimize __rtrs_get_permit() by using find_and_set_bit_lock() Date: Mon, 11 Dec 2023 18:27:39 -0800 Message-Id: <20231212022749.625238-26-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 18:29:29 -0800 (PST) The function opencodes find_and_set_bit_lock() with a while-loop polling on test_and_set_bit_lock(). Use the dedicated function instead. Signed-off-by: Yury Norov --- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c index 7f3167ce2972..9f1c612df392 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c @@ -72,18 +72,9 @@ __rtrs_get_permit(struct rtrs_clt_sess *clt, enum rtrs_clt_con_type con_type) struct rtrs_permit *permit; int bit; - /* - * Adapted from null_blk get_tag(). Callers from different cpus may - * grab the same bit, since find_first_zero_bit is not atomic. - * But then the test_and_set_bit_lock will fail for all the - * callers but one, so that they will loop again. - * This way an explicit spinlock is not required. - */ - do { - bit = find_first_zero_bit(clt->permits_map, max_depth); - if (bit >= max_depth) - return NULL; - } while (test_and_set_bit_lock(bit, clt->permits_map)); + bit = find_and_set_bit_lock(clt->permits_map, max_depth); + if (bit >= max_depth) + return NULL; permit = get_permit(clt, bit); WARN_ON(permit->mem_id != bit); -- 2.40.1