Skip to contentSkip to conversation

tools: counter: add counter_watch_events

PATCH Applied Fabrice Gasnier 2 participants 4 messages Dec 13, 2023 – Dec 18, 2023

Subsystems (3)
lore
Share & tools
lore

Fabrice Gasnier

author maintainer
#0 lore raw

v4 cover tools: counter: add counter_watch_events

Introduces a new tool that can be used for testing. Also add MAINTAINERS entry as per William's recommendations.

Changelog:
Changes in V4:
- Specify linux-iio mailing list in MAINTAINERS
- Revisit error path and handling in counter_watch_events

Series split, e.g. V3:
- This is a split of another series [1].
[1] https://lore.kernel.org/lkml/[email protected]/

Fabrice Gasnier (2):
tools/counter: add a flexible watch events tool
MAINTAINERS: add myself as counter watch events tool maintainer

 MAINTAINERS                          |   6 +
 tools/counter/Build                  |   1 +
 tools/counter/Makefile               |  12 +-
 tools/counter/counter_watch_events.c | 406 +++++++++++++++++++++++++++
 4 files changed, 423 insertions(+), 2 deletions(-)
 create mode 100644 tools/counter/counter_watch_events.c
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v4 1/2 tools/counter: add a flexible watch events tool

This adds a new counter tool to be able to test various watch events. A flexible watch array can be populated from command line, each field may be tuned with a dedicated command line sub-option in "--watch" string. Several watch events can be defined, each can have specific watch options, by using "--watch <watch 1 options> --watch <watch 2 options>". Watch options is a comma separated list.

It also comes with a simple default watch (to monitor overflow/underflow events), used when no watch parameters are provided. It's equivalent to:
counter_watch_events -w comp_count,scope_count,evt_ovf_udf

The print_usage() routine proposes another example, from the command line, which generates a 2 elements watch array, to monitor:
- overflow underflow events
- capture events, on channel 3, that reads read captured data by specifying the component id (capture3_component_id being 7 here).

---
Changes in v4:
- Fix: free the allocated memory and close the char device also upon errors. Add some labels, to unwind in a first-in-last-out order.
- Revisit some error codes and add or improve few error messages.
- Added copyright and author

Changes in v3:
- Free the allocated memory, also close the char device
- Split of another patch series[1].
[1] https://lore.kernel.org/lkml/[email protected]/

Changes in v2:
Review comments from William:
- revisit watch options to be less error prone: add --watch with sub-options to properly define each watch one by one, as a comma separated list
- by the way, drop string/array parsing routines, replaced by getsubopt()
- Improve command-line interface descriptions, e.g. like "-h, --help"
- Makefile: adopt ARRAY_SIZE from tools/include/linux.kernel.h (via CFLAG)
- remove reference to counter_example
- clarify commit message, code comment: Index/overflow/underflow event
- check calloc return value
- Makefile: sort count_watch_events in alphabetic order
- Makefile: add a clean rule to delete .*.o.cmd files

---
 tools/counter/Build                  |   1 +
 tools/counter/Makefile               |  12 +-
 tools/counter/counter_watch_events.c | 406 +++++++++++++++++++++++++++
 3 files changed, 417 insertions(+), 2 deletions(-)
 create mode 100644 tools/counter/counter_watch_events.c
tools/counter/Build +1 -0
index 33f4a51d715e..4bbadb7ec93a 100644
@@ -1 +1,2 @@
 counter_example-y += counter_example.o
+counter_watch_events-y += counter_watch_events.o
tools/counter/Makefile +10 -2
index b2c2946f44c9..d82d35a520f6 100644
@@ -12,9 +12,10 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
-override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
+override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include \
+	 -I$(srctree)/tools/include
 
-ALL_TARGETS := counter_example
+ALL_TARGETS := counter_example counter_watch_events
 ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
 
 all: $(ALL_PROGRAMS)
@@ -37,12 +38,19 @@ $(COUNTER_EXAMPLE): prepare FORCE
 $(OUTPUT)counter_example: $(COUNTER_EXAMPLE)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
 
+COUNTER_WATCH_EVENTS := $(OUTPUT)counter_watch_events.o
+$(COUNTER_WATCH_EVENTS): prepare FORCE
+	$(Q)$(MAKE) $(build)=counter_watch_events
+$(OUTPUT)counter_watch_events: $(COUNTER_WATCH_EVENTS)
+	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
+
 clean:
 	rm -f $(ALL_PROGRAMS)
 	rm -rf $(OUTPUT)include/linux/counter.h
 	rm -df $(OUTPUT)include/linux
 	rm -df $(OUTPUT)include
 	find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
+	find $(or $(OUTPUT),.) -name '\.*.o.cmd' -delete
 
 install: $(ALL_PROGRAMS)
 	install -d -m 755 $(DESTDIR)$(bindir);		\
tools/counter/counter_watch_events.c new file +406 -0

406 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH v4 2/2 MAINTAINERS: add myself as counter watch events tool maintainer

In reply to Fabrice Gasnier

Add MAINTAINERS entry for the counter watch events tool. William has been asking to add at least me as the point of contact for this utility.

---
Changes in v4: Explicitly add 'L' line to specify linux-iio mailing list

Changes in v3: Add MAINTAINERS entry. This is a split of another patch series[1].
[1] https://lore.kernel.org/lkml/[email protected]/

---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index dd5de540ec0b..e561d0b086ef 100644
@@ -5322,6 +5322,12 @@ F:	include/linux/counter.h
 F:	include/uapi/linux/counter.h
 F:	tools/counter/
 
+COUNTER WATCH EVENTS TOOL
+M:	Fabrice Gasnier <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	tools/counter/counter_watch_events.c
+
 CP2615 I2C DRIVER
 M:	Bence Csókás <[email protected]>
 S:	Maintained
Signature · 1 line
2.25.1
#3 lore raw
In reply to Fabrice Gasnier
Quoted 9 lines · Fabrice Gasnier

Introduces a new tool that can be used for testing. Also add MAINTAINERS entry as per William's recommendations.

Changelog:
Changes in V4:
- Specify linux-iio mailing list in MAINTAINERS
- Revisit error path and handling in counter_watch_events

[...]

Applied, thanks!

[1/2] tools/counter: add a flexible watch events tool

      commit: 1e73427f66353b7fe21c138787ff2b711ca1c0dd
[2/2] MAINTAINERS: add myself as counter watch events tool maintainer
      commit: 8e21e4693d8502ee31ef7984e16c3d9cab6c926a

Best regards,

Signature · 1 line
William Breathitt Gray <[email protected]>