Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp880592lqh; Sun, 5 May 2024 06:12:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXEq2UFsDLFocMkq8AQqxV0KeTCrCx/nudKVszaPJPSyZhZmIKxdUSmbhlrJ3JFPQ6b5uaxDLiGOoa4dL/KtK4rTpQZNTY04/rjxdznIw== X-Google-Smtp-Source: AGHT+IHrvKFXpgl6PPYe8E3tKhPC+qncmsFYUkRIdZ13tRZ0hCexwXzNpYCefAlqW3ZJGlpcoC+E X-Received: by 2002:a17:907:3da0:b0:a59:8ef3:7d62 with SMTP id he32-20020a1709073da000b00a598ef37d62mr6151879ejc.40.1714914766256; Sun, 05 May 2024 06:12:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714914766; cv=pass; d=google.com; s=arc-20160816; b=gGEjGWLmkiU9VGlrAnTDNowfWLFSIqzTwIKFALYUCwEQrsRjbzzrB/749Q5i1wIrz/ 5dhEer+aaoyBGiMmrydkh+fH6NuXSiFlAPYj+VY1ybVkiSfVPW4zuGkdg9RoUdX8Xoie z27EcKMBDY4m5OxGMyZQe7HPFNs32vlIwclhKQY/aGPRV9qAwoeQMPns8TzW72fPOzzy f2oSZCI5txGPxpWMNwgF2Im0L+9rBuf/fGMJu1LBUonGaRlrUb5EfXc0CqnXkNuQVm1M YANPJd9Ad4vZUJpHfMHGiQzE1JxZrxSzU/5esWhyodTRiAzwNUZP79jVsB5dz7rMGC+R mLIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=Z3FbS5myL00M9I7OPGe6lVuRzyN7oeuuP1w/wFtShmE=; fh=uzd/1HWWsOW16G0opoQsnxjoy3hc7WEgP4VqTuakAJI=; b=lrnteaMZLYCLhrEWCf9IPpoWQvmpZVSQGTep9m19tR3AdGjcTfAFD0Uebja9EKrQB0 BJT+8mPv6ej7YnTpe70E6GdBtgvsuUK+CO5wXLhsEh+QXRrBaxWUKO7X3JvVquWoZLAI reb4Y+C3sBORrTJMhc5qC1iyTgVRwxLjkNEElPiHLNzUIlzKBP8O13qeradSyeoP7J0X jJR2NrbCx0ZWQ7vYVayDov2Y/HyDGCqJn51uAPr7uLlFQ0BHQ6GqLnhzltn1ZsqXg8Wd bBWjiO1yYJ0Km+xCAgAMlkZNGpD2mZbgbIzzwyuxijk0LjsvshAqEpfl8Pmjg4M5Abjc HmqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-168977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p18-20020a170906785200b00a58f36a9f0csi3911484ejm.915.2024.05.05.06.12.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 06:12:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-168977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 198951F2138E for ; Sun, 5 May 2024 13:12:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE0851CA92; Sun, 5 May 2024 13:12:33 +0000 (UTC) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D09F18C36 for ; Sun, 5 May 2024 13:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.85.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714914753; cv=none; b=Ox3Z0j2vT+qwwjgxAotyLOVxyHK8CEWRSL/KQlvj9CHLKgVZtPymGWKDHs2snXG9lKSk/eipyItemToxID/U+Mk/u1hqiM1ZSnmG8js1R0zoKTEJNZ+L+q/c9uz0HtNuf1R4PGJ1wXbNnHukhP04BotMnkY0ysn4ByMsi2eVOHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714914753; c=relaxed/simple; bh=mqI7Lkx9BEEGcIaH2vP7P85Be4RYE/5c4rJo24kmo3o=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=HRKOntTcIoKvYDQqGKyrBso2k7JaIMoH2rqqjbkP7O41Sbcrp+7sk6qqcfBBUNw9wDLy4nky6en8U6VZZiqfqNPCK1akDlpe23EDs5fEX9A9g0hY7Qo5JK7R3xJ8Uq+Ga/Yu+hV7s7mwpjouX72RmZTJNK/4EAIvjTHTnW4C0LQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.85.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-92--hnA0pcqNy2537LVwsUSTA-1; Sun, 05 May 2024 14:12:28 +0100 X-MC-Unique: -hnA0pcqNy2537LVwsUSTA-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 5 May 2024 14:11:53 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 5 May 2024 14:11:53 +0100 From: David Laight To: 'Yury Norov' , Kuan-Wei Chiu CC: "akpm@linux-foundation.org" , "linux@rasmusvillemoes.dk" , "n26122115@gs.ncku.edu.tw" , "jserv@ccns.ncku.edu.tw" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v4 1/2] lib/test_bitops: Add benchmark test for fns() Thread-Topic: [PATCH v4 1/2] lib/test_bitops: Add benchmark test for fns() Thread-Index: AQHam+S8XBnnR43Z8kaIhRcpvR0+crGIoopw Date: Sun, 5 May 2024 13:11:53 +0000 Message-ID: <62fdb348791949c08e53936e3bc442b5@AcuMS.aculab.com> References: <20240501132047.14536-1-visitorckw@gmail.com> <20240501132047.14536-2-visitorckw@gmail.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable From: Yury Norov > Sent: 01 May 2024 17:30 >=20 > On Wed, May 01, 2024 at 09:20:46PM +0800, Kuan-Wei Chiu wrote: > > Introduce a benchmark test for the fns(). It measures the total time > > taken by fns() to process 1,000,000 test data generated using > > get_random_bytes() for each n in the range [0, BITS_PER_LONG). > > > > example: > > test_bitops: fns: 5876762553 ns, 64000000 iterations >=20 > So... 5 seconds for a test sounds too much. I see the following patch > improves it dramatically, but in general let's stay in a range of > milliseconds. On other machines it may run much slower and trigger > a stall watchdog. >=20 > > Signed-off-by: Kuan-Wei Chiu >=20 > Suggested-by: Yury Norov >=20 > > --- > > > > Changes in v4: > > - Correct get_random_long() -> get_random_bytes() in the commit > > message. > > > > lib/test_bitops.c | 22 ++++++++++++++++++++++ > > 1 file changed, 22 insertions(+) > > > > diff --git a/lib/test_bitops.c b/lib/test_bitops.c > > index 3b7bcbee84db..ed939f124417 100644 > > --- a/lib/test_bitops.c > > +++ b/lib/test_bitops.c > > @@ -50,6 +50,26 @@ static unsigned long order_comb_long[][2] =3D { > > }; > > #endif > > > > +static unsigned long buf[1000000]; >=20 > Can you make it __init, or allocate with kmalloc_array(), so that 64M > of memory will not last forever in the kernel? >=20 > > +static int __init test_fns(void) > > +{ > > +=09unsigned int i, n; > > +=09ktime_t time; > > + > > +=09get_random_bytes(buf, sizeof(buf)); > > +=09time =3D ktime_get(); > > + > > +=09for (n =3D 0; n < BITS_PER_LONG; n++) > > +=09=09for (i =3D 0; i < 1000000; i++) > > +=09=09=09fns(buf[i], n); >=20 > What concerns me here is that fns() is a in fact a const function, and > the whole loop may be eliminated. Can you make sure it's not your case > because 450x performance boost sounds a bit too much to me. >=20 > You can declare a "static volatile __used __init" variable to assign > the result of fns(), and ensure that the code is not eliminated Yep, without 'c' this compiler to 'return 0'. static inline unsigned long fns(unsigned long word, unsigned int n) { =09while (word && n--) =09=09word &=3D word - 1; =09return word ? __builtin_ffs(word) : 8 * sizeof (long); } unsigned long buf[1000000]; volatile int c; int test_fns(void) { =09unsigned int i, n; =09for (n =3D 0; n < 8*sizeof (long); n++) =09=09for (i =3D 0; i < 1000000; i++) =09=09=09c =3D fns(buf[i], n); =09return 0; } You are also hitting the random number generator. It would be better to use a predictable sequence. Then you could, for instance, add up all the fns() results and check you get the expected value. With a really trivial 'RNG' (like step a CRC one bit) you could do it inside the loop and not nee a buffer at all. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)