All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: Prarit Bhargava <prarit@redhat.com>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	Xunlei Pang <pang.xunlei@linaro.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Baolin Wang <baolin.wang@linaro.org>,
	Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH 1/2] kernel, timekeeping, add trylock option to ktime_get_with_offset()
Date: Wed, 6 Jan 2016 09:28:09 -0800	[thread overview]
Message-ID: <CALAqxLUsQNswOM33vMezyEpM7L8tmK-oOkDwQ2UxNdtEXsHX-w@mail.gmail.com> (raw)
In-Reply-To: <1452085234-10667-2-git-send-email-prarit@redhat.com>

On Wed, Jan 6, 2016 at 5:00 AM, Prarit Bhargava <prarit@redhat.com> wrote:
> -ktime_t ktime_get_with_offset(enum tk_offsets offs)
> +ktime_t ktime_get_with_offset(enum tk_offsets offs, int trylock)
>  {
>         struct timekeeper *tk = &tk_core.timekeeper;
>         unsigned int seq;
>         ktime_t base, *offset = offsets[offs];
>         s64 nsecs;
> +       unsigned long flags = 0;
> +
> +       if (unlikely(!timekeeping_initialized))
> +               return ktime_set(0, 0);
>
>         WARN_ON(timekeeping_suspended);
>
> +       if (trylock && !raw_spin_trylock_irqsave(&timekeeper_lock, flags))
> +               return ktime_set(KTIME_MAX, 0);

Wait.. this doesn't make sense. The timekeeper lock is only for reading.

What I was suggesting to you off line is to have something that avoids
spinning on the seqcounter should if a bug occurs and we IPI all the
cpus, that we don't deadlock or block any printk messages.


> +
>         do {
>                 seq = read_seqcount_begin(&tk_core.seq);
>                 base = ktime_add(tk->tkr_mono.base, *offset);
> @@ -721,6 +730,9 @@ ktime_t ktime_get_with_offset(enum tk_offsets offs)
>
>         } while (read_seqcount_retry(&tk_core.seq, seq));

So instead of the do/while() loop above... Something closer to:

int __ktime_get_with_offset(enum tk_offsets offs, ktime_t* base, s64 *nsec)
{
       unsigned int seq;

       seq = read_seqcount_begin(&tk_core.seq);
       *base = ktime_add(tk->tkr_mono.base, *offset);
       *nsecs = timekeeping_get_ns(&tk->tkr_mono);

       return read_seqcount_retry(&tk_core.seq, seq);
}

Then ktime_get_with_offset() would just call:
      ...
      while(__ktime_get_with_offset(offs, &base, &nsecs))
                          /*spin*/;
      return ktime_add_ns(base,nsecs);

Then you add a simple:
int ktime_try_get_with_offset(enum tk_offsets offs, ktime_t* ret)
{
   ...
    if (__ktime_get_with_offset(offs, &base, &nsecs))
           return -EAGAIN;
    *ret = ktime_add_ns(base,nsecs);
     return 0;
}


thanks
-john

  parent reply	other threads:[~2016-01-06 17:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-06 13:00 [PATCH 0/2] printk, Add a printk.clock kernel parameter Prarit Bhargava
2016-01-06 13:00 ` [PATCH 1/2] kernel, timekeeping, add trylock option to ktime_get_with_offset() Prarit Bhargava
2016-01-06 16:04   ` Jiri Bohac
2016-01-06 16:27     ` Prarit Bhargava
2016-01-06 16:25   ` Petr Mladek
2016-01-06 17:28   ` John Stultz [this message]
2016-01-06 17:33     ` John Stultz
2016-01-06 18:06       ` Prarit Bhargava
2016-01-06 18:10         ` Thomas Gleixner
2016-01-06 17:34     ` Thomas Gleixner
2016-01-06 18:09       ` Prarit Bhargava
2016-01-06 18:12         ` Thomas Gleixner
2016-01-06 19:04       ` John Stultz
2016-01-06 19:06         ` Prarit Bhargava
2016-01-06 13:00 ` [PATCH 2/2] printk, Add printk.clock kernel parameter Prarit Bhargava
2016-01-07 14:57   ` Petr Mladek
2016-01-07 15:38     ` Prarit Bhargava
2016-01-07 15:52       ` Petr Mladek
2016-01-08  9:04         ` Thomas Gleixner
2016-01-06 17:09 ` [PATCH 0/2] printk, Add a " Joe Perches

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=CALAqxLUsQNswOM33vMezyEpM7L8tmK-oOkDwQ2UxNdtEXsHX-w@mail.gmail.com \
    --to=john.stultz@linaro.org \
    --cc=arnd@arndb.de \
    --cc=baolin.wang@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=pang.xunlei@linaro.org \
    --cc=peterz@infradead.org \
    --cc=prarit@redhat.com \
    --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.