From patchwork Mon Aug 7 22:54:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 109599 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp3316985obb; Mon, 7 Aug 2017 15:55:15 -0700 (PDT) X-Received: by 10.98.12.78 with SMTP id u75mr2251985pfi.18.1502146515627; Mon, 07 Aug 2017 15:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502146515; cv=none; d=google.com; s=arc-20160816; b=wiOD5ZKHko4G4HvQ8ysXuJPCG8muEKLcfK+8RErB/8zfMyl8Katy95fZKZCCagOn1G 019rU94nWU7wuU0jaPXMX3uaS7YRv5Z798cPdbfphFP9AibZrGBbkZtN8fXTAahp4ajs cwxMYnKYxWjenRSs2oHEcusE1bJ4Y7aWRVYnqSaVv/J/7J548zFifUUrnh8K5AFwadrm v+yVhEKjXQ9A0hIBTonn7qPG3zdOEJZCEl8j9TTdv13xevwu9zEb2vA7Z691vRg6LalD RzIxKj04MnYvzEROHyEPnZM+kMvh0CqnZEOXfL/NXifX4dxarH/Z5SvB0Ly3sA0fVvZe n6Mg== 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=KZwuHEpkhTRaeByjoq8+nXQW9O/tpiAPgRKWmKfS2dM=; b=ZhgGlENhDqlYP4/yRhl1xxlQjVOH0/Cp7bqPeEtFVwrQYHrkzbDpub9rDbeQchs1yj lZjizVTu9RZxqFu1ZpPcXXY0rd92Bl0abqXdf+UOdlqnz+SW9RP3M/V2J6JOdeGYqxSx 1yRcHM/udjKpxYUptV/oDEK7nEB7K5LAyx8TJU8O9C7MN9OAX5R9FiRGqAQCvWx07FRw MeGNg1ri4LZcjEoDO+W5vZEXn8zmQeQ0i2uUng8kz0kqM/dtmJNI40T4mHU+/kol1rMu 6wuxlJbVyQkfAJ3hAM3M+XRVwBK3uci9myci3+A3NP9IUhrbzw/K+5ezVRddQBNP1YYF nyWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.b=McntjHSK; 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 12si5293043pfb.405.2017.08.07.15.55.15; Mon, 07 Aug 2017 15:55:15 -0700 (PDT) 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.b=McntjHSK; 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 S1751963AbdHGWzM (ORCPT + 25 others); Mon, 7 Aug 2017 18:55:12 -0400 Received: from mail-cys01nam02on0059.outbound.protection.outlook.com ([104.47.37.59]:6656 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751761AbdHGWzL (ORCPT ); Mon, 7 Aug 2017 18:55:11 -0400 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=KZwuHEpkhTRaeByjoq8+nXQW9O/tpiAPgRKWmKfS2dM=; b=McntjHSKC8MQ3KphYRsp/92aNfx06o1PXeYgE/2MyRvJCKn6WmiN721NLina2hqPvsbZXCxKBcMAfpgarrJ//hTRFP8WfIhuPEl8rmpT9QdhLKZWwu3XwPmgA448qX4+tAwI1qazV21/VR6Zefbw+wAm6esyUR5yDNn7nn9wk50= Received: from localhost (41.141.196.40) by SN1PR07MB2127.namprd07.prod.outlook.com (10.164.46.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1320.16; Mon, 7 Aug 2017 22:55:07 +0000 From: Yury Norov To: Andrew Morton , Noam Camus , Rasmus Villemoes Cc: Matthew Wilcox , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Yury Norov Subject: [PATCH 1/2] lib: make bitmap_parselist thread-safe and much faster Date: Tue, 8 Aug 2017 01:54:37 +0300 Message-Id: <20170807225438.16161-1-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Originating-IP: [41.141.196.40] X-ClientProxiedBy: HE1PR0102CA0031.eurprd01.prod.exchangelabs.com (10.170.250.44) To SN1PR07MB2127.namprd07.prod.outlook.com (10.164.46.157) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9a093972-4ed8-4a33-cbae-08d4dde759f2 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:SN1PR07MB2127; X-Microsoft-Exchange-Diagnostics: 1; SN1PR07MB2127; 3:aJC3FXEoX22XX8GQ+mDT56bgUfQDkEz+Kj8iJUClwnIs5+394Uy+eXtiJLjmVndu0svwsVAENsQsbeRVJ1K6EO0trBe1RB+gURPrpgBjRPxSkEnq0E/vOT6an2YEqWjmzbiGFGS9xNOnNP7VTKMU77FR015GtBE8VecH5lPRjjkPCFxG1r9Do1EVFeXfFSNF9RlIQzUba05Vt2sOXS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Cacj/Q7UfOr6UPGZjfqrOFoZEd3KB7uu0S4pan2yJOaCZrbbV5FgBiyoqszWXDR9RLdrQ80OHleNlswzz3n7m+nuyWHzQ5pboIZaY6lsbZTAmXZ9FdAJEj93CIsV8Q+W+G1zqdOzeHbhTT08gzYze8AkBJdDj5TyPOlkdZg5mte/MzBEWqy1GaGxLxcB+PJcp94uxanA8EVtp8DXAFi7XLNnnAr06Gn+hk5D/6qCw46TXshkO1xN0=; 4:Mlt3yS1tN8qsSb5NvHicS/imTz9vvUPlLSjJO2xjg+kQwJyk5wZ/8+vQsXc+nVoxmNo5InqRSd0ld8epaKZnDwI4FeYCodV1yIrh5Bw6wWAXl0oaRKF62jrsmQ5Y5KxvfBJaOW6HU3k6ccPcA17WDokJYxTW+WJLbf6PrJTQEjuhtdiSKraBf1i2QSIapWUl00/Qn8VEAKqzOmshP/zP8KBBmjN0PWDYnfVkJa3zMI2Yu8U2DZsM6h98ZLPsypGj X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(3002001)(100000703101)(100105400095)(10201501046)(6041248)(20161123555025)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR07MB2127; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR07MB2127; X-Forefront-PRVS: 0392679D18 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(6069001)(39450400003)(39410400002)(39840400002)(39400400002)(39850400002)(189002)(199003)(51444003)(8676002)(6116002)(106356001)(3846002)(33646002)(101416001)(42186005)(10646004)(50986999)(68736007)(76506005)(48376002)(50466002)(1076002)(5003940100001)(72206003)(305945005)(6486002)(4326008)(105586002)(7736002)(7350300001)(6496005)(53936002)(38730400002)(107886003)(478600001)(8666007)(97736004)(5001810100001)(25786009)(47776003)(2906002)(66066001)(54906002)(6666003)(36756003)(50226002)(10916006)(81166006)(81156014)(5660300001)(42882006)(189998001)(3486003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR07MB2127; 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) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; X-Microsoft-Exchange-Diagnostics: 1; SN1PR07MB2127; 23:mwFNtpsa6EoQqeKnmc806w/9BbB6BJtDg1UpGSxIXeCQxSsCKFnZCGLxN/1J6HdkNlAbGyaIhJTkyMbX5aUcKt6UcvzDFxDZYBLExydycZhCxKQYtWE4JwCdsOIu3pTnFg1qJFonx+j/zBfCbmNb1pKJSG6F350jMTzOuGRlbjAl1jcVYkCRlcBqCawRwwEiaPjOOd5nFV4UpO05esKsgR50p4C9VcwLy/+JgEQQmGFeZWNAFdbgssFhsvfjOLsU4FdZSTmdHiFLBAyfcnMXk7Q5WBg3w/aN3+n3+egnhhWsSx6D3tusKA0wQhU4Dkc4me/HZUjhuUJFnGPkyZYhHaOh3KXyKmRkFfjTZhtiFR3w1C9BM/c6Ab88lZ3x0Cvkw8Yv32WatMBCIYl10oONTGFHZ1aq2TTSmsJRIpTl+HzzKbH9ezESv65GVnkiOQHYem0BRtCjwrywS/X8ABeG61x9dEDuSGhcKF/xoe8Gy+1xXd5/MZJKswkXEFH5DxE3i+shSbRF/wMlVlIUaqkZCXE1z0ZZ30iKt0NJJ2VSkPokqJ89merITVyXC54WsCSMnm1a9PnhPyywFCYZOXHSFqxShS1V3VTsRB0wDfAmjn0ypqFstfaJpaS5xZkfOyQN/f5yNnc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AW4LEkW7m/VlbgUN8AwBSZn5RsRFl+Mr1XgC2s40s/KWTRKfNg==; 5:JSsetwVFQNIUurP6ncn9EivMDShHFWZ9V9zzriPwaMspT6x3QerHx8RPE/4gFoiUN4N7XUJEGpM88+nVqavmhWKqFMKRl35nQQZKZzEw68tt3qYJ4SA8u9XHbjJE48v+/LkiWd2s54BA4Fmna5S/Sw==; 24:o6ocx6RZC67ozccAU/BjynuR8QZTKwdLphAdTJ+Fj7+K3NT8UU+lUO63eAd+BubVNAehxZBcm6rIZ26LOuVYZQESXMnU8sM0nFAaeTLpQJQ=; 7:gUF4sozugW9u6Eab+T0jd+E1H5m1mYkaufl0q0+W6vTBM0RP5+kf5clw/0ZeqhqXFfGZ/xiO2wPSTumFgOgVGxloWgIKGX06THS5LI0EqdVmD93bsLMK1W8AP/NdHdjZCizZ71hj5pV1+Yc4mYuQwKWT6YPqmBCcuuDdC3RZuWSw6Arol0cBk8ai97jytlDqm0J5MTMfjOer8YyURiZRtYMSP+2Qjke6IZrOHtHi9fc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2017 22:55:07.2662 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR07MB2127 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current implementation of bitmap_parselist() uses the static variable to save local state while setting bits in the bitmap. It is obviously wrong if we assume execution in multiprocessor environment. Fortunately, it's possible to rewrite this portion of code to avoid using the static variable. It is also possible to set bits in the mask per-range with bitmap_set(), not per-bit, as it is implemented now, with set_bit(); which is way faster. The important side effect of this changes is that setting bits in this function from now is not per-bit atomic and less memory-ordered. This is because set_bit() guaranties the order of memory accesses, while bitmap_set() does not. I think that it is the advantage of the new approach, because the bitmap_parselist() is intended to initialise bit arrays, and user should protect the whole bitmap during initialisation if needed. So protecting individual bits looks expensive and useless. Also, other range-oriented functions in lib/bitmap.c don't worry much about atomicity. With all that, setting 2k bits in map with the pattern like 0-2047:128/256 becomes ~50 times faster after applying the patch in my testing environment (arm64 hosted on qemu). The second patch of the series adds the test for bitmap_parselist(). It's not intended to cover all tricky cases, just to make sure that I didn't screw up during rework. Signed-off-by: Yury Norov --- lib/bitmap.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) -- 2.11.0 diff --git a/lib/bitmap.c b/lib/bitmap.c index 9a532805364b..c82c61b66e16 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -513,7 +513,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, int nmaskbits) { unsigned int a, b, old_a, old_b; - unsigned int group_size, used_size; + unsigned int group_size, used_size, off; int c, old_c, totaldigits, ndigits; const char __user __force *ubuf = (const char __user __force *)buf; int at_start, in_range, in_partial_range; @@ -599,6 +599,8 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, a = old_a; b = old_b; old_a = old_b = 0; + } else { + used_size = group_size = b - a + 1; } /* if no digit is after '-', it's wrong*/ if (at_start && in_range) @@ -608,17 +610,9 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, if (b >= nmaskbits) return -ERANGE; while (a <= b) { - if (in_partial_range) { - static int pos_in_group = 1; - - if (pos_in_group <= used_size) - set_bit(a, maskp); - - if (a == b || ++pos_in_group > group_size) - pos_in_group = 1; - } else - set_bit(a, maskp); - a++; + off = min(b - a + 1, used_size); + bitmap_set(maskp, a, off); + a += group_size; } } while (buflen && c == ','); return 0; From patchwork Mon Aug 7 22:54:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 109600 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp3317325obb; Mon, 7 Aug 2017 15:55:42 -0700 (PDT) X-Received: by 10.99.98.193 with SMTP id w184mr2033987pgb.358.1502146542392; Mon, 07 Aug 2017 15:55:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502146542; cv=none; d=google.com; s=arc-20160816; b=PGZUGa2m7eTEqMibwurGnScpqV12CW4zWDRpKM8GJK2XWXOjZESaKg6LlMBfkhbaKZ 7fJ+0n9pj2jMpXE8FONWoNzqMYs4BKx9auFr+oYS+5VeXgydngwEwjPTPaiFDrL4uPB6 2dXWbwq9teZBN/uLn+hQFqpi1jBx702cFM/6wPIipYjRH8HNp24Pw+b9/SIMfrXElMYH 5Q3eNaemUSIJTPb+7Wo8s0rFEi15iN0UsS1HlyWD4/ix8w+CgMAYFIDa3dm1xxf5nQ43 tm6DQQDnaDxMPFizGw1PXSW1cnQUMzSFL4zD1kHGv7UOO9bCbeqG8L4Ly/Iq4K1vSwk1 FvOg== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=sifgOgbgX7P5d0QkI/qPLIjqIOJc9T6y+xZ3ImBCkT4=; b=aDrWOMTSevbUdzz1xsMHu1dNm0ek/rv6ECW0CagqK7u4EL+7bT+LtXN8Ia0rwrkzW5 KFUkcThxCUnJClCnulq0z2QJh55XwDOxlKnJxQb+JXov4sF41PiQY2HkdKvSwnxlc+/q 9p4IO9fhJ2Z1P1Et+FG00Bp6KmDwqVCs7ZDa208PVEYtbKg80CyEGE2RAGQCT1jYo9/I 1OfZC/gIFv9YmxtvH5YYg4Lub6m3W7SEf23h+UPDJDu9KT4S7rV2LH/b0VD//JjuTuj0 8GPm/EzWIifBA4JPN9et+vKvzKxwE1azFW1Xq6g/m5/PTHGPQrzKNLKHYWmPDeilFcw7 5NFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.b=NU+KisAd; 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 q14si5135046pli.588.2017.08.07.15.55.42; Mon, 07 Aug 2017 15:55:42 -0700 (PDT) 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.b=NU+KisAd; 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 S1752062AbdHGWzk (ORCPT + 25 others); Mon, 7 Aug 2017 18:55:40 -0400 Received: from mail-sn1nam02on0062.outbound.protection.outlook.com ([104.47.36.62]:52821 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751761AbdHGWzi (ORCPT ); Mon, 7 Aug 2017 18:55:38 -0400 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=sifgOgbgX7P5d0QkI/qPLIjqIOJc9T6y+xZ3ImBCkT4=; b=NU+KisAdvI9i2GBcOT609vLGnor6v+8sJ5sMnVlut4g0gDJDzZ6F3mJWZrvRttdb2lozSvzjknFELe+vTuEj+JoN45pHaxxtabCjQiSpFa3vG/QQr3P7SMOe17b8vC6FK0BsmPFLIrJtcstMbjDnQ+UhhiO8hAHOOnRDv2/RA0g= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; Received: from localhost (41.141.196.40) by DM3PR07MB2121.namprd07.prod.outlook.com (10.164.4.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1320.16; Mon, 7 Aug 2017 22:55:23 +0000 From: Yury Norov To: Andrew Morton , Noam Camus , Rasmus Villemoes Cc: Matthew Wilcox , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Yury Norov Subject: [PATCH 2/2] lib: add test for bitmap_parselist() Date: Tue, 8 Aug 2017 01:54:38 +0300 Message-Id: <20170807225438.16161-2-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170807225438.16161-1-ynorov@caviumnetworks.com> References: <20170807225438.16161-1-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [41.141.196.40] X-ClientProxiedBy: DB6PR02CA0004.eurprd02.prod.outlook.com (10.170.218.145) To DM3PR07MB2121.namprd07.prod.outlook.com (10.164.4.139) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 800b077d-5f42-4580-681b-08d4dde76a90 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DM3PR07MB2121; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2121; 3:6p9R1psix1wN6WUtJTHrGRlXq954Uu9QYQ80ZNOa3gbg1olu4iBOGw3zb7G4bEd3AvOsptqJFreAcbrTt+LVljVoF0X0rcVEf+nJq/n2tGQMm13xwRvW5pLx78ly/FG/Wfqf7w9lIagr1k3nKdG4DKCmNU3YczMb1+6LAyqOvliRMSrUJpcsm97XTvvQJ2bbtogdRVTIwSk//VU3PZ7ruizebYM3Nshzw6Y6vVmEqUAW9HXuIeS0R8Il5oQPobKx; 25:bwUMWAyq4xYiL/JyMB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6ydnN2mpP4oFfmcjq0ErHe/qFMuOvzibPUFea9F2fPGkYM50+tHuveuc1Y7kNpc9q9ve0QJEqfJJTqBCGGtyN1H3l3m98vt32yJ4APMZolwkZhXd2pdrKxEuN8oS+afaX3EH5a6LpDrIBCXXoWixjZgCATFXqmaxRuTXxLsAvapZFpbbmwYF+bcDTQ=; 4:VRY+TfGIqU26OGgFGk5QF/a8zTtUd4AcGRT89ZpsBnf7DZMj2XSaNQcHzqpU0Rd8L+8pLh1PTLvNDZCv8wXtg4+PnLPpj+VSKiEsduWfMpvEKN3JwAvpvNpAVoJl35cqAy/M6Dd7ggNrq+DXbhtSZq1x5KWONtstQkODA0k3iLPgcQZiImoZGMFsa+4nqcMjrUK5WL0ZzLeRo56/ek4XhBcHuMpfv10ALN1wj9snHh41SLWiDD96GeFNVku0326y X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(100000703101)(100105400095)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM3PR07MB2121; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM3PR07MB2121; X-Forefront-PRVS: 0392679D18 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(6069001)(39400400002)(39850400002)(39410400002)(39840400002)(39450400003)(189002)(199003)(305945005)(3846002)(8676002)(76506005)(105586002)(478600001)(81166006)(25786009)(106356001)(50226002)(97736004)(5001810100001)(42186005)(38730400002)(5003940100001)(7350300001)(72206003)(81156014)(6486002)(10646004)(66066001)(47776003)(68736007)(101416001)(76176999)(2906002)(5660300001)(50986999)(189998001)(10916006)(2950100002)(42882006)(6116002)(36756003)(8666007)(33646002)(107886003)(7736002)(53936002)(4326008)(6496005)(6666003)(1076002)(54906002)(50466002)(48376002)(3486003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR07MB2121; 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: 1; DM3PR07MB2121; 23:7FxcUiLJuhQtU9Ktcda5gxtjwHLJ6bmOAPqnwYivN5VTFhNHDVI5uTWHSOeIviRdOgf06zy7bQTAj8Nk8by/+hA4ELJiEFqC28FWSfhXE6u+YYhhMFPrY8gl2RNWI04j+i0doZgigmXWDHxn0Vp40npfwabTQDe/iFUSy9QC9PqaN0H65GjegX8eU7it6hhHEALmEDUk5PF6VKRwqjFGlV+6UgdvWkcTLCZODMHvfuhrtRp6LAKDWCmxzoDcfTRxRlVAbytxG1SN0QJLvVw+i2hiMJommM/iPktS82z+B11AxbpPgeyVr0ubkRzxVmYda7G+8ByvSjyVbMvwAa9rZaRtwtm7znVozn4GfULNSlAK8p+L6PY19XLgtVCgp1z1q1fLes3zFD894fgh19ImjYHTUidZnam2lDpDv8obsivTzJAvODBz8kNW9t6eJU1QAiYAmWYg0CmWjs2QrH/8U4AbJ73Vhtm9knlRh7puszMVd8Rpvvi7dbxL3RFY+QPaHvzG/848/uECGD58nTT1Ftgfbg/vOWPJypr64Tzq+XGwYPmnu+StkkEulQ3UqrT8nkcUkynNg4k0QbJNa9CEai7JyWVTyfHzidAHqvWXqrSFZ9bS/fokHan28ZFVX8bsl0a1+teQ9+yOMsGPpxSn/F8Sg+C2cIsHv1V4Eq5XD48+kWij8vFJ+2QRn10HHrWj1Pry7Coo6HnFtqXaeNv9LPTMhIE60Ugu2bnUpWNvn60mLvEmgcyhl2qr8LJhHpjq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dHZZA95RarGGV/Dnez4SOBFnkTI4ariDUizvXWAiiZq4CyUqKr+8GfAQLfKCjkZoM8YXN+UmisuzMCevKNbLv92lvsTA1a8CwUnZiuD+nmozRPGOFIKWWOl5xzqaR8RPASCaA==; 24:TwGSoKz9OPDfhxsLF4jgHvkdrpDVu2v3gfptOBzPWWL+9giAwg6uPrScsU7UJnANZp6NzcK9/ZXg2IH/wO2z6rLo0OBb/scRsVMp+a+D5LY=; 7:1UzOKp5onYEQkuUUfcOJxQfcsXRycSetYo+IVcLSJZP5jnKVqnMAbive21QlqdG0DNrtJLnmWo6woGzYHmF4zahjwssSihvwcTUaZMqEsv18UWQq5B8zB78iZXajFKwvKF3gQBTqpi+Lz592fXDhSE63VuUgVRInxBgzMNB4r4OwKhwzY6qR9SJgnLn7plqRw5HIVGSmpDpmk7+81VwnG0urytmQo9YBhRTHGxzFyB0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2017 22:55:23.3922 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR07MB2121 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do some basic checks for the bitmap_parselist(). Signed-off-by: Yury Norov --- lib/test_bitmap.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) -- 2.11.0 Signed-off-by: Yury Norov diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 2526a2975c51..5b80dd94e4d1 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -165,6 +165,78 @@ static void __init test_zero_fill_copy(void) expect_eq_pbl("128-1023", bmap2, 1024); } +#define PARSE_TIME 0x1 + +struct test_bitmap_parselist{ + const int errno; + const char *in; + const unsigned long *expected; + const int nbits; + const int flags; +}; + +static const unsigned long exp[] = {1, 2, 0x0000ffff, 0xffff0000, 0x55555555, + 0xaaaaaaaa, 0x11111111, 0x22222222, 0xffffffff, + 0xfffffffe, 0x3333333311111111, 0xffffffff77777777}; +static const unsigned long exp2[] = {0x3333333311111111, 0xffffffff77777777}; + +static const struct test_bitmap_parselist parselist_tests[] __initconst = { + {0, "0", &exp[0], 8, 0}, + {0, "1", &exp[1], 8, 0}, + {0, "0-15", &exp[2], 32, 0}, + {0, "16-31", &exp[3], 32, 0}, + {0, "0-31:1/2", &exp[4], 32, 0}, + {0, "1-31:1/2", &exp[5], 32, 0}, + {0, "0-31:1/4", &exp[6], 32, 0}, + {0, "1-31:1/4", &exp[7], 32, 0}, + {0, "0-31:4/4", &exp[8], 32, 0}, + {0, "1-31:4/4", &exp[9], 32, 0}, + {0, "0-31:1/4,32-63:2/4", &exp[10], 64, 0}, + {0, "0-31:3/4,32-63:4/4", &exp[11], 64, 0}, + + {0, "0-31:1/4,32-63:2/4,64-95:3/4,96-127:4/4", exp2, 128, 0}, + + {0, "0-2047:128/256", NULL, 2048, PARSE_TIME}, + + {-EINVAL, "-1", NULL, 8, 0}, + {-EINVAL, "-0", NULL, 8, 0}, + {-EINVAL, "10-1", NULL, 8, 0}, + {-EINVAL, "0-31:10/1", NULL, 8, 0}, +}; + +static void __init test_bitmap_parselist(void) +{ + int i; + int err; + cycles_t cycles; + DECLARE_BITMAP(bmap, 2048); + + for (i = 0; i < ARRAY_SIZE(parselist_tests); i++) { +#define ptest parselist_tests[i] + + cycles = get_cycles(); + err = bitmap_parselist(ptest.in, bmap, ptest.nbits); + cycles = get_cycles() - cycles; + + if (err != ptest.errno) { + pr_err("test %d: input is %s, errno is %d, expected %d\n", + i, ptest.in, err, ptest.errno); + continue; + } + + if (!err && ptest.expected + && !__bitmap_equal(bmap, ptest.expected, ptest.nbits)) { + pr_err("test %d: input is %s, result is 0x%lx, expected 0x%lx\n", + i, ptest.in, bmap[0], *ptest.expected); + continue; + } + + if (ptest.flags & PARSE_TIME) + pr_err("test %d: input is '%s' OK, Time: %lu\n", + i, ptest.in, cycles); + } +} + static void __init test_bitmap_u32_array_conversions(void) { DECLARE_BITMAP(bmap1, 1024); @@ -365,6 +437,7 @@ static int __init test_bitmap_init(void) { test_zero_fill_copy(); test_bitmap_u32_array_conversions(); + test_bitmap_parselist(); test_mem_optimisations(); if (failed_tests == 0)