Skip to contentSkip to conversation

Update API to get 256 bits op_cap

PATCH In review ramesh.thomas at intel.com 2 participants 8 messages May 7, 2021 – May 10, 2021

lore
Share & tools
lore

ramesh.thomas at intel.com

#0 lore raw

cover Update API to get 256 bits op_cap

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

Remove existing API that assumes op_cap is 64 bits. New API returns 256 bits.

Update json implementation to use the new API and print 256 bits.

Fix some issues found in other areas of code during implementation.

Ramesh Thomas (6):
accel-config: Remove duplicated function
accel-config: Fix an inconsistent error return value
accel-config: Free some allocated memory that were not being freed
accel-config: Remove existing op_cap API to be replaced with new one
accel-config: Add new API to support 256 bits op_cap
accel-config: Call new op_cap API in json implementation

 accfg/lib/libaccel-config.sym |  7 +++--
 accfg/lib/libaccfg.c          | 56 ++++++++++++++++++++++++++---------
 accfg/libaccel_config.h       |  7 ++++-
 accfg/list.c                  |  2 +-
 util/json.c                   | 35 +++++++---------------
 util/json.h                   |  2 --
 6 files changed, 64 insertions(+), 45 deletions(-)
Signature · 1 line
2.26.3
#1 lore raw

PATCH 1/6 accel-config: Remove duplicated function

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

Function used to write to stdout can also be used to write to a file on disk because both are exactly same and take FILE * as argument

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/list.c |  2 +-
 util/json.c  | 21 ---------------------
 util/json.h  |  2 --
 3 files changed, 1 insertion(+), 24 deletions(-)
accfg/list.c +1 -1
index 7e6ca6a..d03cf30 100644
@@ -373,7 +373,7 @@ static int save_config(struct list_filter_arg *lfa, const char *saved_file)
 	}
 
 	if (jdevices)
-		__util_display_json_array(fd, jdevices, lfa->flags);
+		util_display_json_array(fd, jdevices, lfa->flags);
 
 	/* free all the allocated container data structure */
 	free_containers(lfa);
util/json.c +0 -21
index 25514af..fd30383 100644
@@ -106,7 +106,6 @@ struct json_object *util_json_object_hex(uint64_t val,
 	return jobj;
 }
 
-/* API used to output json object display to console */
 void util_display_json_array(FILE *f_out, struct json_object *jarray,
 			     uint64_t flags)
 {
@@ -126,26 +125,6 @@ void util_display_json_array(FILE *f_out, struct json_object *jarray,
 	json_object_put(jarray);
 }
 
-/* API used to output json object display to specified file */
-void __util_display_json_array(FILE *fd, struct json_object *jarray,
-			     uint64_t flags)
-{
-	int len = json_object_array_length(jarray);
-	int jflag = JSON_C_TO_STRING_PRETTY;
-
-	if (json_object_array_length(jarray) > 1 || !(flags & UTIL_JSON_HUMAN))
-		fprintf(fd, "%s\n",
-			json_object_to_json_string_ext(jarray, jflag));
-	else if (len) {
-		struct json_object *jobj;
-
-		jobj = json_object_array_get_idx(jarray, 0);
-		fprintf(fd, "%s\n",
-			json_object_to_json_string_ext(jobj, jflag));
-	}
-	json_object_put(jarray);
-}
-
 struct json_object *util_device_to_json(struct accfg_device *device,
 					uint64_t flags)
 {
util/json.h +0 -2
index 79aad84..7828489 100644
@@ -17,8 +17,6 @@ enum util_json_flags {
 struct json_object;
 void util_display_json_array(FILE *f_out, struct json_object *jarray,
 		uint64_t flags);
-void __util_display_json_array(FILE *fd, struct json_object *jarray,
-		uint64_t flags);
 struct json_object *util_device_to_json(struct accfg_device *device,
 		uint64_t flags);
 struct json_object *util_wq_to_json(struct accfg_wq *accfg_wq,
Signature · 1 line
2.26.3
#2 lore raw

PATCH 2/6 accel-config: Fix an inconsistent error return value

In reply to ramesh.thomas at intel.com

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

accfg_device_get_errors was returning 0 even when sscanf has not read the 4 error values. It was returning 1 on success which is inconsistent with the success = 0. Updated one place where it was getting called.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 14 +++++---------
 util/json.c          |  2 +-
 2 files changed, 6 insertions(+), 10 deletions(-)
accfg/lib/libaccfg.c +5 -9
index 24ae65c..57e6d1f 100644
@@ -1290,17 +1290,13 @@ ACCFG_EXPORT int accfg_device_get_errors(struct accfg_device *device,
 	rc = sscanf(read_error, "%" SCNx64 " %" SCNx64 " %" SCNx64 " %" SCNx64,
 			&error->val[0], &error->val[1],
 			&error->val[2], &error->val[3]);
-	if (rc < 0) {
-		free(read_error);
-		return -errno;
-	}
-	else if (rc != 4) {
-		free(read_error);
-		return 0;
-	}
 
 	free(read_error);
-	return 1;
+
+	if (rc != 4)
+		return errno ? -errno : -EIO;
+
+	return 0;
 }
 
 ACCFG_EXPORT enum accfg_device_state accfg_device_get_state(
util/json.c +1 -1
index fd30383..0ce7848 100644
@@ -212,7 +212,7 @@ struct json_object *util_device_to_json(struct accfg_device *device,
 		goto err;
 	json_object_object_add(jdevice, "numa_node", jobj);
 
-	if (accfg_device_get_errors(device, error) == 1
+	if (!accfg_device_get_errors(device, error)
 			&& (error->val[0] || error->val[1]
 				|| error->val[2] || error->val[3])) {
 		jobj = json_object_new_array();
Signature · 1 line
2.26.3
#3 lore raw

PATCH 3/6 accel-config: Free some allocated memory that were not being freed

In reply to ramesh.thomas at intel.com

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

accfg_get_param_str() allocates memory and returns a pointer. The returned memory was not getting freed.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
accfg/lib/libaccfg.c +11 -1
index 57e6d1f..548827e 100644
@@ -205,6 +205,9 @@ static void free_wq(struct accfg_wq *wq)
 	list_del_from(&device->wqs, &wq->list);
 	free(wq->wq_path);
 	free(wq->wq_buf);
+	free(wq->mode);
+	free(wq->state);
+	free(wq->name);
 	free(wq);
 }
 
@@ -215,6 +218,8 @@ static void free_group(struct accfg_group *group)
 	list_del_from(&device->groups, &group->list);
 	free(group->group_buf);
 	free(group->group_path);
+	free(group->group_engines);
+	free(group->group_wqs);
 	free(group);
 }
 
@@ -754,6 +759,9 @@ static void *add_wq(void *parent, int id, const char *wq_base,
 err_read:
 	free(wq->wq_buf);
 	free(wq->wq_path);
+	free(wq->mode);
+	free(wq->state);
+	free(wq->name);
 err_wq:
 	free(wq);
 	free(path);
@@ -842,8 +850,10 @@ static void *add_group(void *parent, int id, const char *group_base,
 
 err_read:
 	free(group->group_buf);
-	free(group);
+	free(group->group_engines);
+	free(group->group_wqs);
 err_group:
+	free(group);
 	free(path);
 	return NULL;
 }
Signature · 1 line
2.26.3
#4 lore raw

PATCH 4/6 accel-config: Remove existing op_cap API to be replaced with new one

In reply to ramesh.thomas at intel.com

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

Remove the existing op_cap API which only handles the first 64 bits of op_cap. Following patches will add new API supporting all 256 bits of op_cap.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccel-config.sym | 2 --
 accfg/lib/libaccfg.c          | 7 -------
 accfg/libaccel_config.h       | 1 -
 util/json.c                   | 8 --------
 4 files changed, 18 deletions(-)
accfg/lib/libaccel-config.sym +0 -2
index 87b53f5..bffb8d8 100644
@@ -22,11 +22,9 @@ LIBACCFG_1 {
 	accfg_device_get_ims_size;
 	accfg_device_get_max_batch_size;
 	accfg_device_get_max_transfer_size;
-	accfg_device_get_op_cap;
 	accfg_device_get_configurable;
 	accfg_device_get_pasid_enabled;
 	accfg_device_get_errors;
-	accfg_device_get_op_cap;
 	accfg_device_get_state;
 	accfg_device_get_max_tokens;
 	accfg_device_get_max_batch_size;
accfg/lib/libaccfg.c +0 -7
index 548827e..1d39bd6 100644
@@ -574,7 +574,6 @@ static void *add_device(void *parent, int id, const char *ctl_base,
 			"max_batch_size");
 	device->max_transfer_size =
 	    accfg_get_param_unsigned_llong(ctx, dfd, "max_transfer_size");
-	device->opcap = accfg_get_param_unsigned_llong(ctx, dfd, "op_cap");
 	device->gencap = accfg_get_param_unsigned_llong(ctx, dfd, "gen_cap");
 	device->configurable = accfg_get_param_unsigned_llong(ctx, dfd,
 			"configurable");
@@ -1251,12 +1250,6 @@ ACCFG_EXPORT uint64_t accfg_device_get_max_transfer_size(
 	return device->max_transfer_size;
 }
 
-ACCFG_EXPORT uint64_t accfg_device_get_op_cap(
-		struct accfg_device *device)
-{
-	return device->opcap;
-}
-
 ACCFG_EXPORT uint64_t accfg_device_get_gen_cap(struct accfg_device *device)
 {
 	return device->gencap;
accfg/libaccel_config.h +0 -1
index 238ca1a..3354028 100644
@@ -168,7 +168,6 @@ int accfg_device_get_numa_node(struct accfg_device *device);
 unsigned int accfg_device_get_ims_size(struct accfg_device *device);
 unsigned int accfg_device_get_max_batch_size(struct accfg_device *device);
 uint64_t accfg_device_get_max_transfer_size(struct accfg_device *device);
-uint64_t accfg_device_get_op_cap(struct accfg_device *device);
 uint64_t accfg_device_get_gen_cap(struct accfg_device *device);
 unsigned int accfg_device_get_configurable(struct accfg_device *device);
 bool accfg_device_get_pasid_enabled(struct accfg_device  *device);
util/json.c +0 -8
index 0ce7848..e6e12e4 100644
@@ -228,14 +228,6 @@ struct json_object *util_device_to_json(struct accfg_device *device,
 		json_object_object_add(jdevice, "errors", jobj);
 	}
 
-	ulong_val = accfg_device_get_op_cap(device);
-	if (ulong_val > 0) {
-		jobj = util_json_object_hex(ulong_val, flags);
-		if (!jobj)
-			goto err;
-		json_object_object_add(jdevice, "op_cap", jobj);
-	}
-
 	jobj = util_json_object_hex(accfg_device_get_gen_cap(device), flags);
 	if (!jobj)
 		goto err;
Signature · 1 line
2.26.3
#5 lore raw

PATCH 5/6 accel-config: Add new API to support 256 bits op_cap

In reply to ramesh.thomas at intel.com

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

Adds new API to get 256 bits op_cap field. It will return a structure containing for 64 bit values as returned by the sysfs interface

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccel-config.sym |  5 +++++
 accfg/lib/libaccfg.c          | 29 +++++++++++++++++++++++++++++
 accfg/libaccel_config.h       |  6 ++++++
 3 files changed, 40 insertions(+)
accfg/lib/libaccel-config.sym +5 -0
index bffb8d8..aecc98b 100644
@@ -144,3 +144,8 @@ LIBACCFG_8 {
 global:
 	accfg_wq_get_user_dev_path;
 } LIBACCFG_7;
+
+LIBACCFG_9 {
+global:
+	accfg_device_get_op_cap;
+} LIBACCFG_8;
accfg/lib/libaccfg.c +29 -0
index 1d39bd6..12a97f5 100644
@@ -1250,6 +1250,35 @@ ACCFG_EXPORT uint64_t accfg_device_get_max_transfer_size(
 	return device->max_transfer_size;
 }
 
+ACCFG_EXPORT int accfg_device_get_op_cap(struct accfg_device *device,
+		struct accfg_op_cap *op_cap)
+{
+	char *oc;
+	int dfd;
+	int rc;
+	struct accfg_ctx *ctx;
+
+	if (!device)
+		return -EINVAL;
+
+	ctx = accfg_device_get_ctx(device);
+	dfd = open(device->device_path, O_PATH);
+	if (dfd < 0)
+		return -errno;
+	oc = accfg_get_param_str(ctx, dfd, "op_cap");
+	close(dfd);
+	rc = sscanf(oc, "%" SCNx64 " %" SCNx64 " %" SCNx64 " %" SCNx64,
+			&op_cap->bits[0], &op_cap->bits[1],
+			&op_cap->bits[2], &op_cap->bits[3]);
+
+	free(oc);
+
+	if (rc != 4)
+		return errno ? -errno : -EIO;
+
+	return 0;
+}
+
 ACCFG_EXPORT uint64_t accfg_device_get_gen_cap(struct accfg_device *device)
 {
 	return device->gencap;
accfg/libaccel_config.h +6 -0
index 3354028..5b37790 100644
@@ -79,6 +79,10 @@ struct accfg_error {
 	uint64_t val[4];
 };
 
+struct accfg_op_cap {
+	uint64_t bits[4];
+};
+
 /* parameters read from sysfs of accfg driver */
 struct dev_parameters {
 	unsigned int token_limit;
@@ -168,6 +172,8 @@ int accfg_device_get_numa_node(struct accfg_device *device);
 unsigned int accfg_device_get_ims_size(struct accfg_device *device);
 unsigned int accfg_device_get_max_batch_size(struct accfg_device *device);
 uint64_t accfg_device_get_max_transfer_size(struct accfg_device *device);
+int accfg_device_get_op_cap(struct accfg_device *device,
+		struct accfg_op_cap *op_cap);
 uint64_t accfg_device_get_gen_cap(struct accfg_device *device);
 unsigned int accfg_device_get_configurable(struct accfg_device *device);
 bool accfg_device_get_pasid_enabled(struct accfg_device  *device);
Signature · 1 line
2.26.3
#6 lore raw

PATCH 6/6 accel-config: Call new op_cap API in json implementation

In reply to ramesh.thomas at intel.com

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

Call the new op_cap API that supports 256 bits to populate json objects used in listing and saving the op_cap value.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 util/json.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
util/json.c +14 -0
index e6e12e4..4fb43d2 100644
@@ -131,6 +131,7 @@ struct json_object *util_device_to_json(struct accfg_device *device,
 	struct json_object *jdevice = json_object_new_object();
 	struct json_object *jobj;
 	struct accfg_error *error;
+	struct accfg_op_cap op_cap;
 	enum accfg_device_state dev_state;
 	int int_val;
 	uint64_t ulong_val;
@@ -228,6 +229,19 @@ struct json_object *util_device_to_json(struct accfg_device *device,
 		json_object_object_add(jdevice, "errors", jobj);
 	}
 
+	if (!accfg_device_get_op_cap(device, &op_cap)) {
+		jobj = json_object_new_array();
+		if (!jobj)
+			goto err;
+		for (int i = 0; i < 4; i++) {
+			struct json_object *json_oc;
+
+			json_oc = util_json_object_hex(op_cap.bits[i], flags);
+			json_object_array_add(jobj, json_oc);
+		}
+		json_object_object_add(jdevice, "op_cap", jobj);
+	}
+
 	jobj = util_json_object_hex(accfg_device_get_gen_cap(device), flags);
 	if (!jobj)
 		goto err;
Signature · 1 line
2.26.3
Reviewed-by on the v1 series
#7 lore raw
In reply to ramesh.thomas at intel.com
Quoted 8 lines · ramesh.thomas(a)intel.com

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

Remove existing API that assumes op_cap is 64 bits. New API returns 256 bits.

Update json implementation to use the new API and print 256 bits.

Fix some issues found in other areas of code during implementation.

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

Ramesh Thomas (6):
accel-config: Remove duplicated function
accel-config: Fix an inconsistent error return value
accel-config: Free some allocated memory that were not being freed
accel-config: Remove existing op_cap API to be replaced with new one
accel-config: Add new API to support 256 bits op_cap
accel-config: Call new op_cap API in json implementation

  accfg/lib/libaccel-config.sym |  7 +++--
  accfg/lib/libaccfg.c          | 56 ++++++++++++++++++++++++++---------
  accfg/libaccel_config.h       |  7 ++++-
  accfg/list.c                  |  2 +-
  util/json.c                   | 35 +++++++---------------
  util/json.h                   |  2 --
  6 files changed, 64 insertions(+), 45 deletions(-)