From patchwork Tue Mar 5 12:55:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159642 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp4937594jad; Tue, 5 Mar 2019 04:55:32 -0800 (PST) X-Received: by 2002:a19:4b0d:: with SMTP id y13mr723552lfa.58.1551790532123; Tue, 05 Mar 2019 04:55:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551790532; cv=none; d=google.com; s=arc-20160816; b=KxUNnDqmLzTt80IaMukakfitzQ216qL0jisXFPBtlanOjmJu8ZLTtF79j/z4MM/d0L JHgDDFwIPkQ5OjykBlyERYQS8gVFzSTq35hxGId/ZT67DxR4WkxAFJ5YxyWkGZcHZhQg 5siasY12atLRuTCI9Kj+KcBdSAPJeYOn0tzJzwYiIMGVLwbW5cVl1dmqpMivDAOPY/zA i+rZqaMNh8vK+4nBEcuv5DneX59o9ueRnjTtjBldEP2qEuqQ0kTsdnobgc3mnXjRm6/H B+TGEAXM8DadNajuhfw6t2JmJAdIAvDeWjQ0PbwuVu9/4ait3dGt2QABwLIHn0gDXZPZ NH8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=gWyEqHA/4lgOIuTcQX9h9/NrX1gZ//qhXqd0YHJexV4=; b=KxUPAuT68j/0qrLnMsFYH4KPv3R+sYPpksAjUHN45dX1v6Twmd2szYORCw8pbBlshQ FuRLghS72gdcdLq+nSw/ygULj31q33pA27QZNVjFMujejhsfr0n7c87dM8rIv1bV6HcT eYwKUZiz18zu5+nNrcI4/Cw9kMv6vekjZVj+pdbf5d4ByI5+Cyry4Jr1uXC2HCAo03NP pQPMw5nT4kr34jLd1yY9Dy9tLTE3kwGtwuAFzxWEC0dwlQUnYfG71Pyl+ApLRPLulxw5 u3PQrgDK4JVcGXP4cvi4H9wd9op/YkpybhtcTqA2A4Y4MzGY9nl1v8xKwwaBuUzKFIAd AetQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Lvt/2Ps1"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id e9sor4990782ljk.10.2019.03.05.04.55.31 for (Google Transport Security); Tue, 05 Mar 2019 04:55:32 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Lvt/2Ps1"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=gWyEqHA/4lgOIuTcQX9h9/NrX1gZ//qhXqd0YHJexV4=; b=Lvt/2Ps1sQsZNLREbbQRguwhDwfRM3dChaip9tVgk9TLS3bFs0qdNMIFa05LbPanHZ N9zqUUv1hVoc8/B8t5vWsH4Xex4+5xGf+/0fLASd/FA6nbzw4das4awKIDyPLZt4h4Ag B072r3reqV+ug8iU91tfbr2gDgWZYHm99FzMOqfKXilkSILchk14bzdPaBe0oog6XOD4 XTa1qzf7IB+qienZIiZw0clEcn7MfQf9zeoj6+7g9m7lUssnGxtLjRNZ+QP+d89d4ozq mmF16CGeG6MDQTegZ3avZbMlIJA45R862GQNEuVwYZDG2hiF8e2S2bN0+VL9EMokUW9J sOLA== 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=gWyEqHA/4lgOIuTcQX9h9/NrX1gZ//qhXqd0YHJexV4=; b=ZK7iqNIPNQjmqKKev4//qFSfpTXCG8fsN4YVqBOmYOFMBZrCw1zRt8EKB3R7BTobd/ RRyP7kr+Rycr0NBe51++1leFwJvdX3GvBOJEHfDJDtw+U4aiR5Yv1TutyW4sQOgBQ7oh AXgUTrMoaSIfjSUgNk+w0S5gBEsla2xn9qGLmn5YhsM3RAsUtzPpr+6BZYCS8GC0yo1C tfcAaih6NxhUG54yFHMRydOzTgxhfee0OLO7l2sAOWXFperBoOL/jL6e+E6v8jwVGFAd wj37RVXIz9niBwpwGvx9/CgOOBjzK7L5yAlXdt6oZusctd4ROcdYbH2dsyqGF2wXg5JH 23yg== X-Gm-Message-State: APjAAAWKmYM+ArAwTt6YUv+93BHMHZrkUKpNiI3eH39/rjZH97i7bZaa cU4N8+e7Y9pGHnaMISXftBbwZOjy X-Google-Smtp-Source: APXvYqykXo951xPI4G3ZyPY38e+LHgEgCM/dc0wcZ9IMF+6vbQFvK5Cy1GjbQv1p0/K9Ia5RJBLsww== X-Received: by 2002:a2e:780a:: with SMTP id t10mr11978377ljc.19.1551790531531; Tue, 05 Mar 2019 04:55:31 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id l20sm2104499ljb.24.2019.03.05.04.55.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Mar 2019 04:55:30 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] PM / Runtime: Consolidate code to get active/suspended time Date: Tue, 5 Mar 2019 13:55:26 +0100 Message-Id: <20190305125526.21360-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In a step to consolidate code around fetching the runtime PM active/suspend time for a device, let's re-factor the existing pm_runtime_suspended_time() and add a new corresponding pm_runtime_active_time(). Make the latter shared internally to the PM core, as in following changes it starts making use of it. Signed-off-by: Ulf Hansson --- drivers/base/power/power.h | 1 + drivers/base/power/runtime.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index c511def48b48..ec33fbdb919b 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h @@ -21,6 +21,7 @@ static inline void pm_runtime_early_init(struct device *dev) extern void pm_runtime_init(struct device *dev); extern void pm_runtime_reinit(struct device *dev); extern void pm_runtime_remove(struct device *dev); +extern u64 pm_runtime_active_time(struct device *dev); #define WAKE_IRQ_DEDICATED_ALLOCATED BIT(0) #define WAKE_IRQ_DEDICATED_MANAGED BIT(1) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 78937c45278c..d1908fc422cc 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -98,7 +98,7 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status) dev->power.runtime_status = status; } -u64 pm_runtime_suspended_time(struct device *dev) +static u64 rpm_account_time(struct device *dev, bool suspend) { u64 time; unsigned long flags; @@ -106,12 +106,22 @@ u64 pm_runtime_suspended_time(struct device *dev) spin_lock_irqsave(&dev->power.lock, flags); update_pm_runtime_accounting(dev); - time = dev->power.suspended_time; + time = suspend ? dev->power.suspended_time : dev->power.active_time; spin_unlock_irqrestore(&dev->power.lock, flags); return time; } + +u64 pm_runtime_active_time(struct device *dev) +{ + return rpm_account_time(dev, false); +} + +u64 pm_runtime_suspended_time(struct device *dev) +{ + return rpm_account_time(dev, true); +} EXPORT_SYMBOL_GPL(pm_runtime_suspended_time); /** From patchwork Tue Mar 5 12:55:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159643 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp4937684jad; Tue, 5 Mar 2019 04:55:39 -0800 (PST) X-Received: by 2002:ac2:52b6:: with SMTP id r22mr749798lfm.123.1551790539590; Tue, 05 Mar 2019 04:55:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551790539; cv=none; d=google.com; s=arc-20160816; b=TkdBQ7F+qt62kX9JQeP1yJjT5sfuySr7aMzMCI24+tiZ+LfcdE74ujUUGTnz98lyGw 8l6EbM2ArHmo5FmV3iqrjqxcJQoeDnrCJyZNOguINUKwmc0dKu0S9vS7VA+R2s9qNC67 b1DWIKUi4ImPDxPZg1vV6wlZ1+aeEA7F8+Z+kCh4zTRcMGLaJRyZxtlTuCiFxRMIJTQn RlkDZbrqq14KZyWWOAP3e6zpezSGsB4GN2ZU3vXwUyP1iL2SA15iGr2YU5aLI+awvB6j KCBWanvFtKdhgpNNFlHA28XsblQXDq3ICrWFNofQnPEFFPxLI9nEkwd0gUzLlbNtdX6x rtvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=lqBcCIf/d3yMHBCDc7uCjcM4/5sbo4a5Rm1FkoZ24m8=; b=nogYchS9Bl+jCukJXt8RgkmRmYLZzo6IJwHvRkMRmeO2P+12dRpAhbG7dwdSidHLBe 1RD04rz9YbPUVkjCxeNA9Ln+ZXASorxI1rD5S3Gd32rCoGqLuBSXk1wpa67lxRV3AFjX CzdClJuqTNDIAVRBPL2N2psgMbAE3eYX9ZSAQ4HwCCHNuiI3ZdR1O3WclKFRpJDHMT58 tmxt45/31Z4xBUvSSPBrX/KmCKMurXyUBD2a9J4IyUdrt+MPz7eW2m3sv5kGhTmAFqV1 s41FJmf2v6CigCE8ZuS47RNqVQ7GdfTEehFdtKfLUrK4Ok+mrXuL1aLjGWppohr5RX/B 8M3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p2DNdgdH; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b16sor4782014lji.16.2019.03.05.04.55.39 for (Google Transport Security); Tue, 05 Mar 2019 04:55:39 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p2DNdgdH; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=lqBcCIf/d3yMHBCDc7uCjcM4/5sbo4a5Rm1FkoZ24m8=; b=p2DNdgdH9eMxR2E++Lrar2GThCfCbYHvgcFwiJwd+ePO7f+tA7lQ96cnNnbNAqNnWP Pju+2X728td6pviAx3KqA9zUpXvon2i/iSdFEftfLYwVIKF0PXfZLtV1zclijEhJRzWJ nNyzfXRksVQdaI5OlYlNkdRbNCjYUIKy5r1iRSpGtxLrslZNZt1jk+3xP4kaoxgegHfb TcIH9krvOimL4kBuuwt6RLgM91wq1teTbgHh4H3IrE0pE5I/NVUnfx3KiQ2tRA3SHJtB XO5SlA+faA3NCuU70vpDtyzpzkE/L+5bY9yG3/PgFL+nfa8siydPRSPswY/klOtI0xyM 43sw== 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=lqBcCIf/d3yMHBCDc7uCjcM4/5sbo4a5Rm1FkoZ24m8=; b=KSDAxLZTxCETeYFdcNhIFqXIv+iZbK313ESYa6I821pwWO2aRg61KJgpGtsWVivwKK kcs2ImuWpusBpcBhJx21J201OaZO7fo07a+AV4mgvLakbcdfEPN28OV+0xr1tT41CMMm Uybn9/GM1Tsvcbs37Iadvytzn9UTaIbx9GCMQoGmWsQia6ayDpwIGem3rdvCwC1NL1Hf ZCieNrJpIgNS8lG49AuABJw/42IiOQgK5ySUNCzSzMkYm/3zQGL7GSSIo+j4FWfjowG4 gLF9HmZcY8psVWRFHRGlzO3Q1fLo8Jrk7dWc6rjrSQW2+TDFhBVtU4l+iQAQvgGSSQlV LZmQ== X-Gm-Message-State: APjAAAVyy2IfQqIBI5fn9jYyHCF+982ky+KB4ijxvDAh5tbC3dspdfmm b26SS2MSt23lHse0UJnpLPLrpV+Y X-Google-Smtp-Source: APXvYqxTdspo6Pc6tE+bHBjMOehdXVbcah5poJiNRYfhzjPV7k6ExH/yenBBeF30aHV7t6Jul5Jlag== X-Received: by 2002:a2e:2285:: with SMTP id i127mr13833745lji.40.1551790539141; Tue, 05 Mar 2019 04:55:39 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id m1sm443898lfh.36.2019.03.05.04.55.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Mar 2019 04:55:38 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] PM / Runtime: Use pm_runtime_active|suspended_time() from sysfs Date: Tue, 5 Mar 2019 13:55:35 +0100 Message-Id: <20190305125535.21412-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 Let's avoid the open-coding in runtime_active|suspend_time_show() and convert to use pm_runtime_active|suspended_time() instead. Note that, this change also indirectly avoid us from keeping the dev->power.lock held, while doing the do_div() and the sprintf() operations, which is yet another improvement. Signed-off-by: Ulf Hansson --- drivers/base/power/runtime.c | 2 +- drivers/base/power/sysfs.c | 12 ++---------- include/linux/pm.h | 1 - 3 files changed, 3 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index d1908fc422cc..17136da0bb6a 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -64,7 +64,7 @@ static int rpm_suspend(struct device *dev, int rpmflags); * runtime_status field is updated, to account the time in the old state * correctly. */ -void update_pm_runtime_accounting(struct device *dev) +static void update_pm_runtime_accounting(struct device *dev) { u64 now, last, delta; diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index c6bf76124184..1226e441ddfe 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c @@ -125,13 +125,9 @@ static ssize_t runtime_active_time_show(struct device *dev, struct device_attribute *attr, char *buf) { int ret; - u64 tmp; - spin_lock_irq(&dev->power.lock); - update_pm_runtime_accounting(dev); - tmp = dev->power.active_time; + u64 tmp = pm_runtime_active_time(dev); do_div(tmp, NSEC_PER_MSEC); ret = sprintf(buf, "%llu\n", tmp); - spin_unlock_irq(&dev->power.lock); return ret; } @@ -141,13 +137,9 @@ static ssize_t runtime_suspended_time_show(struct device *dev, struct device_attribute *attr, char *buf) { int ret; - u64 tmp; - spin_lock_irq(&dev->power.lock); - update_pm_runtime_accounting(dev); - tmp = dev->power.suspended_time; + u64 tmp = pm_runtime_suspended_time(dev); do_div(tmp, NSEC_PER_MSEC); ret = sprintf(buf, "%llu\n", tmp); - spin_unlock_irq(&dev->power.lock); return ret; } diff --git a/include/linux/pm.h b/include/linux/pm.h index 06f7ed893928..66c19a65a514 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -643,7 +643,6 @@ struct dev_pm_info { struct dev_pm_qos *qos; }; -extern void update_pm_runtime_accounting(struct device *dev); extern int dev_pm_get_subsys_data(struct device *dev); extern void dev_pm_put_subsys_data(struct device *dev);