diff mbox series

[RFC,v1,13/20] tools: gpio: Add event count capability to event monitor application

Message ID 20210824164801.28896-14-lakshmi.sowjanya.d@intel.com
State New
Headers show
Series Review Request: Add support for Intel PMC | expand

Commit Message

D, Lakshmi Sowjanya Aug. 24, 2021, 4:47 p.m. UTC
From: Lakshmi Sowjanya D <lakshmi.sowjanya.d@intel.com>

Add -t command line flag requesting event count to the gpio-event-mon
application. If event count is unsupported an invalid argument error is
returned by GPIOlib and the application exits with an error. The event
count is printed with the event type and timestamp.

Co-developed-by: Christopher Hall <christopher.s.hall@intel.com>
Signed-off-by: Christopher Hall <christopher.s.hall@intel.com>
Signed-off-by: Tamal Saha <tamal.saha@intel.com>
Signed-off-by: Lakshmi Sowjanya D <lakshmi.sowjanya.d@intel.com>
Reviewed-by: Mark Gross <mgross@linux.intel.com>
---
 tools/gpio/gpio-event-mon.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Comments

Linus Walleij Sept. 16, 2021, 9:57 p.m. UTC | #1
On Tue, Aug 24, 2021 at 6:48 PM <lakshmi.sowjanya.d@intel.com> wrote:

> From: Lakshmi Sowjanya D <lakshmi.sowjanya.d@intel.com>

>

> Add -t command line flag requesting event count to the gpio-event-mon

> application. If event count is unsupported an invalid argument error is

> returned by GPIOlib and the application exits with an error. The event

> count is printed with the event type and timestamp.

>

> Co-developed-by: Christopher Hall <christopher.s.hall@intel.com>

> Signed-off-by: Christopher Hall <christopher.s.hall@intel.com>

> Signed-off-by: Tamal Saha <tamal.saha@intel.com>

> Signed-off-by: Lakshmi Sowjanya D <lakshmi.sowjanya.d@intel.com>

> Reviewed-by: Mark Gross <mgross@linux.intel.com>


This looks wrong.

If this hardware can report timestamped events, which I believe
it does, each event should be reported to userspace uniquely,
ideally using the native timestamp, and using the in-progress HTE
subsystem.

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/tools/gpio/gpio-event-mon.c b/tools/gpio/gpio-event-mon.c
index d8f0bbf78728..4bdd6b3d6ad8 100644
--- a/tools/gpio/gpio-event-mon.c
+++ b/tools/gpio/gpio-event-mon.c
@@ -33,6 +33,9 @@  int monitor_device(const char *device_name,
 		   int verbosity)
 {
 	struct gpio_v2_line_values values;
+	struct gpio_v2_line_event *event;
+	bool req_event_count;
+	size_t event_size;
 	char *chrdev_name;
 	int cfd, lfd;
 	int ret;
@@ -55,6 +58,10 @@  int monitor_device(const char *device_name,
 		goto exit_device_close;
 	else
 		lfd = ret;
+	req_event_count = config->flags & GPIO_V2_LINE_FLAG_EVENT_COUNT;
+	event_size = sizeof(*event);
+	event_size += req_event_count ? sizeof(event->ext[0]) : 0;
+	event = alloca(event_size);
 
 	/* Read initial states */
 	values.mask = 0;
@@ -111,7 +118,7 @@  int monitor_device(const char *device_name,
 			}
 		}
 
-		if (ret != sizeof(event)) {
+		if (ret != event_size) {
 			fprintf(stderr, "Reading event failed\n");
 			ret = -EIO;
 			break;
@@ -133,6 +140,9 @@  int monitor_device(const char *device_name,
 			fprintf(stdout, "unknown event spec: %x", event.id);
 		}
 		fprintf(stdout, "\n");
+		if (req_event_count)
+			fprintf(stdout, "Event count: %u\n",
+				event.ext[0].event_count);
 
 		i++;
 		if (i == loops)
@@ -163,6 +173,7 @@  void print_usage(void)
 		"  -w         Report the wall-clock time for events\n"
 		"  -b <n>     Debounce the line with period n microseconds\n"
 		"  -v	      Verbosity\n"
+		"  -t         Request event count\n"
 		" [-c <n>]    Do <n> loops (optional, infinite loop if not stated)\n"
 		"  -?         This helptext\n"
 		"\n"
@@ -188,7 +199,7 @@  int main(int argc, char **argv)
 
 	memset(&config, 0, sizeof(config));
 	config.flags = GPIO_V2_LINE_FLAG_INPUT;
-	while ((c = getopt(argc, argv, "c:n:o:b:dsrfwv?")) != -1) {
+	while ((c = getopt(argc, argv, "c:n:o:b:dsrfwvt?")) != -1) {
 		switch (c) {
 		case 'c':
 			loops = strtoul(optarg, NULL, 10);
@@ -225,6 +236,9 @@  int main(int argc, char **argv)
 		case 'v':
 			++verbosity;
 			break;
+		case 't':
+			config.flags |= GPIO_V2_LINE_FLAG_EVENT_COUNT;
+			break;
 		case '?':
 			print_usage();
 			return -1;