From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 3888142B72B for ; Fri, 6 Feb 2026 19:11:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770405093; cv=none; b=a/sOm1Ufehzp4LxmZvHjSw0NdHWRUSUHdsv1ScJdQiCDS65eX/AniKgXS1MihCFma2vVHy64tswa4s5wN+IcSEMQOiq3vJvV4zOTugPIPgpexPEDrMTulrmEDaoRPNc+szO0hcChkyxJ9ZoyBpGhrflf091genpi6dumvCNBwRk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770405093; c=relaxed/simple; bh=iaI52W51ZxC90xPwakjBzA7Xh0vP4DctiyNT/NiUqDM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rXHNkY+cb+q2XRBTmyjeJMLvCAROrVXAc7TBKYGBjlfKe2LPFY3HNYQHXQO/didiXWH83PPwcR8i9ES9twrdUNspXBgv/yX1djIQzwFhFTyu+mfk2HNcB/tPQx/vT6BvesNspnOESAL3xk3Ugujr5dwNCnK6Nuj3PBsKKu2Xdkg= 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=Pui3K+zx; arc=none smtp.client-ip=209.85.221.44 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="Pui3K+zx" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-4359a16a400so2380012f8f.1 for ; Fri, 06 Feb 2026 11:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770405092; x=1771009892; 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=cy3BRgjtwDXlEZIz2gmXCOLxA/1l1kyL5Gw8gXmM2j0=; b=Pui3K+zxuK6JioxIlAPHJIqDr0UQPM0KCCu+28nXbypVCd5PwSaRS05W9Di2RQJ7nD L9lbTwKxR+27cOuSCz6eyzADIG2LXk4n8JBWrIgU8hni5WyTq+9thPaZ95TkbfafweSa HB0MBjtMCL2UTI3MI0gPHBcjNVx6RFYwg9fvwDRwzAM7gRNqNSD8/+CD+dQf07nM5snk SN+t0vZRjoPEGx58uZgpWqJyH3Kb+LSO5GDpdvQ4ILZ82ICYg0On8u45T4evKPyq9ZxZ 0c0lbsVKH6l4NzyZo6tlVQ/fL5FAq6meTrwe2hikx5lIfTdIu7TnMi2VfU5jhI4UZDRZ dzwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770405092; x=1771009892; 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=cy3BRgjtwDXlEZIz2gmXCOLxA/1l1kyL5Gw8gXmM2j0=; b=i7EdXHaLtvCKW7wSDw8sDfosQa/ko3gH6EITfkGITBYsX5SCjuKzWBk0teN07bLbUs 1xXVY9PkhYKW7BSPY59OJqZM26xvfuL0Jzl7Lu9kbOWGHbmDcliAseYONvyauZEAiiiQ DUhH026+ujB7RdUKln2cv0FiOfYuRxrMpmhdj7fIeOUqvC4vP07qDjMypTjSFV36IyYA pnuTV8eUycQZNnuEa39PP5AANKjsQp9RGUiI3ubPk96A+7MZAZCqu5Ft+JurrN40KJmI kQ1n2s0HhT/ktPsPnkKRpJk8qLMVFtzJxLgkBfmbG4KKJeQVUb9+FFxc/A6ZWBA4jln6 CR4g== X-Forwarded-Encrypted: i=1; AJvYcCVKPQ8IY7uCIEUGR5ARFTHi7WBhb4CQCD+zbKQ49zuZqypiL/xY1PNLektmpVLIsL8ULczpt8FF7XSuMi0=@vger.kernel.org X-Gm-Message-State: AOJu0YwjqVLzUqdr5XJhMqZvZx8TVhSOHcQJmrcoKyvAzOZZ0Xa3/QOJ pAh4CALLm3A7r3/Wt2MhFM8H1EpeoUg0iNc7pYxM8ksY66cfTlhOhvvd X-Gm-Gg: AZuq6aK3DKDv8fTxUzAMjlndXi9BwhWijbKxOCwY6DKdQoQDCLFH5u0wZRgNf+5hJ/m cHJDkB0qwyvt9hbkf+xmzbifsW0lAmCZ2fZRnsu9J+yc3ssU2qZftwjOTO+VXe+Ix8MN9BTNkeY Fmviicj1pK8aZrAGp+ZwPrqQuhiW0hIBWpkaj0Vxbtlnzt8WfircvkPbg2mtMnfYbxqyDEl3m+R rn6OIOqV6TYGd6FRbouHpcaLzTjATPZ4BLFKaepOwaiEtTBIcstG7A2UzKum9Gjm7+NQJ1Qn4Q7 +VIx5phEImrGlPgvJMq1gABD4xXBKd08E88RUuuekTlmamqQuaF7dZQwaXOXtYR3ryzH+Ie9bVW e3yxFiNDn/9y5Wrz/UVfgG4OdVJykuz7XmCetZOo1a1T0xVNns2Tph6oiOtQECJ/ejR5jwSaC3W dGqA8vA25NNHSgfVMYe7HN14GgdaUCLFJsCRrAm2PHH1jcO6t65NEH0kbzThv3DGlIRBnShZPs X-Received: by 2002:a05:6000:186c:b0:436:1ca2:67e with SMTP id ffacd0b85a97d-4362933ab08mr5325915f8f.8.1770405091587; Fri, 06 Feb 2026 11:11:31 -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-4362972fb81sm8703681f8f.20.2026.02.06.11.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Feb 2026 11:11:31 -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 v2 next 03/11] tools/nolibc/printf: Add buffering to vfprintf() callback. Date: Fri, 6 Feb 2026 19:11:13 +0000 Message-Id: <20260206191121.3602-4-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260206191121.3602-1-david.laight.linux@gmail.com> References: <20260206191121.3602-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: 8bit 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 --- Changes for v2: Formally patch 2, unchanged. 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 36733ecd4261..552f09d51d82 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -382,15 +382,41 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list return written; } -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 = v_state; + unsigned int off = state->buf_offset; + + if (off + size > sizeof(state->buf) || buf == NULL) { + state->buf_offset = 0; + if (off && _fwrite(state->buf, off, state->stream)) + return -1; + if (size > sizeof(state->buf)) + return _fwrite(buf, size, state->stream); + off = 0; + } + + if (size) { + state->buf_offset = off + size; + memcpy(state->buf + off, buf, size); + } + return 0; } 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 = stream; + state.buf_offset = 0; + return __nolibc_printf(__nolibc_fprintf_cb, &state, fmt, args); } static __attribute__((unused, format(printf, 1, 0))) -- 2.39.5