Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2105205imn; Mon, 1 Aug 2022 11:15:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR4TjxQ6JdoOiinet4Wr8wkx8WqQEt6l5fb2GIyF1+s2hYlygoUR1w8JwDpaewyt/phPpkfP X-Received: by 2002:a63:89c6:0:b0:41c:84c:bdae with SMTP id v189-20020a6389c6000000b0041c084cbdaemr5477709pgd.300.1659377713451; Mon, 01 Aug 2022 11:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659377713; cv=none; d=google.com; s=arc-20160816; b=i4eYnSvLUv1A4hLeOGjJ9YqdLzJ5Dn9eMcuKXiW2JspVG3rgW1R7RL/rsYFxo26Dnv qwMPtYCOY6WLkK4V7sPyC16tclxr2IorTBu+QLD61zGgH5pY8lRymm46ykaSlbvVoVw2 AusEnAC4PLbYmwj/Da0+6Q7VGYp5DqJrTqlELTKj5bcl4CN7vlrZ97t+jnZ9RyTpV3vo ddtsX/NLEr7yY3KbLha2dzEmeHuLSS74oDxqJjEcMh5B7YBzle7LeYBQr4XU5dQ2217R SvQJQKgHBuniQY/rTIVPDOr9xizRQvC3/Pz+iZ+xKlm7AR2RIlsaA4ooS+CRfWK489wk hLmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=6rXHqmMSOCzza8aJg/Olqz/OuT0Z/81WNIkW7V8qF/c=; b=Sp5466pjM8pYee2zrcjmwnYV00oBL7k4SRAMvWTpFaUwOofU2ziK5aOzrfQGDVUzXP fQF8MUKrBpYlF/zdaXX6BmBwBNgYFoGdkor0yB/+OmwCeGkE35E09YA1G2DHHyNo/1pj kYnSgSJAuosHfP1dO6+SSzDNuZsuFeBjwWoeKEWDeijhanDHvH8zcxNmqTutdi1Y+t23 SK9/kAOWGUuC0SLUvl9YjGBQiGQKUeIjSl+Y67CxfTFPU6Pr8nOmS/5YGgHqHFOcMRjV 6mdWUwDqb8J3IADf54F1WkzaXuj3X8Rlhqj4Bog1PW3Npk60sO2wAYpqOJoI6/JtAFWM KoYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020a655584000000b0041b68824422si15490235pgs.749.2022.08.01.11.14.58; Mon, 01 Aug 2022 11:15:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232386AbiHASBx (ORCPT + 99 others); Mon, 1 Aug 2022 14:01:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231865AbiHASBu (ORCPT ); Mon, 1 Aug 2022 14:01:50 -0400 Received: from smtp.smtpout.orange.fr (smtp01.smtpout.orange.fr [80.12.242.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C70109FCE for ; Mon, 1 Aug 2022 11:01:47 -0700 (PDT) Received: from [192.168.1.18] ([90.11.190.129]) by smtp.orange.fr with ESMTPA id IZjdo9v61vbzbIZjdofJ15; Mon, 01 Aug 2022 20:01:46 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Mon, 01 Aug 2022 20:01:46 +0200 X-ME-IP: 90.11.190.129 Message-ID: Date: Mon, 1 Aug 2022 20:01:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v2] timers: Optimize usleep_range() Content-Language: en-US To: David Laight , John Stultz , Thomas Gleixner , Stephen Boyd Cc: "linux-kernel@vger.kernel.org" , "kernel-janitors@vger.kernel.org" References: <03c2bbe795fe4ddcab66eb852bae3715@AcuMS.aculab.com> From: Christophe JAILLET In-Reply-To: <03c2bbe795fe4ddcab66eb852bae3715@AcuMS.aculab.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 01/08/2022 à 10:18, David Laight a écrit : > From: Christophe JAILLET >> Sent: 29 July 2022 21:29 >> >> Most of the time the 'min' and 'max' parameters of usleep_range() are >> constant. We can take advantage of it to pre-compute at compile time >> some values otherwise computer at run-time in usleep_range_state(). >> >> Replace usleep_range_state() by a new __nsleep_range_delta_state() function >> that takes as parameters the pre-computed values. >> >> The main benefit is to save a few instructions, especially 2 >> multiplications (x1000 when converting us to ns). > ... >> 53 push %rbx >> 48 89 fb mov %rdi,%rbx >> 81 e5 cc 00 00 00 and $0xcc,%ebp >> - 49 29 dc sub %rbx,%r12 ; (max - min) >> - 4d 69 e4 e8 03 00 00 imul $0x3e8,%r12,%r12 ; us --> ns (x 1000) >> 48 83 ec 68 sub $0x68,%rsp >> 48 c7 44 24 08 b3 8a movq $0x41b58ab3,0x8(%rsp) >> b5 41 >> @@ -10721,18 +10719,16 @@ >> 31 c0 xor %eax,%eax >> e8 00 00 00 00 call ... >> e8 00 00 00 00 call ... >> - 49 89 c0 mov %rax,%r8 >> - 48 69 c3 e8 03 00 00 imul $0x3e8,%rbx,%rax ; us --> ns (x 1000) >> + 48 01 d8 add %rbx,%rax >> + 48 89 44 24 28 mov %rax,0x28(%rsp) >> 65 48 8b 1c 25 00 00 mov %gs:0x0,%rbx >> 00 00 >> - 4c 01 c0 add %r8,%rax >> - 48 89 44 24 28 mov %rax,0x28(%rsp) >> e8 00 00 00 00 call ... > ... > > Is that really measurable in any test? I don't think so, even on 32 bits arch. > Integer multiply is one clock on almost every modern cpu. > > By the time you've allowed for superscaler cpu there is > probably no difference at all on anything except the simplest > cpus. My point is that it is a low hanging fruit. Just moving some simple computations from one function to another, to have the compiler do the job instead of at runtime. I won't argue the value of the patch itself. I spotted a potential opportunity and proposed a patch for it. If someone finds it valuable enough, just take it. If no-one care, just forget about it. Both alternative are fine for me. Best regards, CJ > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales) > >