xenomai.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Clara Kowalsky <clara.kowalsky@siemens.com>
To: xenomai@lists.linux.dev
Cc: jan.kiszka@siemens.com, florian.bezdeka@siemens.com,
	Clara Kowalsky <clara.kowalsky@siemens.com>
Subject: [PATCH 5/5] driver/gpio: Take timestamp according to used clock
Date: Tue, 16 Apr 2024 10:59:11 +0200	[thread overview]
Message-ID: <20240416085911.62073-6-clara.kowalsky@siemens.com> (raw)
In-Reply-To: <20240416085911.62073-1-clara.kowalsky@siemens.com>

The log of the loopback device shows that there are problems in the
clock reading and therefore in the diff calculation of the timestamps:

----rt task, gpio loop, test run----
index: 0, inner_diff:       12, outer_diff:       25
index: 1, inner_diff: 18446744073699568, outer_diff:        9
index: 2, inner_diff:        5, outer_diff:       13
index: 3, inner_diff: 18446744073699543, outer_diff:        8
index: 4, inner_diff:        4, outer_diff:       12
index: 5, inner_diff: 18446744073699553, outer_diff:        8

Inner_diff, the difference between gpio_write (write time) and
rdo.timestamp (read time), should always be positive. However, as the
selected clock (monotonic or realtime) is not correctly used for
determining rdo.timestamp, the case occurs that rdo.timestamp is smaller
than gpio_write, resulting in a negative difference and in an overflow.

To fix this, the rdo.timestamp is correctly read from selected clock,
either monotonic or realtime clock.

Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
---
 kernel/drivers/gpio/gpio-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/drivers/gpio/gpio-core.c b/kernel/drivers/gpio/gpio-core.c
index e41c64050..8ab9ae43e 100644
--- a/kernel/drivers/gpio/gpio-core.c
+++ b/kernel/drivers/gpio/gpio-core.c
@@ -233,8 +233,9 @@ static ssize_t gpio_pin_read_rt(struct rtdm_fd *fd,
 			ret = rtdm_event_wait(&pin->event);
 			if (ret)
 				return ret;
-			rdo.timestamp = pin->timestamp;
-		} else if (pin->monotonic_timestamp) {
+		}
+
+		if (pin->monotonic_timestamp) {
 			rdo.timestamp = rtdm_clock_read_monotonic();
 		} else {
 			rdo.timestamp = rtdm_clock_read();
-- 
2.39.2


  parent reply	other threads:[~2024-04-16  9:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16  8:59 [PATCH 0/5] I/O benchmark fixes Clara Kowalsky
2024-04-16  8:59 ` [PATCH 1/5] drivers/gpio: Add driver for BCM2711-based SoCs Clara Kowalsky
2024-05-21 16:48   ` Jan Kiszka
2024-04-16  8:59 ` [PATCH 2/5] testsuite/gpiobench: Toggle output pin in react mode Clara Kowalsky
2024-05-21 16:48   ` Jan Kiszka
2024-06-07 13:40     ` Kowalsky, Clara
2024-04-16  8:59 ` [PATCH 3/5] testsuite/gpiobench: Synchronize index of loopback mode and " Clara Kowalsky
2024-05-21 16:48   ` Jan Kiszka
2024-04-16  8:59 ` [PATCH 4/5] testsuite/gpiobench: Fix calculation of maximum latency Clara Kowalsky
2024-05-21 16:49   ` Jan Kiszka
2024-04-16  8:59 ` Clara Kowalsky [this message]
2024-05-21 17:00   ` [PATCH 5/5] driver/gpio: Take timestamp according to used clock Jan Kiszka
2024-06-07 13:41     ` Kowalsky, Clara

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=20240416085911.62073-6-clara.kowalsky@siemens.com \
    --to=clara.kowalsky@siemens.com \
    --cc=florian.bezdeka@siemens.com \
    --cc=jan.kiszka@siemens.com \
    --cc=xenomai@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).