Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2031468rda; Tue, 24 Oct 2023 10:09:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGI2K02LR50MoxLI533Mp1xz/8xx28q1YUtIKP5nCD8mgsYQA90bRLjR3Ov0hKo6qj03+Ah X-Received: by 2002:a17:902:dac9:b0:1bb:30c5:835a with SMTP id q9-20020a170902dac900b001bb30c5835amr13531245plx.7.1698167358402; Tue, 24 Oct 2023 10:09:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698167358; cv=none; d=google.com; s=arc-20160816; b=G+kF1c66mhKSi/+0/VT2VLd1oFW2KsKCu8GNfCKiDcr0FUu0rNIpOo+eSfwq2NsdvJ t+OdkjctXpxoClkoz24FJdlsg79aN7cQir9Qmrul2ihVuTVe92BVKAxPa2P79p222ZT1 WAjxy6g8eieMvyzsb6qEb2n/1l9WENSpxv6x30EInoNlwBjmqyysfYZCqcEg7MuqDJi3 0BA/rpK3UNm41uZkmkWBdCC8HI/2i2FWTMk4OalQgp1QGI69jfqaKGYZ5LGjx7X5+P3h oGQ/cC/AIcH/nfhKjB9kxVq4212McG4WLAsj2H/wqE96UPGQtGDZb59cZ9OjtpNcsZWQ U7ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=c4gL1zk6o610KyaQl0n4olXPspFqgwU/6otslNbLOBs=; fh=iw82VLHlad7y5WGnQGutmF2aEizorVWPwtJ+cbKDTns=; b=Ii4lWYNb2oYbCFd+g0jhShMfLs0oZJTuY5jO1AIElFObRHv62VMNYbm2MffqzU/U+p r1Y6+cdSDZZtbFvZ4tICRgec6aDzZ2A7Xrbx9cX2+kGhC7mbmFuGI27j/MaPRryS4QKp mxogaVIftziNPAlhXsACogGVPJxvYoB5Dezqa0aHlphnb/r9MmtDCbvOJmTxyIVMcPRX BYxVla9UpQqHhY79lTPUgvyHT6zu9PMrytzYxq7meJ9YE1/mcNvfvO+GB7yCmaVPTKWh hT+CRq2FOoJLkxTg01/QPjw+J7r5OhC/WWfn+QK6NcciO4Zbv8R5OmgpFDY9A5aD4M2L 6ySw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="WF/ZULq8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id p2-20020a170902eac200b001c4329b77bfsi8429594pld.123.2023.10.24.10.09.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 10:09:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="WF/ZULq8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 97BE080307A7; Tue, 24 Oct 2023 10:09:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234589AbjJXRIt (ORCPT + 99 others); Tue, 24 Oct 2023 13:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233065AbjJXRIq (ORCPT ); Tue, 24 Oct 2023 13:08:46 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EFCF10D0 for ; Tue, 24 Oct 2023 10:08:43 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-d9beb865a40so4367194276.1 for ; Tue, 24 Oct 2023 10:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698167322; x=1698772122; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=c4gL1zk6o610KyaQl0n4olXPspFqgwU/6otslNbLOBs=; b=WF/ZULq8VLYX+rkQgSzXWZrKSvXHNHZ6NF3OqyAi34Nnivy6FLhrH2v8sdnXbG67p1 q0yyqKGcyhSAuEovArml+Gi+wzBhVXEQEBlX75iObbHZ4fQuyXYt2sOCOUwvIJQXLubW nPJl0SIhwuhRCn9UKmXO2o3WJrPSkwpImtxdQZ5R75Qg3XPxbHSufp1iVMhUxsRieViO 9+PZZTQKLLeEbnNJUa+bs+/D7r/8B5NHTUOMcAVuFBmrfj/lVFOKAfNnRg3xy70eEqdE pb1lnrkXEBpoAJLPzu0vH5E1JkO94J7HnBfCZ/IoG/MwWk6OxfCqDT7Ys+nqika6DVBm ZNyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698167322; x=1698772122; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c4gL1zk6o610KyaQl0n4olXPspFqgwU/6otslNbLOBs=; b=Lg7IUgKSFJ4gXn4gulJ5/Kvtp/svcFRkDGVAIiBqdRDDSa0DtJ1gejvsj8lpMllt4s rvyo6Xpo1OD/A4BeJ6/lRGqH018L2g5psEhtS/V41W2cZfr7fQl1Ep8PBXiIdojOp3Pf TqlYLNbN/jJ3GHJ1+eM9zDIDZh/HC4y2F5IfE0gzFxlsW3VpmjPVwqQa0R4AyAc89DRA j1Uy2WXodlY9Gbi/U49uLpIFFKsE/9+ZEQQ3LSBCaBsVe6vylv3g4m3m3uTZRsbrMXWq NiCK4yZvr5ldJWtitSu5aOZ1oS2VER99ygo/VAKePnTX882DaLFPX120Bb4frroY+rHF 2Bcg== X-Gm-Message-State: AOJu0YzvWQqeWYunk/z8gqcaMI441wFJEK/M7oMGaUuuw7uEX/2q+yvf PcmHgV6kZRDFT140EKTKaW2hK4O82X7natqVvwHozIwumeQIe+i9LAI= X-Received: by 2002:a25:d107:0:b0:d9b:6262:43be with SMTP id i7-20020a25d107000000b00d9b626243bemr12726896ybg.16.1698167322201; Tue, 24 Oct 2023 10:08:42 -0700 (PDT) MIME-Version: 1.0 References: <20231024134637.3120277-1-surenb@google.com> <20231024134637.3120277-2-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 24 Oct 2023 10:08:29 -0700 Message-ID: Subject: Re: [PATCH v2 01/39] lib/string_helpers: Add flags param to string_get_size() To: Andy Shevchenko Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, keescook@chromium.org, rostedt@goodmis.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 10:09:05 -0700 (PDT) On Tue, Oct 24, 2023 at 7:26=E2=80=AFAM Andy Shevchenko w= rote: > > (Minimized the list of people for my review / comments) Thanks! I'll let Kent address your feedback. > > On Tue, Oct 24, 2023 at 06:45:58AM -0700, Suren Baghdasaryan wrote: > > From: Kent Overstreet > > > > The new flags parameter allows controlling > > - Whether or not the units suffix is separated by a space, for > > compatibility with sort -h > > - Whether or not to append a B suffix - we're not always printing > > bytes. > > ... > > > string_get_size(nblocks, queue_logical_block_size(q), > > - STRING_UNITS_10, cap_str_10, sizeof(cap_str_10)); > > + 0, cap_str_10, sizeof(cap_str_10)); > > This doesn't seem right (even if it works). We shouldn't rely on the > implementation details. > > ... > > > - string_get_size(sdkp->capacity, sector_size, > > - STRING_UNITS_10, cap_str_10, sizeof(cap_str_10)); > > > + string_get_size(sdkp->capacity, sector_size, 0, > > + cap_str_10, sizeof(cap_str_10)); > > Neither this. > > ... > > > -/* Descriptions of the types of units to > > - * print in */ > > -enum string_size_units { > > - STRING_UNITS_10, /* use powers of 10^3 (standard SI) */ > > - STRING_UNITS_2, /* use binary powers of 2^10 */ > > +enum string_size_flags { > > So, please add UNITS_10 as it is now. It will help if anybody in the futu= re > wants to add, e.g., 8-base numbers. > > > + STRING_SIZE_BASE2 =3D (1 << 0), > > + STRING_SIZE_NOSPACE =3D (1 << 1), > > + STRING_SIZE_NOBYTES =3D (1 << 2), > > }; > > Please, add necessary comments. > > ... > > > +enum string_size_units { > > + STRING_UNITS_10, /* use powers of 10^3 (standard SI) */ > > + STRING_UNITS_2, /* use binary powers of 2^10 */ > > +}; > > And what a point now in having these? > > I assume you need to split this to a few patches: > > 1) rename parameter to be a flags without renaming the definitions (this = will > touch only string_helpers part); > 2) do the end job by renaming it all over the drivers; > 3) add the other flags one-by-one (each in a separate change); > 4) use new flags where it's needed; > > Also see below. > > ... > > > static const char *const units_10[] =3D { > > - "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" > > + "", "k", "M", "G", "T", "P", "E", "Z", "Y" > > }; > > static const char *const units_2[] =3D { > > - "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "Yi= B" > > + "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" > > }; > > Ouch, instead of leaving this and actually "cutting the letter" with NO* = flags, > you did something different. > > ... > > Now the main part. Since in 50+% cases (I briefly estimated, it may be mo= re) > this is used in printf() why not introducing a new pointer extension for = that? > > Yes, it may be done separately, but it will look like a double effort to = me. > Instead it might give us a possibility to scale w/o touching users each t= ime > we want to do something and at the same time hide this complete API under > printf() implementation. > > -- > With Best Regards, > Andy Shevchenko > >