From nobody Sun Feb 8 13:08:53 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 E63F3320CA9 for ; Tue, 3 Feb 2026 10:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770114614; cv=none; b=SOjEy2Sl1BBN4ribOMglhfrdfSflY7WvdVhbooi951Rs4dAZ4lIj/biexAfz475ICNeXBl0tWoV5ziPkOdK9vnFd8hO4gr98Lz5I4fypkz+togfjo6lyeJPlggTwRCoikC1jHpHMoNlWOsyn+HGkbAasPPltbCugkgUZ402no7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770114614; c=relaxed/simple; bh=neT8lO755voJMGxMVzYkk//vb6OqJjD7qoRGhYArAWw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s3388WhgHvMYV1NC30JHUMpvY7T2ilQldKahWAM8c+H+lgye4iyEGQrziylMWnbneWQICj5j4ve3bAVJavLUOffmuGuRTC7Vuf9xIU6mS2fPCRDNOZjDiNjff7MWf1V8zL49Mt4Jq7jEwB7ByTgJk8A+ucsbRinugeEBwoAu3go= 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=g+drZHAS; arc=none smtp.client-ip=209.85.128.45 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="g+drZHAS" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-47fedb7c68dso55435225e9.2 for ; Tue, 03 Feb 2026 02:30:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770114611; x=1770719411; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bHKF35rgduIXryq8iyoVCS15Hn5/OcfLPncoO1eDa7s=; b=g+drZHASmTcl21OlEHjAV2EvuSoXulkmn38MnqeqC0T3hDcDxhkmVm/Lw39/b814nV GET37jLWFxqtEAPmmsO4KWXvK4LrgoRk7ZML/shdTQAbtPo3p5kBFckWyLkL86MUaYu4 EQGgcSXDhMBeBMpTs7Ae+d5I+vjI1OwddsPQLaIwCYkxlbCX8pznZeUy+Ho0RLyjs5DR XojdjZBv1MJqs33GY77PSrXqAdJhAxyCzcMdEPWRbZtnmmj9h0bXfumqfVAVYQcEbz8N RBi2Mo4KMhwSdfCk/tahBiGk+2lBoI6Rj15xljhWZesYLGsaKnfHPvPA8z75url6xtGg w13A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770114611; x=1770719411; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bHKF35rgduIXryq8iyoVCS15Hn5/OcfLPncoO1eDa7s=; b=dHi6jdb+3m3DOzc2BS2kyrnwpyQ1WkSVxHdtfOqOxdeaQe+SaSMbduDGkOnsCILERN 7/b9rZrVpzj2MJp+Mtm1FQu2+o/SRtbowS1JcDS8jodM+rDrdauKS5H3aAw0K2f26gXJ CbS8B+vFLm/3MsNC1IsMhjEkul0JHEH3m0W7t6vndg2/PYIqdnc6on6QdA4ecBdl/xBt w22pJqEEnq6gjxJoIqrwCvfN52IY2DHWIgMUz07RNI+PgUPighpxX3Q2o/uNkqLeA5QK QCVwg9tghPKJge1iq+h+n2qR+4A9W5gnp6IuosNQv9Ill2bs5sNScByX/yiScQ1BP+YJ iovA== X-Forwarded-Encrypted: i=1; AJvYcCVhPuYJ4sYkaCvQkfgr5Sl5Kho/LDr56N1NYLboTFSYNuSQtgHh7j1myqW9YtZ1g+xrK7wmWn1PgVjHotg=@vger.kernel.org X-Gm-Message-State: AOJu0Yyiedl2fXB58iybrLzvF6Lw/d6C9fyWf11xWCUu5H5QMCTuDfmW THpjqeT8pk9NQyT6FZQbEQqA5bxXQoVTNK81efkdElZTKHJNqVY9iWka X-Gm-Gg: AZuq6aK5cMjQTNm4j9q1e91vvc4Jjyl+yzS88Z6VGVIGxvE6ZMiHwzxtv0vA4SMtxBq uDCDJ71odVRKOTVD3fUnc6/Zp/0bgeMg6gxvukqkNJIHq3Oo0OXymM5zVb6ZMCTEFYVwLemXdJY pzIq2KJ5ewfDseWl59iUiGD4eMCauYHCl2Jpf0XZDYgeCPoE0Q2Dn8YYYcMPAJiOP/0IG5EK66l xbo4hpekwznBWDZUjTBGb60ej8Pj/PHZcm4Ey6WYkA3GdnZfywJC0+xmtRGYnihWzhvhXkn21J4 1h5UnbcYP3ARqUZOjELu+TZY0zQuRZnZCsWIAh1j7tS5fYqnIvGzi5SwRfJlfPhrseeeVnsbYH/ hu6Xhxm2QBFw9D4bHgAnrnhWeXLNuGln+KgICZKJ3PFMWjQCSjDabihD3qptzVrSinvRA6GF+/S MeZ0VyNEHc3GaM++IxdyxospxmjXCRXOOUkxbCZ8tOhQxUnTE3JL3qJBhPImOR7ezWwwE5WbBLm 8pENrfeKj4= X-Received: by 2002:a05:600c:1da8:b0:480:3a71:92b2 with SMTP id 5b1f17b1804b1-482db498227mr179296045e9.26.1770114611336; Tue, 03 Feb 2026 02:30:11 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435e10edf62sm55940729f8f.13.2026.02.03.02.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 02:30:11 -0800 (PST) From: david.laight.linux@gmail.com To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, Cheng Li Cc: David Laight Subject: [PATCH next 02/12] tools/nolibc/printf: Add buffering to vfprintf() callback. Date: Tue, 3 Feb 2026 10:29:50 +0000 Message-Id: <20260203103000.20206-3-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260203103000.20206-1-david.laight.linux@gmail.com> References: <20260203103000.20206-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Add per-call buffering to the vprintf() callback. While this adds some extra code it will speed things up and makes a massive difference to anyone looking at strace output. Signed-off-by: David Laight --- tools/include/nolibc/stdio.h | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 6c8fa41dbc01..985e10d747db 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -381,15 +381,41 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *stat= e, const char *fmt, va_list return written; } =20 -static int __nolibc_fprintf_cb(void *stream, const char *buf, size_t size) +struct __nolibc_fprintf_cb_state { + FILE *stream; + unsigned int buf_offset; + char buf[128]; +}; + +static int __nolibc_fprintf_cb(void *v_state, const char *buf, size_t size) { - return size ? _fwrite(buf, size, stream) : 0; + struct __nolibc_fprintf_cb_state *state =3D v_state; + unsigned int off =3D state->buf_offset; + + if (off + size > sizeof(state->buf) || buf =3D=3D NULL) { + state->buf_offset =3D 0; + if (off && _fwrite(state->buf, off, state->stream)) + return -1; + if (size > sizeof(state->buf)) + return _fwrite(buf, size, state->stream); + off =3D 0; + } + + if (size) { + state->buf_offset =3D off + size; + memcpy(state->buf + off, buf, size); + } + return 0; } =20 static __attribute__((unused, format(printf, 2, 0))) int vfprintf(FILE *stream, const char *fmt, va_list args) { - return __nolibc_printf(__nolibc_fprintf_cb, stream, fmt, args); + struct __nolibc_fprintf_cb_state state; + + state.stream =3D stream; + state.buf_offset =3D 0; + return __nolibc_printf(__nolibc_fprintf_cb, &state, fmt, args); } =20 static __attribute__((unused, format(printf, 1, 0))) --=20 2.39.5