mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Haris Okanovic <haris.okanovic@ni.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Anna-Maria Gleixner <anna-maria@linutronix.de>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	julia.cartwright@ni.com, gratian.crisan@ni.com
Subject: Re: [PATCH] Revert "timers: Don't wake ktimersoftd on every tick"
Date: Fri, 2 Jun 2017 09:37:04 -0500	[thread overview]
Message-ID: <b1486490-5a96-7ba3-c280-5d5622c8c488@ni.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1705262232590.2137@nanos>

On 05/26/2017 03:50 PM, Thomas Gleixner wrote:
> On Fri, 26 May 2017, Haris Okanovic wrote:
>
>> Oh crap. I think I see the problem. I decrement expired_count before
>> processing the list. Dropping the lock permits another run of
>> tick_find_expired()->find_expired_timers() in the middle of __expire_timers()
>> since it uses expired_count==0 as a condition.
>>
>> This should fix it, but I'll wait for Anna-Maria's test next week before
>> submitting a patch.
>>
>>>  static void expire_timers(struct timer_base *base)
>>>  {
>>>         struct hlist_head *head;
>>> +       int expCount = base->expired_count;
>
> No camel case for heavens sake!
>
> And this requires:
>
>    	 cnt = READ_ONCE(base->expired_count);
>
>>> -       while (base->expired_count--) {
>>> -               head = base->expired_lists + base->expired_count;
>>> +       while (expCount--) {
>>> +               head = base->expired_lists + expCount;
>>>                 __expire_timers(base, head);
>>>         }
>
> Plus a comment.

Fixed, thanks.

Are your recommending READ_ONCE() purely for documentation purposes?
All reads and writes to base->expired_count happen while base->lock is 
held. It just can't reach zero until expired_lists is ready to be rewritten.

>
>>>         base->expired_count = 0;
>
> Anna-Maria spotted the same issue, but I voted for the revert right now
> because I was worried about the consistency of base->clk under all
> circumstances.
>
> The other thing I noticed was this weird condition which does not do the
> look ahead when base->clk is back for some time.

The soft interrupt fires unconditionally if base->clk hasn't advanced in 
some time to limit how long cpu spends in hard interrupt context.

> Why don't you use the
> existing optimization which uses the bitmap for fast forward?
>

Are you referring to forward_timer_base()/base->next_expiry? I think 
it's only updated in the nohz case. Can you share function name/line 
number(s) if you're thinking of something else.

> The other issue I have is that this can race at all. If you raised the
> softirq in the look ahead then you should not go into that function until
> the softirq has actually completed. There is no point in wasting time in
> the hrtimer interrupt if the softirq is running anyway.
>

Makes sense. Skipping the large `if` block in run_local_timers() when 
`local_softirq_pending() & TIMER_SOFTIRQ`.

> Thanks,
>
> 	tglx
>
>
>
>

I also ran Anna-Maria's test for 12h without failure; I.e. no "Stalled" 
messages. It fails withing 10-15m on my qemu VM without the fix (4-core 
Nehalem, 1GB RAM).

You can view a diff at
https://github.com/harisokanovic/linux/tree/dev/hokanovi/timers-race

-- Haris

  reply	other threads:[~2017-06-02 14:37 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 21:44 [RFC v2] timers: Don't wake ktimersoftd on every tick Haris Okanovic
2016-12-23 17:28 ` Sebastian Andrzej Siewior
2016-12-28 18:06   ` Haris Okanovic
2017-02-03 16:51 ` Sebastian Andrzej Siewior
2017-02-03 18:21   ` [PATCH] " Haris Okanovic
2017-02-10 17:02     ` Sebastian Andrzej Siewior
2017-05-26 17:16       ` [PATCH] Revert "timers: Don't wake ktimersoftd on every tick" Anna-Maria Gleixner
2017-05-26 19:27         ` Haris Okanovic
2017-05-26 19:49           ` Thomas Gleixner
2017-05-26 20:25             ` Haris Okanovic
2017-05-26 20:50               ` Thomas Gleixner
2017-06-02 14:37                 ` Haris Okanovic [this message]
2017-06-04 14:17                   ` Thomas Gleixner
2017-07-17 21:58                     ` Haris Okanovic
2017-07-17 22:04                     ` [PATCH v2] timers: Don't wake ktimersoftd on every tick Haris Okanovic
2017-07-18 21:33                       ` Thomas Gleixner
2017-08-03 21:04                         ` Haris Okanovic
2017-08-03 21:06                         ` [PATCH v3 1/2] " Haris Okanovic
2017-08-03 21:06                           ` [PATCH v3 2/2] timers: Don't search for expired timers while TIMER_SOFTIRQ is scheduled Haris Okanovic
2018-01-05 19:37                             ` Haris Okanovic
2018-03-01 15:49                               ` Haris Okanovic
2018-03-01 15:54                                 ` Thomas Gleixner
2018-03-01 16:35                                   ` Haris Okanovic
2018-03-01 16:47                                 ` Sebastian Andrzej Siewior
2018-03-01 18:37                                   ` Haris Okanovic
2018-03-01 19:06                                     ` Sebastian Andrzej Siewior
2018-03-02 14:52                                     ` Sebastian Andrzej Siewior
2018-03-02 16:29                                       ` Haris Okanovic
2018-03-02 16:39                                         ` Sebastian Andrzej Siewior
2018-03-02 17:19                                           ` Haris Okanovic
2018-03-06 23:39                         ` [PATCH v4 1/2] timers: Don't wake ktimersoftd on every tick Haris Okanovic
2018-03-06 23:39                           ` [PATCH v4 2/2] timers: Don't search for expired timers while TIMER_SOFTIRQ is scheduled Haris Okanovic
     [not found]                           ` <1523332961.4827.1.camel@gmx.de>
2018-04-12 15:00                             ` [PATCH v4 1/2] timers: Don't wake ktimersoftd on every tick Haris Okanovic
2018-06-19 12:43                               ` Daniel Bristot de Oliveira
2018-06-20 14:24                                 ` Haris Okanovic
2018-06-28 16:36                               ` Haris Okanovic
2018-06-28 16:40                                 ` [PATCH v5 " Haris Okanovic
2018-06-28 16:40                                   ` [PATCH v5 2/2] timers: Don't search for expired timers while TIMER_SOFTIRQ is scheduled Haris Okanovic
2018-07-13 12:01                                   ` [PATCH v5 1/2] timers: Don't wake ktimersoftd on every tick Anna-Maria Gleixner
2018-07-13 14:37                                     ` Haris Okanovic
2017-05-27  7:47         ` [PATCH] Revert "timers: Don't wake ktimersoftd on every tick" Sebastian Andrzej Siewior
2017-02-03 18:27   ` [RFC v2] timers: Don't wake ktimersoftd on every tick Haris Okanovic

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=b1486490-5a96-7ba3-c280-5d5622c8c488@ni.com \
    --to=haris.okanovic@ni.com \
    --cc=anna-maria@linutronix.de \
    --cc=bigeasy@linutronix.de \
    --cc=gratian.crisan@ni.com \
    --cc=julia.cartwright@ni.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®