| Message ID | 20251210005354.44726-22-bryan.odonoghue@linaro.org |
|---|---|
| State | Superseded |
| Headers | show |
| Series |
|
| Related | show |
Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes: > Create an algorithm without having YAML data input. > > Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> > --- > src/ipa/libipa/module.h | 45 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 45 insertions(+) > > diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h > index c27af7718..c5767c6f3 100644 > --- a/src/ipa/libipa/module.h > +++ b/src/ipa/libipa/module.h > @@ -70,6 +70,51 @@ public: > factories().push_back(factory); > } > > + /** > + * \fn int Module::createSelfEnumeratingAlgorithm(Context &context, const std::string &name) > + * \brief Create and initialise a self-enumerating algorithm by name > + * > + * This function creates an algorithm instance from the registered algorithm > + * factories using only the algorithm name, without requiring YAML configuration > + * data. > + * > + * This is useful for algorithms that don't require external configuration > + * parameters and can self-configure or use default values. > + * > + * \param[in] context The IPA context to pass to the algorithm's init function > + * \param[in] name The name of the algorithm to instantiate > + * > + * \return 0 on success, negative errno value on failure: > + * -EINVAL if the algorithm is not found in the factory registry > + * Other negative values if algorithm initialisation fails > + */ The docstring should go to the .cpp file. > + int createSelfEnumeratingAlgorithm(Context &context, const std::string &name) > + { > + YamlObject dummy; > + > + std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name); > + if (!algo) { > + LOG(IPAModuleAlgo, Error) > + << "Algorithm '" << name << "' not found"; > + return -EINVAL; > + } > + > + context.selfInitialising = true; > + > + int ret = algo->init(context, dummy); > + if (ret) { > + LOG(IPAModuleAlgo, Error) > + << "Algorithm '" << name << "' failed to initialize"; > + return ret; > + } > + > + LOG(IPAModuleAlgo, Debug) > + << "Instantiated algorithm '" << name << "'"; > + > + algorithms_.push_back(std::move(algo)); > + return 0; > + } Hmm, this code duplication doesn't feel good. For example, it already omits the change that allows disabling algorithms in the tuning file; or is it on purpose? I should look into my simple algorithms refactoring and think more whether there is a chance to find a better mechanism. > private: > int createAlgorithm(Context &context, const YamlObject &data) > {
diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h index c27af7718..c5767c6f3 100644 --- a/src/ipa/libipa/module.h +++ b/src/ipa/libipa/module.h @@ -70,6 +70,51 @@ public: factories().push_back(factory); } + /** + * \fn int Module::createSelfEnumeratingAlgorithm(Context &context, const std::string &name) + * \brief Create and initialise a self-enumerating algorithm by name + * + * This function creates an algorithm instance from the registered algorithm + * factories using only the algorithm name, without requiring YAML configuration + * data. + * + * This is useful for algorithms that don't require external configuration + * parameters and can self-configure or use default values. + * + * \param[in] context The IPA context to pass to the algorithm's init function + * \param[in] name The name of the algorithm to instantiate + * + * \return 0 on success, negative errno value on failure: + * -EINVAL if the algorithm is not found in the factory registry + * Other negative values if algorithm initialisation fails + */ + int createSelfEnumeratingAlgorithm(Context &context, const std::string &name) + { + YamlObject dummy; + + std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name); + if (!algo) { + LOG(IPAModuleAlgo, Error) + << "Algorithm '" << name << "' not found"; + return -EINVAL; + } + + context.selfInitialising = true; + + int ret = algo->init(context, dummy); + if (ret) { + LOG(IPAModuleAlgo, Error) + << "Algorithm '" << name << "' failed to initialize"; + return ret; + } + + LOG(IPAModuleAlgo, Debug) + << "Instantiated algorithm '" << name << "'"; + + algorithms_.push_back(std::move(algo)); + return 0; + } + private: int createAlgorithm(Context &context, const YamlObject &data) {
Create an algorithm without having YAML data input. Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> --- src/ipa/libipa/module.h | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)