linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] samples: timers: hpet_example: Improve user experience
@ 2025-08-17 13:23 Akhilesh Patil
  2025-08-17 13:24 ` [PATCH 1/2] samples: timers: hpet_example: Improve argument parsing Akhilesh Patil
  2025-08-17 13:24 ` [PATCH 2/2] samples: Kconfig: Add help for CONFIG_SAMPLE_TIMER Akhilesh Patil
  0 siblings, 2 replies; 3+ messages in thread
From: Akhilesh Patil @ 2025-08-17 13:23 UTC (permalink / raw)
  To: skhan, gregkh, akpm, sj, dakr, mic, masahiroy, corbet, clemens
  Cc: linux-kernel, akhileshpatilvnit

Hi all, 
  This patch series improves user experience for
samples/timers/hpet_example

PATCH 1/2 --> Add support to print help text if user does not provide
required arguments.

PATCH 2/2  --> add help text in timers Kconfig

Testing: 
I have tested the changes on x86 with hpet device as follows. 

1. Build the sample program 
$ gcc hpet_example.c -o hpet_example

2. Run hpet program with no args

$ ./hpet_example
-hpet: requires command
Format: hpet_example <command> </dev/device_name>
Supported commands:
        open-close
        info
        poll
        fasync

Example: $ ./hpet_example info /dev/hpet

3. Run and verify hpet commands on /dev/hpet

$ sudo ./hpet_example info /dev/hpet
-hpet: executing info
hpet_info: hi_irqfreq 0x0 hi_flags 0x10 hi_hpet 0 hi_timer 0


Akhilesh Patil (2):
  samples: timers: hpet_example: Improve argument parsing
  samples: Kconfig: Add help for CONFIG_SAMPLE_TIMER

 samples/Kconfig               |  3 +++
 samples/timers/hpet_example.c | 11 +++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] samples: timers: hpet_example: Improve argument parsing
  2025-08-17 13:23 [PATCH 0/2] samples: timers: hpet_example: Improve user experience Akhilesh Patil
@ 2025-08-17 13:24 ` Akhilesh Patil
  2025-08-17 13:24 ` [PATCH 2/2] samples: Kconfig: Add help for CONFIG_SAMPLE_TIMER Akhilesh Patil
  1 sibling, 0 replies; 3+ messages in thread
From: Akhilesh Patil @ 2025-08-17 13:24 UTC (permalink / raw)
  To: skhan, gregkh, akpm, sj, dakr, mic, masahiroy, corbet, clemens
  Cc: linux-kernel, akhileshpatilvnit

Improve user experience by adding helper text while argument parsing.
Print format of the command line arguments for the program along
with example invocation and supported commands.
Define and use ARRAY_SIZE() macro to iterate over command array to
improve readability of the code.

Print as below upon incorrect invocation:
$ ./hpet_example

-hpet: requires command
Format: hpet_example <command> </dev/device_name>
Supported commands:
        open-close
        info
        poll
        fasync

Example: $ ./hpet_example info /dev/hpet

Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
---
 samples/timers/hpet_example.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/samples/timers/hpet_example.c b/samples/timers/hpet_example.c
index f1cb622f6ec0..59474c7be576 100644
--- a/samples/timers/hpet_example.c
+++ b/samples/timers/hpet_example.c
@@ -25,6 +25,8 @@ extern void hpet_read(int, const char **);
 #include <sys/poll.h>
 #include <sys/ioctl.h>
 
+#define ARRAY_SIZE(x)	(sizeof(x) / sizeof(x[0]))
+
 struct hpet_command {
 	char		*command;
 	void		(*func)(int argc, const char ** argv);
@@ -56,12 +58,17 @@ main(int argc, const char ** argv)
 	argv++;
 
 	if (!argc) {
-		fprintf(stderr, "-hpet: requires command\n");
+		fprintf(stderr, "-hpet: requires command\n"
+			"Format: hpet_example <command> </dev/device_name>\n");
+		fprintf(stderr, "Supported commands:\n");
+		for (i = 0; i < ARRAY_SIZE(hpet_command); i++)
+			fprintf(stderr, "\t%s\n", hpet_command[i].command);
+		fprintf(stderr, "\nExample: $ ./hpet_example info /dev/hpet\n");
 		return -1;
 	}
 
 
-	for (i = 0; i < (sizeof (hpet_command) / sizeof (hpet_command[0])); i++)
+	for (i = 0; i < ARRAY_SIZE(hpet_command); i++)
 		if (!strcmp(argv[0], hpet_command[i].command)) {
 			argc--;
 			argv++;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] samples: Kconfig: Add help for CONFIG_SAMPLE_TIMER
  2025-08-17 13:23 [PATCH 0/2] samples: timers: hpet_example: Improve user experience Akhilesh Patil
  2025-08-17 13:24 ` [PATCH 1/2] samples: timers: hpet_example: Improve argument parsing Akhilesh Patil
@ 2025-08-17 13:24 ` Akhilesh Patil
  1 sibling, 0 replies; 3+ messages in thread
From: Akhilesh Patil @ 2025-08-17 13:24 UTC (permalink / raw)
  To: skhan, gregkh, akpm, sj, dakr, mic, masahiroy, corbet, clemens
  Cc: linux-kernel, akhileshpatilvnit

Add help text in samples Kconfig for CONFIG_SAMPLE_TIMER to help user
selecting this configuration.

Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
---
 samples/Kconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/samples/Kconfig b/samples/Kconfig
index 6e072a5f1ed8..84ce196c2eb8 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -183,6 +183,9 @@ config SAMPLE_SECCOMP
 config SAMPLE_TIMER
 	bool "Timer sample"
 	depends on CC_CAN_LINK && HEADERS_INSTALL
+	help
+	  Build sample programs to demostrate timers.
+	  Currenlty supports High Precision Event Timer (HPET) sample.
 
 config SAMPLE_TSM_MR
 	tristate "TSM measurement sample"
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-17 13:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-17 13:23 [PATCH 0/2] samples: timers: hpet_example: Improve user experience Akhilesh Patil
2025-08-17 13:24 ` [PATCH 1/2] samples: timers: hpet_example: Improve argument parsing Akhilesh Patil
2025-08-17 13:24 ` [PATCH 2/2] samples: Kconfig: Add help for CONFIG_SAMPLE_TIMER Akhilesh Patil

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).