linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Thara Gopinath <thara.gopinath@linaro.org>
Cc: agross@kernel.org, bjorn.andersson@linaro.org,
	rui.zhang@intel.com, daniel.lezcano@linaro.org,
	rjw@rjwysocki.net, robh+dt@kernel.org, steev@kali.org,
	linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [Patch v4 3/6] cpufreq: qcom-cpufreq-hw: Add dcvs interrupt support
Date: Thu, 29 Jul 2021 11:47:13 +0530	[thread overview]
Message-ID: <20210729061713.kzhka7nymo53zw2o@vireshk-i7> (raw)
In-Reply-To: <9a257605-d282-cd06-cc44-5ad5a5f8484d@linaro.org>

On 28-07-21, 18:19, Thara Gopinath wrote:
> Ha! I was too lazy to write this down! So how about I make this a mutex and

mutex may not work as you come here from irq.

> put mod_delayed_work() inside the lock. So it will be something like below
> 
> qcom_lmh_dcvs_notify()			qcom_cpufreq_hw_lmh_exit()
> 
> mutex_lock()				mutex_lock()
>   if (data->cancel_throttle) {		cancel_throttle = true
> 	mutex_unlock()			mutex_unlock()
> 	return				cancel_delayed_work_sync()
>   }					free_irq()
>   enable_irq() / mod_delayed_work()
> mutex_unlock()
> 
> I will let you break it!

I can't any further :)

Consider merging below to this patch, it fixes sever other minor
issues I see in the code.

-- 
viresh

-------------------------8<-------------------------

diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c
index 3cc27d9e2ed1..4261299fa9e5 100644
--- a/drivers/cpufreq/qcom-cpufreq-hw.c
+++ b/drivers/cpufreq/qcom-cpufreq-hw.c
@@ -38,13 +38,17 @@ struct qcom_cpufreq_soc_data {
 struct qcom_cpufreq_data {
        void __iomem *base;
        struct resource *res;
-       struct delayed_work throttle_work;
        const struct qcom_cpufreq_soc_data *soc_data;
-       struct cpufreq_policy *policy;
-       /* Lock to synchronize between de-init sequence and re-starting LMh polling/interrupts */
+
+       /*
+        * Lock to synchronize between de-init sequence and re-starting LMh
+        * polling/interrupts.
+        */
        spinlock_t throttle_lock;
        int throttle_irq;
        bool cancel_throttle;
+       struct delayed_work throttle_work;
+       struct cpufreq_policy *policy;
 };

 static unsigned long cpu_hw_rate, xo_rate;
@@ -271,10 +275,11 @@ static unsigned int qcom_lmh_get_throttle_freq(struct qcom_cpufreq_data *data)

 static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data)
 {
+       unsigned long max_capacity, capacity, freq_hz, throttled_freq;
        struct cpufreq_policy *policy = data->policy;
+       int cpu = cpumask_first(policy->cpus);
+       struct device *dev = get_cpu_device(cpu);
        struct dev_pm_opp *opp;
-       struct device *dev;
-       unsigned long max_capacity, capacity, freq_hz, throttled_freq;
        unsigned int freq;

        /*
@@ -284,7 +289,6 @@ static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data)
        freq = qcom_lmh_get_throttle_freq(data);
        freq_hz = freq * HZ_PER_KHZ;

-       dev = get_cpu_device(cpumask_first(policy->cpus));
        opp = dev_pm_opp_find_freq_floor(dev, &freq_hz);
        if (IS_ERR(opp) && PTR_ERR(opp) == -ERANGE)
                opp = dev_pm_opp_find_freq_ceil(dev, &freq_hz);
@@ -293,34 +297,37 @@ static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data)

        /* Update thermal pressure */

-       max_capacity = arch_scale_cpu_capacity(cpumask_first(policy->cpus));
+       max_capacity = arch_scale_cpu_capacity(cpu);
        capacity = mult_frac(max_capacity, throttled_freq, policy->cpuinfo.max_freq);
+
        /* Don't pass boost capacity to scheduler */
        if (capacity > max_capacity)
                capacity = max_capacity;

        arch_set_thermal_pressure(policy->cpus, max_capacity - capacity);

-       /* In the unlikely case cpufreq is de-registered do not enable polling or h/w interrupt */
-
+       /*
+        * In the unlikely case, where the policy is going away, do not enable
+        * polling or h/w interrupt.
+        */
        spin_lock(&data->throttle_lock);
-       if (data->cancel_throttle) {
-               spin_unlock(&data->throttle_lock);
-               return;
-       }
-       spin_unlock(&data->throttle_lock);
+
+       if (data->cancel_throttle)
+               goto out;

        /*
-        * If h/w throttled frequency is higher than what cpufreq has requested for, stop
-        * polling and switch back to interrupt mechanism
+        * If h/w throttled frequency is higher than what cpufreq has requested
+        * for, then stop polling and switch back to interrupt mechanism.
         */

-       if (throttled_freq >= qcom_cpufreq_hw_get(cpumask_first(policy->cpus)))
-               /* Clear the existing interrupts and enable it back */
+       if (throttled_freq >= qcom_cpufreq_hw_get(cpu)) {
                enable_irq(data->throttle_irq);
-       else
+       } else {
                mod_delayed_work(system_highpri_wq, &data->throttle_work,
                                 msecs_to_jiffies(10));
+       }
+out:
+       spin_unlock(&data->throttle_lock);
 }

 static void qcom_lmh_dcvs_poll(struct work_struct *work)
@@ -328,7 +335,6 @@ static void qcom_lmh_dcvs_poll(struct work_struct *work)
        struct qcom_cpufreq_data *data;

        data = container_of(work, struct qcom_cpufreq_data, throttle_work.work);
-
        qcom_lmh_dcvs_notify(data);
 }

@@ -407,6 +413,7 @@ static void qcom_cpufreq_hw_lmh_exit(struct qcom_cpufreq_data *data)
        spin_lock(&data->throttle_lock);
        data->cancel_throttle = true;
        spin_unlock(&data->throttle_lock);
+
        cancel_delayed_work_sync(&data->throttle_work);
        free_irq(data->throttle_irq, data);
 }


  reply	other threads:[~2021-07-29  6:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 15:25 [Patch v4 0/6] Introduce LMh driver for Qualcomm SoCs Thara Gopinath
2021-07-27 15:25 ` [Patch v4 1/6] firmware: qcom_scm: Introduce SCM calls to access LMh Thara Gopinath
2021-07-27 15:25 ` [Patch v4 2/6] thermal: qcom: Add support for LMh driver Thara Gopinath
2021-07-27 15:25 ` [Patch v4 3/6] cpufreq: qcom-cpufreq-hw: Add dcvs interrupt support Thara Gopinath
2021-07-28  3:50   ` Viresh Kumar
2021-07-28 22:19     ` Thara Gopinath
2021-07-29  6:17       ` Viresh Kumar [this message]
2021-07-29 11:13         ` Thara Gopinath
2021-07-29 11:15           ` Viresh Kumar
2021-07-27 15:25 ` [Patch v4 4/6] arm64: dts: qcom: sdm45: Add support for LMh node Thara Gopinath
2021-07-27 15:25 ` [Patch v4 5/6] arm64: dts: qcom: sdm845: Remove cpufreq cooling devices for CPU thermal zones Thara Gopinath
2021-07-27 15:25 ` [Patch v4 6/6] dt-bindings: thermal: Add dt binding for QCOM LMh Thara Gopinath
2021-07-27 18:26   ` Rob Herring
2021-07-28 16:10   ` Rob Herring
2021-08-02 21:29     ` Thara Gopinath
2021-07-27 17:44 ` [Patch v4 0/6] Introduce LMh driver for Qualcomm SoCs Steev Klimaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210729061713.kzhka7nymo53zw2o@vireshk-i7 \
    --to=viresh.kumar@linaro.org \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=robh+dt@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=steev@kali.org \
    --cc=thara.gopinath@linaro.org \
    --subject='Re: [Patch v4 3/6] cpufreq: qcom-cpufreq-hw: Add dcvs interrupt support' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).