From patchwork Tue Jul 16 09:54:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 169045 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp619064ilk; Tue, 16 Jul 2019 02:55:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzP5B3gwh7QmEOQLpP/GlajMCL9IO1vdnRu54KA54LyRAWtEGWysC8dPr8jjgwwPzFKoT7u X-Received: by 2002:a65:534c:: with SMTP id w12mr32517686pgr.51.1563270914767; Tue, 16 Jul 2019 02:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563270914; cv=none; d=google.com; s=arc-20160816; b=K4/gPU5A/+MQpeoWMgdb1WlKA4oIL5aUAdxTrFs9krzDX5n5DIJLBA4zHwJF7VRIBz GqZ/z2PKjsJi13W1xCJvJaaaP6rv2U/uUNiVDGS6ZBPbn8s6wzmXfp7C137TVWYOt6lO sJ1ePOHNr984BdJwBnMfnXyYtg+aUgPox5/ly4BFHk64JAG0tvfXru9vKBBhwLJ19YgM V7Y+cQNkA2Hv7Dn8p4p1B1u1rhe1Dsq9MGcV+7BIjVUcUkZImi03+fORODGGkItXl5PP ryRnuawWdOVRqJrs/3F1T2PnAdydyj8S7uBkJNMztlcrFuarVTa3YN87MXlWjrhxccnQ atXw== 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=T27u9AQsojQ674GAmNKFLMWAOrQITFIdhdVL3SNGHa0=; b=seRensEAEQ8jL7bvAeu/fshYbSMtEHtsAQPBRoum0jkMVF+91bEE/Fq9aMmX+QXtP6 9NY9mCRqMWu9Xuml+CKOG7k0QWnQb5T4HJB/j39t43SBgUb7bBxGv3f4ypKQ+Duz11Oa s8qmoLpOjkuy0af0CqnWRBRLlZOjVn0F9p2T3TczyXKB1JgQRo9ltyCbFvgQB6W9CZOQ NaGoq7jQ/+30r6vYOJz1dijXgIKXHcyuTe6gWJQGU0RaxXfdKKEQnGs6y2+GZ7Y45kWM PQDOsJmXIYIARJiPZvREl7sKaL9/RBgzoori5e4PMEmrCHV1Soex4pWaHZ3s7WP2o6+S 5Sfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ya2E0F0K; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si471011plz.109.2019.07.16.02.55.14; Tue, 16 Jul 2019 02:55:14 -0700 (PDT) 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=@linaro.org header.s=google header.b=Ya2E0F0K; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732920AbfGPJzN (ORCPT + 29 others); Tue, 16 Jul 2019 05:55:13 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40687 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732520AbfGPJzM (ORCPT ); Tue, 16 Jul 2019 05:55:12 -0400 Received: by mail-pf1-f196.google.com with SMTP id p184so8853985pfp.7 for ; Tue, 16 Jul 2019 02:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T27u9AQsojQ674GAmNKFLMWAOrQITFIdhdVL3SNGHa0=; b=Ya2E0F0Kpsdp0ttA6naaYP2zJx2kYW+h4/n4+NG/MQdbcO2+aQfnQEJkZLQ9tg1IiE LX+8ONNPhgfmujOE3LMRsyCTIjud6ZaL7d6XCXOEcyGKlhQkrJ5/w23QMtezvJRWLK+O mGs6kCsv0aUcf2RmgTLl1X8bv9Y6GQNBTCj2Nn27JzU3c/LizhYZC7T9mmsXsR0ap6d0 31PngFy12ihQsVK8r/izjoBloFuA3ryi2Ck8VejmUOML+kOxbEpWBCPFW/dx57VUIu05 y95wt1MSwxZH2sGlHEYflMvAabRwvVHwUKC5SUZutrT4j7T25CfaZAMxh5h4SS/hVJze cvew== 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=T27u9AQsojQ674GAmNKFLMWAOrQITFIdhdVL3SNGHa0=; b=BuJiyYP7MIaJs+24P/Aq97Yt8HvWm/W5wuKPDoMaovIH4sxiKrYT60lQtQHa2ZwwnL HfOdBVz4cFZODx4YLVlQ+a7awWRt3yNhl2Sf2cQnWLAOdPujeBtTK8ZZzF1WDrkFSOk4 HPhqfJ8m5hMsPbAMfsaCOhtKozufTXLSu1oakQHqeIwDabde0B7/aiJnCBeKS2fZwyJs dszh5am0k975+AcqD0J1RFurz2n2sGV8U9Cktk57rlRKl/kHpXTJV6MAiZEdsXWAzZ/V V+0nfP4Fbf1Y8xLYF5zfN3v9nFTR3k2IsjMM69l4zJtHKuyfn5QdfhZSZ8SgfrB1pTt2 lLjA== X-Gm-Message-State: APjAAAUmzlve2IVPv+xJ08DYeAZyK0VaFBCM1AdOQNcq8kLRRHbbdZGr jNfr20ObOV9n2ywfc37QvlUqrQ== X-Received: by 2002:a63:3fc9:: with SMTP id m192mr32998253pga.429.1563270911165; Tue, 16 Jul 2019 02:55:11 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id n7sm24363826pff.59.2019.07.16.02.55.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 02:55:10 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Amit Daniel Kachhap , Viresh Kumar , Javi Merino , Zhang Rui , Eduardo Valentin , Daniel Lezcano Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 05/10] thermal: cpu_cooling: Switch to QoS requests instead of cpufreq notifier Date: Tue, 16 Jul 2019 15:24:49 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cpufreq core now takes the min/max frequency constraints via QoS requests and the CPUFREQ_ADJUST notifier shall get removed later on. Switch over to using the QoS request for maximum frequency constraint for cpu_cooling driver. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 110 ++++++++-------------------------- 1 file changed, 26 insertions(+), 84 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 4c5db59a619b..391f39776c6a 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -66,8 +67,6 @@ struct time_in_idle { * @last_load: load measured by the latest call to cpufreq_get_requested_power() * @cpufreq_state: integer value representing the current state of cpufreq * cooling devices. - * @clipped_freq: integer value representing the absolute value of the clipped - * frequency. * @max_level: maximum cooling level. One less than total number of valid * cpufreq frequencies. * @freq_table: Freq table in descending order of frequencies @@ -84,12 +83,12 @@ struct cpufreq_cooling_device { int id; u32 last_load; unsigned int cpufreq_state; - unsigned int clipped_freq; unsigned int max_level; struct freq_table *freq_table; /* In descending order */ struct cpufreq_policy *policy; struct list_head node; struct time_in_idle *idle_time; + struct dev_pm_qos_request qos_req; }; static DEFINE_IDA(cpufreq_ida); @@ -118,59 +117,6 @@ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, return level - 1; } -/** - * cpufreq_thermal_notifier - notifier callback for cpufreq policy change. - * @nb: struct notifier_block * with callback info. - * @event: value showing cpufreq event for which this function invoked. - * @data: callback-specific data - * - * Callback to hijack the notification on cpufreq policy transition. - * Every time there is a change in policy, we will intercept and - * update the cpufreq policy with thermal constraints. - * - * Return: 0 (success) - */ -static int cpufreq_thermal_notifier(struct notifier_block *nb, - unsigned long event, void *data) -{ - struct cpufreq_policy *policy = data; - unsigned long clipped_freq; - struct cpufreq_cooling_device *cpufreq_cdev; - - if (event != CPUFREQ_ADJUST) - return NOTIFY_DONE; - - mutex_lock(&cooling_list_lock); - list_for_each_entry(cpufreq_cdev, &cpufreq_cdev_list, node) { - /* - * A new copy of the policy is sent to the notifier and can't - * compare that directly. - */ - if (policy->cpu != cpufreq_cdev->policy->cpu) - continue; - - /* - * policy->max is the maximum allowed frequency defined by user - * and clipped_freq is the maximum that thermal constraints - * allow. - * - * If clipped_freq is lower than policy->max, then we need to - * readjust policy->max. - * - * But, if clipped_freq is greater than policy->max, we don't - * need to do anything. - */ - clipped_freq = cpufreq_cdev->clipped_freq; - - if (policy->max > clipped_freq) - cpufreq_verify_within_limits(policy, 0, clipped_freq); - break; - } - mutex_unlock(&cooling_list_lock); - - return NOTIFY_OK; -} - /** * update_freq_table() - Update the freq table with power numbers * @cpufreq_cdev: the cpufreq cooling device in which to update the table @@ -374,7 +320,6 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) { struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; - unsigned int clip_freq; /* Request state should be less than max_level */ if (WARN_ON(state > cpufreq_cdev->max_level)) @@ -384,13 +329,10 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, if (cpufreq_cdev->cpufreq_state == state) return 0; - clip_freq = cpufreq_cdev->freq_table[state].frequency; cpufreq_cdev->cpufreq_state = state; - cpufreq_cdev->clipped_freq = clip_freq; - - cpufreq_update_policy(cpufreq_cdev->policy->cpu); - return 0; + return dev_pm_qos_update_request(&cpufreq_cdev->qos_req, + cpufreq_cdev->freq_table[state].frequency); } /** @@ -554,11 +496,6 @@ static struct thermal_cooling_device_ops cpufreq_power_cooling_ops = { .power2state = cpufreq_power2state, }; -/* Notifier for cpufreq policy change */ -static struct notifier_block thermal_cpufreq_notifier_block = { - .notifier_call = cpufreq_thermal_notifier, -}; - static unsigned int find_next_max(struct cpufreq_frequency_table *table, unsigned int prev_max) { @@ -596,9 +533,16 @@ __cpufreq_cooling_register(struct device_node *np, struct cpufreq_cooling_device *cpufreq_cdev; char dev_name[THERMAL_NAME_LENGTH]; unsigned int freq, i, num_cpus; + struct device *dev; int ret; struct thermal_cooling_device_ops *cooling_ops; - bool first; + + dev = get_cpu_device(policy->cpu); + if (unlikely(!dev)) { + pr_warn("No cpu device for cpu %d\n", policy->cpu); + return ERR_PTR(-ENODEV); + } + if (IS_ERR_OR_NULL(policy)) { pr_err("%s: cpufreq policy isn't valid: %p\n", __func__, policy); @@ -671,25 +615,29 @@ __cpufreq_cooling_register(struct device_node *np, cooling_ops = &cpufreq_cooling_ops; } + ret = dev_pm_qos_add_request(dev, &cpufreq_cdev->qos_req, + DEV_PM_QOS_MAX_FREQUENCY, + cpufreq_cdev->freq_table[0].frequency); + if (ret < 0) { + pr_err("%s: Failed to add freq constraint (%d)\n", __func__, + ret); + cdev = ERR_PTR(ret); + goto remove_ida; + } + cdev = thermal_of_cooling_device_register(np, dev_name, cpufreq_cdev, cooling_ops); if (IS_ERR(cdev)) - goto remove_ida; - - cpufreq_cdev->clipped_freq = cpufreq_cdev->freq_table[0].frequency; + goto remove_qos_req; mutex_lock(&cooling_list_lock); - /* Register the notifier for first cpufreq cooling device */ - first = list_empty(&cpufreq_cdev_list); list_add(&cpufreq_cdev->node, &cpufreq_cdev_list); mutex_unlock(&cooling_list_lock); - if (first) - cpufreq_register_notifier(&thermal_cpufreq_notifier_block, - CPUFREQ_POLICY_NOTIFIER); - return cdev; +remove_qos_req: + dev_pm_qos_remove_request(&cpufreq_cdev->qos_req); remove_ida: ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); free_table: @@ -777,7 +725,6 @@ EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) { struct cpufreq_cooling_device *cpufreq_cdev; - bool last; if (!cdev) return; @@ -786,15 +733,10 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) mutex_lock(&cooling_list_lock); list_del(&cpufreq_cdev->node); - /* Unregister the notifier for the last cpufreq cooling device */ - last = list_empty(&cpufreq_cdev_list); mutex_unlock(&cooling_list_lock); - if (last) - cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, - CPUFREQ_POLICY_NOTIFIER); - thermal_cooling_device_unregister(cdev); + dev_pm_qos_remove_request(&cpufreq_cdev->qos_req); ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); kfree(cpufreq_cdev->idle_time); kfree(cpufreq_cdev->freq_table);