Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2485220rbb; Wed, 28 Feb 2024 03:26:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWlZK0wH56EigqeRKZk+nf0WyaO70OKvaGXXrTzqhU2h0vF23W/PXz9Ob3UL3Aj2IjrfbhPtL06KSEsttk5feI3eBIT/18H6ZB/k1vaJA== X-Google-Smtp-Source: AGHT+IGEEtaqWdTHEst+aoKMxir1lFPbel2vmwqvMRLOLIQN+8PXCQvQQndcPG4pYtiZ+JK6WQlM X-Received: by 2002:a17:906:750:b0:a3f:7fac:6cd2 with SMTP id z16-20020a170906075000b00a3f7fac6cd2mr9101617ejb.43.1709119607100; Wed, 28 Feb 2024 03:26:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709119607; cv=pass; d=google.com; s=arc-20160816; b=dD3Ene4yDUNRjrQvXBhm5fdr54P6KJaZoWxS0hS4KmziMYcR0c8mLM3zautVU064HP gVI8wpiqNHTVFYk97pNP5+P/EU8VpEbHxINNkJYaSPgEP6eHXz07BQxEe/tUsb5uE6bh On1ltrHlv6jwOefKZEizq1gFcAqmq9YWQqIyY6HGHQdPqWlY+oy5bCOa/biUyVBwnNsr 8PNZpypmfeHhk6LDLLkjBFI4D0RF1CK3IaEluUKt8pyr6AYsRClplqRMv+p+LdWhDtHx Cq2pBeHWH+2mCNnq/R6s3yot3x2QXy9fk1PeQuFCl5nD7ugRrclCA0bNJ0VWMfvSKiZJ MvQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=jIUrY9KDv7usIWFJU72QBMyWmzWFvkj4Y1/FWWb0GFA=; fh=TLZMPf+ohcoTTGC07a0V3EpPIB5MG4ZXrLcqBar+nRQ=; b=BVBQmM5Oj1z0AH6ZaG3IaaWIUxTSCPWdE+xb97sze6wHE+kkcfzBEZoBqto1gKyWgr 5pmJ+8PdBnj2+FkbQRSanopQL22u1yJDkfpbt1mwhYoc7Sd0WxCHNJ3t+vUe8t7bDAG7 SRoi7kI4WlkET0MA3jLnGDm0iQSbl6ZrG8fdxcYgbkT5m6Ah3E3JskTibhAbLzOzVs4w /bSTl/gGgoEyp1Dt8Ytl20SXhOnuqHeYiZCHOF1Z+ktq8Lex6+HOSIAu/8QZMLar5rjP lMQk8LNigvDlE/i4pneQNMNhaYfB/p9zZJMIRuYDaVOf1PhUwV12Eb7aVf9/4mlOrLtr xtSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=ZgpveGg4; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-84869-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84869-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kj27-20020a170907765b00b00a43faa5e9f1si559993ejc.635.2024.02.28.03.26.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:26:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84869-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; dkim=pass header.i=@suse.com header.s=google header.b=ZgpveGg4; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-84869-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84869-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.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 8CC371F2732D for ; Wed, 28 Feb 2024 11:20:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 895DD13A86F; Wed, 28 Feb 2024 11:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="ZgpveGg4" Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 145DA12D74F for ; Wed, 28 Feb 2024 11:20:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709119221; cv=none; b=S6XQamTf2hIQxBRFZTE+9eLljecmP/clk8sIm9pv281YnkgKQN+7dV0mn3j5habx9z4XrCz43Lab2PP8RybrJCGy1q24op99lyZ0lJRDpWpx7BVNakCFq7mT+mW259YZaBVb5pmVi15hjIjJrQ+VTU5VM/uAZl8aMVPgU6nIvGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709119221; c=relaxed/simple; bh=9Pjb8ad1dWopeClTm1dO7F0uJkozJKBfGd87+TqwJvU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m38Il1HiItCC0Upzp5LUXVRrYwKDg/2bTBKcSPGBY6kQ3d2qNQAeZn72v1zN1pmMp2EGSbblvjy9rjnLcy2ur91YEmJfClPWXIlR4/chd+MiuDUdt8EDjusrslkTZSI5hP07NkTtWVwrbGwB/wjmhS1D257UZKT3qupfMcpgNCs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=ZgpveGg4; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a3f893ad5f4so740940466b.2 for ; Wed, 28 Feb 2024 03:20:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1709119216; x=1709724016; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jIUrY9KDv7usIWFJU72QBMyWmzWFvkj4Y1/FWWb0GFA=; b=ZgpveGg4xq/XgoyEYabBsRbocLVbwIaU6J4I/pjURJ7F06gAUewxgoAkz2st/LXfIf KOxqsVg3IRdHxp1ZJWiZFZpOJKjX217TuwaWRgG6Eia0HhoBtMKGD+Lw4L9DdSlYm0mb Epc6CXVh1wTDcgZJLBN1Y3YS865iAlswWnXqiIE21JoQVT1W30lcsjm/4cv/JmEaznt0 SXxWhKls53pjjqtR6KaxJKxOYceWs7nKzeXqZL3tZviN08IfmLppCztTnxAwA83WdOx+ jcU8os0Ab12/beMB/pnCx7yQJ1mi1WeMkg+19MBKEgsaH2/1uwKOjEj2fustWV3oDe+u u/Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709119216; x=1709724016; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jIUrY9KDv7usIWFJU72QBMyWmzWFvkj4Y1/FWWb0GFA=; b=V3WP/q3Y50IW9In7EAXFxHJfY3gACqkJi1C6txorn3cRGL2M89c/yI88cnDQRFO0UH 9vSWJnC5fcej9viznsi1K8OKuFkHId1XrouRkqrgeJEBQDWzP5wp0vxEXyVXzrA5Ooks 59H2IBNaxl7aHI0Ns/QhrDV5rRW2+LalkF+/f7p3EKzboYAv6Y6Hx6hrYgbW8yEmzatY cvZodE7HRw254p8lgQ3IMH29sUi10J/mg9lXOS+yeL81u11GW0psT6gowx9ZeF32OtEj TWfRfQbfsGQSgRXRL5bHvAPU6H26h/4kqI/0jxYUIu8lCesxSTNkOBggEY8iCX6HEysZ efgg== X-Forwarded-Encrypted: i=1; AJvYcCXAyZ8jy/obAefDZriGpCww+PxB4hWDN1GLTilgUR1WTNtjOKK8VOhfu++889Jnvt86SQkD2oSOjZkSY2yX4ioxjq7Ghq3xMQhmX2mr X-Gm-Message-State: AOJu0YyKDPZhgpc7FD3+2zbx/9ZJ8G1wsSqiP2F2S0a92gPtRSetg/ks 2es/HnRiogTFC0ZZA4oS2Y6FFZ1KZ/rqmUO0g/prwB6b3j8WYEAs14sZluCQofE= X-Received: by 2002:a17:906:131a:b0:a43:9ad1:f1d2 with SMTP id w26-20020a170906131a00b00a439ad1f1d2mr3638380ejb.1.1709119216393; Wed, 28 Feb 2024 03:20:16 -0800 (PST) Received: from alley ([176.114.240.50]) by smtp.gmail.com with ESMTPSA id kf5-20020a17090776c500b00a438d594d3esm1732203ejc.217.2024.02.28.03.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:20:16 -0800 (PST) Date: Wed, 28 Feb 2024 12:20:14 +0100 From: Petr Mladek To: Rasmus Villemoes Cc: Matthew Wilcox , Steven Rostedt , Andy Shevchenko , Sergey Senozhatsky , Randy Dunlap , linux-kernel@vger.kernel.org Subject: Re: [RFC] Printing numbers in SI units Message-ID: References: <94713e86-30a8-4828-959d-bd95800149e4@rasmusvillemoes.dk> 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-Disposition: inline In-Reply-To: <94713e86-30a8-4828-959d-bd95800149e4@rasmusvillemoes.dk> On Wed 2024-01-24 23:43:15, Rasmus Villemoes wrote: > On 24/01/2024 19.58, Matthew Wilcox wrote: > > I was looking at hugetlbfs and it has several snippets of code like > > this: > > > > string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); > > pr_warn("HugeTLB: allocating %u of page size %s failed node%d. Only allocated %lu hugepages.\n", > > h->max_huge_pages_node[nid], buf, nid, i); > > > > That's not terribly ergonomic, so I wondered if I could do better. > > Unfortunately, I decided to do it using the SPECIAL flag which GCC > > warns about. But I've written the code now, so I'm sending it out in > > case anybody has a better idea for how to incorporate it. > > Well, something that gcc will warn about with Wformat isn't gonna fly, > obviously. But my man page also mentions ' as a possible flag for d > conversions: > > ' For decimal conversion (i, d, u, f, F, g, G) the output is > to be grouped with thousands' > grouping characters if the locale information indicates any. > > Obviously, our printf wouldn't implement that, but "grouping by > (roughly) 1000s" is kinda related to what you want the output to be, so > it seems apt. The man page also says "Note that many versions of gcc(1) > cannot parse this option and will issue a warning.", but I think that's > an ancient and irrelevant note. None of the gcc (or clang) versions > godbolt knows about give that warning. I am personally not a big fan of using random printf() modifiers for a non-standard behavior. For me, it is much easier to look up what string_get_size() does. The alternative would be to check "man 3 printf" just to realize that %#d or %'d does something else in the kernel. And where the hell is the behavior documented. I know it but how many others do? And if I wanted to use it in a new code then I would not expect that it is supported by vsprintf() kernel implementation. I would try to find it in the existing string helpers and get sad that it is not there. I see only 18 users: $> git grep string_get_size | grep -v -e test -e string_helpers | wc -l 18 > I'm not really sure the implementation should imply a trailing B; that > might as well be included in the format string itself - perhaps the > quantity is bits, so a lowercase b is better, or perhaps it's some > frequency so the user wants Hz. > > As for frequency, one would probably prefer the real, 1000^n, SI > prefixes and not the IEC 1024^n ones, and regardless, I think there > should be some way of doing both STRING_UNITS_2 and STRING_UNITS_10. At > first I thought one could distinguish by using either one or two ', but > gcc does warn for repeated flags. Two options I can think of: (a) > Overload the precision, so a precision p >= 10 means STRING_UNITS_10 > with actual precision being p-10 (and yes, by all means cap that at 2). Yet another non-standard behavior. > (b) Currently %i and %d are completely equivalent, we could make them > different in case a ' flag is present and make one do the 2^n and other > the 10^n. Same here. IMHO, this "feature" would add more harm than good. And it is not worth it. Best Regards, Petr