Received: by 10.223.164.202 with SMTP id h10csp269413wrb; Thu, 9 Nov 2017 06:08:59 -0800 (PST) X-Google-Smtp-Source: ABhQp+QitlOH2zjnkUZ/QEmKu9IoNsKH9eFRr2l+E61JPoczgjoLpDK+A+cxjCgkVmXooe/n98qU X-Received: by 10.98.103.206 with SMTP id t75mr601394pfj.173.1510236538919; Thu, 09 Nov 2017 06:08:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510236538; cv=none; d=google.com; s=arc-20160816; b=MgW184cYQIHkPU6USXRev8Tj2NH0k9QZy3pnca6VMfbJkMg4aYzWbUGALTi/N7X+OP lx9XTrW9W197zvafdun3Uk221s3h5LOCZtMq+/rAw7/Xh6uFdbT9h+s09QorX5x6/gM2 hT8wBti9j979RcVNOqLARnNPnH06hMLBSdz/iUdWirfFL27VoW7P4dC3Qe9VIeNBLd8g VyGJRjI/eE1pz4xod+u0gnlpEXKpAKGw+/yDBWq6lagTPgWbuX2bjEK3B81LRbKwWxR4 sQh08ZUyvmrbYb+NguFCkeoyY0HTceESK8l8zF/6/M5J3cd7TTFgJCCDO7CGWYStImm8 R2+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=AoT2ZPuh6PmWuocjs6/HkRmar/FMqaQSA1mnBI3fllc=; b=XN3Ba0e4UJE8D14XOKgVK8UglJ9PMnlO4+qLJhKx1x5FWzk6dNdDYsvnhXK9o9byJs etQrmN+gFsTR+E6tyDTEhufhwkMYd5rZYKYHqUip+vxUc2dDDv9lvcB70jeOQBEQu99t tGadR7s/iTZNdBHDWQkqzvwJ2KDWcb1LgX83JH4RmZG8Zrn6j9oDS0G8m0ufZbM17SHh cD3jc9qAZVnrzZRDZkLcWjfrdzGu/nGYNx84iwHI1CTOzkfBpxCVe40Jjkdvw+NijlD+ zV6moNwVXHeP/eTFYtlbMTTUBzor4KftmMjmkoiIjYqLRzbjsoFGRixRc4ocv2eKPPef H2lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=LNR2eE5f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 32si6225551pla.672.2017.11.09.06.08.47; Thu, 09 Nov 2017 06:08:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=LNR2eE5f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754895AbdKIOHh (ORCPT + 80 others); Thu, 9 Nov 2017 09:07:37 -0500 Received: from mail-by2nam03on0071.outbound.protection.outlook.com ([104.47.42.71]:45713 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754071AbdKIOHd (ORCPT ); Thu, 9 Nov 2017 09:07:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=AoT2ZPuh6PmWuocjs6/HkRmar/FMqaQSA1mnBI3fllc=; b=LNR2eE5f6/+KPM8VKJQKR1mLAHAywhxrhtVrX2r9hDzYwYld+Bu603d8MkdDXM5Byl0P9bNYJkQwXwMPl0D1G03F0TmwcwIvrUBWvA4MnYP61glayym1PZ9ctnrHjBYeByAG2650cn0DrEN8Wk6kD7AJ7rJ8G3A8s9oK6BFvMKg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; Received: from localhost (50.233.148.156) by MWHPR0701MB3833.namprd07.prod.outlook.com (2603:10b6:301:7f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.218.12; Thu, 9 Nov 2017 14:07:29 +0000 From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Alexey Dobriyan , Andrew Morton , Clement Courbet , Matthew Wilcox , Rasmus Villemoes Subject: [PATCH] lib: test module for find_*_bit() functions Date: Thu, 9 Nov 2017 17:07:14 +0300 Message-Id: <20171109140714.13168-1-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: HE1PR0102CA0020.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::33) To MWHPR0701MB3833.namprd07.prod.outlook.com (2603:10b6:301:7f::26) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 771df7ea-599f-4f9b-8702-08d5277b37cb X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603199);SRVR:MWHPR0701MB3833; X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3833;3:uHUadlK/V6/IBHU+VV3nAAxE42oao/uMo132yFyHaoQI+4xpJE/wG35v66Q6q2QFFIMrnXfPavK4rgS2UH70di0u0c8Iu/i6woJ+pne5YZVz8ltg2pjEgGURCNZtZMQ4dOK6ySGps02WedOXvTcNIcvPHfNVwUqRh5rQy1bOFo8ftfB9Wf9ypqTANdMa0IJkpGZ0sBngXpNjThNEhEfKlYgGSGBgbX9LHfDes07/2DI0g+8Kd4HxxJnuggwdib/b;25:dYrvJ7XrhMbbh4HnIMtuyUnXhMl7ZdL38MrQDyo8wIS8yE4pZo1Nq4Xi/gR1WcfA4CKd+JgeVajQH0+TSElBYUnpNAMPoiAyPSDUPaWETmkOoyPy4SMebiZJCpFLkYckC19fIVwyNsGIgiVo+00/6TCbl3M59u4FjzVad11SoJS3G3gzF025kvaIj/CHTlm/ulsIYs47TxiTnxgUKJuOv4+DRsN4UP85zwVNjyfvJbvA1FtJGA2xjhoyaucV6XIg5W48nQsuxxTkcQRfLjt6MG1kW+woz350qWqlb2oYPXq7raQB4rjQlgobFm+1kCvtSB3KQr3/OJ3lJQxnj+ni9g==;31:tXu3go5301CJNruvA6/SoYWeorcMbpy9NHbehWFY4wiKJFgNdDuVypJB5zfimpkofNX16XaCzqDsbdc6CUzvwTU4BD+2MzlFJLcQg+3ReDM+FTd29T/F/HZVlQXcbNDZkM8OGghY75KTAXdJsaxEj5s5Ytykw1N/MwmqgScJuDfbHvk0AaZ/voIp2koni6E7YkZyuScmtsCcI6cLVdPFlLKwGflTzkFLQtruDvfndwI= X-MS-TrafficTypeDiagnostic: MWHPR0701MB3833: X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3833;20:HYFFyaaJNAzCpyetN+APJ6RtpPNK+++MvUolP7FRDMUW/tYSieJWOMsl4d1VRHcS4sH1lOqRPtsPr3/gwW8qpkmciuBZMAj2Vx8Pr8U6ip0fTp04hxc9rJFL2osGxbVyQqJQ24JyVSO23WJDizpQyLxovGNR9gfZspEoGGcWDoeJ3XKLjBvNPQWzdzaCBDAHl87Moj2YYOmcEy6wxZyiR2JwBvmtEoz8wsAkTcGp+D7BjyJq3zfaUugVrkpZkmLCf4s6GNgB2wh4otTJ8qr/FEzHDVtftgklLhwcuRC2LfBGyroPT9FDQF1YW7HIB24WzoMSMIa8ZIPHrqpRMKBQfDQNFR2cLg9vu1W3W48O03+dDv5mZbgiv+y39QkpCfLqKb44jKLaOp+WgoKFF6YFeVscB+CO+TcIsAHr5X3zAg1vXGscLGk36Mna6rdOSu6PuT1LS6vwqvOT5K2V+I3YwWvVVma3mALA2tItp07Zg7x7QlMdF2EXTUueYAXWepl8r3MXShJGtZUH6hKY4dA8LYT3eyfyvra2q9us8Ml28HB9EqoEp2XS+mMlsZiZAbisOtz3anuX1xY2EcIQD2CINqKUX7sy7dqkA0LQo8uj6Ew= X-Exchange-Antispam-Report-Test: UriScan:(89211679590171)(211936372134217)(153496737603132); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(10201501046)(3231021)(920507027)(93006095)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR0701MB3833;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR0701MB3833; X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3833;4:VKV2YE3B4ZiikjgqfW7Ha+vOPoLENK8kxWdjAXAvCKIyJUZxiuT5bmQQwsdms7a8MQIQnZI6dZSauB6Y57O0/Gjc/dkld3Ifqicm8hORNrooY3RVr2p6py8UHB71AblSek62ObEgqiR5b485k4AoNxLbSvg0LzUqldRScKXDHuSyZbCYij2Qhl3cnWXA5nURNp3M0oqc0Y/mn/GsVwBTzYgpLiPbvAiM/P6TXxLy2pitSIqnZIv8ViM9yvm5V/dGFd2kavmNPK7fAuC1MxS+2mxwL3PzpD0EhPq+X0ng+OlvCyLTBfeW/328YcFUeWTewWvyNxGIrhKTJSqGFK6NLZVQW+JgT3fcRXehFK/x4uPWs/NE3mb5Eaz1nJkABmbb X-Forefront-PRVS: 0486A0CB86 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6069001)(6009001)(376002)(346002)(189002)(199003)(72206003)(101416001)(50986999)(2361001)(36756003)(48376002)(105586002)(33646002)(68736007)(478600001)(106356001)(76506005)(575784001)(2351001)(5003940100001)(4326008)(50466002)(25786009)(50226002)(47776003)(6666003)(39060400002)(6116002)(6496005)(45080400002)(3846002)(7736002)(1076002)(2906002)(53936002)(305945005)(189998001)(97736004)(316002)(5660300001)(42882006)(8666007)(8936002)(54906003)(8676002)(16526018)(34040400001)(16586007)(81166006)(6916009)(81156014)(66066001)(6486002)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR0701MB3833;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;MWHPR0701MB3833;23:2ENqldx20UsjZk6A4QXev2EA4O9wLc79Hll3kt3?= =?us-ascii?Q?Uv+bZcJ+DEwheO+Kbi+TzOsCCEawCTWwULmkoB//OS3cDzBGMcK1+JzbmVzG?= =?us-ascii?Q?snKCXuRdSrL+SWGiiuX3WcyjDUdWA20xL2EfRaJGr2XS7Bpt7ptxpIG4CA1e?= =?us-ascii?Q?ewOTTCRK4wTX0ag2ljmG5yvDKWsrWiiNqvcWbg6sxVeXWwA267yqd/ewqb9a?= =?us-ascii?Q?8sDJNpRdtDa2MqCLYyfu5z/dsgHeLAInwuR3ARlL8roaUO52up1iAMKwZXgg?= =?us-ascii?Q?9XlAA5KreamxlmgqoSzPiLjZUo8SsfDTLBwC0CzvrZafwA5oRHjihf1Spujf?= =?us-ascii?Q?I3fDfZAZnTbFQl/oglyU9zDdeuqfPZ1uZxBbFU/8sA78w/I0snZhoW9XoIef?= =?us-ascii?Q?PcQJZioVUpETn6zL8zVw56/YvOenSC3KWM0TE1Pg22zR0hfb4F4jk/SxyyAe?= =?us-ascii?Q?9IZN9YT/+Zel4yeMvAuPgMEiR+OYsejdidepBfmuXV//PJgqq/F86PQaMSC8?= =?us-ascii?Q?CDPE/TrnljMgus1qPGc3FIXfeBsP1KM2n7O2G0h+PAWQiZ12Po+Lx9940JBc?= =?us-ascii?Q?K2jvuWUcSsYt0hXgTtW74/m/jnNIVwUlyx9LojbmeqfrgG+PRS6PNRyYhege?= =?us-ascii?Q?tsTz63vwhnpFDx/OYebx9zx5VKZwZLNZAxoVQN6D126KIAwrHIa3/tE+oCA4?= =?us-ascii?Q?1nbnAouN9nmmt8nKKGfPjMGL1n39T1qv9bf4NflSoaAW4gl70/bZmfRvxMLM?= =?us-ascii?Q?nvVWTno2FoP+H4ER1+EFJkQo9XRT9oxuE73GIgLp2RgW1QLZ8EfPxSH6TN1o?= =?us-ascii?Q?HDkiakPmwW0bYBY456+9wcdwRBjDZOHI6V64zogG0bLtwdLRNNiAfVJhxExP?= =?us-ascii?Q?zMS/BjBmpeW/AbF594c34WfP4+R4eHBquV7PhlCtSkLTG7XZzkw3a1VTemMw?= =?us-ascii?Q?kI353cwcQIvwNM4L2mbtYdT0lZO/HpAwTGCOFZZOB71jA3MbcSojUtT4Za23?= =?us-ascii?Q?SsJeWnzH3HQnauWkkNRXKQx+i/pwIaLiCIypXHnFcWkKRQ+JpL0sgeLsJ4pN?= =?us-ascii?Q?0C9O9vvDy6j6MkqknzJboiIoCA0YzYnknKEKhbV3B2ytbTUnWZmI5Qf78YYD?= =?us-ascii?Q?Mc0vzqrIDmxaLU6Iy1tirJ2YPiJVRx8kizXjBqDa0wFlb8eFXSNBtdxVqscG?= =?us-ascii?Q?Be2jkcEaq91E6FXw1GPBGatsSvig5QVdA4HueuO3mZFBneZk+b1PhaJ2iF+B?= =?us-ascii?Q?cZrzdO+hgq65cTfI3E9A+6//GCA2KTmbhsn2XO8Jd?= X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3833;6:lZ31ngrDFOHwcbQuFMkU+663z6ww3DnZPCDswEEWMBN26KtDF/uNBAxuu973bNMclTO5OirAYyMSAbqS5+ToOKVZJOD6jRQ+s8M5LKc15HLQMea3bEVEsq0ki6qz6gZkzmzjBE49pcpC9Vtzx2dTNCbdQAB7CtLJ1mxwAhqsiowFtY1YG8hCUXompccIC4Ax3nXaYhxFX+FpRuIVENKytsHq4ZL+EzGRig0lBYl88RNQ8nz05j8yvG0x2ew0rtRJKHyefUEHzRBhs2CvFrheJFBcpSAvU77lue1Cq5ZIYC0JYtl4sqTzCD3GFwdZ8CLHDlcsgzlAkoDtUqJ6eElXYBD9hEaeoAxf/hmp0ueDx5Y=;5:fNHTtLGkU4nrRZ0fRGAKugmNYBLJNtdq3m8+9P5eAmxqgZhWLTsHhTNE9oC8QLRPKoTZw6AuG7J0Shch5pqELVmfOdrnGroOBjstYwSPvmal/DOVSUm/hs8ZsJSy8zDPNRVTb7bDlePzyNMQ1llo5qTcjRoDzlg/LtGK8szKoaA=;24:Q2H1NpSjeHqAeyBgIfDpJTQS2SEPDWPIZgtiPis8OOP3sTvVNq57vX0sYM3a9ejrLDJ6leLYQLNjaTtmF2RvcJaF1Ga8rj1w7OzZzGxIoME=;7:ILhSKDUdmVls45DVpMyTiDeWHfY8QbouS30z1I8MHFtslzKv7bEFNnSGHeDzSy+6TcQd78Qpqj8K138KhlG1r7v4Ap0GPFQujTj4vwA9+PJiqr2a9NvcGyqEu6avzfNigEQBtSxSJ0NvJkXBc4pA3IAVe5r2XM6ArbucGb0TIVnL3iOy4dBZ9aOuTINM+C/VSV4t9YEqD++sNnfc+XkOMPohipibPr0Yq6REOgnpenqJZ44/d+tU4frxdmj0i+ZJ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Nov 2017 14:07:29.8807 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 771df7ea-599f-4f9b-8702-08d5277b37cb X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR0701MB3833 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org find_bit functions are widely used in the kernel, including hot paths. This module tests performance of that functions in 2 typical scenarios: randomly filled bitmap with relatively equal distribution of set and cleared bits, and sparse bitmap which has 1 set bit for 500 cleared bits. On ThunderX machine: Start testing find_bit() with random-filled bitmap [1032111.632383] find_next_bit: 240043 cycles, 164062 iterations [1032111.647236] find_next_zero_bit: 312848 cycles, 163619 iterations [1032111.661585] find_last_bit: 193748 cycles, 164062 iterations [1032113.450517] find_first_bit: 177720874 cycles, 164062 iterations [1032113.462930] Start testing find_bit() with sparse bitmap [1032113.477229] find_next_bit: 3633 cycles, 656 iterations [1032113.494281] find_next_zero_bit: 620399 cycles, 327025 iterations [1032113.506723] find_last_bit: 3038 cycles, 656 iterations [1032113.524485] find_first_bit: 691407 cycles, 656 iterations v2: - pretty printing; - increase length of bitmap to suppress noise; - drop inlining _find_next_bit(); CC: Alexey Dobriyan CC: Andrew Morton CC: Clement Courbet CC: Matthew Wilcox CC: Rasmus Villemoes Signed-off-by: Yury Norov --- lib/Kconfig.debug | 9 ++++ lib/Makefile | 1 + lib/test_find_bit.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 lib/test_find_bit.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index dfdad67d8f6c..138034cc68a3 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1838,6 +1838,15 @@ config TEST_BPF If unsure, say N. +config TEST_FIND_BIT + tristate "Test find_bit functions" + default n + help + This builds the "test_find_bit" module that measure find_*_bit() + functions performance. + + If unsure, say N. + config TEST_FIRMWARE tristate "Test firmware loading via userspace interface" default n diff --git a/lib/Makefile b/lib/Makefile index b8f2c16fccaa..97ec69d843f2 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -46,6 +46,7 @@ obj-y += hexdump.o obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o obj-y += kstrtox.o obj-$(CONFIG_TEST_BPF) += test_bpf.o +obj-$(CONFIG_TEST_FIND_BIT) += test_find_bit.o obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o diff --git a/lib/test_find_bit.c b/lib/test_find_bit.c new file mode 100644 index 000000000000..920d5a0ca456 --- /dev/null +++ b/lib/test_find_bit.c @@ -0,0 +1,141 @@ +/* + * Test for find_*_bit functions. + * + * Copyright (c) 2017 Cavium. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +/* + * find_bit functions are widely used in kernel, so the successful boot + * is good enough test for correctness. + * + * This test is focused on performance of traversing bitmaps. Two typical + * scenarios are reproduced: + * - randomly filled bitmap with approximately equal number of set and + * cleared bits; + * - sparse bitmap with few set bits at random positions. + */ + +#include +#include +#include +#include +#include +#include + +#define BITMAP_LEN (4096UL * 8 * 10) +#define SPARSE 500 + +static DECLARE_BITMAP(bitmap, BITMAP_LEN) __initdata; + +/* + * This is Schlemiel the Painter's algorithm. It should be called after + * all other tests for the same bitmap because it sets all bits of bitmap to 1. + */ +static int __init test_find_first_bit(void *bitmap, unsigned long len) +{ + unsigned long i, cnt; + cycles_t cycles; + + cycles = get_cycles(); + for (cnt = i = 0; i < len; cnt++) { + i = find_first_bit(bitmap, len); + __clear_bit(i, bitmap); + } + cycles = get_cycles() - cycles; + pr_err("find_first_bit:\t\t%ld cycles,\t%ld iterations\n", cycles, cnt); + + return 0; +} + +static int __init test_find_next_bit(const void *bitmap, unsigned long len) +{ + unsigned long i, cnt; + cycles_t cycles; + + cycles = get_cycles(); + for (cnt = i = 0; i < BITMAP_LEN; cnt++) + i = find_next_bit(bitmap, BITMAP_LEN, i) + 1; + cycles = get_cycles() - cycles; + pr_err("find_next_bit:\t\t%ld cycles,\t%ld iterations\n", cycles, cnt); + + return 0; +} + +static int __init test_find_next_zero_bit(const void *bitmap, unsigned long len) +{ + unsigned long i, cnt; + cycles_t cycles; + + cycles = get_cycles(); + for (cnt = i = 0; i < BITMAP_LEN; cnt++) + i = find_next_zero_bit(bitmap, len, i) + 1; + cycles = get_cycles() - cycles; + pr_err("find_next_zero_bit:\t%ld cycles,\t%ld iterations\n", + cycles, cnt); + + return 0; +} + +static int __init test_find_last_bit(const void *bitmap, unsigned long len) +{ + unsigned long l, cnt = 0; + cycles_t cycles; + + cycles = get_cycles(); + do { + cnt++; + l = find_last_bit(bitmap, len); + if (l >= len) + break; + len = l; + } while (len); + cycles = get_cycles() - cycles; + pr_err("find_last_bit:\t\t%ld cycles,\t%ld iterations\n", cycles, cnt); + + return 0; +} + +static int __init find_bit_test(void) +{ + unsigned long nbits = BITMAP_LEN / SPARSE; + + pr_err("\nStart testing find_bit() with random-filled bitmap\n"); + + get_random_bytes(bitmap, sizeof(bitmap)); + + test_find_next_bit(bitmap, BITMAP_LEN); + test_find_next_zero_bit(bitmap, BITMAP_LEN); + test_find_last_bit(bitmap, BITMAP_LEN); + test_find_first_bit(bitmap, BITMAP_LEN); + + pr_err("\nStart testing find_bit() with sparse bitmap\n"); + + bitmap_zero(bitmap, BITMAP_LEN); + + while (nbits--) + __set_bit(prandom_u32() % BITMAP_LEN, bitmap); + + test_find_next_bit(bitmap, BITMAP_LEN); + test_find_next_zero_bit(bitmap, BITMAP_LEN); + test_find_last_bit(bitmap, BITMAP_LEN); + test_find_first_bit(bitmap, BITMAP_LEN); + + return 0; +} +module_init(find_bit_test); + +static void __exit test_find_bit_cleanup(void) +{ +} +module_exit(test_find_bit_cleanup); + +MODULE_LICENSE("GPL"); -- 2.11.0 From 1585312756076841274@xxx Tue Nov 28 12:27:38 +0000 2017 X-GM-THRID: 1585306499475305366 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread