Allow GPIO timestamps also via real-time clock
cover Allow GPIO timestamps also via real-time clock
As discussed, we need to add a separate control to manage whether the monotonic or the real-time clock should be used for GPIO timestamping.
Patch 1 adds this, keeping the default to monotonic. This can be added to 3.1.x stable as well. Patch 2 aligns the default to the rest of Xenomai, using real-time from now on. That's 3.2 material.
Jan
Jan Kiszka (2):
drivers/gpio: Add support for selecting real-time clock timestamps drivers/gpio: Flip default for GPIO_RTIOC_TS to real-time clock
include/cobalt/kernel/rtdm/gpio.h | 1 + include/rtdm/uapi/gpio.h | 4 +++- kernel/drivers/gpio/gpio-core.c | 14 +++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 drivers/gpio: Add support for selecting real-time clock timestamps
From: Jan Kiszka <[email protected]>
This allows to compare timestamps of GPIO pins against other devices and ensures that the stamps are synchronized cross-systems in case PTP is in use (dovetail-based kernels). Keep default to monotonic for now.
--- include/cobalt/kernel/rtdm/gpio.h | 1 + include/rtdm/uapi/gpio.h | 4 +++- kernel/drivers/gpio/gpio-core.c | 14 +++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-)
include/cobalt/kernel/rtdm/gpio.h +1 -0
@@ -34,6 +34,7 @@ struct rtdm_gpio_pin {char *name;struct gpio_desc *desc;nanosecs_abs_t timestamp; +bool monotonic_timestamp; };struct rtdm_gpio_chip {
include/rtdm/uapi/gpio.h +3 -1
@@ -29,7 +29,9 @@ struct rtdm_gpio_readout {#define GPIO_RTIOC_IRQDIS _IO(RTDM_CLASS_GPIO, 3)#define GPIO_RTIOC_REQS _IO(RTDM_CLASS_GPIO, 4)#define GPIO_RTIOC_RELS _IO(RTDM_CLASS_GPIO, 5) -#define GPIO_RTIOC_TS _IOR(RTDM_CLASS_GPIO, 7, int) +#define GPIO_RTIOC_TS_MONO _IOR(RTDM_CLASS_GPIO, 7, int) +#define GPIO_RTIOC_TS GPIO_RTIOC_TS_MONO +#define GPIO_RTIOC_TS_REAL _IOR(RTDM_CLASS_GPIO, 8, int)#define GPIO_TRIGGER_NONE 0x0/* unspecified */ #define GPIO_TRIGGER_EDGE_RISING 0x1
kernel/drivers/gpio/gpio-core.c +11 -3
@@ -189,11 +189,13 @@ static int gpio_pin_ioctl_nrt(struct rtdm_fd *fd,gpio_free (gpio); chan->requested = false;break ; -case GPIO_RTIOC_TS : +case GPIO_RTIOC_TS_MONO : +case GPIO_RTIOC_TS_REAL : ret =rtdm_safe_copy_from_user (fd, &val, arg,sizeof (val));if (ret)return ret; chan->want_timestamp = !!val; + pin->monotonic_timestamp = request ==GPIO_RTIOC_TS_MONO ;break ;default :return -EINVAL ;
@@ -228,8 +230,11 @@ static ssize_t gpio_pin_read_rt(struct rtdm_fd *fd,if (ret)return ret; rdo.timestamp = pin->timestamp; - }else + }else if (pin->monotonic_timestamp) { rdo.timestamp =rtdm_clock_read_monotonic (); + }else { + rdo.timestamp =rtdm_clock_read (); + } len =sizeof (rdo); rdo.value =gpiod_get_raw_value (pin->desc);
@@ -489,7 +494,10 @@ int rtdm_gpiochip_post_event(struct rtdm_gpio_chip *rgc,return -EINVAL ; pin = rgc->pins + offset; - pin->timestamp =rtdm_clock_read_monotonic (); +if (pin->monotonic_timestamp) + pin->timestamp =rtdm_clock_read_monotonic (); +else + pin->timestamp =rtdm_clock_read ();rtdm_event_signal (&pin->event);return 0 ;
Signature · 1 line
2.31.1
PATCH 2/2 drivers/gpio: Flip default for GPIO_RTIOC_TS to real-time clock
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
This is in line with other drivers and should avoid surprises like [1] in the future.
[1] https://xenomai.org/pipermail/xenomai/2021-June/045661.html
--- include/rtdm/uapi/gpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/rtdm/uapi/gpio.h +1 -1
@@ -30,8 +30,8 @@ struct rtdm_gpio_readout {#define GPIO_RTIOC_REQS _IO(RTDM_CLASS_GPIO, 4)#define GPIO_RTIOC_RELS _IO(RTDM_CLASS_GPIO, 5)#define GPIO_RTIOC_TS_MONO _IOR(RTDM_CLASS_GPIO, 7, int) -#define GPIO_RTIOC_TS GPIO_RTIOC_TS_MONO#define GPIO_RTIOC_TS_REAL _IOR(RTDM_CLASS_GPIO, 8, int) +#define GPIO_RTIOC_TS GPIO_RTIOC_TS_REAL#define GPIO_TRIGGER_NONE 0x0/* unspecified */ #define GPIO_TRIGGER_EDGE_RISING 0x1
Signature · 1 line
2.31.1
Quoted 9 lines · Jan Kiszka via Xenomai
As discussed, we need to add a separate control to manage whether the monotonic or the real-time clock should be used for GPIO timestamping.
Patch 1 adds this, keeping the default to monotonic. This can be added to 3.1.x stable as well. Patch 2 aligns the default to the rest of Xenomai, using real-time from now on. That's 3.2 material.
Jan
Quoted 9 lines
Jan Kiszka (2):
drivers/gpio: Add support for selecting real-time clock timestampsdrivers/gpio: Flip default forGPIO_RTIOC_TSto real-time clockinclude/cobalt/kernel/rtdm/gpio.h | 1 + include/rtdm/uapi/gpio.h | 4 +++- kernel/drivers/gpio/gpio-core.c | 14 +++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-)
BTW, as I do not have a test setup for this in reach, I definitely need someone to test this and let us know that it works as desired.
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux