Re: [PATCH 1/4] rtla: Allow unsetting non-list custom-callback CLI options

From: Wander Lairson Costa

Date: Thu Jul 16 2026 - 10:14:33 EST


On Mon, Jun 29, 2026 at 10:36:51AM +0200, Tomas Glozar wrote:
> libsubcmd implicitly allows the user to unset already set options using
> a "no-" prefix for long options. For example, if I set the period like
> this:
>
> $ rtla timerlat -D
> Loading BPF program
> reading osnoise/timerlat_period_us returned 1000
> setting osnoise/timerlat_period_us to 1000
> reading osnoise/print_stack returned 0
> setting osnoise/print_stack to 0
> ...
> <timerlat top>
>
> it can be unset by a subsequent --no-debug:
>
> $ rtla timerlat -D --no-debug
> ...
> <timerlat top>
>
> Currently, this works only for boolean options. Extend the feature for
> all options by implementing handling of the "unset" argument in opt_*()
> callbacks defined in cli_p.h, except for list options, i.e. options that
> can be passed multiple times (--event, --filter, --trigger,
> --on-threshold, --on-end).
>
> This allows, for example, unsetting of int/long long options, e.g. "-p":
>
> $ rtla timerlat -D -p100 --no-period
> ...
> setting osnoise/timerlat_period_us to 1000
> ...
>
> By default, options in params struct are reset to zero. A constant is
> added for every parameter with a different default value, which is then
> used both in <tool>_hist_args() while setting the initial value and in
> opt_*() when unsetting the option. This refactoring ensures there is no
> duplicate "magic number".
>
> The default value for opt_llong_callback() and opt_int_callback() is
> passed in struct option's defval field; new macros
> RTLA_OPT_{LLONG,INT}{,_DEFVAL} are added to define the field
> conveniently. The default value for other callbacks is hardcoded inside
> each callback's unset logic.
>
> Signed-off-by: Tomas Glozar <tglozar@xxxxxxxxxx>

Reviewed-by: Wander Lairson Costa <wander@xxxxxxxxxx>