* [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
2025-09-11 16:17 ` [PATCH 0/2] samples: timers: hpet_example: Improve user experience Akhilesh Patil
2 siblings, 0 replies; 4+ 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 [flat|nested] 4+ 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
2025-09-11 16:17 ` [PATCH 0/2] samples: timers: hpet_example: Improve user experience Akhilesh Patil
2 siblings, 0 replies; 4+ 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 [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] samples: timers: hpet_example: Improve user experience
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
@ 2025-09-11 16:17 ` Akhilesh Patil
2 siblings, 0 replies; 4+ messages in thread
From: Akhilesh Patil @ 2025-09-11 16:17 UTC (permalink / raw)
To: skhan, gregkh, akpm, sj, dakr, mic, masahiroy, corbet, clemens
Cc: linux-kernel, akhileshpatilvnit
On Sun, Aug 17, 2025 at 06:54:00PM +0530, Akhilesh Patil wrote:
> 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
Hi all, I Would like to follow-up on this patch series for any feedback or
improvements needed.
Regards,
Akhilesh
^ permalink raw reply [flat|nested] 4+ messages in thread