Skip to contentSkip to conversation

Add support for Intel PPS Generator

PATCH Superseded [email protected] 3 participants 9 messages Feb 10, 2025

Subsystems (2)

v13 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v13 cover Add support for Intel PPS Generator

From: Subramanian Mohan <[email protected]>

The goal of the PPS (Pulse Per Second) hardware/software is to generate a signal from the system on a wire so that some third-party hardware can observe that signal and judge how close the system's time is to another system or piece of hardware.

Existing methods (like parallel ports) require software to flip a bit at just the right time to create a PPS signal. Many things can prevent software from doing this precisely. This (Timed I/O) method is better because software only "arms" the hardware in advance and then depends on the hardware to "fire" and flip the signal at just the right time.

To generate a PPS signal with this new hardware, the kernel wakes up twice a second, once for 1->0 edge and other for the 0->1 edge. It does this shortly (~10ms) before the actual change in the signal needs to be made. It computes the TSC value at which edge will happen, convert to a value hardware understands and program this value to Timed I/O hardware. The actual edge transition happens without any further action from the kernel.

The result here is a signal coming out of the system that is roughly 1,000 times more accurate than the old methods. If the system is heavily loaded, the difference in accuracy is larger in old methods.

Application Interface:
The API to use Timed I/O is very simple. It is enabled and disabled by writing a '1' or '0' value to the sysfs enable attribute associated with the Timed I/O PPS device. Each Timed I/O pin is represented by a PPS device. When enabled, a pulse-per-second (PPS) synchronized with the system clock is continuously produced on the Timed I/O pin, otherwise it is pulled low.

The Timed I/O signal on the motherboard is enabled in the BIOS setup. Intel Advanced Menu -> PCH IO Configuration -> Timed I/O <Enable>

References:
https://en.wikipedia.org/wiki/Pulse-per-second_signal
https://drive.google.com/file/d/1vkBRRDuELmY8I3FlfOZaEBp-DxLW6t_V/view
https://youtu.be/JLUTT-lrDqw

Patch 1 Replaced copy of pps-gen info struct with const pointer in pps-gen framework..
Patch 2 adds the pps(pulse per second) generator tio driver to the pps subsystem.
Patch 3 documentation and usage of the pps tio generator module. Patch 4 includes documentation for sysfs interface.

These patches are based on the timers/core branch:
[1] https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/?h=timers/core
These changes are dependent on patches that are merged in [1].

Please help to review the changes.

Thanks in advance,
Subramanian Mohan

Changes from v2:
- Split patch 1 to remove the functions in later stages.
- Include required headers in pps_gen_tio.

Changes from v3:
- Corrections in Documentation.
- Introducing non-RFC version of the patch series.

Changes from v4:
- Setting id in ice_ptp
- Modified conversion logic in convert_base_to_cs.
- Included the usage of the APIs in the commit message of 2nd patch.

Changes from v5:
- Change nsecs variable to use_nsecs.
- Change order of 1&2 patches and modify the commit message.
- Add sysfs abi file entry in MAINTAINERS file.
- Add check to find if any event is missed and disable hardware accordingly.

Changes from v6:
- Split patch 1 into 1&2 patches.
- Add check for overflow in convert_ns_to_cs().
- Refine commit messages.

Changes from v7:
- Split the if condition and return error if current time exceeds expire time.
- Update kernel version and month in ABI file.

Changes from v8:
- Add function to enable Timed I/O.
- Changed the updating of tio->enabled to a centralized place in disable and enable functions.

Changes from v9:
- use tio->enabled instead of reading ctrl register.
- change error code in enable_store to -ENODEV.

Changes from v10:
- Rebased to latest codebase.

Changes from v11:
- Rebased to latest codebase.

Changes from v12:
- As part of pps-gen framework, Replaced copy of pps-gen info struct with const pointer.
- TIO driver adapted to pps-gen framework.
- Fixed review comments by Andy.
- Rebased to latest codebase.

Subramanian Mohan (4):
drivers pps/generators: replace copy of pps-gen info struct with const
pointer
pps: generators: Add PPS Generator TIO Driver
Documentation: driver-api: pps: Add Intel Timed I/O PPS generator
ABI: pps: Add ABI documentation for Intel TIO

 Documentation/ABI/testing/sysfs-pps-gen-tio |   6 +
 Documentation/driver-api/pps.rst            |  27 +-
 MAINTAINERS                                 |   1 +
 drivers/pps/generators/Kconfig              |  16 ++
 drivers/pps/generators/Makefile             |   1 +
 drivers/pps/generators/pps_gen-dummy.c      |   2 +-
 drivers/pps/generators/pps_gen.c            |  13 +-
 drivers/pps/generators/pps_gen_tio.c        | 272 ++++++++++++++++++++
 drivers/pps/generators/sysfs.c              |   6 +-
 include/linux/pps_gen_kernel.h              |   4 +-
 10 files changed, 334 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-pps-gen-tio
 create mode 100644 drivers/pps/generators/pps_gen_tio.c
Signature · 1 line
2.35.3
#1 lore raw

PATCH v13 1/4 drivers pps/generators: replace copy of pps-gen info struct with const pointer

From: Subramanian Mohan <[email protected]>

Some PPS generator drivers may need to retrieve a pointer to their internal data while executing the PPS generator enable() method.

During the driver registration the pps_gen_device pointer is returned from the framework, and for that reason, there is difficulty in getting generator driver data back in the enable function. We won't be able to use container_of macro as it results in static assert, and we might end up in using static pointer.

To solve the issue and to get back the generator driver data back, we should not copy the struct pps_gen_source_info within the struct pps_gen_device during the registration stage, but simply save the pointer of the driver one. In this manner, driver may get a pointer to their internal data as shown below:

struct pps_gen_foo_data_s {
        ...
	struct pps_gen_source_info gen_info;
	struct pps_gen_device *pps_gen;
	...
};

static int __init pps_gen_foo_init(void)

{
        struct pps_gen_foo_data_s *foo;
	...

        foo->pps_gen = pps_gen_register_source(&foo->gen_info);
	...
}

Then, in the enable() method, we can retrieve the pointer to the main struct by using the code below:

static int pps_gen_foo_enable(struct pps_gen_device *pps_gen, bool enable)

{
        struct pps_gen_foo_data_s *foo = container_of(pps_gen->info,
	       			      struct pps_gen_foo_data_s, gen_info);
        ...
}
---
 Documentation/driver-api/pps.rst       |  3 +--
 drivers/pps/generators/pps_gen-dummy.c |  2 +-
 drivers/pps/generators/pps_gen.c       | 13 +++++++------
 drivers/pps/generators/sysfs.c         |  6 +++---
 include/linux/pps_gen_kernel.h         |  4 ++--
 5 files changed, 14 insertions(+), 14 deletions(-)
Documentation/driver-api/pps.rst +1 -2
index 71ad04c82d6c..04f1b88778fc 100644
@@ -206,8 +206,7 @@ To do so the class pps-gen has been added. PPS generators can be
 registered in the kernel by defining a struct pps_gen_source_info as
 follows::
 
-    static struct pps_gen_source_info pps_gen_dummy_info = {
-            .name                   = "dummy",
+    static const struct pps_gen_source_info pps_gen_dummy_info = {
             .use_system_clock       = true,
             .get_time               = pps_gen_dummy_get_time,
             .enable                 = pps_gen_dummy_enable,
drivers/pps/generators/pps_gen-dummy.c +1 -1
index b284c200cbe5..55de4aecf35e 100644
@@ -61,7 +61,7 @@ static int pps_gen_dummy_enable(struct pps_gen_device *pps_gen, bool enable)
  * The PPS info struct
  */
 
-static struct pps_gen_source_info pps_gen_dummy_info = {
+static const struct pps_gen_source_info pps_gen_dummy_info = {
 	.use_system_clock	= true,
 	.get_time		= pps_gen_dummy_get_time,
 	.enable			= pps_gen_dummy_enable,
drivers/pps/generators/pps_gen.c +7 -6
index ca592f1736f4..bea00113b55f 100644
@@ -66,7 +66,7 @@ static long pps_gen_cdev_ioctl(struct file *file,
 		if (ret)
 			return -EFAULT;
 
-		ret = pps_gen->info.enable(pps_gen, status);
+		ret = pps_gen->info->enable(pps_gen, status);
 		if (ret)
 			return ret;
 		pps_gen->enabled = status;
@@ -76,7 +76,7 @@ static long pps_gen_cdev_ioctl(struct file *file,
 	case PPS_GEN_USESYSTEMCLOCK:
 		dev_dbg(pps_gen->dev, "PPS_GEN_USESYSTEMCLOCK\n");
 
-		ret = put_user(pps_gen->info.use_system_clock, uiuarg);
+		ret = put_user(pps_gen->info->use_system_clock, uiuarg);
 		if (ret)
 			return -EFAULT;
 
@@ -175,7 +175,7 @@ static int pps_gen_register_cdev(struct pps_gen_device *pps_gen)
 	devt = MKDEV(MAJOR(pps_gen_devt), pps_gen->id);
 
 	cdev_init(&pps_gen->cdev, &pps_gen_cdev_fops);
-	pps_gen->cdev.owner = pps_gen->info.owner;
+	pps_gen->cdev.owner = pps_gen->info->owner;
 
 	err = cdev_add(&pps_gen->cdev, devt, 1);
 	if (err) {
@@ -183,7 +183,7 @@ static int pps_gen_register_cdev(struct pps_gen_device *pps_gen)
 				MAJOR(pps_gen_devt), pps_gen->id);
 		goto free_ida;
 	}
-	pps_gen->dev = device_create(pps_gen_class, pps_gen->info.parent, devt,
+	pps_gen->dev = device_create(pps_gen_class, pps_gen->info->parent, devt,
 					pps_gen, "pps-gen%d", pps_gen->id);
 	if (IS_ERR(pps_gen->dev)) {
 		err = PTR_ERR(pps_gen->dev);
@@ -225,7 +225,8 @@ static void pps_gen_unregister_cdev(struct pps_gen_device *pps_gen)
  * Return: the PPS generator device in case of success, and ERR_PTR(errno)
  *	 otherwise.
  */
-struct pps_gen_device *pps_gen_register_source(struct pps_gen_source_info *info)
+struct pps_gen_device *pps_gen_register_source(
+					const struct pps_gen_source_info *info)
 {
 	struct pps_gen_device *pps_gen;
 	int err;
@@ -235,7 +236,7 @@ struct pps_gen_device *pps_gen_register_source(struct pps_gen_source_info *info)
 		err = -ENOMEM;
 		goto pps_gen_register_source_exit;
 	}
-	pps_gen->info = *info;
+	pps_gen->info = info;
 	pps_gen->enabled = false;
 
 	init_waitqueue_head(&pps_gen->queue);
drivers/pps/generators/sysfs.c +3 -3
index faf8b1c6d202..6d6bc0006fea 100644
@@ -19,7 +19,7 @@ static ssize_t system_show(struct device *dev, struct device_attribute *attr,
 {
 	struct pps_gen_device *pps_gen = dev_get_drvdata(dev);
 
-	return sysfs_emit(buf, "%d\n", pps_gen->info.use_system_clock);
+	return sysfs_emit(buf, "%d\n", pps_gen->info->use_system_clock);
 }
 static DEVICE_ATTR_RO(system);
 
@@ -30,7 +30,7 @@ static ssize_t time_show(struct device *dev, struct device_attribute *attr,
 	struct timespec64 time;
 	int ret;
 
-	ret = pps_gen->info.get_time(pps_gen, &time);
+	ret = pps_gen->info->get_time(pps_gen, &time);
 	if (ret)
 		return ret;
 
@@ -49,7 +49,7 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
 	if (ret)
 		return ret;
 
-	ret = pps_gen->info.enable(pps_gen, status);
+	ret = pps_gen->info->enable(pps_gen, status);
 	if (ret)
 		return ret;
 	pps_gen->enabled = status;
include/linux/pps_gen_kernel.h +2 -2
index 022ea0ac4440..6214c8aa2e02 100644
@@ -43,7 +43,7 @@ struct pps_gen_source_info {
 
 /* The main struct */
 struct pps_gen_device {
-	struct pps_gen_source_info info;	/* PSS generator info */
+	const struct pps_gen_source_info *info;	/* PSS generator info */
 	bool enabled;				/* PSS generator status */
 
 	unsigned int event;
@@ -70,7 +70,7 @@ extern const struct attribute_group *pps_gen_groups[];
  */
 
 extern struct pps_gen_device *pps_gen_register_source(
-				struct pps_gen_source_info *info);
+				const struct pps_gen_source_info *info);
 extern void pps_gen_unregister_source(struct pps_gen_device *pps_gen);
 extern void pps_gen_event(struct pps_gen_device *pps_gen,
 				unsigned int event, void *data);
Signature · 1 line
2.35.3
#2 lore raw

Re: [PATCH v13 1/4] drivers pps/generators: replace copy of pps-gen info struct with const pointer

Quoted 33 lines · On Mon, Feb 10, 2025 at 10:34:18AM +0530, [email protected] wrote:

From: Subramanian Mohan <[email protected]>

Some PPS generator drivers may need to retrieve a pointer to their internal data while executing the PPS generator enable() method.

During the driver registration the pps_gen_device pointer is returned from the framework, and for that reason, there is difficulty in getting generator driver data back in the enable function. We won't be able to use container_of macro as it results in static assert, and we might end up in using static pointer.

To solve the issue and to get back the generator driver data back, we should not copy the struct pps_gen_source_info within the struct pps_gen_device during the registration stage, but simply save the pointer of the driver one. In this manner, driver may get a pointer to their internal data as shown below:

struct pps_gen_foo_data_s {
        ...
	struct pps_gen_source_info gen_info;
	struct pps_gen_device *pps_gen;
	...
};

static int __init pps_gen_foo_init(void)

{
        struct pps_gen_foo_data_s *foo;
	...

        foo->pps_gen = pps_gen_register_source(&foo->gen_info);
	...
}
Quoted 8 lines

Then, in the enable() method, we can retrieve the pointer to the main struct by using the code below:

static int pps_gen_foo_enable(struct pps_gen_device *pps_gen, bool enable)

{
        struct pps_gen_foo_data_s *foo = container_of(pps_gen->info,

	       			      struct pps_gen_foo_data_s, gen_info);

TABs/spaces mix.

Quoted 4 lines
        ...
}

Hmm... Is Rodolfo indeed a correct to be mentioned here? I think you wanted Suggested-by with somebody else.

...

drivers/pps/generators/pps_gen.c static void pps_gen_unregister_cdev(struct pps_gen_device *pps_gen) · line 229

Quoted 3 lines
drivers/pps/generators/pps_gen.c +2 -1
-struct pps_gen_device *pps_gen_register_source(struct pps_gen_source_info *info)
+struct pps_gen_device *pps_gen_register_source(
+					const struct pps_gen_source_info *info)

Still leave it a single line.

...

Otherwise looks good to me, thanks for taking this approach!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Tested-by Mohan Subramanian
#3 lore raw

Re: [PATCH v13 1/4] drivers pps/generators: replace copy of pps-gen info struct with const pointer

Quoted 4 lines · Andy Shevchenko
Quoted 1 line

Hmm... Is Rodolfo indeed a correct to be mentioned here? I think you wanted Suggested-by with somebody else.

Honestly speaking, the patch was written by me, tested by Mohan, and suggested by you. :)

Then I proposed to Mohan to send the patch with other patches in his patch set, since this patch is logically connected with them.

Maybe we can put:

?

Rodolfo

Signature · 4 lines
GNU/Linux Solutions                  e-mail: [email protected]
Linux Device Driver                          [email protected]
Embedded Systems                     phone:  +39 349 2432127
UNIX programming
#4 lore raw

Re: [PATCH v13 1/4] drivers pps/generators: replace copy of pps-gen info struct with const pointer

Quoted 12 lines · Rodolfo Giometti
Quoted 4 lines · Andy Shevchenko
Quoted 1 line

Hmm... Is Rodolfo indeed a correct to be mentioned here? I think you wanted Suggested-by with somebody else.

Honestly speaking, the patch was written by me, tested by Mohan, and suggested by you. :)

Then I proposed to Mohan to send the patch with other patches in his patch set, since this patch is logically connected with them.

Quoted 7 lines

Maybe we can put:

?

Sounds good to me! Whatever you agree on.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

RE: [PATCH v13 1/4] drivers pps/generators: replace copy of pps-gen info struct with const pointer

Quoted 30 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Monday, February 10, 2025 1:37 PM
To: Rodolfo Giometti <[email protected]>
Cc: Mohan, Subramanian <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Dong, Eddie <[email protected]>; Hall, Christopher S <[email protected]>; N, Pandith <[email protected]>; T R, Thejesh Reddy <[email protected]>; Zage, David <[email protected]>; Chinnadurai, Srinivasan <[email protected]>
Subject: Re: [PATCH v13 1/4] drivers pps/generators: replace copy of pps-gen info struct with const pointer

Quoted 14 lines · Rodolfo Giometti
Quoted 4 lines · Andy Shevchenko
Quoted 1 line

Hmm... Is Rodolfo indeed a correct to be mentioned here? I think you wanted Suggested-by with somebody else.

Honestly speaking, the patch was written by me, tested by Mohan, and suggested by you. :)

Then I proposed to Mohan to send the patch with other patches in his patch set, since this patch is logically connected with them.

Maybe we can put:

Quoted 8 lines
Quoted 5 lines

?

Sounds good to me! Whatever you agree on.

Thanks Andy and Rodolfo.
Will wait for some more time for the additional review comments and take the above changes with review comments by Andy as part of v14 patch set.

Thanks,
Subbu

#6 lore raw

PATCH v13 2/4 pps: generators: Add PPS Generator TIO Driver

In reply to [email protected]

From: Subramanian Mohan <[email protected]>

The Intel Timed IO PPS generator driver outputs a PPS signal using dedicated hardware that is more accurate than software actuated PPS. The Timed IO hardware generates output events using the ART timer. The ART timer period varies based on platform type, but is less than 100 nanoseconds for all current platforms. Timed IO output accuracy is within 1 ART period.

PPS output is enabled by writing '1' the 'enable' sysfs attribute. The driver uses hrtimers to schedule a wake-up 10 ms before each event (edge) target time. At wakeup, the driver converts the target time in terms of CLOCK_REALTIME to ART trigger time and writes this to the Timed IO hardware. The Timed IO hardware generates an event precisely at the requested system time without software involvement.

---
 drivers/pps/generators/Kconfig       |  16 ++
 drivers/pps/generators/Makefile      |   1 +
 drivers/pps/generators/pps_gen_tio.c | 272 +++++++++++++++++++++++++++
 3 files changed, 289 insertions(+)
 create mode 100644 drivers/pps/generators/pps_gen_tio.c
drivers/pps/generators/Kconfig +16 -0
index cd94bf3bfaf2..b3f340ed3163 100644
@@ -31,4 +31,20 @@ config PPS_GENERATOR_PARPORT
 	  utilizes STROBE pin of a parallel port to send PPS signals. It uses
 	  parport abstraction layer and hrtimers to precisely control the signal.
 
+config PPS_GENERATOR_TIO
+	tristate "TIO PPS signal generator"
+	depends on X86 && CPU_SUP_INTEL
+	help
+	  If you say yes here you get support for a PPS TIO signal generator
+	  which generates a pulse at a prescribed time based on the system clock.
+	  It uses time translation and hrtimers to precisely generate a pulse.
+	  This hardware is present on 2019 and newer Intel CPUs. However, this
+	  driver is not useful without adding highly specialized hardware outside
+	  the Linux system to observe these pulses.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pps_gen_tio.
+
+	  If unsure, say N.
+
 endif # PPS_GENERATOR
drivers/pps/generators/Makefile +1 -0
index dc1aa5a4688b..e109920e8a2d 100644
@@ -8,5 +8,6 @@ obj-$(CONFIG_PPS_GENERATOR)	:= pps_gen_core.o
 
 obj-$(CONFIG_PPS_GENERATOR_DUMMY)   += pps_gen-dummy.o
 obj-$(CONFIG_PPS_GENERATOR_PARPORT) += pps_gen_parport.o
+obj-$(CONFIG_PPS_GENERATOR_TIO)     += pps_gen_tio.o
 
 ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
drivers/pps/generators/pps_gen_tio.c new file +272 -0

272 lines not on this page · raw message

Signature · 1 line
2.35.3
#7 lore raw

PATCH v13 3/4 Documentation: driver-api: pps: Add Intel Timed I/O PPS generator

In reply to [email protected]

From: Subramanian Mohan <[email protected]>

Add Intel Timed I/O PPS usage instructions.

---
 Documentation/driver-api/pps.rst | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Documentation/driver-api/pps.rst +24 -0
index 04f1b88778fc..598729f9cd27 100644
@@ -285,3 +285,27 @@ delay between assert and clear edge as small as possible to reduce system
 latencies. But if it is too small slave won't be able to capture clear edge
 transition. The default of 30us should be good enough in most situations.
 The delay can be selected using 'delay' pps_gen_parport module parameter.
+
+
+Intel Timed I/O PPS signal generator
+------------------------------------
+
+Intel Timed I/O is a high precision device, present on 2019 and newer Intel
+CPUs, that can generate PPS signals.
+
+Timed I/O and system time are both driven by same hardware clock. The signal
+is generated with a precision of ~20 nanoseconds. The generated PPS signal
+is used to synchronize an external device with system clock. For example,
+it can be used to share your clock with a device that receives PPS signal,
+generated by Timed I/O device. There are dedicated Timed I/O pins to deliver
+the PPS signal to an external device.
+
+Usage of Intel Timed I/O as PPS generator:
+
+Start generating PPS signal::
+
+        $echo 1 > /sys/class/pps-gen/pps-genx/enable
+
+Stop generating PPS signal::
+
+        $echo 0 > /sys/class/pps-gen/pps-genx/enable
Signature · 1 line
2.35.3
#8 lore raw

PATCH v13 4/4 ABI: pps: Add ABI documentation for Intel TIO

In reply to [email protected]

From: Subramanian Mohan <[email protected]>

Document sysfs interface for Intel Timed I/O PPS driver.

---
 Documentation/ABI/testing/sysfs-pps-gen-tio | 6 ++++++
 MAINTAINERS                                 | 1 +
 2 files changed, 7 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-pps-gen-tio
Documentation/ABI/testing/sysfs-pps-gen-tio new file +6 -0
new file mode 100644
index 000000000000..3c34ff17a335
@@ -0,0 +1,6 @@
+What:		/sys/class/pps-gen/pps-genx/enable
+Date:		April 2025
+KernelVersion:	6.15
+Contact:	Subramanian Mohan<[email protected]>
+Description:
+		Enable or disable PPS TIO generator output.
MAINTAINERS +1 -0
index 25c86f47353d..d4280facbe51 100644
@@ -18916,6 +18916,7 @@ S:	Maintained
 W:	http://wiki.enneenne.com/index.php/LinuxPPS_support
 F:	Documentation/ABI/testing/sysfs-pps
 F:	Documentation/ABI/testing/sysfs-pps-gen
+F:	Documentation/ABI/testing/sysfs-pps-gen-tio
 F:	Documentation/devicetree/bindings/pps/pps-gpio.yaml
 F:	Documentation/driver-api/pps.rst
 F:	drivers/pps/
Signature · 1 line
2.35.3