From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============1310240133505693406==" MIME-Version: 1.0 From: Ramesh Thomas Subject: [Accel-config] [PATCH 1/4] accel-config: Add "enable" option to load-config command Date: Tue, 07 Dec 2021 19:51:49 -0500 Message-ID: <20211208005152.220518-2-ramesh.thomas@intel.com> In-Reply-To: 20211208005152.220518-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============1310240133505693406== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Add an option to enable devices and wqs while configuring devices using the load-config command. This is a convenience feature so user does not need to manually enable the newly configured devices and wqs. The option is -e, enable=3Dtrue Signed-off-by: Ramesh Thomas --- accfg/config.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/accfg/config.c b/accfg/config.c index b0ab701..91a71e3 100644 --- a/accfg/config.c +++ b/accfg/config.c @@ -21,8 +21,16 @@ #include = static bool verbose; +static bool enable; static struct util_filter_params util_param; = +static LIST_HEAD(activate_dev_list); +static LIST_HEAD(activate_wq_list); +struct activate_dev { + void *dev; + struct list_node list; +}; + static struct config { bool devices; bool groups; @@ -417,6 +425,57 @@ static int engine_json_set_val(struct accfg_engine *en= gine, return -ENOENT; } = +/* + * Add configured devices and wqs to activation list + */ +static int add_to_activation_list(struct list_head *activate_list, void *d= ev) +{ + struct activate_dev *act_dev; + + act_dev =3D calloc(1, sizeof(struct activate_dev)); + if (!act_dev) { + fprintf(stderr, "Error allocating memory for activation list\n"); + return -ENOMEM; + } + act_dev->dev =3D dev; + list_add(activate_list, &act_dev->list); + + return 0; +} + +/* + * Enable devices in activation list + */ +static int activate_devices(void) +{ + struct activate_dev *iter, *next; + int rc; + + list_for_each_safe(&activate_dev_list, iter, next, list) { + printf("Enabling device %s\n", + accfg_device_get_devname(iter->dev)); + rc =3D accfg_device_enable(iter->dev); + if (rc) { + fprintf(stderr, "Error enabling device\n"); + return rc; + } + + free(iter); + } + + list_for_each_safe(&activate_wq_list, iter, next, list) { + printf("Enabling wq %s\n", accfg_wq_get_devname(iter->dev)); + rc =3D accfg_wq_enable(iter->dev); + if (rc) { + fprintf(stderr, "Error enabling wq\n"); + return rc; + } + free(iter); + } + + return 0; +} + /* * Configuring the value corresponding to integer and strings */ @@ -471,6 +530,12 @@ static int configure_json_value(struct accfg_ctx *ctx, wq =3D NULL; engine =3D NULL; group =3D NULL; + + if (enable) { + rc =3D add_to_activation_list(&activate_dev_list, dev); + if (rc) + return rc; + } break; } accel_type =3D accfg_basenames[i]; @@ -500,6 +565,12 @@ static int configure_json_value(struct accfg_ctx *ctx, dev =3D NULL; engine =3D NULL; group =3D NULL; + + if (enable) { + rc =3D add_to_activation_list(&activate_wq_list, wq); + if (rc) + return rc; + } } = if (strstr(parsed_string, "engine") !=3D NULL) { @@ -1004,6 +1075,8 @@ int cmd_config(int argc, const char **argv, void *ctx) "override the default config"), OPT_BOOLEAN('v', "verbose", &verbose, "emit extra debug messages to stderr"), + OPT_BOOLEAN('e', "enable", &enable, + "enable configured devices and wqs"), OPT_END(), }; const char *const u[] =3D { @@ -1049,5 +1122,9 @@ int cmd_config(int argc, const char **argv, void *ctx) fprintf(stderr, "Parse json and set device fail: %d\n", rc); = free_containers(&cfa); + + if (enable && !rc) + rc =3D activate_devices(); + return rc; } -- = 2.26.3 --===============1310240133505693406==--