Skip to contentSkip to conversation

Add support to get enhanced details of error

PATCH In review ramesh.thomas at intel.com 2 participants 5 messages Jul 15, 2021

lore
Share & tools
lore

ramesh.thomas at intel.com

#0 lore raw

v4 cover Add support to get enhanced details of error

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Add support to take a snapshot of error details containing hw/sw error code and associated devices. Added new API to retreive the saved information. Using the new API accel-config prints a more detailed error message at exit.

v2:
Use masks and other constants defined in idxd.h
Clear cmd_status during device initialization

v3:
Specify if the error is from driver or library

v4:
Specify if the error is platform configuration error Don't fail if clearing cmd_status is RO to support older drivers

Ramesh Thomas (3):
accel-config: Add APIs to get details of last error and associated
devices
accel-config: Print details of error at exit using new last_error API
accel-config: Reset cmd_status during device init

 accfg/accel-config.c          |  25 ++++-
 accfg/enable.c                |  25 +----
 accfg/lib/libaccel-config.sym |   6 ++
 accfg/lib/libaccfg.c          | 187 ++++++++++++++++++++++++++++++----
 accfg/lib/private.h           |   9 ++
 accfg/libaccel_config.h       |   9 +-
 6 files changed, 219 insertions(+), 42 deletions(-)
Signature · 1 line
2.26.3
#1 lore raw

PATCH v4 1/3 accel-config: Add APIs to get details of last error and associated devices

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Capture a snapshot of error condition containing cmd_status and the associated devices. Provide APIs to return the captured details. Handles both hw and sw error codes stored in sysfs cmd_status field of devices. Following APIs are added:
- accfg_ctx_get_last_error;
- accfg_ctx_get_last_error_str;
- accfg_ctx_get_last_error_device;
- accfg_ctx_get_last_error_wq;
- accfg_ctx_get_last_error_group;
- accfg_ctx_get_last_error_engine;

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccel-config.sym |   6 ++
 accfg/lib/libaccfg.c          | 162 ++++++++++++++++++++++++++++++----
 accfg/lib/private.h           |   9 ++
 accfg/libaccel_config.h       |   9 +-
 4 files changed, 166 insertions(+), 20 deletions(-)
accfg/lib/libaccel-config.sym +6 -0
index e9b54e2..f44a3ca 100644
@@ -154,4 +154,10 @@ LIBACCFG_10 {
 global:
 	accfg_wq_get_ats_disable;
 	accfg_wq_set_ats_disable;
+	accfg_ctx_get_last_error;
+	accfg_ctx_get_last_error_str;
+	accfg_ctx_get_last_error_device;
+	accfg_ctx_get_last_error_wq;
+	accfg_ctx_get_last_error_group;
+	accfg_ctx_get_last_error_engine;
 } LIBACCFG_9;
accfg/lib/libaccfg.c +144 -18

329 lines not on this page · raw message

accfg/lib/private.h +9 -0
index b28fd40..57aa1ed 100644
@@ -131,6 +131,14 @@ struct accfg_wq {
 
 #define ACCFG_EXPORT __attribute__ ((visibility("default")))
 
+struct accfg_error_ctx {
+	unsigned int cmd_status;
+	struct accfg_device *device;
+	struct accfg_group *group;
+	struct accfg_wq *wq;
+	struct accfg_engine *engine;
+};
+
 /**
  * struct accfg_ctx - library user context to find device instances
  *
@@ -149,6 +157,7 @@ struct accfg_ctx {
 	uint64_t timeout;
 	void *private_data;
 	bool compat;
+	struct accfg_error_ctx *error_ctx;
 };
 
 static inline int check_udev(struct udev *udev)
accfg/libaccel_config.h +7 -2
index c0b1f16..f8b9bf9 100644
@@ -194,9 +194,14 @@ unsigned int accfg_device_get_version(struct accfg_device *device);
 int accfg_device_get_clients(struct accfg_device *device);
 int accfg_device_set_token_limit(struct accfg_device *dev, int val);
 int accfg_device_is_active(struct accfg_device *device);
-int accfg_device_get_cmd_status(struct accfg_device *device);
+unsigned int accfg_device_get_cmd_status(struct accfg_device *device);
 const char *accfg_device_get_cmd_status_str(struct accfg_device *device);
-
+unsigned int accfg_ctx_get_last_error(struct accfg_ctx *ctx);
+const char *accfg_ctx_get_last_error_str(struct accfg_ctx *ctx);
+struct accfg_device *accfg_ctx_get_last_error_device(struct accfg_ctx *ctx);
+struct accfg_wq *accfg_ctx_get_last_error_wq(struct accfg_ctx *ctx);
+struct accfg_group *accfg_ctx_get_last_error_group(struct accfg_ctx *ctx);
+struct accfg_engine *accfg_ctx_get_last_error_engine(struct accfg_ctx *ctx);
 struct accfg_device_mdev;
 struct accfg_device_mdev *accfg_device_first_mdev(struct accfg_device *device);
 struct accfg_device_mdev *accfg_device_next_mdev(struct accfg_device_mdev *mdev);
Signature · 1 line
2.26.3
#2 lore raw

PATCH v4 2/3 accel-config: Print details of error at exit using new last_error API

In reply to ramesh.thomas at intel.com

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

On error exit, if cmd_status was set get the details of the error using new last_error APIs and print. Do this at a common place at exit and remove from other places to avoid duplication.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/accel-config.c | 25 ++++++++++++++++++++++++-
 accfg/enable.c       | 25 ++++---------------------
 2 files changed, 28 insertions(+), 22 deletions(-)
accfg/accel-config.c +24 -1
index d373f88..0840e0b 100644
@@ -103,6 +103,7 @@ int main(int argc, const char **argv)
 	struct accfg_ctx *ctx;
 	struct kmod_ctx *kmod_ctx;
 	struct kmod_module *mod;
+	unsigned int last_error;
 	int rc;
 
 	/* Look for flags.. */
@@ -136,6 +137,29 @@ int main(int argc, const char **argv)
 
 	rc = main_handle_internal_command(argc, argv, ctx, commands,
 				     ARRAY_SIZE(commands));
+
+	last_error = accfg_ctx_get_last_error(ctx);
+	if (rc && last_error) {
+		struct accfg_device *d;
+		struct accfg_group *g;
+		struct accfg_wq *w;
+		struct accfg_engine *e;
+
+		printf("Error[%#10x] ", last_error);
+		d = accfg_ctx_get_last_error_device(ctx);
+		g = accfg_ctx_get_last_error_group(ctx);
+		w = accfg_ctx_get_last_error_wq(ctx);
+		e = accfg_ctx_get_last_error_engine(ctx);
+		if (d)
+			printf("%s", accfg_device_get_devname(d));
+		if (g)
+			printf("/%s", accfg_group_get_devname(g));
+		if (w)
+			printf("/%s", accfg_wq_get_devname(w));
+		if (e)
+			printf("/%s", accfg_engine_get_devname(e));
+		printf(": %s\n", accfg_ctx_get_last_error_str(ctx));
+	}
 	accfg_unref(ctx);
 	kmod_module_unref(mod);
 	kmod_unref(kmod_ctx);
@@ -144,7 +168,6 @@ int main(int argc, const char **argv)
 		return EXIT_SUCCESS;
 error_exit:
 	errno = abs(rc);
-	perror("Error");
 
 	return EXIT_FAILURE;
 }
accfg/enable.c +4 -21
index 90d899c..973f0b8 100644
@@ -81,17 +81,6 @@ static int dev_action_switch(struct accfg_device *device,
 	}
 }
 
-static void print_device_cmd_status(struct accfg_device *device)
-{
-	const char *status;
-
-	if (accfg_device_get_cmd_status(device) > 0) {
-		status = accfg_device_get_cmd_status_str(device);
-		if (status)
-			fprintf(stderr, "device command status: %s\n", status);
-	}
-}
-
 static int device_action(int argc, const char **argv, const char *usage,
 			 const struct option *options, enum dev_action action,
 			 struct accfg_ctx *ctx)
@@ -143,13 +132,10 @@ static int device_action(int argc, const char **argv, const char *usage,
 					(action == DEV_ACTION_DISABLE)))
 				rc = ENXIO;
 		}
-		if (rc == 0) {
+		if (rc == 0)
 			success++;
-		} else {
+		else
 			fprintf(stderr, "failed in %s\n", argv[i]);
-
-			print_device_cmd_status(device);
-		}
 	}
 
 	fprintf(stderr, "%s %d device(s) out of %d\n",
@@ -249,13 +235,10 @@ static int wq_action(int argc, const char **argv, const char *usage,
 		}
 
 		rc = wq_action_switch(wq, action, argv[i]);
-		if (rc == 0) {
+		if (rc == 0)
 			success++;
-		} else {
+		else
 			fprintf(stderr, "failed in %s\n", argv[i]);
-
-			print_device_cmd_status(device);
-		}
 	}
 
 	fprintf(stderr, "%s %d wq(s) out of %d\n",
Signature · 1 line
2.26.3
#3 lore raw

PATCH v4 3/3 accel-config: Reset cmd_status during device init

In reply to ramesh.thomas at intel.com

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Initialize cmd_status at device init to avoid getting stale value during error checks.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
accfg/lib/libaccfg.c +25 -0
index 5df19a7..f21cab5 100644
@@ -154,6 +154,23 @@ static inline bool is_mdev_registered(struct accfg_device *device)
 	return device->mdev_path && !access(device->mdev_path, R_OK);
 }
 
+static int accfg_set_param(struct accfg_ctx *ctx, int dfd, char *name,
+		void *buf, int len)
+{
+	int fd = openat(dfd, name, O_RDWR);
+	int n;
+
+	if (fd == -1)
+		return -errno;
+
+	n = write(fd, buf, len);
+	close(fd);
+	if (n != len)
+		return -errno;
+
+	return 0;
+}
+
 static long accfg_get_param_long(struct accfg_ctx *ctx, int dfd, char *name)
 {
 	int fd = openat(dfd, name, O_RDONLY);
@@ -589,6 +606,14 @@ static void *add_device(void *parent, int id, const char *ctl_base,
 		return NULL;
 	}
 
+	rc = accfg_set_param(ctx, dfd, "cmd_status", "1", 1);
+	/* older drivers don't support writing to cmd_status */
+	if (rc && rc != -EACCES) {
+		err(ctx, "Failed resetting cmd status %d\n", rc);
+		close(dfd);
+		goto err_device;
+	}
+
 	device = calloc(1, sizeof(*device));
 	if (!device) {
 		err(ctx, "allocation of device failed\n");
Signature · 1 line
2.26.3
Reviewed-by on the v4 series
#4 lore raw
In reply to ramesh.thomas at intel.com
Quoted 24 lines · ramesh.thomas(a)intel.com

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Add support to take a snapshot of error details containing hw/sw error code and associated devices. Added new API to retreive the saved information. Using the new API accel-config prints a more detailed error message at exit.

v2:
Use masks and other constants defined in idxd.h
Clear cmd_status during device initialization

v3:
Specify if the error is from driver or library

v4:
Specify if the error is platform configuration error Don't fail if clearing cmd_status is RO to support older drivers

Ramesh Thomas (3):
accel-config: Add APIs to get details of last error and associated
devices
accel-config: Print details of error at exit using new last_error API
accel-config: Reset cmd_status during device init

Quoted 7 lines
  accfg/accel-config.c          |  25 ++++-
  accfg/enable.c                |  25 +----
  accfg/lib/libaccel-config.sym |   6 ++
  accfg/lib/libaccfg.c          | 187 ++++++++++++++++++++++++++++++----
  accfg/lib/private.h           |   9 ++
  accfg/libaccel_config.h       |   9 +-
  6 files changed, 219 insertions(+), 42 deletions(-)
Reviewed-by Dave Jiang <dave.jiang(a)intel.com> for the series