All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] timers: Use only bucket expiry for base->next_expiry value
Date: Fri, 10 Jul 2020 23:44:59 +0200	[thread overview]
Message-ID: <20200710214458.GA31351@lenoir> (raw)
In-Reply-To: <20200710154622.14989-1-anna-maria@linutronix.de>

Hi Anna-Maria,

Nice change, it indeed makes more sense that way.
Just a few details below:

On Fri, Jul 10, 2020 at 05:46:22PM +0200, Anna-Maria Behnsen wrote:
> The bucket expiry time is the effective expriy time of timers and is
> greater than or equal to the requested timer expiry time. This is due
> to the guarantee that timers never expire early and the reduced expiry
> granularity in the secondary wheel levels.
> 
> When a timer is enqueued, trigger_dyntick_cpu() checks whether the
> timer is the new first timer. This check compares next_expiry with
> the requested timer expiry value and not with the effective expiry
> value of the bucket into which the timer was queued.
> 
> Storing the requested timer expiry value in base->next_expiry can lead
> to base->clk going backwards if the requested timer expiry value is
> smaller than base->clk. Commit 30c66fc30ee7 ("timer: Prevent base->clk
> from moving backward") worked around this by preventing the store when
> timer->expiry is before base->clk, but did not fix the underlying
> problem.
> 
> Use the expiry value of the bucket into which the timer is queued to
> do the new first timer check. This fixes the base->clk going backward
> problem and also prevents unnecessary softirq invocations when the
> timer->expiry is not equal to the bucket expiry time in case of a new
> first timer which is queued in a secondary wheel level.

I think there shouldn't be such unecessary softirq invocations. Either they
fire at the bucket expiry time or the timer expiry time, it doesn't make
much difference.

More important below:

> -static int calc_wheel_index(unsigned long expires, unsigned long clk)
> +static int calc_wheel_index(unsigned long expires, unsigned long clk,
> +			    unsigned long *bucket_expiry)
>  {
>  	unsigned long delta = expires - clk;
>  	unsigned int idx;
>  
>  	if (delta < LVL_START(1)) {
> -		idx = calc_index(expires, 0);
> +		idx = calc_index(expires, 0, bucket_expiry);
>  	} else if (delta < LVL_START(2)) {
> -		idx = calc_index(expires, 1);
> +		idx = calc_index(expires, 1, bucket_expiry);
>  	} else if (delta < LVL_START(3)) {
> -		idx = calc_index(expires, 2);
> +		idx = calc_index(expires, 2, bucket_expiry);
>  	} else if (delta < LVL_START(4)) {
> -		idx = calc_index(expires, 3);
> +		idx = calc_index(expires, 3, bucket_expiry);
>  	} else if (delta < LVL_START(5)) {
> -		idx = calc_index(expires, 4);
> +		idx = calc_index(expires, 4, bucket_expiry);
>  	} else if (delta < LVL_START(6)) {
> -		idx = calc_index(expires, 5);
> +		idx = calc_index(expires, 5, bucket_expiry);
>  	} else if (delta < LVL_START(7)) {
> -		idx = calc_index(expires, 6);
> +		idx = calc_index(expires, 6, bucket_expiry);
>  	} else if (LVL_DEPTH > 8 && delta < LVL_START(8)) {
> -		idx = calc_index(expires, 7);
> +		idx = calc_index(expires, 7, bucket_expiry);
>  	} else if ((long) delta < 0) {
>  		idx = clk & LVL_MASK;

You also need to handle that part. That's in fact the critical one  :)

I'll rebase my series on top of that.

Thanks!

  reply	other threads:[~2020-07-10 21:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-10 15:46 [PATCH] timers: Use only bucket expiry for base->next_expiry value Anna-Maria Behnsen
2020-07-10 21:44 ` Frederic Weisbecker [this message]
2020-07-14  7:08   ` Anna-Maria Behnsen

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=20200710214458.GA31351@lenoir \
    --to=frederic@kernel.org \
    --cc=anna-maria@linutronix.de \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.