From patchwork Thu Feb 23 00:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 60730 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp35538wrd; Wed, 22 Feb 2023 16:50:43 -0800 (PST) X-Google-Smtp-Source: AK7set9HfPVvDAw2ZJYnWTIOqz/a5K1Sq64CbWv3HWJUVs+7m28FgT06shvn82R+rORjCbZAXPCQ X-Received: by 2002:a17:906:1d45:b0:884:930:b014 with SMTP id o5-20020a1709061d4500b008840930b014mr15786515ejh.6.1677113443108; Wed, 22 Feb 2023 16:50:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677113443; cv=none; d=google.com; s=arc-20160816; b=NNyNqm9riY++PKGgfVycMpoRnkRKMFuiQWB7CC0DKFllBJnxRaTtPRgfWEIuN3VxTv 51tjC4juzvC/DWJWCWP3rKga1Pc5LVxISaK4m3ZQ55FO+4lrJ7WcB6aWysiSQrLRwgBb 7xwqe1x90025rAtmtHYUed6UVIkJ3FhJDsOUuB6sku0gAUbk0BwAz3ZRI15YqfhyIQyo eUm016LxqnsZHXJ/2+ybScq9Fm+jDZRjGrcscaAVudyhPv1ua7mDeuFXCAJOmEWuVKXE rU5N1GRw08Cann+AO/0HRl9QvBdDvX3KzlPkmjuWYJhNnvBrmHvIzFec/NksKeE4LjxF /CnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qiIzKPUUv1iOBvt89lezv2ZkxW0me3bA2w+4a4Beaic=; b=qeKfbeWFwdnFoYTrFM9OyQICRqk2RpAW08YinpBtW4YrWoq3a/g1o44VHwn9nEh9hU MrtznIPRtjVbuxz9GEVuYmy0WVqZ08BABaJ3pi9PA6SZE3sWTaEd02iJxKuAkpR3gvQV U1Avlo2o3n1KEQVuWAC7ZZ35R/nOk9W5oEx2cvkMtqszqBd1lcdLQGmWLW5F8khauL8d 8Y+kwedpI8LyWvG7Oyfv353hgOS5oW1/mBP+qQZ9PBIAqRJtTXrB169DcT6CmBxaTwSJ gg13KZMfUUPSQmVDZQjJVWS08CT9Rm6Z1xmSIbleHqwk2ACSq4fNLTEmDeVRma5KpNKe b/nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GWyY4rZF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id zu7-20020a17090708c700b008cbae8a5109si1332970ejb.249.2023.02.22.16.50.06; Wed, 22 Feb 2023 16:50:43 -0800 (PST) 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; dkim=pass header.i=@chromium.org header.s=google header.b=GWyY4rZF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232929AbjBWAdm (ORCPT + 99 others); Wed, 22 Feb 2023 19:33:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232920AbjBWAdj (ORCPT ); Wed, 22 Feb 2023 19:33:39 -0500 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76877BDC0 for ; Wed, 22 Feb 2023 16:33:33 -0800 (PST) Received: by mail-il1-x133.google.com with SMTP id o8so1687221ilt.13 for ; Wed, 22 Feb 2023 16:33:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qiIzKPUUv1iOBvt89lezv2ZkxW0me3bA2w+4a4Beaic=; b=GWyY4rZFZfGpPzhK85+Z+BwjVqx0BpQlR+0EWmWrNvYWB8wBv2bbTCIS0hGnMZddnK iYoMAChm4bOGN4vrjGzZOjRlmncGITBJYIYHqanYnwSXTCkaQaTscCbs3fBUDlYxDXZy Zvck5NfCqSZA823aFXCvFrsza9T31uScMlyeE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qiIzKPUUv1iOBvt89lezv2ZkxW0me3bA2w+4a4Beaic=; b=K0GlOEeIKu/yxcCItBzOgp1kJM/zYIeln6qs1B1ssj64+E4MUreT/6bCfwruzxXydZ CGKnuYnnI4lVvVvN8MYixY7uhhZ60DoUEe38HpdmkDsxy71qSytGUBVpbJKb1EiawT2f 8cPWaVz9PdHtPCpaQnZuEk9Ap5gkOHS8q2aRbR7pyYaMBn0coTyRv/h4Qgq1sIbTW+G6 SvdvFpUygEQ5ujncDoUvRrwGU/dAOOnZZw5+xiBGswxiaTZxNVVCQrcSvj/+B923V2rJ V+Jx13LjNbVNEdL9p8BpgI8kTf50wdH58ws5/9zY0fyNlBLqQHwGiGzPieGQPhZYO6CH iuhA== X-Gm-Message-State: AO0yUKXlk5rNI6MUwLLb94BHspgqJ5V5t5c0OQkH7Lb5rJdC9Se72qRM 3Go9doUoZS22ZGt/CJHcWplsiA== X-Received: by 2002:a05:6e02:16ce:b0:315:4f52:213e with SMTP id 14-20020a056e0216ce00b003154f52213emr11753440ilx.12.1677112412865; Wed, 22 Feb 2023 16:33:32 -0800 (PST) Received: from localhost (30.23.70.34.bc.googleusercontent.com. [34.70.23.30]) by smtp.gmail.com with UTF8SMTPSA id z25-20020a02ceb9000000b003c5170ddcedsm1152044jaq.110.2023.02.22.16.33.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Feb 2023 16:33:32 -0800 (PST) From: Matthias Kaehlcke To: Liam Girdwood , Mark Brown Cc: Vincent Whitchurch , Stephen Boyd , linux-kernel@vger.kernel.org, Douglas Anderson , Matthias Kaehlcke , stable@vger.kernel.org Subject: [PATCH v2] regulator: core: Use ktime_get_boottime() to determine how long a regulator was off Date: Thu, 23 Feb 2023 00:33:30 +0000 Message-Id: <20230223003301.v2.1.I9719661b8eb0a73b8c416f9c26cf5bd8c0563f99@changeid> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,TVD_PH_BODY_ACCOUNTS_PRE autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758560194372855624?= X-GMAIL-MSGID: =?utf-8?q?1758580905473490009?= For regulators with 'off-on-delay-us' the regulator framework currently uses ktime_get() to determine how long the regulator has been off before re-enabling it (after a delay if needed). A problem with using ktime_get() is that it doesn't account for the time the system is suspended. As a result a regulator with a longer 'off-on-delay' (e.g. 500ms) that was switched off during suspend might still incurr in a delay on resume before it is re-enabled, even though the regulator might have been off for hours. ktime_get_boottime() accounts for suspend time, use it instead of ktime_get(). Fixes: a8ce7bd89689 ("regulator: core: Fix off_on_delay handling") Cc: stable@vger.kernel.org # 5.13+ Signed-off-by: Matthias Kaehlcke Reviewed-by: Stephen Boyd --- The issue already existed before the commit in the 'Fixes' tag, but it's probably not worth backporting this to older kernels that use jiffies instead of ktime. Changes in v2: - added 'Fixes' and Cc: stable tags - added 'Reviewed-by' tag from Stephen drivers/regulator/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index ae69e493913d..4fcd36055b02 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1584,7 +1584,7 @@ static int set_machine_constraints(struct regulator_dev *rdev) } if (rdev->desc->off_on_delay) - rdev->last_off = ktime_get(); + rdev->last_off = ktime_get_boottime(); /* If the constraints say the regulator should be on at this point * and we have control then make sure it is enabled. @@ -2673,7 +2673,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev) * this regulator was disabled. */ ktime_t end = ktime_add_us(rdev->last_off, rdev->desc->off_on_delay); - s64 remaining = ktime_us_delta(end, ktime_get()); + s64 remaining = ktime_us_delta(end, ktime_get_boottime()); if (remaining > 0) _regulator_delay_helper(remaining); @@ -2912,7 +2912,7 @@ static int _regulator_do_disable(struct regulator_dev *rdev) } if (rdev->desc->off_on_delay) - rdev->last_off = ktime_get(); + rdev->last_off = ktime_get_boottime(); trace_regulator_disable_complete(rdev_get_name(rdev));