From patchwork Mon Sep 10 21:47:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fieah Lim X-Patchwork-Id: 10594797 X-Patchwork-Delegate: rjw@sisk.pl 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 C359C920 for ; Mon, 10 Sep 2018 21:47:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2A9A28E9B for ; Mon, 10 Sep 2018 21:47:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A59A129252; Mon, 10 Sep 2018 21:47:46 +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 46EF028E9B for ; Mon, 10 Sep 2018 21:47:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726780AbeIKCni (ORCPT ); Mon, 10 Sep 2018 22:43:38 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43700 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726740AbeIKCni (ORCPT ); Mon, 10 Sep 2018 22:43:38 -0400 Received: by mail-pf1-f193.google.com with SMTP id j26-v6so11125641pfi.10 for ; Mon, 10 Sep 2018 14:47:34 -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=rZ/OKmh2EdrSEB5JUF2McdFFK7q1SMCf21VNiWROUfY=; b=cs6iqBy3EEC29HrzYfFu7m2lUOMMpd7xKn5tgdkc2y/GDdYoJhVRGid7tIWAbwLnme uDKYIrokqyTxeuMzTxm3KaWaXNQLiZCGzsAFxYAqIpSnQ5kC18Pi7dKgnp6BiccxAlKI fAlMk0N5gTWO9mRVYjiDSbX3JWMjgb5c4nUeb2CgAdqGu/Ccn1dv60/nK+qFsWwnpHNF hsRfLvHfocsnPhOnsxnJKkL2eoSNVoRcUam2kzm8Uw+4OEy0YdRqhA1k7fF5sJGpYsTS pi0wuJ2HFrEG3GqiE/v6agNFgrZ0DbknF6t/VCI6sX4divEuIzAfi0CduYDHpzmVXJhR YbHQ== 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=rZ/OKmh2EdrSEB5JUF2McdFFK7q1SMCf21VNiWROUfY=; b=iQDf4mL4W0GqBoJnu4CZdglEG/0hAUStqj7zrKOZhelqZ6a8eiO0dKdYqLWe3k3q7N bXts509mFQUoSrWhm3YwS1UHWbrGvPW/9Uk3XXYgAqNHjV63IiSGw4Rg9tEIqYSx6MLu R75nDrXT/PMl7fPF+83rmvJ9InjONeM549te8jpN7dScXoxIUNIc4kTkG1So2MQHburd kEG+ZW75ACqs395MbgPZ8zHlgbGBxVyMN073FvVqj2ZDgySGfZEcvY0j6Pm79MM2BBIX pTecPtfj4TdwpeGN9fecKrLyDe1B2yeCvp5qu/BqHhJv5FTQ0kFXZ2iY/x2juDJd9Jrb B+HA== X-Gm-Message-State: APzg51CucPXHYOQUM6c2aql+C7S/7dUPWEU0Z/wwWkjrHVOyk2rO5+E4 WyVC6CE0YR1Rt0BrxlhfBaquLD47WBuwhA== X-Google-Smtp-Source: ANB0VdZtXHMUZ5HuNzD/jw4bO10g+4YXCbNAaIESvr0UIjO1GWj8edQPkqGGwhky4LdklDnkqyADZw== X-Received: by 2002:a63:7f06:: with SMTP id a6-v6mr25035424pgd.296.1536616054622; Mon, 10 Sep 2018 14:47:34 -0700 (PDT) Received: from WorkZone.localdomain ([60.51.52.116]) by smtp.gmail.com with ESMTPSA id o21-v6sm24454323pfi.165.2018.09.10.14.47.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 14:47:33 -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 v3] cpuidle: enter_state: Don't needlessly calculate diff time Date: Tue, 11 Sep 2018 05:47:25 +0800 Message-Id: <20180910214725.19525-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 Currently we use ktime_us_delta() to calculate last residency and state usage unconditionally, it makes no sense to do this calculation when we fails to enter any idle state. It can be optimize by moving the calculation after entered_state >= 0 While at it, merge those comment blocks into one and remove a space between type casting of diff. This patch has no functional changes. Signed-off-by: Fieah Lim --- Changes from v1: - Rewrite changelog as Rafael J. Wysocki suggested Changes from v2: - Minor adjustment --- drivers/cpuidle/cpuidle.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 6df894d65d9e..40442c3631ce 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -247,17 +247,16 @@ 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; - 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 {