From patchwork Fri Oct 27 14:13:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 158945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp635348vqb; Fri, 27 Oct 2023 07:14:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGs0gTxM/sHFrGb4EkiOsbr8vMRgDk1OtmrZP/z6omWR/AczyIY5Hr6I5FT2OJ5j8xZaQB7 X-Received: by 2002:a05:690c:d87:b0:5a8:1fea:37ee with SMTP id da7-20020a05690c0d8700b005a81fea37eemr3619367ywb.22.1698416066674; Fri, 27 Oct 2023 07:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698416066; cv=none; d=google.com; s=arc-20160816; b=rRP2VXzOJ5LhLVbV9G9qdjVEEIZZZ17rpp9h0QoZi5CI9DhV2PrOsM+bpMkB/2J0cG 39S5r4R5ZWw0iY5CFG7lGyrbGM3GNrjBwA6EMfKFa5dUUx6l2PVdTR7DPHUG++dZ0eSN SV3b2K0mQowaYI83F4vIBFt1GbtZ4j92lJ3TT4KdoY/S4P80nsyiTBMU4HT8iPO5h/4/ 1SLjSshzAeLIOAhH7eQwxyq+bvSzNjWZZZmMSOI4M9jnVtgl2GCgtTW+k4Ot3Xddpwc8 0+TpJXQ/sQPo7UdYGOyp3lR8FBr/bBlcGHsQnkcs3XDVMeSm9pqgAivrVwFR6QKXEIt4 hRnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=lp1+7YjGbDfdS0f0bEXkOm+6Hu4+gGbqezgHyNjvf+s=; fh=dTXAfGnHeXG7hHcqyyrvZC152Q6HwM43PGP1k7B5uDA=; b=dPrjv1tYOwN8g/41p+WQsZKbUKmEP76klWydsXin+Dn+RZnIxxk3JfWrYO0lBMiZox +uFjcTa7gx5dbqNWxJfzVm3bWCejRygze7TuxnzqUAkFHlxA0gTTDFjBOO/orJrZgO39 Z1GsJmozujHF2vU9Y49YnPVxbYce+Fz5F36/3WvL4MBkL/IjCaCEXru1zOqFCu703Nil puM0qiX2fCsl/FkKh6K31uOHkwhQgqVVLMT9IkNjbBq4oE8kW2O1doi7YvpC1t83kNG7 Wriq/HZ1ZUJRW6GezxAY6T5YHzt+gOVDdbwLDDGSMz+DFzrUr6H4hNjXBj4y0W2f201t 7u6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iaCzi8Pu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id a1-20020a0df101000000b005a442e68a4bsi2846606ywf.295.2023.10.27.07.14.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:14:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iaCzi8Pu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id EF7788370DB7; Fri, 27 Oct 2023 07:14:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345998AbjJ0OOG (ORCPT + 25 others); Fri, 27 Oct 2023 10:14:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbjJ0OOE (ORCPT ); Fri, 27 Oct 2023 10:14:04 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 679AAFA for ; Fri, 27 Oct 2023 07:14:02 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9d10972e63eso17802766b.2 for ; Fri, 27 Oct 2023 07:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698416041; x=1699020841; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=lp1+7YjGbDfdS0f0bEXkOm+6Hu4+gGbqezgHyNjvf+s=; b=iaCzi8PufDrBJdH+/UqKgny6/v3FLqMP+OYyJxVJljZ/QPeXnxAiiJ9dzGi0hyABi+ YM5paK3Ru87L3pv8PzYEii55LDnh71FFGQvQJHnUzfw60zavNp105SIBT5jx9rHqQvZO kAr2TQG6t53Pb3kHNpxKu/E7TNpRRkIN2gSx9Z782JnlPIJo55heX5ZeIh4r5AeykOTM AKHpfeGnOtYSFvA9+GhUBtdQBP5xtrLPfn7E/8H7VWbECd+a6uCb51n345nHuulire/h urNc0EgjGeeXDU8HO9TxevEHOBwOThn94RW9U4xnmO9+F+GFoD7HfbyRiBns8Flf7Evu EwoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698416041; x=1699020841; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lp1+7YjGbDfdS0f0bEXkOm+6Hu4+gGbqezgHyNjvf+s=; b=ll0rfK6EJcynn3L6+eVwXy+BsTBqyXhM0sgEMOmLPYAC1eixZBf6V/RDxN3WszoYw4 Ul4Pc7TW/d2p2nQ+Bt8yemAythIo/MLuAC5al+FNjr4aGPEFQlCuFhycFCAP9uVKC5Gn EL4fDWlQI28WuxlC8i93j/thYYKwXr9Pnu1dPgtlZc1KqGaXZgwPX9m8c22GX0L78GL2 vhZulMBwIQhh7O66iCGSfzkhwLRpEs9IsfCwNXtfT98Sx5QfQ22anst9azxpRyQGV3La GDssjzRawhEd3Co4LpXWOHFfMFi1jJYtI8/yADScB6Qh8u8zjLszgXq2W/afpIXWt/29 m5eQ== X-Gm-Message-State: AOJu0YzOfDsSuIV4Nvf/jBKccaP8fCtz/WtVHiEhU8MsQ0gpaEw13f0j ncfSK7gZkFOQBrQNQQXAcgva85u/7w== X-Received: by 2002:a17:907:26c4:b0:9b2:aa2f:ab69 with SMTP id bp4-20020a17090726c400b009b2aa2fab69mr2157182ejc.30.1698416040533; Fri, 27 Oct 2023 07:14:00 -0700 (PDT) Received: from p183 ([46.53.253.206]) by smtp.gmail.com with ESMTPSA id ox9-20020a170907100900b009b65b2be80bsm1250046ejb.76.2023.10.27.07.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:14:00 -0700 (PDT) Date: Fri, 27 Oct 2023 17:13:58 +0300 From: Alexey Dobriyan To: Petr Mladek , Steven Rostedt Cc: Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , linux-kernel@vger.kernel.org Subject: [PATCH] vsprintf: uninline simple_strntoull(), reorder arguments Message-ID: <82a2af6e-9b6c-4a09-89d7-ca90cc1cdad1@p183> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Fri, 27 Oct 2023 07:14:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780918325632271335 X-GMAIL-MSGID: 1780918325632271335 * uninline simple_strntoull(), gcc overinlines and this function is not performance critical * reorder arguments, so that appending INT_MAX as 4th argument generates very efficient tail call Space savings: add/remove: 1/0 grow/shrink: 0/3 up/down: 27/-179 (-152) Function old new delta simple_strntoll - 27 +27 simple_strtoull 15 10 -5 simple_strtoll 41 7 -34 vsscanf 1930 1790 -140 Signed-off-by: Alexey Dobriyan Reviewed-by: Andy Shevchenko Reviewed-by: Petr Mladek --- lib/vsprintf.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -60,7 +60,8 @@ bool no_hash_pointers __ro_after_init; EXPORT_SYMBOL_GPL(no_hash_pointers); -static noinline unsigned long long simple_strntoull(const char *startp, size_t max_chars, char **endp, unsigned int base) +noinline +static unsigned long long simple_strntoull(const char *startp, char **endp, unsigned int base, size_t max_chars) { const char *cp; unsigned long long result = 0ULL; @@ -95,7 +96,7 @@ static noinline unsigned long long simple_strntoull(const char *startp, size_t m noinline unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) { - return simple_strntoull(cp, INT_MAX, endp, base); + return simple_strntoull(cp, endp, base, INT_MAX); } EXPORT_SYMBOL(simple_strtoull); @@ -130,8 +131,8 @@ long simple_strtol(const char *cp, char **endp, unsigned int base) } EXPORT_SYMBOL(simple_strtol); -static long long simple_strntoll(const char *cp, size_t max_chars, char **endp, - unsigned int base) +noinline +static long long simple_strntoll(const char *cp, char **endp, unsigned int base, size_t max_chars) { /* * simple_strntoull() safely handles receiving max_chars==0 in the @@ -140,9 +141,9 @@ static long long simple_strntoll(const char *cp, size_t max_chars, char **endp, * and the content of *cp is irrelevant. */ if (*cp == '-' && max_chars > 0) - return -simple_strntoull(cp + 1, max_chars - 1, endp, base); + return -simple_strntoull(cp + 1, endp, base, max_chars - 1); - return simple_strntoull(cp, max_chars, endp, base); + return simple_strntoull(cp, endp, base, max_chars); } /** @@ -155,7 +156,7 @@ static long long simple_strntoll(const char *cp, size_t max_chars, char **endp, */ long long simple_strtoll(const char *cp, char **endp, unsigned int base) { - return simple_strntoll(cp, INT_MAX, endp, base); + return simple_strntoll(cp, endp, base, INT_MAX); } EXPORT_SYMBOL(simple_strtoll); @@ -3648,13 +3649,11 @@ int vsscanf(const char *buf, const char *fmt, va_list args) break; if (is_sign) - val.s = simple_strntoll(str, - field_width >= 0 ? field_width : INT_MAX, - &next, base); + val.s = simple_strntoll(str, &next, base, + field_width >= 0 ? field_width : INT_MAX); else - val.u = simple_strntoull(str, - field_width >= 0 ? field_width : INT_MAX, - &next, base); + val.u = simple_strntoull(str, &next, base, + field_width >= 0 ? field_width : INT_MAX); switch (qualifier) { case 'H': /* that's 'hh' in format */