From: William Breathitt Gray <william.gray@linaro.org>
To: "Hall, Christopher S" <christopher.s.hall@intel.com>
Cc: "N, Pandith" <pandith.n@intel.com>,
"Jonathan.Cameron@Huawei.com" <Jonathan.Cameron@huawei.com>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"vilhelm.gray@gmail.com" <vilhelm.gray@gmail.com>,
"jic23@kernel.org" <jic23@kernel.org>,
"lars@metafoo.de" <lars@metafoo.de>,
"Shevchenko, Andriy" <andriy.shevchenko@intel.com>,
"Sangannavar,
Mallikarjunappa" <mallikarjunappa.sangannavar@intel.com>,
"D, Lakshmi Sowjanya" <lakshmi.sowjanya.d@intel.com>,
"T R, Thejesh Reddy" <thejesh.reddy.t.r@intel.com>
Subject: Re: Intel Timed-IO driver in IIO/Counter subsystem
Date: Tue, 21 Jun 2022 09:58:31 -0400 [thread overview]
Message-ID: <YrHOh2jqfwc0gCao@fedora> (raw)
In-Reply-To: <ff67454b89fa444db36dee57fac5eb74@intel.com>
[-- Attachment #1: Type: text/plain, Size: 5589 bytes --]
On Sat, Jun 18, 2022 at 01:01:47AM +0000, Hall, Christopher S wrote:
> N, Pandith <pandith.n@intel.com> wrote:
> > Hi,
> >
> > We have a Intel Timed IO peripheral with following functionalities :
> >
> > 1. Event capture capability - Captures event count and timestamp.
>
> An event is an edge on the input or output signal. Rising, falling,
> or both edges can be selected for counting / timestamping. The
> timestamp and count are captured synchronously.
>
> If, for example, the hardware is configured to capture both types of
> input edges, each input edge causes the count to increment by one and
> the ART value (see below) to be captured atomically.
>
> To see how this may be useful, consider the case where two event
> occur before software is able to read the first. A count delta of >1
> indicates that an event timestamp was missed.
>
> For another example: If the input signal is periodic, the frequency
> offset between the input clock and the local clock can be computed:
>
> (delta ART / delta count) * (nom. input freq / 1e9 ns) *
> (1e9 / ART frequency)
>
> It is not necessary to read each event to determine the average
> frequency for multiple events.
>
> > 2. Pulse generation - periodic or single event generation.
> > 3. Return cross-timestamp on request.
>
> This may imply that the Timed I/O logic is driven by a separate device clock.
> It is not. It is driven by the platform clock - the Always Running
> Timer (ART). ART is directly related to the CPU timestamp counter (TSC).
> ART and TSC can be converted to one another using the following equation:
>
> TSC_Value = (ART_Value * CPUID.15H:EBX[31:0] )/ CPUID.15H:EAX[31:0] + K
>
> ART ticks at the core crystal frequency. Typically this is 38.4 MHz. The
> frequency can be discovered by reading CPUID.15H:ECX[31:0].
>
> More information can be found in the Intel Software Developer's
> Manual (SDM) in the Invariant Timekeeping section
> 17.17.4 and Determining the Processor Base Frequency section 18.7.3
> (https://cdrdv2.intel.com/v1/dl/getContent/671200)
>
> K is typically zero. A virtualized guest is an example where K != 0. In
> this case, K is offset by the value of the VMCS TSC offset.
>
> An example of how ART can be directly converted to system time is in the
> e1000e driver:
>
> drivers/net/ethernet/intel/e1000e/ptp.c:e1000e_phc_getcrosststamp()
>
> using the following functions:
>
> - arch/x86/kernel/tsc.c:convert_art_to_tsc() [ART->TSC]
> - kernel/time/timekeeping.c:get_device_system_crosststamp() [TSC->System Time]
>
> These are dependent upon TSC being selected as the clocksource. The
> attempted conversion results in an error otherwise.
>
> A PHC driver implementation of Timed I/O was proposed:
> - https://lkml.org/lkml/2020/1/31/25
>
> that included a cross-timestamp function. This crosstimestamp - in the sense
> of determining the relationship between two independent clocks - is a
> software fiction because system time is based on ART. The cross-timestamp
> value enabled conversion of an event timestamp from ART -> System Time in
> the application in the usual way when using the PHC API.
>
> In my opinion, given a (more) greenfield API implementation. ART timestamps
> should not be exposed at the application level at all. All timestamps
> returned to the application should be in terms of system time.
>
> There is a chapter (21.3.5) in the Atom(r) x6000E datasheet for Timed I/O:
>
> https://cdrdv2.intel.com/v1/dl/getContent/636112?explicitVersion=true&wapkw=EHL%20datasheet
>
> Note that the hardware function is called TGPIO.
>
> There is also Timed I/O example code using the PHC driver referenced above:
>
> https://www.intel.com/content/www/us/en/develop/documentation/tcc-tools-2021-2-developer-guide/top/time-synchronization-and-communication-tools/time-aware-gpio-tgpio-samples.html
>
> Thanks,
> Christopher
Hi Christopher,
I'm not familiar with the recent HTE code, so I don't know whether it
can handle arbitrary data values; does the HTE code only track GPIO line
states (whether high or low) with respective timestamps, or can it also
track events count values with a respective timestamps?
Despite the events being triggered by GPIO, it seems from your
description that what you're actually concerned with is getting the
count of "events" and a "timestamp" derived from the ART ticks. If those
two values are what you're trying to handle, then the Counter subsystem
character device should be suitable for your needs:
https://www.kernel.org/doc/html/latest/driver-api/generic-counter.html#counter-character-device
This could be implemented by creating a Counter driver that treats the
events count as its "Count", and the respective ART-derived timestamp as
a its "Count Extension". When an event is triggered, the driver can push
that event to the respective Count character device via a
counter_push_event() call; userspace can add a "Counter Watch" via the
ioctl COUNTER_ADD_WATCH_IOCTL code to watch changes to these two values
(see tools/counter/counter_example.c).
As a side note, the "timestamp" member of struct counter_event serves
more as an event ID for your particular case here because your actual
timestamp is provided by your ART-derived Counter extension component
(whose value can be in terms of system time if you so wish); it'll come
as the "value" member of another struct counter_event following the
struct counter_event containing your events count.
William Breathitt Gray
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
prev parent reply other threads:[~2022-06-21 13:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-17 6:37 Intel Timed-IO driver in IIO/Counter subsystem N, Pandith
2022-06-17 7:22 ` Lars-Peter Clausen
2022-06-17 9:51 ` Shevchenko, Andriy
2022-06-17 11:39 ` Linus Walleij
2022-06-18 2:01 ` Hall, Christopher S
2022-06-23 12:21 ` Linus Walleij
2022-07-05 3:16 ` Kent Gibson
2022-07-06 5:52 ` Hall, Christopher S
2022-07-06 23:05 ` Linus Walleij
2022-07-07 3:21 ` Kent Gibson
2022-06-17 14:03 ` William Breathitt Gray
2022-06-17 17:15 ` Jonathan Cameron
2022-06-18 1:01 ` Hall, Christopher S
2022-06-21 13:58 ` William Breathitt Gray [this message]
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=YrHOh2jqfwc0gCao@fedora \
--to=william.gray@linaro.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=andriy.shevchenko@intel.com \
--cc=christopher.s.hall@intel.com \
--cc=jic23@kernel.org \
--cc=lakshmi.sowjanya.d@intel.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=mallikarjunappa.sangannavar@intel.com \
--cc=pandith.n@intel.com \
--cc=thejesh.reddy.t.r@intel.com \
--cc=vilhelm.gray@gmail.com \
/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.