Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1833400imn; Mon, 1 Aug 2022 01:37:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR6SLucO34RpoAdw9oQt8DXzMz4dvQc2SVVYq2yKMNMY4g4vBELNlXsVG9ZoZEX6itbsH+zh X-Received: by 2002:a17:90b:4c03:b0:1f2:b977:c64e with SMTP id na3-20020a17090b4c0300b001f2b977c64emr17881161pjb.211.1659343077155; Mon, 01 Aug 2022 01:37:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659343077; cv=none; d=google.com; s=arc-20160816; b=L8rajypPkFZgSPdm4DiTstg9WBOljtrdETWoQ00qxDYkqi53Zn1pG8ioEcxW1wB4QP NUXk1el8d0q/4j3rXbJyGDrTZAY3VacJtBkIUWY4Yy8tLxmondPtfLwHZT6Elq3SuzBA K87fZtFPTY5egmUIKTPIBryU6/4sKHVfsUQ0Fe8tvuigFHC2K7cWmXouU0hCLOH6qDHJ r5Nwq7COK4nNpxIfUWD62wiX5ekZjDBJtJL/QwlyD9dkN1QiOM+01h97pz6HZxdwl1vb 3kd8X98f2TKBYQgvbfpC8+IfxDUydIHIxvPPI1F1UlZNjXv/TgeW27OxcZnxBk6+mgdN frEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=xTyyu0vTrwvmTyErzuhAOqiB99awLBXhempQ/+aX76A=; b=t6JqMv6Jl0Xnd/sL4rKuDt1vwwH/0PiVa5sfo+WVON8TJX+cqHhDyXkIsPQPR1qJac mW3hrUM6tFzspva+sxuuqoRyoqb5kpeA++FySwMrepfLfjY+sXcRY/Mvaz/eppE3KaAA iqXRI43b+z3tathvDb9qWrFuuluH6F4nZnFZC8ChwEehnwHBUJ0W3Y0PTftjfGsg+T9p hLsUjfFePPdGdyjzQXDlZnvIk0ceByPMAmiiAmmC4zB0PmTvE1incL50qDwemWooViiV F30f51sLXCWzGgaIRyBKo9IqO0H1jM5cnjLMdV2WGkPIuU2tPRuj8wtVmfdc+c6K6wWf 8Bzg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a170902d50b00b00163f5028fe7si14570685plg.365.2022.08.01.01.37.42; Mon, 01 Aug 2022 01:37:57 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbiHAISf convert rfc822-to-8bit (ORCPT + 99 others); Mon, 1 Aug 2022 04:18:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbiHAISc (ORCPT ); Mon, 1 Aug 2022 04:18:32 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5CFE33A4A0 for ; Mon, 1 Aug 2022 01:18:30 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-90-AvgrXkIoNm6f5CQVlFdnFQ-1; Mon, 01 Aug 2022 09:18:27 +0100 X-MC-Unique: AvgrXkIoNm6f5CQVlFdnFQ-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Mon, 1 Aug 2022 09:18:26 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.036; Mon, 1 Aug 2022 09:18:26 +0100 From: David Laight To: 'Christophe JAILLET' , John Stultz , Thomas Gleixner , Stephen Boyd CC: "linux-kernel@vger.kernel.org" , "kernel-janitors@vger.kernel.org" Subject: RE: [PATCH v2] timers: Optimize usleep_range() Thread-Topic: [PATCH v2] timers: Optimize usleep_range() Thread-Index: AQHYo4nvkYUHE4pe402s230iY96y4q2ZtPDg Date: Mon, 1 Aug 2022 08:18:26 +0000 Message-ID: <03c2bbe795fe4ddcab66eb852bae3715@AcuMS.aculab.com> References: In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, 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 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? 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. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)