From patchwork Tue Jul 16 09:54:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 169046 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp619099ilk; Tue, 16 Jul 2019 02:55:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzz3YlRR6LUw+U69D4dNuh+VQLm/X1JZF5fEgVrqaW9FpVqhWMTXHEsZr55r8vBE/gTCKCk X-Received: by 2002:a17:902:da4:: with SMTP id 33mr31185561plv.209.1563270917376; Tue, 16 Jul 2019 02:55:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563270917; cv=none; d=google.com; s=arc-20160816; b=avVFVvHay/CyUOIpdDmEglZ3YpBWnjdB6fctLBSdic2xdCYUjoyONQzBD+Z0VSKy1Q xv9qhqbiA/Zts/Jw0UQod3VjBLmw9XSSZ5wZM39ADmloXJOtVqJTmSZ3mpFYJaN3aQHD G+pF/ff108A3G+RAQhKsj5PEEpGA6bOFc/Rkq150HZ6I26UbvTsnH5EpcrtKD+jyu0Y3 sYjII7d25NYE2gQjBKBJ0PkoVgSdBIK6LXjNaZc1V8k9APa4fp4HtPs1Tyt9uDduzuZh z07XB0j41xMbzqQafZaeBGEoWKTyX7RnFuHp5/4HEcKC1ezs4Mp+UPBcXIQSaMFsiAgO 1/cQ== 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=SWb56XEnAkwuUUTQuv4g9CftmyTnuWFI0OcyOh8bV4E=; b=uwKs1uYDzCDcZOBT+sAx31+JZc2YiTryfvVdCThaugzq03nHtNL5mbyUOE9J5XsfyV ubvTT4qXET2PCihTCWjCmLoResIWtzckyig+BIS+RUCGDWifBgaq7JNl72l7RBquKWj6 HV2JB+TyaFQofo73jKX92yyaGddh0csR2eBn6C95+PWmheYNS9hj/QwEm/q3gRjTVOIy MnRdFbQoIz3qAoZ+QQZhaPkNA9JWdbI2xsr5hSfhf/pYoTw8e1EeHkKva620tKVBGV0j atJ8cnV9AIj10YfREps5n20120jMmHzaBZ/8GPne59Dk+pPtCFePKNvDF4R9OdqKGm+x 3tWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P7pXuZW1; 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.17; Tue, 16 Jul 2019 02:55:17 -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=P7pXuZW1; 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 S1733048AbfGPJzQ (ORCPT + 29 others); Tue, 16 Jul 2019 05:55:16 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:42077 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732923AbfGPJzP (ORCPT ); Tue, 16 Jul 2019 05:55:15 -0400 Received: by mail-pl1-f196.google.com with SMTP id ay6so9839501plb.9 for ; Tue, 16 Jul 2019 02:55:14 -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=SWb56XEnAkwuUUTQuv4g9CftmyTnuWFI0OcyOh8bV4E=; b=P7pXuZW1lJ8u1aom5nEmPqGoSfpfcmLJUxPBNeM2o020xDjJZewv9KksFoB5SSIQVi QIBeycHlDSjUHhcf4/+gxvCfMbAAfvKV9unZPA3EHVyJH+Sb0UOZieH4z/zj+GuLl6TX IR20OZ6VkiyhUKOFhO4M65yEN3xmPEySfEpi7QIO+Y6OWH44PnWjq9iDQxSA+0l53k5I bho1MEAFwdg9BzUeHBuD5/bt2B9vKl15Jb41phYGVYEZxtClXjm82f9oAe/tTA7Pmcu6 8V13Iblir4uOpr7EzJTuZQL47KZXU19UiWMGXW79C38DHYcjHqmnP5PLPm6zAkJVhAHG TlSQ== 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=SWb56XEnAkwuUUTQuv4g9CftmyTnuWFI0OcyOh8bV4E=; b=J1FkuPssa6RM8Jx0HyHCyYt6T5hpj0tXOJYtdEdapHwxLffraL+2yQLT3YE+Axy8le LzTy0kpur+B61C3MaEzS+Yikl2gSbJOIQ6TQ+cT0ksT70FWcRD7LkvmatlFWNZ22PThg eB6u1J1RsbKMYNh7SKIXSSnwnrogA0J/d1jXVo9Dd7T1KhyjeP2fj2bY8r8MZcN7z2/N uJqjuzKg7X8lTQOYjHhIXm9z/kSRaESGNDXismoqaahm7OwKZrdt6geBlWc7rjGcw9VW zWntk6QbMjXHn7jpDT8Vr8xBUnlkAodaOm6oDaLfTdj389gIk0Sroy4FXtgnqXCXqNsS oHCg== X-Gm-Message-State: APjAAAXjs42W82N0s/yZkjH62rfXlk/ZVZWtY5uDRbdw9hYK4T5+WUsS JMExvbPLLdzY3YfRHadzCnGVUCPudVc= X-Received: by 2002:a17:902:e282:: with SMTP id cf2mr34506552plb.301.1563270914414; Tue, 16 Jul 2019 02:55:14 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id a5sm18383524pjv.21.2019.07.16.02.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 02:55:13 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Benjamin Herrenschmidt Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/10] powerpc: macintosh: Switch to QoS requests instead of cpufreq notifier Date: Tue, 16 Jul 2019 15:24:50 +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 windfarm_cpufreq_clamp driver. Signed-off-by: Viresh Kumar --- drivers/macintosh/windfarm_cpufreq_clamp.c | 77 ++++++++++++++-------- 1 file changed, 50 insertions(+), 27 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/macintosh/windfarm_cpufreq_clamp.c b/drivers/macintosh/windfarm_cpufreq_clamp.c index 52fd5fca89a0..705c6200814b 100644 --- a/drivers/macintosh/windfarm_cpufreq_clamp.c +++ b/drivers/macintosh/windfarm_cpufreq_clamp.c @@ -3,9 +3,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -16,36 +18,24 @@ static int clamped; static struct wf_control *clamp_control; - -static int clamp_notifier_call(struct notifier_block *self, - unsigned long event, void *data) -{ - struct cpufreq_policy *p = data; - unsigned long max_freq; - - if (event != CPUFREQ_ADJUST) - return 0; - - max_freq = clamped ? (p->cpuinfo.min_freq) : (p->cpuinfo.max_freq); - cpufreq_verify_within_limits(p, 0, max_freq); - - return 0; -} - -static struct notifier_block clamp_notifier = { - .notifier_call = clamp_notifier_call, -}; +static struct dev_pm_qos_request qos_req; +static unsigned int min_freq, max_freq; static int clamp_set(struct wf_control *ct, s32 value) { - if (value) + unsigned int freq; + + if (value) { + freq = min_freq; printk(KERN_INFO "windfarm: Clamping CPU frequency to " "minimum !\n"); - else + } else { + freq = max_freq; printk(KERN_INFO "windfarm: CPU frequency unclamped !\n"); + } clamped = value; - cpufreq_update_policy(0); - return 0; + + return dev_pm_qos_update_request(&qos_req, freq); } static int clamp_get(struct wf_control *ct, s32 *value) @@ -74,27 +64,60 @@ static const struct wf_control_ops clamp_ops = { static int __init wf_cpufreq_clamp_init(void) { + struct cpufreq_policy *policy; struct wf_control *clamp; + struct device *dev; + int ret; + + policy = cpufreq_cpu_get(0); + if (!policy) { + pr_warn("%s: cpufreq policy not found cpu0\n", __func__); + return -EPROBE_DEFER; + } + + min_freq = policy->cpuinfo.min_freq; + max_freq = policy->cpuinfo.max_freq; + cpufreq_cpu_put(policy); + + dev = get_cpu_device(0); + if (unlikely(!dev)) { + pr_warn("%s: No cpu device for cpu0\n", __func__); + return -ENODEV; + } clamp = kmalloc(sizeof(struct wf_control), GFP_KERNEL); if (clamp == NULL) return -ENOMEM; - cpufreq_register_notifier(&clamp_notifier, CPUFREQ_POLICY_NOTIFIER); + + ret = dev_pm_qos_add_request(dev, &qos_req, DEV_PM_QOS_MAX_FREQUENCY, + max_freq); + if (ret < 0) { + pr_err("%s: Failed to add freq constraint (%d)\n", __func__, + ret); + goto free; + } + clamp->ops = &clamp_ops; clamp->name = "cpufreq-clamp"; - if (wf_register_control(clamp)) + ret = wf_register_control(clamp); + if (ret) goto fail; clamp_control = clamp; return 0; fail: + dev_pm_qos_remove_request(&qos_req); + + free: kfree(clamp); - return -ENODEV; + return ret; } static void __exit wf_cpufreq_clamp_exit(void) { - if (clamp_control) + if (clamp_control) { wf_unregister_control(clamp_control); + dev_pm_qos_remove_request(&qos_req); + } }