mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-10-26 10:57:38 +08:00
Each osnoise tracer option (in /sys/kernel/tracing/osnoise) used by RTLA requires four functions to be defined: - static osnoise_get_<opt>() - to get the current value of the option and save it into struct osnoise_context's orig_<opt> field, - osnoise_set_<opt>() - to set the value of the option requested by the user after reading and saving the original with osnoise_get_<opt>(), and save it into <opt> field of struct osnoise_context, - osnoise_restore_<opt>() - restore the value recorded in orig_<opt>, - static osnoise_put_<opt>() - restore the value recorded in orig_<opt> and update <opt> to reflect that. The logic is duplicated for all the options, except for cpus (which is the only string option) and period/runtime (which are handled together and feature extra checks). Deduplicate by moving the common code in get/set/restore/put into common helper functions local to osnoise.c. The original set/restore/put functions are reduced to wrappers generated using a set of X macros: - OSNOISE_LL_OPTIONS, which invokes the OSNOISE_LL_OPTION macro for all "long long" options, - OSNOISE_FLAG_OPTIONS, which invokes the OSNOISE_FLAG_OPTION macro for all flag options (boolean values in osnoise/options file). Those are also used to auto-generate the corresponding fields in struct osnoise_context, plus initialization and restoration code for them. There are a few minor changes in the refactored code: - osnoise_set_<opt>() now distinguishes between -2 (option cannot be set) and -1 (option not present in kernel) for all options. - OSNOISE_OPTION_INIT_VAL and OSNOISE_TIME_INIT_VAL are removed and replaced with a plain -1; all unsigned long long fields are changed to signed long long, consistent with pre-existing "%lld" format string in osnoise_write_ll_config(). - osnoise_restore_<opt>() now correctly resets the <opt> field (not orig_<opt>) for all options. The change is intended to simplify adding and modifying tracer options. It also makes the code shorter by a bit over 500 lines. Assisted-by: Claude:claude-opus-4-6 Link: https://lore.kernel.org/r/20260929142944.1841462-1-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>