Update API to get 256 bits op_cap
ramesh.thomas at intel.com
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
ramesh.thomas at intel.com
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
--- accfg/list.c | 2 +- util/json.c | 21 --------------------- util/json.h | 2 -- 3 files changed, 1 insertion(+), 24 deletions(-)
accfg/list.c +1 -1
@@ -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
@@ -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
@@ -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
ramesh.thomas at intel.com
PATCH 2/6 accel-config: Fix an inconsistent error return value
In reply to ramesh.thomas at intel.comFrom: 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.
--- accfg/lib/libaccfg.c | 14 +++++--------- util/json.c | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-)
accfg/lib/libaccfg.c +5 -9
@@ -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
@@ -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
ramesh.thomas at intel.com
PATCH 3/6 accel-config: Free some allocated memory that were not being freed
In reply to ramesh.thomas at intel.comFrom: Ramesh Thomas <ramesh.thomas(a)intel.com>
accfg_get_param_str() allocates memory and returns a pointer. The returned memory was not getting freed.
--- accfg/lib/libaccfg.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
accfg/lib/libaccfg.c +11 -1
@@ -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
ramesh.thomas at intel.com
PATCH 4/6 accel-config: Remove existing op_cap API to be replaced with new one
In reply to ramesh.thomas at intel.comFrom: 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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
ramesh.thomas at intel.com
PATCH 5/6 accel-config: Add new API to support 256 bits op_cap
In reply to ramesh.thomas at intel.comFrom: 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
--- 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
@@ -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
@@ -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
@@ -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
ramesh.thomas at intel.com
PATCH 6/6 accel-config: Call new op_cap API in json implementation
In reply to ramesh.thomas at intel.comFrom: 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.
--- util/json.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
util/json.c +14 -0
@@ -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
Dave Jiang
Reviewed-by on the v1 seriesQuoted 8 lines · ramesh.thomas(a)intel.com
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
Remove existing API that assumes
op_capis 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.
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 existingop_capAPI to be replaced with new one
accel-config: Add new API to support 256 bitsop_cap
accel-config: Call newop_capAPI in json implementationaccfg/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(-)