Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1259909

Re: [PATCH 5/6] cpufreq: governor: replace per-cpu delayed work with timers

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Viresh Kumar <viresh.kumar@linaro.org>
Newsgroups linux.kernel
Subject Re: [PATCH 5/6] cpufreq: governor: replace per-cpu delayed work with timers
Date Sat, 31 Oct 2015 03:40:01 +0100
Message-ID <qpuff-5uz-1@gated-at.bofh.it> (permalink)
References <qoUv7-6P-5@gated-at.bofh.it> <qoUv7-6P-3@gated-at.bofh.it> <qpoMx-22G-7@gated-at.bofh.it>
X-Original-To Ashwin Chaugule <ashwin.chaugule@linaro.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=NMjyIwCvKsTvRytIaFwhYloXuqs81ArAdHC2+TuUmYI=; b=rGv6UmeBVkaKkYIGCJf1ld7FcbdJWZk/FbPmXceKBUn+1/jcBMGeEWocEFIJiQyXmC 8hQi6APxz6YtpF8w6ficcBI1qFIjwEdgM+QfZuJk3RdmohwcdVl87/J48L8cm9uPu+vF lZmUwc1sIu71Y4GkRrKVjiR2sQilfSJbySzV6jCPPcezw9pqpNX3jpwZxszxW9HOkSYy qL6XoN0mVhESNC+whRzY+pb457Cxyy8VIf94Z8Y/UWn4GDc///6K1qURovbeC/nVxdZO E3mo60lnl2qAIdHXxd+euXifUhVscsmqWAeLqvvSoWHKDrn6LlKA4yA6RC+vNckP3KlM N/1g==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=NMjyIwCvKsTvRytIaFwhYloXuqs81ArAdHC2+TuUmYI=; b=QrtImaqBMJrQ9+ZTgX6N8cNpmwTAoxRUJnkzPCNuNmcgw4Yuf3riWnbkcGyVDJR0Bd nAgiP7JgohIqgkTdMDyFdynK2KK0Vzjp7solJtrKIT3mDSpkAOU/+UP4Nk3CWkpAfIUN bOwRDi5D95Cm5FR0leh2ApOErp0hRzD4FkX+OtR9GeyXz7laDv538NKA4HGJKDYuNZQH LmNCaiKa6nO2f3vTP67uLiOD3irgcKatBqCuhFa4ysJhbD0JImb520i+ohivvVCA/U1v lItMspAz5JrCyLkOY/lwrzi/fnSmUkXt4436hjJzMnsY97aNu0gD+uOWL/ILi329aj0U /PYQ==
X-Gm-Message-State ALoCoQmj6PMHNwRQyF5YH6nEDOSEdhIS7rK5Epwf8R5CrrxvtsT7ypCszkzQ2D2znbfsG6M1Ycwa
X-Received by 10.68.228.200 with SMTP id sk8mr12571023pbc.115.1446258980415; Fri, 30 Oct 2015 19:36:20 -0700 (PDT)
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.21 (2010-09-15)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 102
Organization linux.* mail to news gateway
X-Original-Cc Rafael Wysocki <rjw@rjwysocki.net>, Linaro Kernel Mailman List <linaro-kernel@lists.linaro.org>, "linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>, "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>, open list <linux-kernel@vger.kernel.org>
X-Original-Date Sat, 31 Oct 2015 08:06:15 +0530
X-Original-Message-ID <20151031023615.GX3716@ubuntu>
X-Original-References <cover.1446121217.git.viresh.kumar@linaro.org> <e83291bcb6fcb69280f265194801510cf2e02c41.1446121217.git.viresh.kumar@linaro.org> <CAJ5Y-ebyMg1KUSCJ9+5UVN=6TNAMufGP9S4PqQWS0vnfX6XXOg@mail.gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1259909

Show key headers only | View raw


Hi Ashwin,

On 30-10-15, 16:46, Ashwin Chaugule wrote:
> On 29 October 2015 at 08:27, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > This could be made lightweight by keeping per-cpu deferred timers with a
> > single work item, which is scheduled by the first timer that expires.
> 
> Single shared work item - would perhaps make it a bit more clear.

Okay, in case that I need to repost this, I will reword it.

> > +void gov_cancel_work(struct cpu_common_dbs_info *shared)
> > +{
> > +       unsigned long flags;
> > +
> > +       /*
> > +        * No work will be queued from timer handlers after skip_work is
> > +        * updated. And so we can safely cancel the work first and then the
> > +        * timers.
> > +        */
> > +       spin_lock_irqsave(&shared->timer_lock, flags);
> > +       shared->skip_work++;
> > +       spin_unlock_irqrestore(&shared->timer_lock, flags);
> > +
> > +       cancel_work_sync(&shared->work);
> > +
> > +       gov_cancel_timers(shared->policy);
> > +
> > +       shared->skip_work = 0;
> 
> Why doesnt this require the spin_lock protection?

Because there is no race here. We have already removed all
queued-timers and the shared work.

> > -static void dbs_timer(struct work_struct *work)
> > +static void dbs_work_handler(struct work_struct *work)
> >  {

> > +       mutex_lock(&shared->timer_mutex);
> > +       delay = dbs_data->cdata->gov_dbs_timer(policy, eval_load);
> > +       mutex_unlock(&shared->timer_mutex);
> > +
> > +       shared->skip_work--;
> 
> Ditto.

Again, there is no race here. We have already removed the
queued-timers for the entire policy. The only other user is the
gov_cancel_work() thread (which is called while stopping the governor
or updating the sampling rate), which doesn't depend on this being
decremented as that will wait for the work to finish.

> > +       gov_add_timers(policy, delay);
> > +}
> > +
> > +static void dbs_timer_handler(unsigned long data)
> > +{
> > +       struct cpu_dbs_info *cdbs = (struct cpu_dbs_info *)data;
> > +       struct cpu_common_dbs_info *shared = cdbs->shared;
> > +       struct cpufreq_policy *policy;
> > +       unsigned long flags;
> > +
> > +       spin_lock_irqsave(&shared->timer_lock, flags);
> > +       policy = shared->policy;
> > +
> > +       /*
> > +        * Timer handler isn't allowed to queue work at the moment, because:
> > +        * - Another timer handler has done that
> > +        * - We are stopping the governor
> > +        * - Or we are updating the sampling rate of ondemand governor
> > +        */
> > +       if (shared->skip_work)
> > +               goto unlock;
> > +
> > +       shared->skip_work++;
> > +       queue_work(system_wq, &shared->work);
> >
> 
> So, IIUC, in the event that this function gets called back to back and
> the first Work hasn't dequeued yet, then this queue_work() will not
> really enqueue, since queue_work_on() will return False?

In that case we wouldn't reach queue_work() in the first place as
skip_work will be incremented on the first call and the second call
will simply return early.

> If so, then
> does it mean we're skipping more recent CPU freq requests? Should we
> cancel past Work if it hasn't been serviced?

It doesn't matter. Its only the work handler that is going to do some
useful work, and there is no difference in the first or the second
request.

-- 
viresh
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 5/6] cpufreq: governor: replace per-cpu delayed work with timers Viresh Kumar <viresh.kumar@linaro.org> - 2015-10-29 13:30 +0100
  Re: [PATCH 5/6] cpufreq: governor: replace per-cpu delayed work with timers Ashwin Chaugule <ashwin.chaugule@linaro.org> - 2015-10-30 21:50 +0100
    Re: [PATCH 5/6] cpufreq: governor: replace per-cpu delayed work with  timers Viresh Kumar <viresh.kumar@linaro.org> - 2015-10-31 03:40 +0100
      Re: [PATCH 5/6] cpufreq: governor: replace per-cpu delayed work with timers Ashwin Chaugule <ashwin.chaugule@linaro.org> - 2015-11-03 20:10 +0100

csiph-web