Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1469007ybl; Thu, 5 Dec 2019 01:50:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyKqaPRtTQBSqWndcxmnK9hYxxSiKGAf37T+d/AEfdetTCurlsrmSBYfJ2pKw2ZMmshBwUi X-Received: by 2002:aca:3141:: with SMTP id x62mr6096408oix.108.1575539405908; Thu, 05 Dec 2019 01:50:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575539405; cv=none; d=google.com; s=arc-20160816; b=V0a67vmlENJe9ljO2Q/DW0Xf+B44Tyq3lxrlj9xH2XlrUsR7J2YwjXzORHMY/Br8YZ tls8tCdKzHMqlnZjhoBO+zk5uJee4eU7oxh+jIOSG6Jc2XUpAAC10s48jcJtG5nGrY6z dk+a4xn+zS9YW9wkfo70BBdx7gtb5VSW9/c/c9rYW3TLtlqgR3PZyhRQ7y2R3GU5TOUk BlOn1UtvnQfMsz7WmFdrXl47JWpYcq1yWTApjz/FTSu1n5b3k5wbcKhRyHnAv+iTNVGz OD8UN3TJQ2s5vVyrSaXXlMoHUr0LvLmftA81hoiKF714O8tL9kK2aaacUtSijpEJdXZN uZOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=uETehSid0KbgkrMqALuI9xpJZ+8tQuqfj+BUwHEHAkU=; b=t8/et11oIUz67ohradun2QT/d8lCJbBLta+vf+r0T1zoG0sF4J7cM38WZRQY9mZOhA FVRQ5MxNqDjv37/RCHy4ukFb4rjUlSQe0DWhvfbKDM+N9B81oZ3agQDBA5JjgzV0/l19 Pa64visM/avljkRlTlJzm6Vw3HLVmj48WQd8rH/SS7rtfSZeDNWippYO1ZdUxEMHoTzV Ljudg2f9AjY7araZ2hkw69CfFbKqqkKXX4MCwgXrQgTrtk6AOmffGlOaGMmkm4CZwRgH Sui3B/3ed8ZuKlgcXfPhfzoUoePb6peidLrqEySzr1vsQfvTF/ENz8oak2M8EiMan7jl R9qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=Lt3QshLy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p131si4725709oih.34.2019.12.05.01.49.52; Thu, 05 Dec 2019 01:50:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=Lt3QshLy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729018AbfLEJsx (ORCPT + 99 others); Thu, 5 Dec 2019 04:48:53 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:37033 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726239AbfLEJsw (ORCPT ); Thu, 5 Dec 2019 04:48:52 -0500 Received: by mail-io1-f67.google.com with SMTP id k24so2949506ioc.4 for ; Thu, 05 Dec 2019 01:48:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=uETehSid0KbgkrMqALuI9xpJZ+8tQuqfj+BUwHEHAkU=; b=Lt3QshLyBDNGtHfxD8XyRrfuTO5PvedlequdU0OKg3+cNK1MbXUhvdxLtH1BWOymU/ 8p09ygPx3hl6x39mAaM2p2zTkHERx7E+gBOU8q8FkO9aZ9TGhGENt9UvziTKPNvt7hDe x1wh/WquvPJvYiSrgqO11EN5flIVkCyyHmLY6HEsA7Cs/4uiWz39vf21T9nSXedbOjIj oKEK8mqPKPR53mi7dXBocsDm0L6/XCy17RFxZD3HmQ+URVPZis8M7dfBVWb9q6Gh4L2d t1QHBp5OxFWvE+u7qoVTMCTl9v2ZWwJQlr1nmFxzLrspoHm9Nq+LocYo+u2LDRlfHnUT XPCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=uETehSid0KbgkrMqALuI9xpJZ+8tQuqfj+BUwHEHAkU=; b=KLmeNOrPcJNQlR/onHt8680IpMt2fLMQ+Z8YhoX6lnUBKfcjfj2+2/bpy6oFnhhFIe JsWJkiFJfHi05ub8cfFy6Mxa+5bj/lKLrcbb266BODic5/W1jddaAEq2/Oi1Kes7hojb e4TRd37b+YJY1/U9/XuKR9Ie7XoTUcimJ/8OcdRIhnU2jaKy5phRl/+v0srm6Ntx4YcT /+nxZRKUl9pE18WQZl3YaJVA5V3DvxoVCoMwmwLoQmueiwlnOt+dbQCTSeFiQxafZihP oyDjsuxGvLPSzLQrc/0bKpceceg64j/PuhzcT0CAnpqDwsJKUgYSD3JzZ6Yo4jL2Jg/2 8LSA== X-Gm-Message-State: APjAAAXHrL8pzUhTls9faAqCDpoBBF52ndxOj4YVrw9qcNmmYOOaEiHp R4yMZO1umvWnUSQGxdhrD6yhqqhh6q6Hdot0XsyXjA== X-Received: by 2002:a5d:9dd9:: with SMTP id 25mr5741439ioo.287.1575539331814; Thu, 05 Dec 2019 01:48:51 -0800 (PST) MIME-Version: 1.0 References: <20191204155941.17814-1-brgl@bgdev.pl> <20191204155941.17814-2-brgl@bgdev.pl> <20191205094408.GA9303@sol> In-Reply-To: <20191205094408.GA9303@sol> From: Bartosz Golaszewski Date: Thu, 5 Dec 2019 10:48:40 +0100 Message-ID: Subject: Re: [PATCH v2 11/11] tools: gpio: implement gpio-watch To: Kent Gibson Cc: Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org czw., 5 gru 2019 o 10:44 Kent Gibson napisa=C5=82(a)= : > > On Wed, Dec 04, 2019 at 04:59:41PM +0100, Bartosz Golaszewski wrote: > > From: Bartosz Golaszewski > > > > Add a simple program that allows to test the new LINECHANGED_FD ioctl()= . > > > > A minor nit - the ioctl has since been changed to LINEINFO_WATCH. Will fix, thanks. > > Do you have anything else to test the ioctls? > Either way, I'll try to find some time to add some to my gpiod library. > The time I can spend on this is limited, so I decided to go with the kernel API first with a simple user-space test in the kernel source. Once we agree upon it, I'll add support for this to libgpiod. The user-space part would then probably be merged after v5.6-rc1 is tagged and it leaves us 7 weeks to fix any bugs. This is what I plan on doing with your series too. I hope to merge it next week and then we can fix any potential bugs and do a libgpiod release simultaneous with linux v5.5. Bart > Kent. > > > Signed-off-by: Bartosz Golaszewski > > --- > > tools/gpio/.gitignore | 1 + > > tools/gpio/Build | 1 + > > tools/gpio/Makefile | 11 +++- > > tools/gpio/gpio-watch.c | 112 ++++++++++++++++++++++++++++++++++++++++ > > 4 files changed, 124 insertions(+), 1 deletion(-) > > create mode 100644 tools/gpio/gpio-watch.c > > > > diff --git a/tools/gpio/.gitignore b/tools/gpio/.gitignore > > index a94c0e83b209..fffd32969d62 100644 > > --- a/tools/gpio/.gitignore > > +++ b/tools/gpio/.gitignore > > @@ -1,4 +1,5 @@ > > gpio-event-mon > > gpio-hammer > > lsgpio > > +gpio-watch > > include/linux/gpio.h > > diff --git a/tools/gpio/Build b/tools/gpio/Build > > index 4141f35837db..67c7b7f6a717 100644 > > --- a/tools/gpio/Build > > +++ b/tools/gpio/Build > > @@ -2,3 +2,4 @@ gpio-utils-y +=3D gpio-utils.o > > lsgpio-y +=3D lsgpio.o gpio-utils.o > > gpio-hammer-y +=3D gpio-hammer.o gpio-utils.o > > gpio-event-mon-y +=3D gpio-event-mon.o gpio-utils.o > > +gpio-watch-y +=3D gpio-watch.o > > diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile > > index 6080de58861f..842287e42c83 100644 > > --- a/tools/gpio/Makefile > > +++ b/tools/gpio/Makefile > > @@ -18,7 +18,7 @@ MAKEFLAGS +=3D -r > > > > override CFLAGS +=3D -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include > > > > -ALL_TARGETS :=3D lsgpio gpio-hammer gpio-event-mon > > +ALL_TARGETS :=3D lsgpio gpio-hammer gpio-event-mon gpio-watch > > ALL_PROGRAMS :=3D $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) > > > > all: $(ALL_PROGRAMS) > > @@ -66,6 +66,15 @@ $(GPIO_EVENT_MON_IN): prepare FORCE $(OUTPUT)gpio-ut= ils-in.o > > $(OUTPUT)gpio-event-mon: $(GPIO_EVENT_MON_IN) > > $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ > > > > +# > > +# gpio-watch > > +# > > +GPIO_WATCH_IN :=3D $(OUTPUT)gpio-watch-in.o > > +$(GPIO_WATCH_IN): prepare FORCE > > + $(Q)$(MAKE) $(build)=3Dgpio-watch > > +$(OUTPUT)gpio-watch: $(GPIO_WATCH_IN) > > + $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ > > + > > clean: > > rm -f $(ALL_PROGRAMS) > > rm -f $(OUTPUT)include/linux/gpio.h > > diff --git a/tools/gpio/gpio-watch.c b/tools/gpio/gpio-watch.c > > new file mode 100644 > > index 000000000000..69aee43655ae > > --- /dev/null > > +++ b/tools/gpio/gpio-watch.c > > @@ -0,0 +1,112 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > +/* > > + * gpio-watch - monitor unrequested lines for property changes using t= he > > + * character device > > + * > > + * Copyright (C) 2019 BayLibre SAS > > + * Author: Bartosz Golaszewski > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +static bool isnumber(const char *str) > > +{ > > + size_t sz =3D strlen(str); > > + int i; > > + > > + for (i =3D 0; i < sz; i++) { > > + if (!isdigit(str[i])) > > + return false; > > + } > > + > > + return true; > > +} > > + > > +int main(int argc, char **argv) > > +{ > > + struct gpioline_info_changed chg; > > + struct gpioline_info req; > > + struct pollfd pfd; > > + int fd, i, j, ret; > > + char *event; > > + ssize_t rd; > > + > > + if (argc < 3) > > + goto err_usage; > > + > > + fd =3D open(argv[1], O_RDWR | O_CLOEXEC); > > + if (fd < 0) { > > + perror("unable to open gpiochip"); > > + return EXIT_FAILURE; > > + } > > + > > + for (i =3D 0, j =3D 2; i < argc - 2; i++, j++) { > > + if (!isnumber(argv[j])) > > + goto err_usage; > > + > > + memset(&req, 0, sizeof(req)); > > + req.line_offset =3D atoi(argv[j]); > > + > > + ret =3D ioctl(fd, GPIO_GET_LINEINFO_WATCH_IOCTL, &req); > > + if (ret) { > > + perror("unable to set up line watch"); > > + return EXIT_FAILURE; > > + } > > + } > > + > > + pfd.fd =3D fd; > > + pfd.events =3D POLLIN | POLLPRI; > > + > > + for (;;) { > > + ret =3D poll(&pfd, 1, 5000); > > + if (ret < 0) { > > + perror("error polling the linechanged fd"); > > + return EXIT_FAILURE; > > + } else if (ret > 0) { > > + memset(&chg, 0, sizeof(chg)); > > + rd =3D read(pfd.fd, &chg, sizeof(chg)); > > + if (rd < 0 || rd !=3D sizeof(chg)) { > > + if (rd !=3D sizeof(chg)) > > + errno =3D EIO; > > + > > + perror("error reading line change event")= ; > > + return EXIT_FAILURE; > > + } > > + > > + switch (chg.event_type) { > > + case GPIOLINE_CHANGED_REQUESTED: > > + event =3D "requested"; > > + break; > > + case GPIOLINE_CHANGED_RELEASED: > > + event =3D "released"; > > + break; > > + case GPIOLINE_CHANGED_CONFIG: > > + event =3D "config changed"; > > + break; > > + default: > > + fprintf(stderr, > > + "invalid event type received from= the kernel\n"); > > + return EXIT_FAILURE; > > + } > > + > > + printf("line %u: %s at %llu\n", > > + chg.info.line_offset, event, chg.timestamp= ); > > + } > > + } > > + > > + return 0; > > + > > +err_usage: > > + printf("%s: ...\n", argv[0]); > > + return EXIT_FAILURE; > > +} > > -- > > 2.23.0 > >