From b3ced6f83add63cf5d55e50ba887bcd6f6119913 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 19 May 2023 12:57:03 +0100 Subject: [PATCH 1/2] lisa._kmod: Add per-feature parameter support to LISADynamicKmod FEATURE Allow per-feature parameters to be passed to LISADynamicKmod.install() and run(). Instead of passing a list of features, a mapping of features names to feature parameter dict is given. --- lisa/_cli_tools/lisa_load_kmod.py | 9 +++++---- lisa/_kmod.py | 22 ++++++++++++++++++++++ lisa/trace.py | 5 +++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lisa/_cli_tools/lisa_load_kmod.py b/lisa/_cli_tools/lisa_load_kmod.py index db914aa19..23859a3c6 100755 --- a/lisa/_cli_tools/lisa_load_kmod.py +++ b/lisa/_cli_tools/lisa_load_kmod.py @@ -55,15 +55,16 @@ def _main(args, target): if cmd and cmd[0] == '--': cmd = cmd[1:] - kmod_params = {} - if features is not None: - kmod_params['features'] = list(features) + features = { + name: {} + for feature in features + } kmod = target.get_kmod(LISADynamicKmod) pretty_events = ', '.join(kmod.defined_events) logging.info(f'Kernel module provides the following ftrace events: {pretty_events}') - _kmod_cm = kmod.run(kmod_params=kmod_params) + _kmod_cm = kmod.run(features=features) if keep_loaded: @contextlib.contextmanager diff --git a/lisa/_kmod.py b/lisa/_kmod.py index 9f320d4fd..50245cea9 100644 --- a/lisa/_kmod.py +++ b/lisa/_kmod.py @@ -2800,4 +2800,26 @@ class LISADynamicKmod(FtraceDynamicKmod): return ret + + def install(self, features=None, **kwargs): + """ + Install and load the module on the target. + + :param features: Features to enable and associated parameters. + Top-level in the dict is feature names, nested dict is for parameters. + :type features: dict(str, dict(str, object)) or None + """ + features = features or {} + params = dict( + features=sorted(features.keys()), + **{ + f'{feature}___{name}': value + for feature, params in features.items() + for name, value in (params or {}).items() + } + ) + + return super().install(kmod_params=params, **kwargs) + + # vim :set tabstop=4 shiftwidth=4 expandtab textwidth=80 diff --git a/lisa/trace.py b/lisa/trace.py index 8d3f6610f..285c80f3b 100644 --- a/lisa/trace.py +++ b/lisa/trace.py @@ -6110,8 +6110,9 @@ class FtraceCollector(CollectorBase, Configurable): needed, functools.partial( kmod.run, - kmod_params={ - 'features': sorted(kmod._event_features(needed)) + features={ + feature: {} + for feature in sorted(kmod._event_features(needed)) } ) ) -- GitLab From ece0c39d458fbc8ccd8b12633c8a1cc265bf9267 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 19 May 2023 13:04:59 +0100 Subject: [PATCH 2/2] tools/lisa-load-kmod: Add --feature-param option FEATURE Allow passing per-feature parameter using: --feature-param The option can be repeated to pass multiple parameters. --- lisa/_cli_tools/lisa_load_kmod.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lisa/_cli_tools/lisa_load_kmod.py b/lisa/_cli_tools/lisa_load_kmod.py index 23859a3c6..98cb01e5f 100755 --- a/lisa/_cli_tools/lisa_load_kmod.py +++ b/lisa/_cli_tools/lisa_load_kmod.py @@ -20,6 +20,12 @@ def main(): action='append', help='Enable a specific module feature. Can be repeated. By default, the module will try to enable all features and will log in dmesg the ones that failed to enable' ), + 'feature-param': dict( + action='append', + metavar=('FEATURE_NAME', 'PARAM_NAME', 'PARAM_VALUE'), + nargs=3, + help='Set a feature parameter value.' + ), 'cmd': dict( nargs=argparse.REMAINDER, help='Load the module, run the given command then unload the module. If not command is provided, just load the module and exit.' @@ -47,8 +53,8 @@ def main(): def _main(args, target): - - features = args.feature + features = args.feature or [] + features_params = args.feature_param or {} keep_loaded = not bool(args.cmd) cmd = args.cmd or [] @@ -56,9 +62,11 @@ def _main(args, target): cmd = cmd[1:] features = { - name: {} + feature: {} for feature in features } + for feature, param_name, param_value in features_params: + features.setdefault(feature, {})[param_name] = param_value kmod = target.get_kmod(LISADynamicKmod) pretty_events = ', '.join(kmod.defined_events) -- GitLab