Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1164992imj; Thu, 14 Feb 2019 02:15:21 -0800 (PST) X-Google-Smtp-Source: AHgI3IarZ0moQI7rdRuiarl5OY3vskNyDG8TPeuOPkdUEabzmB7ZZxEMr1dOkW6aZ2lh4hOA/SjK X-Received: by 2002:a65:528c:: with SMTP id y12mr3002147pgp.317.1550139321823; Thu, 14 Feb 2019 02:15:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139321; cv=none; d=google.com; s=arc-20160816; b=Yvi+/n8g9ecaWFAA8APo+zT9yvTf6OUddgRKyXe1aJAxypK5+3M4IXz9E8v11nqDiH ENjEsWkVEeFhWOR4nsPxfxL69/UmSfmOhY8ceNboGawkJjyQV6P3yFa5lqse9Gr0+5S7 CQckPJ9CatoZeORecbEurDxZ15LhE//Gqh5kQ7LsNc9nJLR2/P8luu0xuyeSBNUVdvL+ s+WYNGDuGzWGfEGqsprG908NyIrADfZOkSaGJk5JOGNba7EBvLIPwNibC8I/0V03rrSz f2miakiOBzwv+lRkmwoznlpMis9A1C8C013ep4wWpvCTGNnzCUlrKdhKQNHd03PmsC1e xwYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cJPsF4XxjEGWMiB9f3+lShzsGeUaN6tuDYb4BL3O6BA=; b=IRHLjur1EGezGnWAU4SrvdF13xPvHs+MGhNQtZNMnoWXCxrC7ynllY2Tpo7IKsfIN2 crPMqKvH12WmhAkRE1Tqq6ILJlmOQAHaWuhFUuq/acDfEBpPsP1a00j2WHPloMH5hd2I bTrLGWkmgFAZ+4uDXaIPUqX/lQpu7lPmvBTW6bkE4LZ95n1jebhqsXsfTLDZ2MR3MgeE 5SacVDnMgkCg62AlzqGff29Z+cDfFbZEzDTYjUIpFvE4ZOYete692lgrxXJm0uho0dlQ 1+7iqzQSCvdHpC5zWaOXo6PdICb0OnY3GE4QjFh+qcRacWnpD/acsbIND+9QnkZi0cRZ /OJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YIlwuLFn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d188si1960244pgc.97.2019.02.14.02.15.06; Thu, 14 Feb 2019 02:15:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YIlwuLFn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731888AbfBNBa4 (ORCPT + 99 others); Wed, 13 Feb 2019 20:30:56 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43853 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730421AbfBNBaz (ORCPT ); Wed, 13 Feb 2019 20:30:55 -0500 Received: by mail-pl1-f196.google.com with SMTP id f90so2174358plb.10 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=TlOI5T2SlT78m28MgmGKGoA8IuJRUubEXOPkyo/aCDPCEfmITNyh5+CRDNd1SUi6+6 noFo73LB8cbDh8T85SatBq1j0zOxckLpN+nSLkTXRgMZKRVHH/YMEFEGlxp23ktNrCrw +drswz5f3fXM487YdGJVZqhI/NpwYe6FfJujDP1uxA9C20c1NL70ZvRJynKKGrf+omSt lReKm7Id0zd6MblCD4hk/4S59LXI9uNsV1ezCaz0vMOc9pu7vCJItvg40niFeqJCtKxm yA/5aMsVfLnjxDx3pl1hT8v0XSAP0gtJT1eSWq5uXW6+jXKJ2FVRxKWh98UcuJk+Pyqu TLaQ== X-Gm-Message-State: AHQUAuYL4nxd4XWrIlEECWtpxJu2QLqM72y17QAXCktklUomwY6W/tIJ ZacVxo5eBmuMbnRyb1p30Ho8fQ== 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.20.1.791.gb4d0f1c61a-goog