Skip to contentSkip to conversation

Add "enable" and "forced" options to load-config

PATCH In review Ramesh Thomas 2 participants 6 messages Dec 8, 2021 Documentation

lore
Share & tools
lore

Ramesh Thomas

author
#0 lore raw

cover Add "enable" and "forced" options to load-config

Add new convenience options to load-config commmand as follows. -e, enable: Enable configured devices and wqs
-f, forced: Disable devices being configured if enabled

Fix some issues in code that skips configuring device attributes if the device needs to be skipped because it was enabled.

Ramesh Thomas (4):
accel-config: Add "enable" option to load-config command
accel-config: Fix issues in skipping active configurations
accel-config: Add "forced" option to load-config command
accel-config: Update load-config documentation

 .../accfg/accel-config-load-config.txt        |   8 +
 accfg/config.c                                | 155 +++++++++++++-----
 2 files changed, 125 insertions(+), 38 deletions(-)
Signature · 1 line
2.26.3
author
#1 lore raw

PATCH 1/4 accel-config: Add "enable" option to load-config command

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=true

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/config.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
accfg/config.c +77 -0
index b0ab701..91a71e3 100644
@@ -21,8 +21,16 @@
 #include <accfg.h>
 
 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 *engine,
 	return -ENOENT;
 }
 
+/*
+ * Add configured devices and wqs to activation list
+ */
+static int add_to_activation_list(struct list_head *activate_list, void *dev)
+{
+	struct activate_dev *act_dev;
+
+	act_dev = calloc(1, sizeof(struct activate_dev));
+	if (!act_dev) {
+		fprintf(stderr, "Error allocating memory for activation list\n");
+		return -ENOMEM;
+	}
+	act_dev->dev = 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 = 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 = 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 = NULL;
 				engine = NULL;
 				group = NULL;
+
+				if (enable) {
+					rc = add_to_activation_list(&activate_dev_list, dev);
+					if (rc)
+						return rc;
+				}
 				break;
 			}
 			accel_type = accfg_basenames[i];
@@ -500,6 +565,12 @@ static int configure_json_value(struct accfg_ctx *ctx,
 			dev = NULL;
 			engine = NULL;
 			group = NULL;
+
+			if (enable) {
+				rc = add_to_activation_list(&activate_wq_list, wq);
+				if (rc)
+					return rc;
+			}
 		}
 
 		if (strstr(parsed_string, "engine") != 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[] = {
@@ -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 = activate_devices();
+
 	return rc;
 }
Signature · 1 line
2.26.3
author
#2 lore raw

PATCH 2/4 accel-config: Fix issues in skipping active configurations

In reply to Ramesh Thomas

Skipping of active configurations was not being handled correctly. If device is active or encounters an error, all configurations related to that device are skipped. Removed redundant code paths.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/config.c | 60 ++++++++++++++++++++------------------------------
 1 file changed, 24 insertions(+), 36 deletions(-)
accfg/config.c +24 -36
index 91a71e3..9fb8874 100644
@@ -486,8 +486,7 @@ static int configure_json_value(struct accfg_ctx *ctx,
 	char *parsed_string;
 	char dev_type[MAX_DEV_LEN];
 	char *accel_type = NULL;
-	static char *dev_name;
-	static struct accfg_device *dev;
+	static struct accfg_device *dev, *parent;
 	static struct accfg_wq *wq;
 	static struct accfg_engine *engine;
 	static struct accfg_group *group;
@@ -501,6 +500,10 @@ static int configure_json_value(struct accfg_ctx *ctx,
 		parsed_string = (char *)json_object_get_string(jobj);
 		if (!parsed_string)
 			return -EINVAL;
+		dev = NULL;
+		group = NULL;
+		wq = NULL;
+		engine = NULL;
 		for (accel_type = accfg_basenames[0]; accel_type != NULL; i++) {
 			memset(dev_type, 0, MAX_DEV_LEN);
 			if (strstr(parsed_string, accel_type) != NULL) {
@@ -514,6 +517,7 @@ static int configure_json_value(struct accfg_ctx *ctx,
 			}
 
 			if (!strcmp(dev_type, accel_type)) {
+				parent = NULL;
 				dev = accfg_ctx_device_get_by_name(ctx,
 						parsed_string);
 				if (!dev) {
@@ -524,48 +528,43 @@ static int configure_json_value(struct accfg_ctx *ctx,
 				if (dev_state == ACCFG_DEVICE_ENABLED) {
 					fprintf(stderr,
 						"%s is active, will skip...\n", parsed_string);
+					dev = NULL;
 					return 0;
 				}
-				dev_name = parsed_string;
-				wq = NULL;
-				engine = NULL;
-				group = NULL;
 
 				if (enable) {
 					rc = add_to_activation_list(&activate_dev_list, dev);
 					if (rc)
 						return rc;
 				}
+
+				parent = dev;
+
 				break;
 			}
 			accel_type = accfg_basenames[i];
 		}
 
+		/* Skip if device configuration was skipped */
+		if (!parent)
+			return 0;
+
 		if (strstr(parsed_string, "wq") != NULL) {
 			rc = sscanf(&parsed_string[strlen("wq")], "%d.%d",
 					&dev_id, &id);
 			if (rc != 2)
 				return -EINVAL;
 
-			if (dev_name)
-				dev = accfg_ctx_device_get_by_name(ctx, dev_name);
-
-			if (!dev)
-				return -ENOENT;
-
-			wq = accfg_device_wq_get_by_id(dev, id);
+			wq = accfg_device_wq_get_by_id(parent, id);
 			if (!wq)
 				return -ENOENT;
 			wq_state = accfg_wq_get_state(wq);
 			if (wq_state == ACCFG_WQ_ENABLED || wq_state == ACCFG_WQ_LOCKED) {
 				fprintf(stderr, "%s is active, will skip...\n", parsed_string);
+				wq = NULL;
 				return 0;
 			}
 
-			dev = NULL;
-			engine = NULL;
-			group = NULL;
-
 			if (enable) {
 				rc = add_to_activation_list(&activate_wq_list, wq);
 				if (rc)
@@ -579,19 +578,10 @@ static int configure_json_value(struct accfg_ctx *ctx,
 			if (rc != 2)
 				return -EINVAL;
 
-			if (dev_name)
-				dev = accfg_ctx_device_get_by_name(ctx, dev_name);
-
-			if (!dev)
-				return -ENOENT;
-
-			engine = accfg_device_engine_get_by_id(dev, id);
+			engine = accfg_device_engine_get_by_id(parent, id);
 			if (!engine)
 				return -ENOENT;
 
-			dev = NULL;
-			wq = NULL;
-			group = NULL;
 		}
 
 		if (strstr(parsed_string, "group") != NULL) {
@@ -600,20 +590,18 @@ static int configure_json_value(struct accfg_ctx *ctx,
 			if (rc != 2)
 				return -EINVAL;
 
-			if (dev_name)
-				dev = accfg_ctx_device_get_by_name(ctx, dev_name);
-
-			if (!dev)
-				return -ENOENT;
-			group = accfg_device_group_get_by_id(dev, id);
+			group = accfg_device_group_get_by_id(parent, id);
 			if (!group)
 				return -ENOENT;
-			dev = NULL;
-			wq = NULL;
-			engine = NULL;
 		}
+
+		return 0;
 	}
 
+	/* Skip if device configuration was skipped */
+	if (!parent)
+		return 0;
+
 	if (dev && dev_state != ACCFG_DEVICE_ENABLED) {
 		rc = device_json_set_val(dev, jobj, key);
 		if (rc < 0) {
Signature · 1 line
2.26.3
author
#3 lore raw

PATCH 3/4 accel-config: Add "forced" option to load-config command

In reply to Ramesh Thomas

Add forced disabling of devices option as a convenience. Disabling of devices also disables wqs so users can use different configuration files without having to manually disable enabled devices and wqs before reconfiguring. The option is -f, forced=true

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/config.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
accfg/config.c +18 -4
index 9fb8874..e96d3fb 100644
@@ -22,6 +22,7 @@
 
 static bool verbose;
 static bool enable;
+static bool forced;
 static struct util_filter_params util_param;
 
 static LIST_HEAD(activate_dev_list);
@@ -526,10 +527,21 @@ static int configure_json_value(struct accfg_ctx *ctx,
 				}
 				dev_state = accfg_device_get_state(dev);
 				if (dev_state == ACCFG_DEVICE_ENABLED) {
-					fprintf(stderr,
-						"%s is active, will skip...\n", parsed_string);
-					dev = NULL;
-					return 0;
+					fprintf(stderr, "%s is active. ",
+							parsed_string);
+					if (forced) {
+						fprintf(stderr, "Disabling...\n");
+						rc = accfg_device_disable(dev, true);
+						if (rc) {
+							fprintf(stderr,
+								"Failed disabling device\n");
+							return rc;
+						}
+					} else {
+						fprintf(stderr, "Skipping...\n");
+						dev = NULL;
+						return 0;
+					}
 				}
 
 				if (enable) {
@@ -1065,6 +1077,8 @@ int cmd_config(int argc, const char **argv, void *ctx)
 				"emit extra debug messages to stderr"),
 		OPT_BOOLEAN('e', "enable", &enable,
 				"enable configured devices and wqs"),
+		OPT_BOOLEAN('f', "forced", &forced,
+				"enabled devices will be disabled before configuring"),
 		OPT_END(),
 	};
 	const char *const u[] = {
Signature · 1 line
2.26.3
author
#4 lore raw

PATCH 4/4 accel-config: Update load-config documentation

In reply to Ramesh Thomas

Update load-config command documentation with description of "enable" and "forced" features.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 Documentation/accfg/accel-config-load-config.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/accfg/accel-config-load-config.txt +8 -0
index 0a6c711..24549a7 100644
@@ -49,3 +49,11 @@ OPTIONS
 -c::
 --config-file::
 	to specify the location of the customized config file
+
+-e::
+--enable::
+	to enable the configured devices and wqs
+
+-f::
+--forced::
+	to disable enabled devices before configuring
Signature · 1 line
2.26.3
Reviewed-by on the v1 series
#5 lore raw
In reply to Ramesh Thomas
Quoted 13 lines · Ramesh Thomas

Add new convenience options to load-config commmand as follows.

(quoted diff) +0 -2
-e, enable: Enable configured devices and wqs
-f, forced: Disable devices being configured if enabled

Fix some issues in code that skips configuring device attributes if the device needs to be skipped because it was enabled.

Ramesh Thomas (4):
accel-config: Add "enable" option to load-config command
accel-config: Fix issues in skipping active configurations
accel-config: Add "forced" option to load-config command
accel-config: Update load-config documentation

Quoted 3 lines
  .../accfg/accel-config-load-config.txt        |   8 +
  accfg/config.c                                | 155 +++++++++++++-----
  2 files changed, 125 insertions(+), 38 deletions(-)

That was quick. Thanks!

Reviewed-by Dave Jiang <dave.jiang(a)intel.com>

for the series.