* [PATCH v2 0/3] Allow GPIO timestamps also via real-time clock
@ 2021-08-31 7:15 Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 1/3] drivers/gpio: Add support for selecting real-time clock timestamps Jan Kiszka
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jan Kiszka @ 2021-08-31 7:15 UTC (permalink / raw)
To: xenomai
Changes in v2:
- respect selected mode also in gpio_pin_interrupt
- select timestamp mode explicitly in gpiobench
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 3 aligns the default to the rest of
Xenomai, using real-time from now on. That's 3.2 material.
Jan
Jan Kiszka (3):
drivers/gpio: Add support for selecting real-time clock timestamps
testsuite/gpiobench: Explicitly request monotonic 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 | 19 +++++++++++++++----
testsuite/gpiobench/gpiobench.c | 2 +-
4 files changed, 20 insertions(+), 6 deletions(-)
--
2.31.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] drivers/gpio: Add support for selecting real-time clock timestamps
2021-08-31 7:15 [PATCH v2 0/3] Allow GPIO timestamps also via real-time clock Jan Kiszka
@ 2021-08-31 7:15 ` Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 2/3] testsuite/gpiobench: Explicitly request monotonic timestamps Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 3/3] drivers/gpio: Flip default for GPIO_RTIOC_TS to real-time clock Jan Kiszka
2 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2021-08-31 7:15 UTC (permalink / raw)
To: xenomai
From: Jan Kiszka <jan.kiszka@siemens.com>
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.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
include/cobalt/kernel/rtdm/gpio.h | 1 +
include/rtdm/uapi/gpio.h | 4 +++-
kernel/drivers/gpio/gpio-core.c | 19 +++++++++++++++----
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/include/cobalt/kernel/rtdm/gpio.h b/include/cobalt/kernel/rtdm/gpio.h
index 00055ec0a9..72cc3a0356 100644
--- a/include/cobalt/kernel/rtdm/gpio.h
+++ b/include/cobalt/kernel/rtdm/gpio.h
@@ -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 {
diff --git a/include/rtdm/uapi/gpio.h b/include/rtdm/uapi/gpio.h
index 2839f7d51c..fb84274453 100644
--- a/include/rtdm/uapi/gpio.h
+++ b/include/rtdm/uapi/gpio.h
@@ -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
diff --git a/kernel/drivers/gpio/gpio-core.c b/kernel/drivers/gpio/gpio-core.c
index 600ef9789a..5f5ee3d0f7 100644
--- a/kernel/drivers/gpio/gpio-core.c
+++ b/kernel/drivers/gpio/gpio-core.c
@@ -42,7 +42,10 @@ static int gpio_pin_interrupt(rtdm_irq_t *irqh)
pin = rtdm_irq_get_arg(irqh, struct rtdm_gpio_pin);
- 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 RTDM_IRQ_HANDLED;
@@ -189,11 +192,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 +233,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 +497,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;
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] testsuite/gpiobench: Explicitly request monotonic timestamps
2021-08-31 7:15 [PATCH v2 0/3] Allow GPIO timestamps also via real-time clock Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 1/3] drivers/gpio: Add support for selecting real-time clock timestamps Jan Kiszka
@ 2021-08-31 7:15 ` Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 3/3] drivers/gpio: Flip default for GPIO_RTIOC_TS to real-time clock Jan Kiszka
2 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2021-08-31 7:15 UTC (permalink / raw)
To: xenomai
From: Jan Kiszka <jan.kiszka@siemens.com>
The API's default will change, so select monotonic explicitly.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
testsuite/gpiobench/gpiobench.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/testsuite/gpiobench/gpiobench.c b/testsuite/gpiobench/gpiobench.c
index f83d7689f4..50afbd418a 100644
--- a/testsuite/gpiobench/gpiobench.c
+++ b/testsuite/gpiobench/gpiobench.c
@@ -619,7 +619,7 @@ int main(int argc, char **argv)
goto out;
}
- ret = ioctl(ti.fd_dev_intr, GPIO_RTIOC_TS, &value);
+ ret = ioctl(ti.fd_dev_intr, GPIO_RTIOC_TS_MONO, &value);
if (ret) {
printf("ioctl gpio port ts, failed\n");
goto out;
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] drivers/gpio: Flip default for GPIO_RTIOC_TS to real-time clock
2021-08-31 7:15 [PATCH v2 0/3] Allow GPIO timestamps also via real-time clock Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 1/3] drivers/gpio: Add support for selecting real-time clock timestamps Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 2/3] testsuite/gpiobench: Explicitly request monotonic timestamps Jan Kiszka
@ 2021-08-31 7:15 ` Jan Kiszka
2 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2021-08-31 7:15 UTC (permalink / raw)
To: xenomai
From: Jan Kiszka <jan.kiszka@siemens.com>
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
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
include/rtdm/uapi/gpio.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/rtdm/uapi/gpio.h b/include/rtdm/uapi/gpio.h
index fb84274453..82612a53d3 100644
--- a/include/rtdm/uapi/gpio.h
+++ b/include/rtdm/uapi/gpio.h
@@ -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
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-31 7:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31 7:15 [PATCH v2 0/3] Allow GPIO timestamps also via real-time clock Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 1/3] drivers/gpio: Add support for selecting real-time clock timestamps Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 2/3] testsuite/gpiobench: Explicitly request monotonic timestamps Jan Kiszka
2021-08-31 7:15 ` [PATCH v2 3/3] drivers/gpio: Flip default for GPIO_RTIOC_TS to real-time clock Jan Kiszka
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.