linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Gabriel Matni <gabriel.matni@exfo.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>
Cc: "linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod][PATCH] tools: gpiomon: add timeout option
Date: Tue, 30 May 2023 17:29:23 +0800	[thread overview]
Message-ID: <ZHXB83x85Qchv1XJ@sol> (raw)
In-Reply-To: <PH8PR11MB71425AE7A35F6E651A5B3425864A9@PH8PR11MB7142.namprd11.prod.outlook.com>

On Mon, May 29, 2023 at 08:20:44PM +0000, Gabriel Matni wrote:
> From: Gabriel Matni <gabriel.matni@exfo.com>
> 
> Add a timeout option which allows gpiomon to gracefully exit upon expiry.
> This is handy for scripting as it allows developers to implement an action
> when no trigger has been detected for a given period of time.
> 

The problem I have with this approach is that gpiomon exiting releases
the line(s) being monitored, so you can lose events.
So I'm not thrilled with the idea as it makes it too easy to throw
together a lossy solution without realising it is lossy.

My preferred solution is to run gpiomon as a coproc and have the
controlling script perform the timeout. e.g.

#!/bin/env bash
coproc gpiomon "$@"
while :
do
        read -t5 -u ${COPROC[0]} event || break
        echo $event
done
kill $COPROC_PID


Bart, if adding the option works for you then I can live with it, but I'm
not keen.

If it were to go ahead I would still like some changes - see below.

> Signed-off-by: Gabriel Matni <gabriel.matni@exfo.com>
> ---
> diff --git a/tools/gpiomon.c b/tools/gpiomon.c
> index cc08f17dd2b4..7ef35fa69b1d 100644
> --- a/tools/gpiomon.c
> +++ b/tools/gpiomon.c
> @@ -30,6 +30,7 @@ struct config {
>  	const char *fmt;
>  	enum gpiod_line_clock event_clock;
>  	int timestamp_fmt;
> +	unsigned int timeout;
>  };

timeout should be signed.

>  
>  static void print_help(void)
> @@ -68,9 +69,12 @@ static void print_help(void)
>  	printf("  -s, --strict\t\tabort if requested line names are not unique\n");
>  	printf("      --unquoted\tdon't quote line or consumer names\n");
>  	printf("      --utc\t\tformat event timestamps as UTC (default for 'realtime')\n");
> +	printf("  -t, --timeout <timeout>\n");
> +	printf("\t\t\tpoll timeout, format similar to debounce-period\n");

Call the option --idle-timeout, and don't provide a short form to
reduce the possibility of confusion with the gpioset -t option, which does
something very different, and to intentionally make it a little less
convenient to access.

Rather than <timeout> use <period>, so it is automatically covered by
print_period_help(), and don't reference debounce-period.

Same option should be added to gpionotify, for consistency if nothing
else.

> --- a/tools/tools-common.c
> +++ b/tools/tools-common.c
> @@ -188,6 +188,13 @@ void print_period_help(void)
>  	printf("    Supported units are 's', 'ms', and 'us'.\n");
>  }
>  
> +void print_timeout_help(void)
> +{
> +	printf("\nTimeout:\n");
> +	printf("    Timeout is taken as milliseconds unless a unit is specified. e.g. 1s.\n");
> +	printf("    Supported units are 's', 'ms'.\n");
> +}
> +

The tools-common changes are unnecessary if you change the help as suggested
above.

And in general, code doesn't belong in common if it only used in one tool.

Cheers,
Kent.

  reply	other threads:[~2023-05-30  9:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-29 20:20 [libgpiod][PATCH] tools: gpiomon: add timeout option Gabriel Matni
2023-05-30  9:29 ` Kent Gibson [this message]
2023-05-30 11:21   ` andy.shevchenko
2023-05-30 13:09     ` Kent Gibson
2023-05-30 19:10       ` Bartosz Golaszewski
2023-05-31  1:26         ` Kent Gibson
2023-05-31 13:56           ` [E!] : " Gabriel Matni

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=ZHXB83x85Qchv1XJ@sol \
    --to=warthog618@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=gabriel.matni@exfo.com \
    --cc=linux-gpio@vger.kernel.org \
    /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 NNTP newsgroup(s).