From patchwork Fri Jul 10 00:43:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1326348 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=BQ9EcKh9; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B2vZc5qvlz9sSn for ; Fri, 10 Jul 2020 10:49:44 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8AB458225B; Fri, 10 Jul 2020 02:43:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="BQ9EcKh9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9423082214; Fri, 10 Jul 2020 02:43:24 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 86878821F6 for ; Fri, 10 Jul 2020 02:43:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd43.google.com with SMTP id y2so4311890ioy.3 for ; Thu, 09 Jul 2020 17:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=owZ6LxWeHhKNVtP399DUtqPEwvdnnorn5bMnnJQZjf8=; b=BQ9EcKh9afKhwSzA9K9xLLJswpKXaEx4h8YNgjSHIPrywB36N1G2lxk0iHmwZKf+lz Ntt0xcbiFOe19cwWzqj0tl1NoN58hjxx7/NXXVIaZUww1ONLhgn+1DWktSPm/XEjzufH MfGxUJwDvwmZzU8VZPyczpDfQyrbqHFc89Dy0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=owZ6LxWeHhKNVtP399DUtqPEwvdnnorn5bMnnJQZjf8=; b=ELnRQmEK2G4lgazuWpbXEAxTZiyvjBPo1GaUr3xRVOoAc2r9MbDHE6z2elK4onJ3vi Zj5vUmqSNOIZI3tY6lmcZUb60W25XgVGbjjYrhA+4c40whmRz+WMWd51PX0oi6udr6h7 IVoeRlUrtntPOV4Z2MCvRdv8F7cp49zEE5An7CpVXQJrYeOOOKNDqxHqOhShg9QaRpxs noFMoeIGqwa1f4CMQO2/Ds+/0O5e+warj3EHWgjn2MuRPYxogf2l50b4T3aXgq9mMFkA U/ttHwfEqWgC7jrEOWfw83u+SPUA6ezJEXE1xRaFuF3L2Rd21gSQ3ONm/LGNIGK0M5Zr OhxA== X-Gm-Message-State: AOAM530F4ksE4o1lB7Rbm2uZxV1t4vJ07Q8ZzSzjOCNaRqbsZDczHH+x 9VaXwgw6eCbSyQhaDTINYWfoBI6P5ZCteQ== X-Google-Smtp-Source: ABdhPJzUgPqJglkJoBMPqV8CPsaGtMex7LiU0/h5D5bMtxx2Ri/Tw2bpsBbuxhxCDLU+zsGhKdoy3g== X-Received: by 2002:a05:6638:236:: with SMTP id f22mr74779858jaq.18.1594341800248; Thu, 09 Jul 2020 17:43:20 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id w21sm2987014ioa.48.2020.07.09.17.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 17:43:19 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bernhard Messerklinger , Heinrich Schuchardt , Simon Glass , Marek Vasut Subject: [PATCH v3 1/4] timer: Allow delays with a 32-bit microsecond timer Date: Thu, 9 Jul 2020 18:43:14 -0600 Message-Id: <20200710004317.3017137-1-sjg@chromium.org> X-Mailer: git-send-email 2.27.0.389.gc38d7665816-goog MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean The current get_timer_us() uses 64-bit arithmetic on 32-bit machines. When implementing microsecond-level timeouts, 32-bits is plenty. Add a new function that uses an unsigned long. On 64-bit machines this is still 64-bit, but this doesn't introduce a penalty. On 32-bit machines it is more efficient. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v3: - Expand the commit message and function comment include/time.h | 11 +++++++++++ lib/time.c | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/include/time.h b/include/time.h index e99f9c8012..3f00e68713 100644 --- a/include/time.h +++ b/include/time.h @@ -17,6 +17,17 @@ unsigned long get_timer(unsigned long base); unsigned long timer_get_us(void); uint64_t get_timer_us(uint64_t base); +/** + * get_timer_us_long() - Get the number of elapsed microseconds + * + * This uses 32-bit arithmetic on 32-bit machines, which is enough to handle + * delays of over an hour. For 64-bit machines it uses a 64-bit value. + * + *@base: Base time to consider + *@return elapsed time since @base + */ +unsigned long get_timer_us_long(unsigned long base); + /* * timer_test_add_offset() * diff --git a/lib/time.c b/lib/time.c index 65db0f6cda..47f8c84327 100644 --- a/lib/time.c +++ b/lib/time.c @@ -152,6 +152,11 @@ uint64_t __weak get_timer_us(uint64_t base) return tick_to_time_us(get_ticks()) - base; } +unsigned long __weak get_timer_us_long(unsigned long base) +{ + return timer_get_us() - base; +} + unsigned long __weak notrace timer_get_us(void) { return tick_to_time(get_ticks() * 1000);