From patchwork Fri Sep 7 18:54:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fieah Lim X-Patchwork-Id: 10592483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 721F71515 for ; Fri, 7 Sep 2018 18:55:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6136B2B8D3 for ; Fri, 7 Sep 2018 18:55:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54F2E2B8E7; Fri, 7 Sep 2018 18:55:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF0CC2B91F for ; Fri, 7 Sep 2018 18:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727751AbeIGXhn (ORCPT ); Fri, 7 Sep 2018 19:37:43 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44405 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbeIGXhn (ORCPT ); Fri, 7 Sep 2018 19:37:43 -0400 Received: by mail-pg1-f193.google.com with SMTP id r1-v6so7403887pgp.11 for ; Fri, 07 Sep 2018 11:55:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieahl-im.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=PEmKaa9wrp957I5Y93g81S/yFO6BjLKXLep4hfxrNzo=; b=qa5uF/vXUjdZB/1Z8l4hMRfVD6dvd19grKTmSXIv322QUFiNCXXEtKodOSD8gG4HVy WV1tp6SwdvUbVynORM1VKez89Bqh5yO6DRpiKHsIALcyuiVtAOqrQIy60HTD2bKpPVVJ HGLqivyfbum4pAspC0uon4X53I0VaaK2wzLflBPzIyH3G8Ez2/wihsvtTfPSwBtiRvOK SiJOjEBtQJfOUwIi2WfRhPOtK21yOvk+fVfrvNcZtl1FXlzoZQ+fYOUdUl+9Mc8wvUdW kkF5puk9ThSTEhRfrU1sGfXrUMTtBztx0MSrzRpq4KFA1vDwC9bKx/W8SZg86y4WN9XZ fbDw== 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; bh=PEmKaa9wrp957I5Y93g81S/yFO6BjLKXLep4hfxrNzo=; b=NxzN0nKOxi5sd95R7GF1Pb21zTAL5+FFF035ffJgSKIigHejqy6zdj38yyr1QBajB9 RCqg3uE1amwdLw2UANejOeSCAES7VmH+cs8Er4V9xWjDC3XF9Dj2K4Welogg57Ki+PO1 MwwF57oVARsZCwV2C8wzxv2nOX/fTE67lkiWED7kQYLZVUMmryE4rRuZD/5l3s89vv9M B58eBBBjAbqn1TsDLwV6sp/3at9Escqy/c9KZFafxEnTXx3cx8ss9Zg00G8sUEUxuKw+ CPZWZw99lG5Zq4Tjjq+CoputVgKLHCpeaYcwu3Q0IePuwmgfWD8QXMEYu/TkGdUvWdY6 4vpA== X-Gm-Message-State: APzg51Ccf4JWhuWyUAveswspWBHj4hPD3Lan4nSX2Jg/Hj+kljFj3Uxt MrCUjW3vT71cvhzqy2cvoy+WFA== X-Google-Smtp-Source: ANB0VdbsW5Fr6HNTqE+MB9a3W+TmIRhapW8xpRAzUcb0W7Z9qjgkUgxhuG6Q9XuI9DdieHx6t2fe2A== X-Received: by 2002:a63:455d:: with SMTP id u29-v6mr9589085pgk.342.1536346527135; Fri, 07 Sep 2018 11:55:27 -0700 (PDT) Received: from WorkZone.localdomain ([175.138.183.133]) by smtp.googlemail.com with ESMTPSA id a90-v6sm19794249pfg.106.2018.09.07.11.55.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 11:55:26 -0700 (PDT) From: Fieah Lim To: "Rafael J. Wysocki" , Daniel Lezcano , linux-pm@vger.kernel.org (open list:CPUIDLE DRIVERS), linux-kernel@vger.kernel.org (open list) Cc: Fieah Lim Subject: [PATCH] cpuidle: enter_state: Don't needlessly calculate diff time Date: Sat, 8 Sep 2018 02:54:48 +0800 Message-Id: <20180907185448.30987-1-kw@fieahl.im> X-Mailer: git-send-email 2.18.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ktime_us_delta() is not that cheap on some platform, and I think this is also the right thing to do. While at it, fix some coding style as well. Signed-off-by: Fieah Lim --- drivers/cpuidle/cpuidle.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 6df894d65d9e..5f6b2c9b6555 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -247,21 +247,20 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, if (!cpuidle_state_is_coupled(drv, index)) local_irq_enable(); - diff = ktime_us_delta(time_end, time_start); - if (diff > INT_MAX) - diff = INT_MAX; - - dev->last_residency = (int) diff; + dev->last_residency = 0; if (entered_state >= 0) { - /* Update cpuidle counters */ - /* This can be moved to within driver enter routine + /* Update cpuidle counters + * This can be moved to within driver enter routine, * but that results in multiple copies of same code. */ + diff = ktime_us_delta(time_end, time_start); + if (diff > INT_MAX) + diff = INT_MAX; + + dev->last_residency = (int)diff; dev->states_usage[entered_state].time += dev->last_residency; dev->states_usage[entered_state].usage++; - } else { - dev->last_residency = 0; } return entered_state;