From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1955E38A9C6 for ; Wed, 14 Jan 2026 10:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768386128; cv=none; b=QoiU6A7xf+x6ode3W0UciP/WsYUacsm2jfP2Bxh95Zr+w4RG1IJgqJKmT7UUWDih+h3A5tV8FayFQTqZW7NWpN5uIs4SIHOAvZwJEqNfg+PigwAS7YWrd9X05suplWocYBFLqUdK0lnp3lSKcLIrYtWf1fQ15m2i12WichSyWII= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768386128; c=relaxed/simple; bh=y/Tx52YVSUIzWNI8DzLbQiG3rqi2DQ3nJ4pmqX4O5XI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gB7OwBZPQ7pGdpvQaJagXsvSJdOMIOIpzXAmlo6gZtkhkmu4NWeY3MBvem9Yyyi6szoJ4C4kqt6pioM7FcNlNFLHDkVeq4+6hUGH7KAMs5qaOC+cXrPDtgPbXbvQsud4DmFFVvNQ2efEYyk+GMaYZhce9vFzYpSdKxNoD/zEuZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=INXHe+GX; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="INXHe+GX" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-42fbc544b09so6724568f8f.1 for ; Wed, 14 Jan 2026 02:21:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768386116; x=1768990916; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=aby9hG1Lpv1OF3fYnEo/Zyk0Fv/I6aSt+58OzVwNuFQ=; b=INXHe+GXjxIhAFebKhydD0fRRa9e/N8q/qvefQjDgi6WvdfNZyh+Ow4j6jFYzvcZEo 83L+80NP768ACYYWD1mC0RogfAJ7tsHOwJVmgg346bjaNTkav/BH8pno/k6vDJJwWf8q QK6CHpzmoBfTkLgYue+xXK8bw2lf5zGfyEvcvSReD7Q8ks2RVUQq6tx50kwn39CTbQG/ 8+6IZ/O3uRc0qn9ZbjOXp0RnG7gZq2cpYpvY4hLY/Zmaz2ZbNM2fQFmTFIPGzQOB89J6 ZVjpWAacWZr49S+pANnPUl/u210G42b7Fu1Mtxf6Hz1BU1QCbAo29+ZWdITojpDufhPC BdQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768386116; x=1768990916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=aby9hG1Lpv1OF3fYnEo/Zyk0Fv/I6aSt+58OzVwNuFQ=; b=YFSleyViefrA7kTCQ8KlLNE2zFedMsnj0ERv12siYzuVhsG7AUM82BR8tm8niC/mDe qk8PvuIDQnlFwS5n7CTTKTmcWwCkESjQB970LJ6P8FefIORuky1m7PxTzVpzUMt568z9 aHBsQmjTtZyT0EXX/V98VQYQ88pJyr4OstZS89JUGfEoPD3ilrt6Ki/AesbiPE1AhtvF Raztnid4ZIg4i+zp1wCyB+0zlQGWQqmA7/dKmwHgakdT64JqUIkJ+AZwjpZHtVEUs7c0 OAXk+ZkGVvf6koraQxCzVmB54RBbHVc5IrbCCaaSc39iifR9EZRUfhZzAfCTeEuABNFX s5jA== X-Forwarded-Encrypted: i=1; AJvYcCVbVRokeRzYsQckMRGpZp4ds5IUINPKQADy5opAI12do8NADmMwPdidqW1BBcPvv5TUIfyxfT/9pTN0Jsg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6e0Eg63mB+oGz3jRaXp62rtnOASuQUt/HLevbgA7qVR9o1As1 dHmGpkAEd1JGwLfAxB57T4BpOuDFi7VxFtsEx6jlGLKNdFjxpvrl8659 X-Gm-Gg: AY/fxX5Stm6rTAR91VV3NUjNETe4hlDgCjvpF0UAiwlmogiMlV1DPYIlLW/t0YDhyL6 rGsDp/BJbWU40ZAGibCAZjxwPZ+c79dXqGFcqVWQE58elT6wm8vPFKYCXk2NhaPB7ld9161teF1 ndP49PuPDZM2mDFCdo5tbN9Q0+9psHMZ/w9SFy1OnY52crgDBvrPcitIADr4yhyrrRy5ebOJqj1 nE1Jq/1B+BHl2y+NxVUhCIdj0ENdXY7EcCkDMCvm/ALHKaYoSjvtg5pQoJNB/9U2z9NphaC/aZN 9VYNDp13JwIqE+QvShFpoBc3p/upulSEqU1IzgO8GFj+7fOfYhApE3nk1YB1GQ9KXVVzv+2fbmI 6ozQPid6MEKsn3bffVOtZ4/KNZQKyMSx/V0zmd4jaKzH8/+BwRMqmnejDIj+ihiqY2kW2XRYo5f TuZCu7YXXSHYjwyFdb/ZfPfVTYYHsM8aDDbNlN3CkUx5Qk9X4wJWtC X-Received: by 2002:a05:6000:1789:b0:433:42d1:f71f with SMTP id ffacd0b85a97d-4342c543bc2mr2513654f8f.38.1768386116121; Wed, 14 Jan 2026 02:21:56 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-432bd0860f5sm48694254f8f.0.2026.01.14.02.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 02:21:55 -0800 (PST) Date: Wed, 14 Jan 2026 10:21:54 +0000 From: David Laight To: Feng Jiang Cc: Andy Shevchenko , pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, kees@kernel.org, andy@kernel.org, akpm@linux-foundation.org, ebiggers@kernel.org, martin.petersen@oracle.com, ardb@kernel.org, ajones@ventanamicro.com, conor.dooley@microchip.com, samuel.holland@sifive.com, linus.walleij@linaro.org, nathan@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 08/14] lib/string_kunit: add performance benchmark for strlen() Message-ID: <20260114102154.251082c6@pumpkin> In-Reply-To: References: <20260113082748.250916-1-jiangfeng@kylinos.cn> <20260113082748.250916-9-jiangfeng@kylinos.cn> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 14 Jan 2026 15:04:58 +0800 Feng Jiang wrote: > On 2026/1/14 14:14, Feng Jiang wrote: > > On 2026/1/13 16:46, Andy Shevchenko wrote: > >> On Tue, Jan 13, 2026 at 04:27:42PM +0800, Feng Jiang wrote: > >>> Introduce a benchmark to compare the architecture-optimized strlen() > >>> implementation against the generic C version (__generic_strlen). > >>> > >>> The benchmark uses a table-driven approach to evaluate performance > >>> across different string lengths (short, medium, and long). It employs > >>> ktime_get() for timing and get_random_bytes() followed by null-byte > >>> filtering to generate test data that prevents early termination. > >>> > >>> This helps in quantifying the performance gains of architecture-specific > >>> optimizations on various platforms. ... > Preliminary results with this change look much more reasonable: > > ok 4 string_test_strlen > # string_test_strlen_bench: strlen performance (short, len: 8, iters: 100000): > # string_test_strlen_bench: arch-optimized: 4767500 ns > # string_test_strlen_bench: generic C: 5815800 ns > # string_test_strlen_bench: speedup: 1.21x > # string_test_strlen_bench: strlen performance (medium, len: 64, iters: 100000): > # string_test_strlen_bench: arch-optimized: 6573600 ns > # string_test_strlen_bench: generic C: 16342500 ns > # string_test_strlen_bench: speedup: 2.48x > # string_test_strlen_bench: strlen performance (long, len: 2048, iters: 10000): > # string_test_strlen_bench: arch-optimized: 7931000 ns > # string_test_strlen_bench: generic C: 35347300 ns That is far too long. In 35ms you are including a lot of timer interrupts. You are also just testing the 'hot cache' case. The kernel runs 'cold cache' a lot of the time - especially for instructions. To time short loops (or even single passes) you need a data dependency between the 'start time' and the code being tested (easy enough, just add (time & non_compile_time_zero) to a parameter), and between the result of the code and the 'end time' - somewhat harder (doable in x86 if you use the pmc cycle counter). David > # string_test_strlen_bench: speedup: 4.45x > ok 5 string_test_strlen_bench > > I will adopt this pattern in v3, along with cache warm-up and preempt_disable(), > to stay consistent with existing kernel benchmarks and ensure robust measurements. >