From: "Liang, Kan" <kan.liang@linux.intel.com>
To: John Stultz <jstultz@google.com>
Cc: peterz@infradead.org, mingo@redhat.com, tglx@linutronix.de,
sboyd@kernel.org, linux-kernel@vger.kernel.org,
eranian@google.com, namhyung@kernel.org, ak@linux.intel.com
Subject: Re: [PATCH 1/3] timekeeping: NMI safe converter from a given time to monotonic
Date: Tue, 24 Jan 2023 10:09:15 -0500 [thread overview]
Message-ID: <9c17d6be-e532-84e1-4d35-77b9bd3051dc@linux.intel.com> (raw)
In-Reply-To: <CANDhNCpWwxXM8DD9h4zOW+bygshkOg9TWO9Z7wJO_B7bDtgEHw@mail.gmail.com>
On 2023-01-24 2:01 a.m., John Stultz wrote:
> On Mon, Jan 23, 2023 at 10:27 AM <kan.liang@linux.intel.com> wrote:
>> +int notrace get_mono_fast_from_given_time(int (*get_time_fn)
>> + (struct system_counterval_t *sys_counterval,
>> + void *ctx),
>> + void *ctx,
>> + u64 *mono_ns)
>> +{
>> + struct system_counterval_t system_counterval;
>> + struct tk_fast *tkf = &tk_fast_mono;
>> + u64 cycles, now, interval_start;
>> + struct tk_read_base *tkr;
>> + unsigned int seq;
>> + int ret;
>> +
>> + do {
>> + seq = raw_read_seqcount_latch(&tkf->seq);
>> + tkr = tkf->base + (seq & 0x01);
>> +
>> + ret = get_time_fn(&system_counterval, ctx);
>> + if (ret)
>> + return ret;
>> +
>> + /*
>> + * Verify that the clocksource associated with the given
>> + * timestamp is the same as the currently installed
>> + * timekeeper clocksource
>> + */
>> + if (tkr->clock != system_counterval.cs)
>> + return -EOPNOTSUPP;
>> + cycles = system_counterval.cycles;
>> +
>> + /*
>> + * Check whether the given timestamp is on the current
>> + * timekeeping interval.
>> + */
>> + now = tk_clock_read(tkr);
>> + interval_start = tkr->cycle_last;
>> + if (!cycle_between(interval_start, cycles, now))
>> + return -EOPNOTSUPP;
>
> So. I've not fully thought this out, but it seems like it would be
> quite likely that you'd run into the case where the cycle_last value
> is updated and your earlier TSC timestamp isn't valid for the current
> interval. The get_device_system_crosststamp() logic has a big chunk of
> complex code to try to handle this case by interpolating the cycle
> value back in time. How well does just failing in this case work out?
>
For the case, perf fallback to the time captured in the NMI handler, via
ktime_get_mono_fast_ns().
The TSC in PEBS is captured by HW when the sample was generated. There
should be a small delta compared with the time captured in the NMI
handler. But I think the delta should be acceptable as a backup solution
for the most analysis cases. Also, I don't think the case (the
cycle_last value is updated during the monitoring) should occur very
often either. So I drop the history support to simplify the function.
Thanks,
Kan
next prev parent reply other threads:[~2023-01-24 15:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-23 18:27 [PATCH 0/3] Convert TSC to monotonic clock for PEBS kan.liang
2023-01-23 18:27 ` [PATCH 1/3] timekeeping: NMI safe converter from a given time to monotonic kan.liang
2023-01-24 7:01 ` John Stultz
2023-01-24 15:09 ` Liang, Kan [this message]
2023-01-24 18:43 ` John Stultz
2023-01-24 20:12 ` Liang, Kan
2023-01-24 20:33 ` John Stultz
2023-01-24 22:08 ` Liang, Kan
2023-01-24 22:40 ` John Stultz
2023-01-25 16:44 ` Liang, Kan
2023-01-24 8:51 ` Thomas Gleixner
2023-01-24 9:10 ` Stephane Eranian
2023-01-24 16:06 ` Liang, Kan
2023-01-27 13:30 ` Thomas Gleixner
2023-01-23 18:27 ` [PATCH 2/3] x86/tsc: Add set_tsc_system_counterval kan.liang
2023-01-23 18:27 ` [PATCH 3/3] perf/x86/intel/ds: Support monotonic clock for PEBS kan.liang
2023-01-24 6:56 ` John Stultz
2023-01-24 15:17 ` Liang, Kan
2023-01-24 6:13 ` [PATCH 0/3] Convert TSC to " John Stultz
2023-01-24 15:04 ` Liang, Kan
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=9c17d6be-e532-84e1-4d35-77b9bd3051dc@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=sboyd@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 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.