From patchwork Fri Oct 21 13:47:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 6732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp711206wrr; Fri, 21 Oct 2022 06:57:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6kix8u/G00F3aQGn5BSrJnqebxlMWplf8jFPdyRlmTbn/MWt5acXKWReUXl9Vd28QDzs6D X-Received: by 2002:a17:906:5d04:b0:722:f46c:b891 with SMTP id g4-20020a1709065d0400b00722f46cb891mr15550896ejt.4.1666360649938; Fri, 21 Oct 2022 06:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666360649; cv=none; d=google.com; s=arc-20160816; b=Q1p0s//BsTdDZUanIW4m2PxoZKl03jdeQXbNcorLRCZGKssR8S3MP/JHf5aG+KeBpJ CmbkDnBGk7PEEzYKzi/TuXMPiTz2/yWu+XS8dzZth4UoZ+OFLjj+N+K2uh4KP5erlC1l d0VLA3M1Hn5Oluu5ls+TDdLdT1y4xeyp+6vNDYOoN+BPSR55VGLXJZ9zZMVfrcMb6seX +APDRHcf9K/U+OgyAaTlQn4JAPfYH50219hoUV2RKIOXS/6CK2SvRo24G6MlMAHYW3y6 TDt+NCdtTAmxo/r6gJEEQYYnwRUJP0VKTzvK46wXc3n8cqGosXJ80UvI+irYz1VMEIGD muHQ== 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 :message-id:date:subject:cc:to:from; bh=/KYOY4zs6fl6G+lRfUOjsIwjdNNZQUClN8FktPDpRMQ=; b=gpd5O5i1su3hlKYTIoIG0ipiiAXYKKPGV5jsAsSzrRUFgh3rNrFJ48mueZijBuKzgL DSSp92rsseM9/qmXXI4aDw3qXfS8qFNK2zOAcGeip2gOB0HItTPrTVMmbZOBxd0snkg1 HO9On+5zDew8+TDGTrNpIQLQH5fLdGhMLmJsaxDxzRpyPrIKyIbz0vNXar8nRPE0/5pz Sn1An5lFfbcBvwCKGiMaNk6mNQGoCw+E6RIPRLi2O2kLOuRcw8I4QXym2bIl9DXNFCTd NphsmG+s2GTCke5eE6ICOaiM0KsVbFRCEaLDx0JdG0fWMO1Be4nagC0DM+tg3DKzjjTs 68Mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji19-20020a170907981300b007823d2b20fdsi20501469ejc.219.2022.10.21.06.57.05; Fri, 21 Oct 2022 06:57:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231214AbiJUNrI (ORCPT + 99 others); Fri, 21 Oct 2022 09:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230116AbiJUNrH (ORCPT ); Fri, 21 Oct 2022 09:47:07 -0400 Received: from mail.sf-mail.de (mail.sf-mail.de [IPv6:2a01:4f8:1c17:6fae:616d:6c69:616d:6c69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5577425C486 for ; Fri, 21 Oct 2022 06:47:05 -0700 (PDT) Received: (qmail 18710 invoked from network); 21 Oct 2022 13:46:14 -0000 Received: from p200300cf07087500581cdcfffecf391f.dip0.t-ipconnect.de ([2003:cf:708:7500:581c:dcff:fecf:391f]:35114 HELO eto.sf-tec.de) (auth=eike@sf-mail.de) by mail.sf-mail.de (Qsmtpd 0.38dev) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPSA for ; Fri, 21 Oct 2022 15:46:14 +0200 From: Rolf Eike Beer To: Thomas Graf , Herbert Xu , Florian Westphal Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Jason A. Donenfeld" Subject: [PATCH][Resend] rhashtable: make test actually random Date: Fri, 21 Oct 2022 15:47:03 +0200 Message-ID: <5894765.lOV4Wx5bFT@eto.sf-tec.de> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747305784916850589?= X-GMAIL-MSGID: =?utf-8?q?1747305784916850589?= The "random rhlist add/delete operations" actually wasn't very random, as all cases tested the same bit. Since the later parts of this loop depend on the first case execute this unconditionally, and then test on different bits for the remaining tests. While at it only request as much random bits as are actually used. Signed-off-by: Rolf Eike Beer Acked-by: Herbert Xu --- lib/test_rhashtable.c | 58 ++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) [Resend with correct from address] diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c index b358a74ed7ed..f2ba5787055a 100644 --- a/lib/test_rhashtable.c +++ b/lib/test_rhashtable.c @@ -369,18 +369,10 @@ static int __init test_rhltable(unsigned int entries) pr_info("test %d random rhlist add/delete operations\n", entries); for (j = 0; j < entries; j++) { u32 i = prandom_u32_max(entries); - u32 prand = get_random_u32(); + u32 prand = prandom_u32_max(4); cond_resched(); - if (prand == 0) - prand = get_random_u32(); - - if (prand & 1) { - prand >>= 1; - continue; - } - err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); if (test_bit(i, obj_in_table)) { clear_bit(i, obj_in_table); @@ -393,35 +385,29 @@ static int __init test_rhltable(unsigned int entries) } if (prand & 1) { - prand >>= 1; - continue; - } - - err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); - if (err == 0) { - if (WARN(test_and_set_bit(i, obj_in_table), "succeeded to insert same object %d", i)) - continue; - } else { - if (WARN(!test_bit(i, obj_in_table), "failed to insert object %d", i)) - continue; - } - - if (prand & 1) { - prand >>= 1; - continue; + err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); + if (err == 0) { + if (WARN(test_and_set_bit(i, obj_in_table), "succeeded to insert same object %d", i)) + continue; + } else { + if (WARN(!test_bit(i, obj_in_table), "failed to insert object %d", i)) + continue; + } } - i = prandom_u32_max(entries); - if (test_bit(i, obj_in_table)) { - err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); - WARN(err, "cannot remove element at slot %d", i); - if (err == 0) - clear_bit(i, obj_in_table); - } else { - err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); - WARN(err, "failed to insert object %d", i); - if (err == 0) - set_bit(i, obj_in_table); + if (prand & 2) { + i = prandom_u32_max(entries); + if (test_bit(i, obj_in_table)) { + err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); + WARN(err, "cannot remove element at slot %d", i); + if (err == 0) + clear_bit(i, obj_in_table); + } else { + err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); + WARN(err, "failed to insert object %d", i); + if (err == 0) + set_bit(i, obj_in_table); + } } }