From patchwork Mon Sep 10 17:39:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fieah Lim X-Patchwork-Id: 10594651 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 21DB714E0 for ; Mon, 10 Sep 2018 17:40:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05EF12937D for ; Mon, 10 Sep 2018 17:40:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03B0C2937C; Mon, 10 Sep 2018 17:40:40 +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 50E7529396 for ; Mon, 10 Sep 2018 17:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727796AbeIJWfs (ORCPT ); Mon, 10 Sep 2018 18:35:48 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35074 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727687AbeIJWfs (ORCPT ); Mon, 10 Sep 2018 18:35:48 -0400 Received: by mail-pf1-f194.google.com with SMTP id p12-v6so10841684pfh.2 for ; Mon, 10 Sep 2018 10:40:37 -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=4riHQT7qDryyU3g2tY4xvTPz3K+uThbtROHgfuuPfOM=; b=cP74gxUDdN5Gz2UWLwWF3PPhpLOrUvLXbjQpewSYqkYkh1CMbzr0E7zZPI12wHr6Gg yuBawJIvLF5IXIwVc+AiqONg9hyRMnlqyjnqhl1EDmYbe25o2/mhgXnq4IkaeYnzqTTz spDQUJjyhDzsJ3rxaJC7kj6fZvAO8FyjZenjz0VAb01dNpMWBZEuFxGpWwfgRfbgdj8u ORRutcXps7TWkBTPmvgMN9IYNWZbq5n1t8z2/lHphEFc1uCNlOUlSaOtjmrXiShP7UYt n/CCbp+pORhgtpFVnr0YAjgryZ6FA9BsBigpC7U/JwEm1cP369jWjwC2EDYZ0hxPLsBG KwDQ== 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=4riHQT7qDryyU3g2tY4xvTPz3K+uThbtROHgfuuPfOM=; b=Mj2wWi9/dSYZOpv+OjP6CYNNv1bz85BRbb4UT0gnrqR3k9P2iLX9cX0bUXmYdG830H ofw8ucyeqp4cxJOc/aUpD4ULWu0LkB5hcYwnJnWyjxGR3kzzWOqWZQzK9uxNTQ49g9Jl AM11LwpyWDYr/Al58svSiU6R0anhntm7486PsY3AJXV3ROvTpCqnsU0VmH9TK6mlCqhE WnV1WK99NmUEnv7pE2fDHp7HXea7SU2n05X+Ivd1nm8IM+M5NfM9ue6Mj8Y1UYSs/lPu VTwD6gQVxiy3a5elDfnFNw1GOaO6/NXG6ztMOuTlf5ZNP3AQ6c2ymhHHXDrGoLGlLjPX LC6g== X-Gm-Message-State: APzg51D0XS8z/PcXzpLOPDdTiwabU5/VRJi8UZEofN1KifQR9nytDVI+ 5/1BQmM0q6UEE86Fc7gTQKfD6g== X-Google-Smtp-Source: ANB0Vdaz58Aityj44twnJKIXbTUgr6WeSEPT99y4DoqRgByo5dKbQiKLnjFGXpiLMLhNO/L3z3tuYA== X-Received: by 2002:a63:e516:: with SMTP id r22-v6mr24310338pgh.170.1536601237345; Mon, 10 Sep 2018 10:40:37 -0700 (PDT) Received: from WorkZone.localdomain ([60.51.52.116]) by smtp.gmail.com with ESMTPSA id h7-v6sm36004462pfd.155.2018.09.10.10.40.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 10:40:36 -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 v2] cpuidle: enter_state: Don't needlessly calculate diff time Date: Tue, 11 Sep 2018 01:39:53 +0800 Message-Id: <20180910173953.10113-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 --- 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;