From patchwork Thu Feb 14 01:30:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 10811557 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 886E813A4 for ; Thu, 14 Feb 2019 01:31:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 756172DF4C for ; Thu, 14 Feb 2019 01:31:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69B572DF4E; Thu, 14 Feb 2019 01:31:20 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 DEC592DF4C for ; Thu, 14 Feb 2019 01:31:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730236AbfBNBbT (ORCPT ); Wed, 13 Feb 2019 20:31:19 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:42515 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731024AbfBNBay (ORCPT ); Wed, 13 Feb 2019 20:30:54 -0500 Received: by mail-pl1-f196.google.com with SMTP id s1so2174396plp.9 for ; Wed, 13 Feb 2019 17:30:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cJPsF4XxjEGWMiB9f3+lShzsGeUaN6tuDYb4BL3O6BA=; b=YIlwuLFnsN4k9F1/3gvjIie+67GffreLIWW+CwTMVxR8aaH75NsYm79ezmabwTE+7Z HKOgwH8iTSFV0aDF3VdQrSKiHQWde0wU9mwev7P61sdiBhWTY+IeABrsL72f+iNgoG9F EwSsXD9/cRavIJZ2uFuCjTejkPYG6mESFtaxQ= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=cJPsF4XxjEGWMiB9f3+lShzsGeUaN6tuDYb4BL3O6BA=; b=stiE4lEovTbghf5KyUZO3FMq77JL8BcV8wpoppFRrV6T5jTP0YV0lUmgnn9tF3rWRH uIrSG4x5Oo4OaMpBoekeRB4LyIAFlP42oPE180tEC912mmtugrPFXbKzI0x4F/3eiXCR r9/0HKtlvWOUS0NM/r2/dJZxAF/F7AYgvfzjz7OcFIOO8NBTFhRKb78FiFlbIcrE8d3w JcDEeyVbNqhA4TPh9o+oAURThjpLrFWsTgXmRixc7ggalkQ/6TKslj0foS8DN1pUnQmn 7bd3eE1cukMe/fldE46DRqS4py306WLzfrW2GccmvaZRS4Auait9CPNWiqQOB2YSIB55 BDzw== X-Gm-Message-State: AHQUAub2quTqUBjM6CNUXcZ5HXgdA96htNumCqzc1sJ5AHJWJszzJZCh dMP/q/2tFOQeq44EW5op4PEwNQ== X-Google-Smtp-Source: AHgI3Ib0uzj8u4s+io55IqeyUT/B8Bj7K2MGYIcavwhZARaOwvrzHZSNKpOX8d4kySoluce9he4KEQ== X-Received: by 2002:a17:902:aa8c:: with SMTP id d12mr1332765plr.25.1550107854202; Wed, 13 Feb 2019 17:30:54 -0800 (PST) Received: from mka.mtv.corp.google.com ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id p64sm811072pfi.56.2019.02.13.17.30.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 17:30:53 -0800 (PST) From: Matthias Kaehlcke To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Thierry Reding , Jonathan Hunter , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, Lukasz Luba Cc: Matthias Kaehlcke Subject: [PATCH 1/4] PM / devfreq: Track overall load monitor state instead of 'stop_polling' Date: Wed, 13 Feb 2019 17:30:39 -0800 Message-Id: <20190214013042.254790-2-mka@chromium.org> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a-goog In-Reply-To: <20190214013042.254790-1-mka@chromium.org> References: <20190214013042.254790-1-mka@chromium.org> MIME-Version: 1.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 The field ->stop_polling indicates whether load monitoring should be/is stopped, it is set in devfreq_monitor_suspend(). Change the variable to hold the general state of load monitoring (stopped, running, suspended). Besides improving readability of conditions involving the field and this prepares the terrain for moving some duplicated code from the governors into the devfreq core. Hold the devfreq lock in devfreq_monitor_start/stop() to ensure proper synchronization. Signed-off-by: Matthias Kaehlcke --- drivers/devfreq/devfreq.c | 34 +++++++++++++++++++++++++--------- include/linux/devfreq.h | 4 ++-- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 0ae3de76833b7..1d3a43f8b3a10 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -29,6 +29,10 @@ #include #include "governor.h" +#define DEVFREQ_MONITOR_STOPPED 0 +#define DEVFREQ_MONITOR_RUNNING 1 +#define DEVFREQ_MONITOR_SUSPENDED 2 + static struct class *devfreq_class; /* @@ -407,10 +411,17 @@ static void devfreq_monitor(struct work_struct *work) */ void devfreq_monitor_start(struct devfreq *devfreq) { - INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor); - if (devfreq->profile->polling_ms) + mutex_lock(&devfreq->lock); + + if (devfreq->profile->polling_ms) { + INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor); queue_delayed_work(devfreq_wq, &devfreq->work, msecs_to_jiffies(devfreq->profile->polling_ms)); + + devfreq->monitor_state = DEVFREQ_MONITOR_RUNNING; + } + + mutex_unlock(&devfreq->lock); } EXPORT_SYMBOL(devfreq_monitor_start); @@ -425,6 +436,10 @@ EXPORT_SYMBOL(devfreq_monitor_start); void devfreq_monitor_stop(struct devfreq *devfreq) { cancel_delayed_work_sync(&devfreq->work); + + mutex_lock(&devfreq->lock); + devfreq->monitor_state = DEVFREQ_MONITOR_STOPPED; + mutex_unlock(&devfreq->lock); } EXPORT_SYMBOL(devfreq_monitor_stop); @@ -443,13 +458,13 @@ EXPORT_SYMBOL(devfreq_monitor_stop); void devfreq_monitor_suspend(struct devfreq *devfreq) { mutex_lock(&devfreq->lock); - if (devfreq->stop_polling) { + if (devfreq->monitor_state != DEVFREQ_MONITOR_RUNNING) { mutex_unlock(&devfreq->lock); return; } devfreq_update_status(devfreq, devfreq->previous_freq); - devfreq->stop_polling = true; + devfreq->monitor_state = DEVFREQ_MONITOR_SUSPENDED; mutex_unlock(&devfreq->lock); cancel_delayed_work_sync(&devfreq->work); } @@ -468,7 +483,7 @@ void devfreq_monitor_resume(struct devfreq *devfreq) unsigned long freq; mutex_lock(&devfreq->lock); - if (!devfreq->stop_polling) + if (devfreq->monitor_state == DEVFREQ_MONITOR_STOPPED) goto out; if (!delayed_work_pending(&devfreq->work) && @@ -477,7 +492,7 @@ void devfreq_monitor_resume(struct devfreq *devfreq) msecs_to_jiffies(devfreq->profile->polling_ms)); devfreq->last_stat_updated = jiffies; - devfreq->stop_polling = false; + devfreq->monitor_state = DEVFREQ_MONITOR_RUNNING; if (devfreq->profile->get_cur_freq && !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq)) @@ -504,13 +519,14 @@ void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay) mutex_lock(&devfreq->lock); devfreq->profile->polling_ms = new_delay; - if (devfreq->stop_polling) + if (devfreq->monitor_state == DEVFREQ_MONITOR_SUSPENDED) goto out; /* if new delay is zero, stop polling */ if (!new_delay) { mutex_unlock(&devfreq->lock); cancel_delayed_work_sync(&devfreq->work); + devfreq->monitor_state == DEVFREQ_MONITOR_STOPPED; return; } @@ -526,7 +542,7 @@ void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay) mutex_unlock(&devfreq->lock); cancel_delayed_work_sync(&devfreq->work); mutex_lock(&devfreq->lock); - if (!devfreq->stop_polling) + if (devfreq->monitor_state != DEVFREQ_MONITOR_SUSPENDED) queue_delayed_work(devfreq_wq, &devfreq->work, msecs_to_jiffies(devfreq->profile->polling_ms)); } @@ -1372,7 +1388,7 @@ static ssize_t trans_stat_show(struct device *dev, int i, j; unsigned int max_state = devfreq->profile->max_state; - if (!devfreq->stop_polling && + if ((devfreq->monitor_state == DEVFREQ_MONITOR_RUNNING) && devfreq_update_status(devfreq, devfreq->previous_freq)) return 0; if (max_state == 0) diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index fbffa74bfc1bb..0a618bbb8b294 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -130,7 +130,7 @@ struct devfreq_dev_profile { * @max_freq: Limit maximum frequency requested by user (0: none) * @scaling_min_freq: Limit minimum frequency requested by OPP interface * @scaling_max_freq: Limit maximum frequency requested by OPP interface - * @stop_polling: devfreq polling status of a device. + * @monitor_state: State of the load monitor. * @suspend_freq: frequency of a device set during suspend phase. * @resume_freq: frequency of a device set in resume phase. * @suspend_count: suspend requests counter for a device. @@ -168,7 +168,7 @@ struct devfreq { unsigned long max_freq; unsigned long scaling_min_freq; unsigned long scaling_max_freq; - bool stop_polling; + int monitor_state; unsigned long suspend_freq; unsigned long resume_freq; From patchwork Thu Feb 14 01:30:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 10811555 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 9EA5F922 for ; Thu, 14 Feb 2019 01:31:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BE702DF4C for ; Thu, 14 Feb 2019 01:31:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 804672DF4E; Thu, 14 Feb 2019 01:31:18 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 0290A2DF4C for ; Thu, 14 Feb 2019 01:31:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730421AbfBNBbL (ORCPT ); Wed, 13 Feb 2019 20:31:11 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36264 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731894AbfBNBaz (ORCPT ); Wed, 13 Feb 2019 20:30:55 -0500 Received: by mail-pl1-f196.google.com with SMTP id g9so2192804plo.3 for ; Wed, 13 Feb 2019 17:30:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yUOh5urbJ5qKsBwwk9JiS26KJ91s9tOUPSxR5qZLz4c=; b=IopZXxjaiYhOZk3DiEuFXysOr9PyU1OW5shFcoAjWyWQPqzzKxQRq7snvXdol6Yq/0 RAme/rEM5+pHeQIx/CdyqRkkIu04+T1xMew7zbKp2dj5yWfo6QyVMNGs6Wqz+8Qiuq2E UWKCqQR1w+VOm9QC1RZy2CGUSozZVf99HEm1w= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=yUOh5urbJ5qKsBwwk9JiS26KJ91s9tOUPSxR5qZLz4c=; b=UR5NY60HDv9M0NDzzvraLkv3pUCz2xd2Gw54L+uU3yd8JjUD64H01EOX2cLueFkAoT 2VHw0bk/8QDB0eco9SZWJ+RIMEmtoyAyrrIDCO5l9AN6YJYTPNDprzJ9t6pBg9WRRaIn igcmhhG6B+4jQEbeIQfKAeJwLRF0WYoRLDUDmFQrkpVesAWoGAxx8LT+QKm8WRpBm7vk S4PbJVpka0N1oVD/g9kTrjZq6q7wxI4w7wtekoV0EogcIHwa5ZOZXt8JnQoMlppSDsjV I8PE78/WYrzWSoEqxhA7SysPq/Yc22ORRIiB+TtY8tzXH9B4HuSqrZqDx+WCsMv3zJe1 BQWA== X-Gm-Message-State: AHQUAuaqs/SDpKAWCYfQ+kv/vFCIMEBlZCzsGQk5Edx6VAOllyQ//Txp ZMNy4P9PwSf1zd+joKULSEdN5w== X-Google-Smtp-Source: AHgI3IagHH5nYbheS5Y7OhAcpMQHA4CZK4LhO+tqffWsUCWFmoy1vTdSaNNkS/WRKAu890RoBofTJg== X-Received: by 2002:a17:902:1aa:: with SMTP id b39mr1350593plb.244.1550107855170; Wed, 13 Feb 2019 17:30:55 -0800 (PST) Received: from mka.mtv.corp.google.com ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id p64sm811072pfi.56.2019.02.13.17.30.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 17:30:54 -0800 (PST) From: Matthias Kaehlcke To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Thierry Reding , Jonathan Hunter , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, Lukasz Luba Cc: Matthias Kaehlcke Subject: [PATCH 2/4] PM / devfreq: Handle monitor suspend/resume in the devfreq core Date: Wed, 13 Feb 2019 17:30:40 -0800 Message-Id: <20190214013042.254790-3-mka@chromium.org> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a-goog In-Reply-To: <20190214013042.254790-1-mka@chromium.org> References: <20190214013042.254790-1-mka@chromium.org> MIME-Version: 1.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 devfreq expects governors to call devfreq_monitor_suspend/resume() in response to DEVFREQ_GOV_SUSPEND/RESUME events. Since the devfreq core itself generates these events and invokes the governor's event handler the suspend/resume of the load monitoring can be done in the common code. Call devfreq_monitor_suspend/resume() when the governor reports a successful handling of DEVFREQ_GOV_SUSPEND/RESUME and remove these calls from the simpleondemand and tegra governors. Make devfreq_monitor_suspend/resume() static since these functions are now only used by the devfreq core. Signed-off-by: Matthias Kaehlcke --- drivers/devfreq/devfreq.c | 18 ++++++++---------- drivers/devfreq/governor.h | 2 -- drivers/devfreq/governor_simpleondemand.c | 8 -------- drivers/devfreq/tegra-devfreq.c | 2 -- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 1d3a43f8b3a10..7fab6c4cf719b 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -447,15 +447,13 @@ EXPORT_SYMBOL(devfreq_monitor_stop); * devfreq_monitor_suspend() - Suspend load monitoring of a devfreq instance * @devfreq: the devfreq instance. * - * Helper function to suspend devfreq device load monitoing. Function - * to be called from governor in response to DEVFREQ_GOV_SUSPEND - * event or when polling interval is set to zero. + * Helper function to suspend devfreq device load monitoring. * * Note: Though this function is same as devfreq_monitor_stop(), * intentionally kept separate to provide hooks for collecting * transition statistics. */ -void devfreq_monitor_suspend(struct devfreq *devfreq) +static void devfreq_monitor_suspend(struct devfreq *devfreq) { mutex_lock(&devfreq->lock); if (devfreq->monitor_state != DEVFREQ_MONITOR_RUNNING) { @@ -468,17 +466,14 @@ void devfreq_monitor_suspend(struct devfreq *devfreq) mutex_unlock(&devfreq->lock); cancel_delayed_work_sync(&devfreq->work); } -EXPORT_SYMBOL(devfreq_monitor_suspend); /** * devfreq_monitor_resume() - Resume load monitoring of a devfreq instance * @devfreq: the devfreq instance. * - * Helper function to resume devfreq device load monitoing. Function - * to be called from governor in response to DEVFREQ_GOV_RESUME - * event or when polling interval is set to non-zero. + * Helper function to resume devfreq device load monitoring. */ -void devfreq_monitor_resume(struct devfreq *devfreq) +static void devfreq_monitor_resume(struct devfreq *devfreq) { unsigned long freq; @@ -501,7 +496,6 @@ void devfreq_monitor_resume(struct devfreq *devfreq) out: mutex_unlock(&devfreq->lock); } -EXPORT_SYMBOL(devfreq_monitor_resume); /** * devfreq_interval_update() - Update device devfreq monitoring interval @@ -903,6 +897,8 @@ int devfreq_suspend_device(struct devfreq *devfreq) DEVFREQ_GOV_SUSPEND, NULL); if (ret) return ret; + + devfreq_monitor_suspend(devfreq); } if (devfreq->suspend_freq) { @@ -944,6 +940,8 @@ int devfreq_resume_device(struct devfreq *devfreq) DEVFREQ_GOV_RESUME, NULL); if (ret) return ret; + + devfreq_monitor_resume(devfreq); } return 0; diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h index f53339ca610fc..d136792c0cc91 100644 --- a/drivers/devfreq/governor.h +++ b/drivers/devfreq/governor.h @@ -59,8 +59,6 @@ struct devfreq_governor { extern void devfreq_monitor_start(struct devfreq *devfreq); extern void devfreq_monitor_stop(struct devfreq *devfreq); -extern void devfreq_monitor_suspend(struct devfreq *devfreq); -extern void devfreq_monitor_resume(struct devfreq *devfreq); extern void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay); diff --git a/drivers/devfreq/governor_simpleondemand.c b/drivers/devfreq/governor_simpleondemand.c index c0417f0e081e0..52eb0c734b312 100644 --- a/drivers/devfreq/governor_simpleondemand.c +++ b/drivers/devfreq/governor_simpleondemand.c @@ -103,14 +103,6 @@ static int devfreq_simple_ondemand_handler(struct devfreq *devfreq, devfreq_interval_update(devfreq, (unsigned int *)data); break; - case DEVFREQ_GOV_SUSPEND: - devfreq_monitor_suspend(devfreq); - break; - - case DEVFREQ_GOV_RESUME: - devfreq_monitor_resume(devfreq); - break; - default: break; } diff --git a/drivers/devfreq/tegra-devfreq.c b/drivers/devfreq/tegra-devfreq.c index c59d2eee5d309..79efa1e51bd06 100644 --- a/drivers/devfreq/tegra-devfreq.c +++ b/drivers/devfreq/tegra-devfreq.c @@ -591,11 +591,9 @@ static int tegra_governor_event_handler(struct devfreq *devfreq, case DEVFREQ_GOV_SUSPEND: tegra_actmon_disable_interrupts(tegra); - devfreq_monitor_suspend(devfreq); break; case DEVFREQ_GOV_RESUME: - devfreq_monitor_resume(devfreq); tegra_actmon_enable_interrupts(tegra); break; } From patchwork Thu Feb 14 01:30:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 10811551 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 CF6B713A4 for ; Thu, 14 Feb 2019 01:31:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B71E22DF4C for ; Thu, 14 Feb 2019 01:31:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9AFA2DF4F; Thu, 14 Feb 2019 01:31:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 277982DF4C for ; Thu, 14 Feb 2019 01:31:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732743AbfBNBa6 (ORCPT ); Wed, 13 Feb 2019 20:30:58 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38442 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732165AbfBNBa5 (ORCPT ); Wed, 13 Feb 2019 20:30:57 -0500 Received: by mail-pl1-f195.google.com with SMTP id e5so2192091plb.5 for ; Wed, 13 Feb 2019 17:30:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GsKUef20fAh07gfu78gOpr0DjYw/ko20eGV0n0JBmK0=; b=FGkq8uFlHwkBTIIdmp61J0sT/E2AoufEZBgiUVgOfGl1IJq1vgzHtk89MLVZ9ChNE6 Lu6NkZrK/S4kXAEWkN82Vxp2jIQ++s43HLRESAWUipffbH/ezxz8Esato/IWUohJmugo 3Q4S3Qg9SUuLwBTxiZm2LtORx9cS0VkAPdm7c= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=GsKUef20fAh07gfu78gOpr0DjYw/ko20eGV0n0JBmK0=; b=Gxjji+ocOs5R8g7/C1uT4MY+UMLF/yoBO57XmJFtFys61qE8ak0vpX8KB8qZ4m1omv zWWGHdIfHJyEY0ZV6g+fPFaWCzGFZdqz6P9u2pWvOGFbCFy0Yzy3RQ+NU8w52EJrk3mC AGNVnQPHMqygXYE7lXO1dpKpoiMziZQnMW25npVPLNMQnMK7Aa1JLBCFL2TpjZ8/fvX0 /k1ecHJz3wXilJ5wsAQhyoPKjlN/SYZRZo/6uD26UwC95zGazozQoMEs1n3RDH4gzZLV xvi9tz/epwYoDVhMuqPmJEqroUhRLFcw3hPKuKX6iVSC7M9ATsL9pfg2UIDQIqAK9AEC +d/w== X-Gm-Message-State: AHQUAuYWWyV8MUe3Rw/7D0pyWVmcPgga24+4+Ja+ieLu55+tPQQBSwzI /bUXHFTXTzSVcUbi1S4Q80TOPQ== X-Google-Smtp-Source: AHgI3Iawq8vLr9FK/kXBVRcj1L9gwW2DAP72ex0uB2sqO6q1P3TxM8FsANVXz6YDF7YZ5GVK/KlsOg== X-Received: by 2002:a17:902:7086:: with SMTP id z6mr1345620plk.125.1550107856301; Wed, 13 Feb 2019 17:30:56 -0800 (PST) Received: from mka.mtv.corp.google.com ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id p64sm811072pfi.56.2019.02.13.17.30.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 17:30:55 -0800 (PST) From: Matthias Kaehlcke To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Thierry Reding , Jonathan Hunter , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, Lukasz Luba Cc: Matthias Kaehlcke Subject: [PATCH 3/4] PM / devfreq: Add devfreq_governor_start/stop() Date: Wed, 13 Feb 2019 17:30:41 -0800 Message-Id: <20190214013042.254790-4-mka@chromium.org> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a-goog In-Reply-To: <20190214013042.254790-1-mka@chromium.org> References: <20190214013042.254790-1-mka@chromium.org> MIME-Version: 1.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 The following pattern is repeated multiple times: - call governor event handler with DEVFREQ_GOV_START/STOP - check return value - in case of error log a message Add devfreq_governor_start/stop() helper functions with this code and call them instead. Signed-off-by: Matthias Kaehlcke --- drivers/devfreq/devfreq.c | 96 +++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 7fab6c4cf719b..eb86461648d74 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -580,6 +580,53 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type, return ret; } +/** + * devfreq_governor_start() - Start the devfreq governor of the device. + * @devfreq: the devfreq instance + */ +static int devfreq_governor_start(struct devfreq *devfreq) +{ + struct device *dev = devfreq->dev.parent; + int err; + + if (WARN(mutex_is_locked(&devfreq->lock), + "mutex must *not* be held by the caller\n")) + return -EINVAL; + + err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_START, + NULL); + if (err) { + dev_err(dev, "Governor %s not started: %d\n", + devfreq->governor->name, err); + return err; + } + + return 0; +} + +/** + * devfreq_governor_stop() - Stop the devfreq governor of the device. + * @devfreq: the devfreq instance + */ +static int devfreq_governor_stop(struct devfreq *devfreq) +{ + struct device *dev = devfreq->dev.parent; + int err; + + if (WARN(mutex_is_locked(&devfreq->lock), + "mutex must *not* be held by the caller\n")) + return -EINVAL; + + err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_STOP, NULL); + if (err) { + dev_warn(dev, "%s: Governor %s not stopped: %d\n", + devfreq->governor->name, err); + return err; + } + + return 0; +} + /** * devfreq_dev_release() - Callback for struct device to release the device. * @dev: the devfreq device @@ -720,13 +767,9 @@ struct devfreq *devfreq_add_device(struct device *dev, } devfreq->governor = governor; - err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_START, - NULL); - if (err) { - dev_err(dev, "%s: Unable to start governor for the device\n", - __func__); + err = devfreq_governor_start(devfreq); + if (err) goto err_init; - } list_add(&devfreq->node, &devfreq_list); @@ -1029,24 +1072,13 @@ int devfreq_add_governor(struct devfreq_governor *governor) dev_warn(dev, "%s: Governor %s already present\n", __func__, devfreq->governor->name); - ret = devfreq->governor->event_handler(devfreq, - DEVFREQ_GOV_STOP, NULL); - if (ret) { - dev_warn(dev, - "%s: Governor %s stop = %d\n", - __func__, - devfreq->governor->name, ret); - } + ret = devfreq_governor_stop(devfreq); + /* Fall through */ } + devfreq->governor = governor; - ret = devfreq->governor->event_handler(devfreq, - DEVFREQ_GOV_START, NULL); - if (ret) { - dev_warn(dev, "%s: Governor %s start=%d\n", - __func__, devfreq->governor->name, - ret); - } + devfreq_governor_start(devfreq); } } @@ -1081,7 +1113,6 @@ int devfreq_remove_governor(struct devfreq_governor *governor) goto err_out; } list_for_each_entry(devfreq, &devfreq_list, node) { - int ret; struct device *dev = devfreq->dev.parent; if (!strncmp(devfreq->governor_name, governor->name, @@ -1093,13 +1124,8 @@ int devfreq_remove_governor(struct devfreq_governor *governor) continue; /* Fall through */ } - ret = devfreq->governor->event_handler(devfreq, - DEVFREQ_GOV_STOP, NULL); - if (ret) { - dev_warn(dev, "%s: Governor %s stop=%d\n", - __func__, devfreq->governor->name, - ret); - } + + devfreq_governor_stop(devfreq); devfreq->governor = NULL; } } @@ -1149,19 +1175,13 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr, } if (df->governor) { - ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL); - if (ret) { - dev_warn(dev, "%s: Governor %s not stopped(%d)\n", - __func__, df->governor->name, ret); + ret = devfreq_governor_stop(df); + if (ret) goto out; - } } df->governor = governor; strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN); - ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL); - if (ret) - dev_warn(dev, "%s: Governor %s not started(%d)\n", - __func__, df->governor->name, ret); + ret = devfreq_governor_start(df); out: mutex_unlock(&devfreq_list_lock); From patchwork Thu Feb 14 01:30:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 10811553 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 0C73B922 for ; Thu, 14 Feb 2019 01:31:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED16E2DF4C for ; Thu, 14 Feb 2019 01:31:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E11DC2DF4E; Thu, 14 Feb 2019 01:31:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 56C9D2DF4D for ; Thu, 14 Feb 2019 01:31:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387711AbfBNBbI (ORCPT ); Wed, 13 Feb 2019 20:31:08 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43856 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732549AbfBNBa6 (ORCPT ); Wed, 13 Feb 2019 20:30:58 -0500 Received: by mail-pl1-f194.google.com with SMTP id f90so2174428plb.10 for ; Wed, 13 Feb 2019 17:30:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E0/NmLZRXTRsN+OZc6mmHRQXHWfGzPgKXT90TbVPoSY=; b=kwa0apZGhEIq4g7pRcfmyGwZMNNQ55m9TSJ/pfEjxqFB9GTx3/GPdswuAdrz9dILFg whenNhCwryoP6bQ/6MjwrNeEDfwC0XXji5nfytRvPsfdhbz9JGG8ImzFNCb277NwLYQ5 t/9bxN+WjErNwwaPgZiDoSgzk8PczAomktg1Q= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=E0/NmLZRXTRsN+OZc6mmHRQXHWfGzPgKXT90TbVPoSY=; b=SjkC66RXjLrbYC3M4dcgNALy7Z81fsKvAZ7HY2ex/eDPpPxvc5Zwyts/Lnhy+o9h16 NB9NzE2nssnh0xhtL/wNbkwW7Mp7eI6lHqS3w2SyRWgbGcwY2CcKera9H0aOdavjHNfb wa6bM3yIgbP1lXT8Xz3TYpF5pw3vmeZEM3m4YqNYD/ZBLuWyVeqmwn26dTLxGbmTOUqy ixVkCsiEJeFkcR/Q40xw7Vrr9eOuU2I1bD6ANnSKGsD/NJ09Lmxqxc7rzkdPxtOfH+60 b1Rlo11lHdyWlXTLF5G8zTo43t4V43Hzqgjr87bHboj9vBCnyemL6DIYkwSEvSBWgfD8 SHvw== X-Gm-Message-State: AHQUAuYYYUlAlItAOzIbq3x97/6EoOZeswEZMx6qM3KntqUsZf8fJ4Cz iL0Mg5mrTybOeY/E7Tqu2uTQvg== X-Google-Smtp-Source: AHgI3Ib0SaOAA5m/Z8kSp3TIEb+1/gxSM4pIE+2+1w65LMeDBj4aZ4TulQdRZ3KxoKnmpmijMPR8Pw== X-Received: by 2002:a17:902:7e0d:: with SMTP id b13mr1344855plm.154.1550107857290; Wed, 13 Feb 2019 17:30:57 -0800 (PST) Received: from mka.mtv.corp.google.com ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id p64sm811072pfi.56.2019.02.13.17.30.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 17:30:56 -0800 (PST) From: Matthias Kaehlcke To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Thierry Reding , Jonathan Hunter , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, Lukasz Luba Cc: Matthias Kaehlcke Subject: [PATCH 4/4] PM / devfreq: Handle monitor start/stop in the devfreq core Date: Wed, 13 Feb 2019 17:30:42 -0800 Message-Id: <20190214013042.254790-5-mka@chromium.org> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a-goog In-Reply-To: <20190214013042.254790-1-mka@chromium.org> References: <20190214013042.254790-1-mka@chromium.org> MIME-Version: 1.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 devfreq expects governors to call devfreq_monitor_start/stop() in response to DEVFREQ_GOV_START/STOP events. Since the devfreq core itself generates these events and invokes the governor's event handler the start/stop of the load monitor can be done in the common code. Call devfreq_monitor_start/stop() when the governor reports a successful handling of DEVFREQ_GOV_START/STOP and remove these calls from the simpleondemand and tegra governors. Make devfreq_monitor_start/stop() static since these functions are now only used by the devfreq core. For better integration with the callers the functions must now be called with devfreq->lock held. Also stop manipulating the monitor workqueue directly, use devfreq_monitor_start/stop() instead. Signed-off-by: Matthias Kaehlcke --- drivers/devfreq/devfreq.c | 45 +++++++++++------------ drivers/devfreq/governor.h | 2 - drivers/devfreq/governor_simpleondemand.c | 8 ---- drivers/devfreq/tegra-devfreq.c | 2 - 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index eb86461648d74..ac553c00f6790 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -404,14 +404,14 @@ static void devfreq_monitor(struct work_struct *work) * devfreq_monitor_start() - Start load monitoring of devfreq instance * @devfreq: the devfreq instance. * - * Helper function for starting devfreq device load monitoing. By - * default delayed work based monitoring is supported. Function - * to be called from governor in response to DEVFREQ_GOV_START - * event when device is added to devfreq framework. + * Helper function for starting devfreq device load monitoring. By + * default delayed work based monitoring is supported. Must be called + * with devfreq->lock held. */ -void devfreq_monitor_start(struct devfreq *devfreq) +static void devfreq_monitor_start(struct devfreq *devfreq) { - mutex_lock(&devfreq->lock); + WARN(!mutex_is_locked(&devfreq->lock), + "devfreq->lock must be held by the caller.\n"); if (devfreq->profile->polling_ms) { INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor); @@ -420,28 +420,28 @@ void devfreq_monitor_start(struct devfreq *devfreq) devfreq->monitor_state = DEVFREQ_MONITOR_RUNNING; } - - mutex_unlock(&devfreq->lock); } -EXPORT_SYMBOL(devfreq_monitor_start); /** * devfreq_monitor_stop() - Stop load monitoring of a devfreq instance * @devfreq: the devfreq instance. * - * Helper function to stop devfreq device load monitoing. Function - * to be called from governor in response to DEVFREQ_GOV_STOP - * event when device is removed from devfreq framework. + * Helper function to stop devfreq device load monitoring. Must be + * called with devfreq->lock held. */ -void devfreq_monitor_stop(struct devfreq *devfreq) +static void devfreq_monitor_stop(struct devfreq *devfreq) { + /* mutex must be held for symmetry with _start() */ + WARN(!mutex_is_locked(&devfreq->lock), + "devfreq->lock must be held by the caller.\n"); + + mutex_unlock(&devfreq->lock); cancel_delayed_work_sync(&devfreq->work); mutex_lock(&devfreq->lock); devfreq->monitor_state = DEVFREQ_MONITOR_STOPPED; mutex_unlock(&devfreq->lock); } -EXPORT_SYMBOL(devfreq_monitor_stop); /** * devfreq_monitor_suspend() - Suspend load monitoring of a devfreq instance @@ -518,27 +518,22 @@ void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay) /* if new delay is zero, stop polling */ if (!new_delay) { + devfreq_monitor_stop(devfreq); mutex_unlock(&devfreq->lock); - cancel_delayed_work_sync(&devfreq->work); - devfreq->monitor_state == DEVFREQ_MONITOR_STOPPED; return; } /* if current delay is zero, start polling with new delay */ if (!cur_delay) { - queue_delayed_work(devfreq_wq, &devfreq->work, - msecs_to_jiffies(devfreq->profile->polling_ms)); + devfreq_monitor_start(devfreq); goto out; } /* if current delay is greater than new delay, restart polling */ if (cur_delay > new_delay) { - mutex_unlock(&devfreq->lock); - cancel_delayed_work_sync(&devfreq->work); - mutex_lock(&devfreq->lock); + devfreq_monitor_stop(devfreq); if (devfreq->monitor_state != DEVFREQ_MONITOR_SUSPENDED) - queue_delayed_work(devfreq_wq, &devfreq->work, - msecs_to_jiffies(devfreq->profile->polling_ms)); + devfreq_monitor_start(devfreq); } out: mutex_unlock(&devfreq->lock); @@ -601,6 +596,8 @@ static int devfreq_governor_start(struct devfreq *devfreq) return err; } + devfreq_monitor_start(devfreq); + return 0; } @@ -624,6 +621,8 @@ static int devfreq_governor_stop(struct devfreq *devfreq) return err; } + devfreq_monitor_stop(devfreq); + return 0; } diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h index d136792c0cc91..47efe747b6f79 100644 --- a/drivers/devfreq/governor.h +++ b/drivers/devfreq/governor.h @@ -57,8 +57,6 @@ struct devfreq_governor { unsigned int event, void *data); }; -extern void devfreq_monitor_start(struct devfreq *devfreq); -extern void devfreq_monitor_stop(struct devfreq *devfreq); extern void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay); diff --git a/drivers/devfreq/governor_simpleondemand.c b/drivers/devfreq/governor_simpleondemand.c index 52eb0c734b312..e0f0944a9c7aa 100644 --- a/drivers/devfreq/governor_simpleondemand.c +++ b/drivers/devfreq/governor_simpleondemand.c @@ -91,14 +91,6 @@ static int devfreq_simple_ondemand_handler(struct devfreq *devfreq, unsigned int event, void *data) { switch (event) { - case DEVFREQ_GOV_START: - devfreq_monitor_start(devfreq); - break; - - case DEVFREQ_GOV_STOP: - devfreq_monitor_stop(devfreq); - break; - case DEVFREQ_GOV_INTERVAL: devfreq_interval_update(devfreq, (unsigned int *)data); break; diff --git a/drivers/devfreq/tegra-devfreq.c b/drivers/devfreq/tegra-devfreq.c index 79efa1e51bd06..515fb852dbad6 100644 --- a/drivers/devfreq/tegra-devfreq.c +++ b/drivers/devfreq/tegra-devfreq.c @@ -580,13 +580,11 @@ static int tegra_governor_event_handler(struct devfreq *devfreq, switch (event) { case DEVFREQ_GOV_START: - devfreq_monitor_start(devfreq); tegra_actmon_enable_interrupts(tegra); break; case DEVFREQ_GOV_STOP: tegra_actmon_disable_interrupts(tegra); - devfreq_monitor_stop(devfreq); break; case DEVFREQ_GOV_SUSPEND: