xenomai.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Clara Kowalsky <clara.kowalsky@siemens.com>, xenomai@lists.linux.dev
Cc: florian.bezdeka@siemens.com
Subject: Re: [PATCH 5/5] driver/gpio: Take timestamp according to used clock
Date: Tue, 21 May 2024 19:00:39 +0200	[thread overview]
Message-ID: <8545b508-27d7-4e47-b981-6814bd56da89@siemens.com> (raw)
In-Reply-To: <20240416085911.62073-6-clara.kowalsky@siemens.com>

On 16.04.24 10:59, Clara Kowalsky wrote:
> 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();

This looks wrong. Can you explain why gpio_pin_interrupt and
rtdm_gpiochip_post_event select the wrong clock? Or do we rather see
some overflow here so that pin->timestamp here is no longer in sync with
its sampling in those waking functions?

Jan

-- 
Siemens AG, Technology
Linux Expert Center


  reply	other threads:[~2024-05-21 17: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 ` [PATCH 5/5] driver/gpio: Take timestamp according to used clock Clara Kowalsky
2024-05-21 17:00   ` Jan Kiszka [this message]
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=8545b508-27d7-4e47-b981-6814bd56da89@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=clara.kowalsky@siemens.com \
    --cc=florian.bezdeka@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).