Fix bugs in filter, list, config, enable areas
ramesh.thomas at intel.com
cover Fix bugs in filter, list, config, enable areas
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
These patches fixes many of the bugs that were seen due to the addition of iax. While fixing the reqported issues found that the existing code was using assumptions that are obsolete. Many parts of the filter, list, config and enable/disable areas have been rewritten considering latest design changes. This simplifies the implementation and would make future maintenance easier.
Ramesh Thomas (8):
accel-config: Fix some indentation and coding convention errors
accel-config: Fix wrong return values in functions
accel-config: Rewrite filter functions
accel-config: Rewrite listing functions
accel-config: Rewrite device selection using new filter functions
accel-config: Skip negative fields in listings
accel-config: Return error if no args
accel-config: Do not return error if help was specifically called
accfg/accel-config.c | 2 +- accfg/config_attr.c | 154 +++++------------- accfg/enable.c | 106 +++++------- accfg/list.c | 278 +++++++++++++++---------------- util/filter.c | 379 +++++++++++++++++++++---------------------- util/filter.h | 42 ++--- util/json.c | 36 ++-- util/json.h | 1 - util/parse-options.c | 6 +- 9 files changed, 436 insertions(+), 568 deletions(-)
Signature · 1 line
2.26.3
ramesh.thomas at intel.com
PATCH 1/8 accel-config: Fix some indentation and coding convention errors
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
Fixing checkpatch and indentation errors in these files to make review easier
--- accfg/config_attr.c | 27 +++++++++++++------------- accfg/enable.c | 4 ++-- accfg/list.c | 14 +++++++------- util/filter.c | 46 ++++++++++++++++++++------------------------- util/filter.h | 8 ++++---- util/json.c | 16 +++++++++------- util/json.h | 1 - 7 files changed, 56 insertions(+), 60 deletions(-)
accfg/config_attr.c +14 -13
@@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright(c) 2019 Intel Corporation. All rights reserved. */ +// SPDX-License-Identifier: GPL-2.0 +// Copyright(c) 2019 Intel Corporation. All rights reserved. #include <stdio.h> #include <errno.h>
@@ -45,6 +45,7 @@ static int accel_config_parse_device_attribs(struct accfg_device *dev, struct dev_parameters *device_param) {int rc =0 ; + rc =accfg_device_set_token_limit (dev, device_param->token_limit);if (rc <0 )return rc;
@@ -93,10 +94,10 @@ static int accel_config_parse_group_attribs(struct accfg_group *group, }if (group_params->use_token_limit !=UINT_MAX ) { - rc =accfg_group_set_use_token_limit (group, + rc =accfg_group_set_use_token_limit (group, group_params->use_token_limit);if (rc <0 ) -return rc; +return rc; }if (group_params->tokens_reserved !=UINT_MAX ) {
@@ -309,7 +310,7 @@ int cmd_config_device(int argc, const char **argv, void *ctx) }for (i =0 ; i < argc; i++) { -if (accfg_device_type_validate (argv[i])) { +if (accfg_device_type_validate (argv[i])) {/* walkthrough device */ accfg_device_foreach(ctx, device) {if (!util_device_filter (device, argv[i]))
@@ -318,7 +319,7 @@ int cmd_config_device(int argc, const char **argv, void *ctx) &dev_param);if (rc !=0 ) {fprintf (stderr, -"accel_config_parse_device_attribs failed\n" ); +"accel_config_parse_device_attribs failed\n" );return rc; } }
@@ -401,7 +402,7 @@ int cmd_config_group(int argc, const char **argv, void *ctx) accfg_group_foreach(device, group) {if (!util_group_filter (group, group_name)) -continue ; +continue ; rc =accel_config_parse_group_attribs (group, &group_param);
@@ -481,9 +482,9 @@ int cmd_config_wq(int argc, const char **argv, void *ctx)if (!accfg_device_type_validate (dev_name))return -EINVAL ; - rc =sprintf (wq_name,"wq%u.%u" , dev_id, wq_id); -if (rc <0 ) -return rc; + rc =sprintf (wq_name,"wq%u.%u" , dev_id, wq_id); +if (rc <0 ) +return rc; accfg_device_foreach(ctx, device) {if (!util_device_filter (device, dev_name))
@@ -553,9 +554,9 @@ int cmd_config_engine(int argc, const char **argv, void *ctx)if (!accfg_device_type_validate (dev_name))return -EINVAL ; - rc =sprintf (engine_name,"engine%u.%u" , dev_id, engine_id); -if (rc <0 ) -return rc; + rc =sprintf (engine_name,"engine%u.%u" , dev_id, engine_id); +if (rc <0 ) +return rc; accfg_device_foreach(ctx, device) {if (!util_device_filter (device, dev_name))
accfg/enable.c +2 -2
@@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright(c) 2019 Intel Corporation. All rights reserved. */ +// SPDX-License-Identifier: GPL-2.0 +// Copyright(c) 2019 Intel Corporation. All rights reserved. #include <stdio.h> #include <errno.h>
accfg/list.c +7 -7
@@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright(c) 2019 Intel Corporation. All rights reserved. */ +// SPDX-License-Identifier: GPL-2.0 +// Copyright(c) 2019 Intel Corporation. All rights reserved. #include <stdio.h> #include <errno.h>
@@ -128,7 +128,7 @@ static bool filter_wq(struct accfg_wq *wq, struct util_filter_ctx *ctx)if (!jwq)return false; -for (i =0 ; i < max_groups; i ++) { +for (i =0 ; i < max_groups; i++) {/* * Group array will be created only if group contains * the wq.
@@ -308,9 +308,9 @@ static bool filter_device(struct accfg_device *device,if (!jc)return false; - jc->jgroup_assigned =calloc (max_groups,sizeof (struct json_object *)); -if (!jc->jgroup_assigned) - goto err_jc; + jc->jgroup_assigned =calloc (max_groups,sizeof (struct json_object *)); +if (!jc->jgroup_assigned) + goto err_jc; jc->jwq_group =calloc (max_groups,sizeof (struct json_object *));if (!jc->jwq_group)
@@ -361,7 +361,7 @@ static void free_containers(struct list_filter_arg *lfa) } } -static int save_config (struct list_filter_arg *lfa,const char * saved_file) +static int save_config (struct list_filter_arg *lfa,const char *saved_file) {struct json_object *jdevices = lfa->jdevices;FILE *fd =fopen (saved_file,"w" );
util/filter.c +20 -26
118 lines not on this page · raw message
util/filter.h +4 -4
@@ -14,7 +14,7 @@ struct accfg_wq *util_wq_filter(struct accfg_wq *wq,struct accfg_engine *util_engine_filter (struct accfg_engine *engine,const char *ident);struct accfg_device *util_device_filter_by_group (struct accfg_device *device, -const char *ident); +const char *ident);struct accfg_group *util_group_filter_by_wq (struct accfg_group *group,const char *ident); struct accfg_group *util_group_filter_by_engine(struct accfg_group *group,
@@ -40,7 +40,7 @@ struct accfg_json_container {/* array for assigned engines in group */ struct json_object **jengine_group;/* array for unassigned engines in group */ -struct json_object *jengine_ungroup; +struct json_object *jengine_ungroup;/* store group_id when a jgroup is created */ int *jgroup_id;/* device_id bonded with this container */
@@ -54,9 +54,9 @@ struct accfg_json_container {/* json object device for the util_filter_walk() by cmd_list() and cmd_config() */ struct list_filter_arg {/* json object for device array */ -struct json_object *jdevices; +struct json_object *jdevices;/* json object for each device */ -struct json_object *jdevice; +struct json_object *jdevice;/* linked list to add accfg_json_container for each device */ struct list_head jdev_list;/* linked list node for each list_filter_arg */
util/json.c +9 -7
@@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright(c) 2015-2019 Intel Corporation. All rights reserved. */ +// SPDX-License-Identifier: GPL-2.0 +// Copyright(c) 2015-2019 Intel Corporation. All rights reserved. #include <limits.h> #include <string.h> #include <util/json.h>
@@ -17,7 +17,7 @@#include <dirent.h> #include "sysfs.h" -static const char *wq_type_str[] = { +static const char *const wq_type_str[] = {"none" ,"kernel" ,"user" ,
@@ -81,6 +81,7 @@ static int display_hex(struct json_object *jobj, struct printbuf *pbuf, {uint64_t val =json_object_get_int64 (jobj);static char buf[32 ]; +snprintf (buf,sizeof (buf),"\"%#" PRIx64"\"" , val);return printbuf_memappend (pbuf, buf,strlen (buf)); }
@@ -106,7 +107,7 @@ struct json_object *util_json_object_hex(uint64_t val, }/* API used to output json object display to console */ -void util_display_json_array (FILE * f_out,struct json_object *jarray, +void util_display_json_array (FILE *f_out,struct json_object *jarray,uint64_t flags) {int len =json_object_array_length (jarray);
@@ -117,6 +118,7 @@ void util_display_json_array(FILE * f_out, struct json_object *jarray, json_object_to_json_string_ext(jarray, jflag)); else if (len) {struct json_object *jobj; + jobj =json_object_array_get_idx (jarray,0 );fprintf (f_out,"%s\n" ,json_object_to_json_string_ext (jobj, jflag));
@@ -125,7 +127,7 @@ void util_display_json_array(FILE * f_out, struct json_object *jarray, }/* API used to output json object display to specified file */ -void __util_display_json_array (FILE * fd,struct json_object *jarray, +void __util_display_json_array (FILE *fd,struct json_object *jarray,uint64_t flags) {int len =json_object_array_length (jarray);
@@ -136,6 +138,7 @@ void __util_display_json_array(FILE * fd, struct json_object *jarray, 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));
@@ -507,9 +510,8 @@ struct json_object *util_engine_to_json(struct accfg_engine *engine,struct json_object *jaccfg =json_object_new_object ();struct json_object *jobj =NULL ; -if (!jaccfg) { +if (!jaccfg)return NULL ; - } jobj =json_object_new_string (accfg_engine_get_devname (engine));if (!jobj) goto err;
util/json.h +0 -1
@@ -1,4 +1,3 @@ -/* SPDX-License-Identifier: GPL-2.0 */ /* Copyright(c) 2015-2019 Intel Corporation. All rights reserved. */ #ifndef __ACCFG_JSON_H__
Signature · 1 line
2.26.3
ramesh.thomas at intel.com
PATCH 2/8 accel-config: Fix wrong return values in functions
In reply to ramesh.thomas at intel.comFrom: Ramesh Thomas <ramesh.thomas(a)intel.com>
display_xx functions were returning true on success and false. Change to return negitive error code on error and 0 on success.
--- accfg/list.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-)
accfg/list.c +28 -22
@@ -369,7 +369,7 @@ static int save_config(struct list_filter_arg *lfa, const char *saved_file)if (!fd) {fprintf (stderr,"Failed to open %s for save: %s\n" , saved_file,strerror (errno)); -return false; +return -EIO ; }if (jdevices)
@@ -397,10 +397,10 @@ static int display_device(struct json_object *jdevices,util_display_json_array (stdout, jdevices, lfa->flags);if (!util_param.device) -return true; +return 0 ;if (sscanf (util_param.device,"%[a-z]%d" , dev_type, &device_id) !=2 ) -return false; +return -EINVAL ;for (accel_type = accfg_basenames; *accel_type !=NULL ; accel_type++)if (!strcmp (dev_type, *accel_type))
@@ -408,18 +408,18 @@ static int display_device(struct json_object *jdevices,if (*accel_type ==NULL ) {fprintf (stderr,"device type not matched\n" ); -return false; +return -EINVAL ; }if (device_id > lfa->dev_num) {fprintf (stderr,"device_id out of range\n" ); -return false; +return -EINVAL ; } jdevice =json_object_array_get_idx (jdevices,0 );printf ("%s\n" ,json_object_to_json_string_ext (jdevice, jflag)); -return true; +return 0 ; }static int display_group (struct list_filter_arg *lfa,struct accfg_ctx *ctx)
@@ -437,12 +437,12 @@ static int display_group(struct list_filter_arg *lfa, struct accfg_ctx *ctx)list_for_each (&lfa->jdev_list, iter, list)util_display_json_array (stdout, iter->jgroups, lfa->flags); -return true; +return 0 ; }if (sscanf (util_param.group,"group%d.%d" , &device_id, &group_id) !=2 ) -return false; +return -EINVAL ; accfg_device_foreach(ctx, dev) {if (accfg_device_get_id (dev) != device_id)
@@ -452,7 +452,7 @@ static int display_group(struct list_filter_arg *lfa, struct accfg_ctx *ctx)if (device_id > lfa->dev_num || group_id > max_groups) {fprintf (stderr,"device_id or group_id out of range\n" ); -return false; +return -EINVAL ; }list_for_each (&lfa->jdev_list, iter, list) {
@@ -469,7 +469,7 @@ static int display_group(struct list_filter_arg *lfa, struct accfg_ctx *ctx) } } -return true; +return 0 ; }static int display_wq (struct list_filter_arg *lfa,struct accfg_ctx *ctx)
@@ -495,11 +495,11 @@ static int display_wq(struct list_filter_arg *lfa, struct accfg_ctx *ctx) } } -return true; +return 0 ; }if (sscanf (util_param.wq,"wq%d.%d" , &device_id, &wq_id) !=2 ) -return false; +return -EINVAL ; accfg_device_foreach(ctx, dev) {if (accfg_device_get_id (dev) == device_id) {
@@ -509,14 +509,14 @@ static int display_wq(struct list_filter_arg *lfa, struct accfg_ctx *ctx)if (device_id > lfa->dev_num || wq_id > max_wqs) {fprintf (stderr,"device_id or wq_id out of range\n" ); -return false; +return -EINVAL ; }list_for_each (&lfa->jdev_list, iter, list)if (match_device (dev, iter)) jc = iter;if (!jc) -return false; +return -EINVAL ;printf ("device %s:\n" , jc->device_name);for (index =0 ; index < max_groups; index++) {
@@ -534,7 +534,7 @@ static int display_wq(struct list_filter_arg *lfa, struct accfg_ctx *ctx) } } -return true; +return 0 ; }static int display_engine (struct list_filter_arg *lfa,struct accfg_ctx *ctx)
@@ -561,7 +561,7 @@ static int display_engine(struct list_filter_arg *lfa, struct accfg_ctx *ctx) } } -return true; +return 0 ; }if (sscanf (util_param.engine,"engine%d.%d" , &device_id, &engine_id) !=2 )
@@ -576,14 +576,14 @@ static int display_engine(struct list_filter_arg *lfa, struct accfg_ctx *ctx) || engine_id > max_engines) {fprintf (stderr,"dev id or engine id out of range\n" ); -return false; +return -EINVAL ; }list_for_each (&lfa->jdev_list, iter, list)if (match_device (dev, iter)) jc = iter;if (!jc) -return false; +return -EINVAL ;printf ("device %s:\n" , jc->device_name);for (index =0 ; index < max_groups; index++) {
@@ -602,7 +602,7 @@ static int display_engine(struct list_filter_arg *lfa, struct accfg_ctx *ctx) } } -return true; +return 0 ; }static int list_display (struct list_filter_arg *lfa,struct accfg_ctx *ctx)
@@ -635,6 +635,8 @@ static int num_list_flags(void)int cmd_list (int argc,const char **argv,void *ctx) { +int i, rc; +const struct option options[] = {OPT_STRING ('d' ,"device" , &util_param.device,"device-id" ,"filter by device" ),
@@ -662,7 +664,6 @@ int cmd_list(int argc, const char **argv, void *ctx) };struct util_filter_ctx fctx = {0 };struct list_filter_arg lfa = {0 }; -int i, rc; argc =parse_options (argc, argv, options, u,0 );for (i =0 ; i < argc; i++)
@@ -694,8 +695,13 @@ int cmd_list(int argc, const char **argv, void *ctx)if (rc)return rc; -if (list_display (&lfa, ctx) || did_fail) -return -ENOMEM ; + rc =list_display (&lfa, ctx); +if (rc) +return rc; + +if (did_fail) +return -EINVAL ; +return 0 ; }
Signature · 1 line
2.26.3
ramesh.thomas at intel.com
PATCH 3/8 accel-config: Rewrite filter functions
In reply to ramesh.thomas at intel.comFrom: Ramesh Thomas <ramesh.thomas(a)intel.com>
The filter functions were using redundant assumptions and had several bugs. Rewrite them using current design and discard redundant functions and operations. The functions parse arguments containing names of wqs, groups and engines prefixed with parent device, validate and return the pointer to the corresponding structure. This simplifies scanning for devices, wqs, groups and engines and helps keeping interfaces of all commands consistent.
--- util/filter.c | 369 ++++++++++++++++++++++++-------------------------- util/filter.h | 36 ++--- 2 files changed, 198 insertions(+), 207 deletions(-)
util/filter.c +179 -190
@@ -13,274 +13,263 @@#include <accfg/libaccel_config.h> #include <accfg/lib/private.h> -#define NUMA_NO_NODE (-1) - -struct accfg_device *util_device_filter (struct accfg_device *device, -const char *__ident) +int match_device (struct accfg_device *dev,struct accfg_json_container *jc) { -char *end =NULL , *ident, *save; -int device_id, id; -const char *devname, *name; - -if (!__ident) -return device; - ident =strdup (__ident); - -if (!ident) -return NULL ; -for (name =strtok_r (ident," " , &save); name; - name =strtok_r (NULL ," " , &save)) { -if (strcmp (name,"all" ) ==0 ) -break ; +return !strcmp (accfg_device_get_devname (dev), jc->device_name); +} - device_id =strtoul (ident, &end,0 ); +int scan_device_type_id (const char *name,char *dev_type, +unsigned int *dev_id) +{ +char type[MAX_DEV_LEN ]; +unsigned int id; -if (end == ident || end[0 ]) - device_id =UINT_MAX ; +if (sscanf (name,"%[a-z]%u" , type, &id) !=2 ) +return -EINVAL ; - devname =accfg_device_get_devname (device); - id =accfg_device_get_id (device); -if ((unsigned int )device_id <UINT_MAX && device_id == id) -break ; -if ((unsigned int )device_id ==UINT_MAX &&strcmp (devname, name) ==0 ) -break ; - } -free (ident); +if (dev_type) +strcpy (dev_type, type); -if (name) -return device; +if (dev_id) + *dev_id = id; -return NULL ; +return 0 ; } -struct accfg_group *util_group_filter (struct accfg_group *group, -const char *__ident) +int scan_parent_child_names (const char *name,char *parent_name, +char *child_name) { -char *ident, *save; -const char *name; -int device_id, group_id; +char p_name[MAX_DEV_LEN ], c_name[MAX_DEV_LEN ]; -if (!__ident) -return group; +if (sscanf (name,"%[^/]/%s" , p_name, c_name) !=2 ) +return -EINVAL ; - ident =strdup (__ident); -if (!ident) -return NULL ; +if (parent_name) +strcpy (parent_name, p_name); -for (name =strtok_r (ident," " , &save); name; - name =strtok_r (NULL ," " , &save)) { -if (strcmp (name,"all" ) ==0 ) -break ; +if (child_name) +strcpy (child_name, c_name); -if (strcmp (name,accfg_group_get_devname (group)) ==0 ) -break ; +return 0 ; +} -if (sscanf (name,"%d.%d" , &device_id, &group_id) ==2 - &&accfg_group_get_id (group) == group_id - &&accfg_group_get_device_id (group) == device_id) { -break ; - } - } -free (ident); -if (name) -return group; +int scan_parent_child_ids (const char *name,unsigned int *parent_id, +unsigned int *child_id) +{ +unsigned int p_id, c_id; + +if (sscanf (name,"%*[a-z]%u.%u" , &p_id, &c_id) !=2 ) +return -EINVAL ; + +if (parent_id) + *parent_id = p_id; -return NULL ; +if (child_id) + *child_id = c_id; + +return 0 ; } -struct accfg_wq *util_wq_filter (struct accfg_wq *wq,const char *__ident) +int parse_device_name (struct accfg_ctx *ctx,const char *name, +struct accfg_device **device) { -struct accfg_group *group =accfg_wq_get_group (wq); -int group_id, wq_id; -const char *name; -char *ident, *save; +struct accfg_device *dev; +char dev_type[MAX_DEV_LEN ]; +int rc; -if (!__ident) -return wq; + rc =scan_device_type_id (name, dev_type,NULL ); +if (rc || !accfg_device_type_validate (dev_type)) +return -EINVAL ; - ident =strdup (__ident); -if (!ident) -return NULL ; - -for (name =strtok_r (ident," " , &save); name; - name =strtok_r (NULL ," " , &save)) { -if (strcmp (name,accfg_wq_get_devname (wq)) ==0 ) + accfg_device_foreach(ctx, dev) +if (!strcmp (name,accfg_device_get_devname (dev)))break ; -if (sscanf (name,"%d.%d" , &group_id, &wq_id) ==2 - &&accfg_group_get_id (group) == group_id - &&accfg_wq_get_group_id (wq) == wq_id) -break ; +if (!dev) { +fprintf (stderr,"%s device not found\n" , name); +return -EINVAL ; } -free (ident); -if (name) -return wq; -return NULL ; +if (device) + *device = dev; + +return 0 ; } -struct accfg_engine *util_engine_filter (struct accfg_engine *engine, -const char *__ident) +int parse_wq_name (struct accfg_ctx *ctx,const char *name, +struct accfg_device **device,struct accfg_wq **wq) { -struct accfg_group *group =accfg_engine_get_group (engine); -int group_id, engine_id; -const char *name; -char *ident, *save; +struct accfg_device *dev; +struct accfg_wq *q; +char dev_name[MAX_DEV_LEN ], wq_name[MAX_DEV_LEN ]; +int rc; -if (!__ident) -return engine; + rc =scan_parent_child_names (name, dev_name, wq_name); +if (rc) +return rc; - ident =strdup (__ident); -if (!ident) -return NULL ; + rc =parse_device_name (ctx, dev_name, &dev); +if (rc) +return rc; -for (name =strtok_r (ident," " , &save); name; - name =strtok_r (NULL ," " , &save)) { -if (strcmp (name,accfg_engine_get_devname (engine)) ==0 ) + accfg_wq_foreach(dev, q) +if (!strcmp (wq_name,accfg_wq_get_devname (q)))break ; -if (sscanf (name,"%d.%d" , &group_id, &engine_id) ==2 - &&accfg_group_get_id (group) == group_id - &&accfg_engine_get_id (engine) == engine_id) -break ; +if (!q) { +fprintf (stderr,"%s workqueue not found\n" , name); +return -EINVAL ; } -free (ident); -if (name) -return engine; -return NULL ; -} +if (device) + *device = dev; -struct accfg_device *util_device_filter_by_group (struct accfg_device *device, -const char *ident) -{ -struct accfg_group *group; - -if (!ident ||strcmp (ident,"all" ) ==0 ) -return device; +if (wq) + *wq = q; - accfg_group_foreach(device, group) { -if (util_group_filter (group, ident)) -return device; - } -return NULL ; +return 0 ; } -struct accfg_device *util_device_filter_by_wq (struct accfg_device *device, -const char *ident) +int parse_group_name (struct accfg_ctx *ctx,const char *name, +struct accfg_device **device,struct accfg_group **group) { -struct accfg_group *group; -struct accfg_wq *wq; +struct accfg_device *dev; +struct accfg_group *g; +char dev_name[MAX_DEV_LEN ], group_name[MAX_DEV_LEN ]; +int rc; -if (!ident ||strcmp (ident,"all" ) ==0 ) -return device; + rc =scan_parent_child_names (name, dev_name, group_name); +if (rc) +return rc; - accfg_group_foreach(device, group) - accfg_wq_foreach(device, wq) -if (util_wq_filter (wq, ident)) -return device; -return NULL ; -} + rc =parse_device_name (ctx, dev_name, &dev); +if (rc) +return rc; -struct accfg_device *util_device_filter_by_engine (struct accfg_device *device, -const char *ident) -{ -struct accfg_group *group; -struct accfg_engine *engine; + accfg_group_foreach(dev, g) +if (!strcmp (group_name,accfg_group_get_devname (g))) +break ; -if (!ident ||strcmp (ident,"all" ) ==0 ) -return device; +if (!g) { +fprintf (stderr,"%s group not found\n" , name); +return -EINVAL ; + } + +if (device) + *device = dev; - accfg_group_foreach(device, group) - accfg_engine_foreach(device, engine) -if (util_engine_filter (engine, ident)) -return device; -return NULL ; +if (group) + *group = g; + +return 0 ; } -struct accfg_group *util_group_filter_by_wq (struct accfg_group *group, -const char *ident) +int parse_engine_name (struct accfg_ctx *ctx,const char *name, +struct accfg_device **device,struct accfg_engine **engine) { -struct accfg_wq *wq; -struct accfg_device *device = group->device; +struct accfg_device *dev; +struct accfg_engine *e; +char dev_name[MAX_DEV_LEN ], engine_name[MAX_DEV_LEN ]; +int rc; -if (!ident ||strcmp (ident,"all" ) ==0 ) -return group; + rc =scan_parent_child_names (name, dev_name, engine_name); +if (rc) +return rc; - accfg_wq_foreach(device, wq) -if (util_wq_filter (wq, ident)) -return group; -return NULL ; -} + rc =parse_device_name (ctx, dev_name, &dev); +if (rc) +return rc; -struct accfg_group *util_group_filter_by_engine (struct accfg_group *group, -const char *ident) -{ -struct accfg_engine *engine; -struct accfg_device *device = group->device; + accfg_engine_foreach(dev, e) +if (!strcmp (engine_name,accfg_engine_get_devname (e))) +break ; -if (!ident ||strcmp (ident,"all" ) ==0 ) -return group; +if (!e) { +fprintf (stderr,"%s engine not found\n" , name); +return -EINVAL ; + } - accfg_engine_foreach(device, engine) -if (util_engine_filter (engine, ident)) -return group; -return NULL ; -} +if (device) + *device = dev; + +if (engine) + *engine = e; -int match_device (struct accfg_device *dev,struct accfg_json_container *jc) -{ -if ((accfg_device_get_id (dev) == jc->device_id) && -strcmp (accfg_device_get_devname (dev), - jc->device_name) ==0 ) -return 1 ;return 0 ; }int util_filter_walk (struct accfg_ctx *ctx,struct util_filter_ctx *fctx,struct util_filter_params *param) { -struct accfg_device *device; -struct accfg_wq *wq; -struct accfg_engine *engine; -struct accfg_group *group; +struct accfg_device *device, *dev =NULL ; +struct accfg_wq *wq, *q =NULL ; +struct accfg_engine *engine, *e =NULL ; +struct accfg_group *group, *g =NULL ; +bool b, found = false; +int rc =0 ; + +if (param->device) + rc =parse_device_name (ctx, param->device, &dev); +else if (param->group) + rc =parse_group_name (ctx, param->group, &dev, &g); +else if (param->wq) + rc =parse_wq_name (ctx, param->wq, &dev, &q); +else if (param->engine) + rc =parse_engine_name (ctx, param->engine, &dev, &e); +else + found = true; + +if (rc) +return rc; accfg_device_foreach(ctx, device) { -if (!util_device_filter (device, param->device) - || !util_device_filter_by_group (device, param->group) - || !util_device_filter_by_wq (device, param->wq) - || !util_device_filter_by_engine (device, param->engine)) +if (dev && dev != device)continue ;if (!fctx->filter_device (device, fctx))continue ; +if (param->device) + found = true; + accfg_group_foreach(device, group) { -if (!util_group_filter (group, param->group)) -continue ; -if (!fctx->filter_group (group, fctx)) +if (g && g != group)continue ; + b = fctx->filter_group (group, fctx); +if (g) { + found = b; +break ; + } } accfg_wq_foreach(device, wq) { -if (!fctx->filter_wq) -break ; - -if (!util_wq_filter (wq, param->wq)) +if (q && q != wq)continue ; - - fctx->filter_wq (wq, fctx); + b = fctx->filter_wq (wq, fctx); +if (q) { + found = b; +break ; + } } accfg_engine_foreach(device, engine) { -if (!fctx->filter_engine) +if (e && e != engine) +continue ; + b = fctx->filter_engine (engine, fctx); +if (e) { + found = b;break ; + } + } -if (!util_engine_filter (engine, param->engine)) -continue ; +if (dev) +break ; + } - fctx->filter_engine (engine, fctx); - } +if (!found) { +fprintf (stderr,"No matching device found\n" ); +return -EINVAL ; } +return 0 ; }
util/filter.h +19 -17
@@ -6,23 +6,10 @@#include <ccan/list/list.h> #include <ccan/short_types/short_types.h> -struct accfg_device *util_device_filter (struct accfg_device *device,const char *ident); -struct accfg_group *util_group_filter (struct accfg_group *group, -const char *ident); -struct accfg_wq *util_wq_filter (struct accfg_wq *wq, -const char *ident); -struct accfg_engine *util_engine_filter (struct accfg_engine *engine,const char *ident); - -struct accfg_device *util_device_filter_by_group (struct accfg_device *device, -const char *ident); -struct accfg_group *util_group_filter_by_wq (struct accfg_group *group, -const char *ident); -struct accfg_group *util_group_filter_by_engine (struct accfg_group *group, -const char *ident); -struct accfg_wq *util_wq_filter_by_group (struct accfg_wq *wq, -const char *ident); -struct accfg_engine *util_engine_filter_by_group (struct accfg_engine *engine, -const char *ident); +struct accfg_device ; +struct accfg_group ; +struct accfg_wq ; +struct accfg_engine ;struct json_object ;/* json object hierarchy for device */
@@ -99,6 +86,21 @@ struct util_filter_params { };struct accfg_ctx ; + +int scan_device_type_id (const char *name,char *dev_type, +unsigned int *dev_id); +int scan_parent_child_names (const char *name,char *parent_name, +char *child_name); +int scan_parent_child_ids (const char *name,unsigned int *parent_id, +unsigned int *child_id); +int parse_device_name (struct accfg_ctx *ctx,const char *name, +struct accfg_device **device); +int parse_wq_name (struct accfg_ctx *ctx,const char *name, +struct accfg_device **device,struct accfg_wq **wq); +int parse_group_name (struct accfg_ctx *ctx,const char *name, +struct accfg_device **device,struct accfg_group **group); +int parse_engine_name (struct accfg_ctx *ctx,const char *name, +struct accfg_device **device,struct accfg_engine **engine);int util_filter_walk (struct accfg_ctx *ctx,struct util_filter_ctx *fctx,struct util_filter_params *param);int match_device (struct accfg_device *device,struct accfg_json_container *jc);
Signature · 1 line
2.26.3
ramesh.thomas at intel.com
PATCH 4/8 accel-config: Rewrite listing functions
In reply to ramesh.thomas at intel.comFrom: Ramesh Thomas <ramesh.thomas(a)intel.com>
Use the new filter and parse functions and simplify the display functions. The rewrite would also resolve some bugs in the filtering and listing of devices, wqs, groups and engines with options to display specific device or idle devices.
--- accfg/list.c | 232 +++++++++++++++++++++++---------------------------- 1 file changed, 105 insertions(+), 127 deletions(-)
accfg/list.c +105 -127
@@ -155,8 +155,8 @@ static bool filter_wq(struct accfg_wq *wq, struct util_filter_ctx *ctx) }/* for the rest, add into device jobj directly */ -if (!in_group) { -if (!jc->jwq_ungroup && (lfa->flags &UTIL_JSON_IDLE )) { +if (!in_group && (lfa->flags &UTIL_JSON_IDLE )) { +if (!jc->jwq_ungroup) { jc->jwq_ungroup =json_object_new_array ();if (!jc->jwq_ungroup)return false;
@@ -385,223 +385,201 @@ static int save_config(struct list_filter_arg *lfa, const char *saved_file)static int display_device (struct json_object *jdevices,struct list_filter_arg *lfa) { -int jflag =JSON_C_TO_STRING_PRETTY ; -char **accel_type; -int device_id;struct json_object *jdevice; -char dev_type[MAX_DEV_LEN ];printf ("%s\n" ,"devices:" ); - -if (jdevices && (!util_param.device)) +if (!util_param.device) {util_display_json_array (stdout, jdevices, lfa->flags); - -if (!util_param.device)return 0 ; - -if (sscanf (util_param.device,"%[a-z]%d" , dev_type, &device_id) !=2 ) -return -EINVAL ; - -for (accel_type = accfg_basenames; *accel_type !=NULL ; accel_type++) -if (!strcmp (dev_type, *accel_type)) -break ; - -if (*accel_type ==NULL ) { -fprintf (stderr,"device type not matched\n" ); -return -EINVAL ; } -if (device_id > lfa->dev_num) { -fprintf (stderr,"device_id out of range\n" ); + jdevice =json_object_array_get_idx (jdevices,0 ); +if (!jdevice) { +fprintf (stderr,"No matching device found\n" );return -EINVAL ; } - jdevice =json_object_array_get_idx (jdevices,0 ); -printf ("%s\n" ,json_object_to_json_string_ext (jdevice, jflag)); +printf ("%s\n" ,json_object_to_json_string_ext (jdevice, +JSON_C_TO_STRING_PRETTY ));return 0 ; }static int display_group (struct list_filter_arg *lfa,struct accfg_ctx *ctx) { -struct accfg_json_container *iter; -int device_id; -unsigned int group_id, max_groups; -struct json_object *jgroups; +struct accfg_json_container *iter, *jc =NULL ;struct accfg_device *dev; -struct accfg_json_container *jc =NULL ; +int rc;printf ("%s\n" ,"groups:" );if (!util_param.group) { -list_for_each (&lfa->jdev_list, iter, list) +list_for_each (&lfa->jdev_list, iter, list) { +printf ("device %s:\n" , iter->device_name);util_display_json_array (stdout, iter->jgroups, lfa->flags); + }return 0 ; } -if (sscanf (util_param.group,"group%d.%d" , &device_id, &group_id) !=2 ) -return -EINVAL ; + rc =parse_group_name (ctx, util_param.group, &dev,NULL ); +if (rc) +return rc; - accfg_device_foreach(ctx, dev) { -if (accfg_device_get_id (dev) != device_id) +list_for_each (&lfa->jdev_list, iter, list) +if (match_device (dev, iter)) { + jc = iter;break ; - - max_groups =accfg_device_get_max_groups (dev); -if (device_id > lfa->dev_num || group_id > max_groups) { -fprintf (stderr, -"device_id or group_id out of range\n" ); -return -EINVAL ; } -list_for_each (&lfa->jdev_list, iter, list) { -if (!match_device (dev, iter)) -continue ; - jc = iter; -if (!jc) -return false; -printf ("device %s:\n" , iter->device_name); - jgroups = jc->jgroups; -if (jgroups) -util_display_json_array (stdout, jgroups, - lfa->flags); - } +if (!jc) { +fprintf (stderr,"No matching group found\n" ); +return -EINVAL ; } +printf ("device %s:\n" , jc->device_name); +if (jc->jgroups) +util_display_json_array (stdout, jc->jgroups, lfa->flags); +return 0 ; }static int display_wq (struct list_filter_arg *lfa,struct accfg_ctx *ctx) { -int device_id; -unsigned int wq_id, max_wqs, max_groups, i =0 , index =0 ; +unsigned int max_groups, index =0 ;struct accfg_device *dev;struct accfg_json_container *jc =NULL , *iter; +int rc;printf ("%s\n" ,"workqueues:" );if (!util_param.wq) {list_for_each (&lfa->jdev_list, iter, list) { - dev =accfg_ctx_device_get_by_id (ctx, i); +bool once = true; + + dev =accfg_ctx_device_get_by_name (ctx, iter->device_name); max_groups =accfg_device_get_max_groups (dev);printf ("device %s:\n" , iter->device_name);for (index =0 ; index < max_groups; index++) { -if (iter->jwq_group[index] !=NULL ) +if (iter->jwq_group[index] !=NULL ) { +if (once) { +printf ("grouped workqueues:\n" ); + once = false; + } +printf ("group id %u:\n" , iter->jgroup_id[index]);util_display_json_array (stdout, iter->jwq_group[index], lfa->flags); + } + } + +if (iter->jwq_ungroup !=NULL ) { +printf ("ungrouped workqueues:\n" ); +util_display_json_array (stdout, + iter->jwq_ungroup, + lfa->flags); } }return 0 ; } -if (sscanf (util_param.wq,"wq%d.%d" , &device_id, &wq_id) !=2 ) -return -EINVAL ; - - accfg_device_foreach(ctx, dev) { -if (accfg_device_get_id (dev) == device_id) { - max_groups =accfg_device_get_max_groups (dev); - max_wqs =accfg_device_get_max_work_queues (dev); - -if (device_id > lfa->dev_num || wq_id > max_wqs) { -fprintf (stderr, -"device_id or wq_id out of range\n" ); -return -EINVAL ; - } + rc =parse_wq_name (ctx, util_param.wq, &dev,NULL ); +if (rc) +return rc; -list_for_each (&lfa->jdev_list, iter, list) -if (match_device (dev, iter)) - jc = iter; -if (!jc) -return -EINVAL ; + max_groups =accfg_device_get_max_groups (dev); -printf ("device %s:\n" , jc->device_name); -for (index =0 ; index < max_groups; index++) { -struct json_object *jwq_group[max_groups]; - -if (wq_id != index || (lfa->flags &UTIL_JSON_IDLE )) -continue ; - jwq_group[index] = jc->jwq_group[index]; -if (jwq_group[index] !=NULL ) { -util_display_json_array (stdout, - jwq_group[index], - lfa->flags); - } - } +list_for_each (&lfa->jdev_list, iter, list) +if (match_device (dev, iter)) { + jc = iter; +break ; } +if (!jc) { +fprintf (stderr,"No matching workqueue found\n" ); +return -EINVAL ; } +printf ("device %s:\n" , jc->device_name); +for (index =0 ; index < max_groups; index++) +if (jc->jwq_group[index]) +util_display_json_array (stdout, jc->jwq_group[index], + lfa->flags); +if (jc->jwq_ungroup) +util_display_json_array (stdout, jc->jwq_ungroup, lfa->flags); +return 0 ; }static int display_engine (struct list_filter_arg *lfa,struct accfg_ctx *ctx) { -int device_id; -unsigned int engine_id, max_groups, max_engines, - i =0 , index =0 ; -struct accfg_json_container *jc =NULL , *iter; +unsigned int max_groups, index =0 ;struct accfg_device *dev; +struct accfg_json_container *jc =NULL , *iter; +int rc;printf ("%s\n" ,"engines:" );if (!util_param.engine) {list_for_each (&lfa->jdev_list, iter, list) { - dev =accfg_ctx_device_get_by_id (ctx, i); +bool once = true; + + dev =accfg_ctx_device_get_by_name (ctx, iter->device_name); max_groups =accfg_device_get_max_groups (dev);printf ("device %s:\n" , iter->device_name);for (index =0 ; index < max_groups; index++) { -if (iter->jengine_group[index] !=NULL ) +if (iter->jengine_group[index] !=NULL ) { +if (once) { +printf ("grouped engines:\n" ); + once = false; + } +printf ("group id %u:\n" , iter->jgroup_id[index]);util_display_json_array (stdout, iter->jengine_group[index], lfa->flags); + } + } + +if (iter->jengine_ungroup !=NULL ) { +printf ("ungrouped engines:\n" ); +util_display_json_array (stdout, + iter->jengine_ungroup, + lfa->flags); } }return 0 ; } -if (sscanf (util_param.engine,"engine%d.%d" , &device_id, &engine_id) !=2 ) -return false; - - accfg_device_foreach(ctx, dev) { -if (accfg_device_get_id (dev) == device_id) { - max_groups =accfg_device_get_max_groups (dev); - max_engines =accfg_device_get_max_engines (dev); - -if (device_id > lfa->dev_num - || engine_id > max_engines) { -fprintf (stderr, -"dev id or engine id out of range\n" ); -return -EINVAL ; - } - -list_for_each (&lfa->jdev_list, iter, list) -if (match_device (dev, iter)) - jc = iter; -if (!jc) -return -EINVAL ; + rc =parse_engine_name (ctx, util_param.engine, &dev,NULL ); +if (rc) +return rc; -printf ("device %s:\n" , jc->device_name); -for (index =0 ; index < max_groups; index++) { -struct json_object *jengine_group[max_groups]; + max_groups =accfg_device_get_max_groups (dev); -if (lfa->flags &UTIL_JSON_IDLE ) -continue ; - jengine_group[index] = - jc->jengine_group[index]; -if (jengine_group[index]) { -util_display_json_array (stdout, - jengine_group[index], - lfa->flags); - } - } +list_for_each (&lfa->jdev_list, iter, list) +if (match_device (dev, iter)) { + jc = iter; +break ; } +if (!jc) { +fprintf (stderr,"No matching engine found\n" ); +return -EINVAL ; } +printf ("device %s:\n" , jc->device_name); +for (index =0 ; index < max_groups; index++) +if (jc->jengine_group[index]) +util_display_json_array (stdout, + jc->jengine_group[index], lfa->flags); + +if (jc->jengine_ungroup) +util_display_json_array (stdout, jc->jengine_ungroup, + lfa->flags); +return 0 ; }
Signature · 1 line
2.26.3
ramesh.thomas at intel.com
PATCH 5/8 accel-config: Rewrite device selection using new filter functions
In reply to ramesh.thomas at intel.comFrom: Ramesh Thomas <ramesh.thomas(a)intel.com>
Rewrite code that parses and locates devices, wqs, groups and engines using the new filter and parse functions.
--- accfg/config_attr.c | 139 ++++++++++---------------------------------- accfg/enable.c | 102 ++++++++++++-------------------- 2 files changed, 67 insertions(+), 174 deletions(-)
accfg/config_attr.c +31 -108
@@ -310,19 +310,17 @@ int cmd_config_device(int argc, const char **argv, void *ctx) }for (i =0 ; i < argc; i++) { -if (accfg_device_type_validate (argv[i])) { -/* walkthrough device */ - accfg_device_foreach(ctx, device) { -if (!util_device_filter (device, argv[i])) -continue ; - rc =accel_config_parse_device_attribs (device, - &dev_param); -if (rc !=0 ) { -fprintf (stderr, -"accel_config_parse_device_attribs failed\n" ); -return rc; - } - } +if (parse_device_name (ctx, argv[i], &device)) { +fprintf (stderr, +"%s is not a valid device name\n" , argv[i]); +continue ; + } + + rc =accel_config_parse_device_attribs (device, &dev_param); +if (rc !=0 ) { +fprintf (stderr, +"accel_config_parse_device_attribs failed\n" ); +return rc; } }
@@ -332,7 +330,6 @@ int cmd_config_device(int argc, const char **argv, void *ctx) int cmd_config_group(int argc, const char **argv, void *ctx) { int i, rc = 0; - unsigned int dev_id, group_id; const struct option options[] = { OPT_UINTEGER('r', "tokens-reserved",
@@ -373,43 +370,17 @@ int cmd_config_group(int argc, const char **argv, void *ctx) }for (i =0 ; i < argc; i++) { -struct accfg_device *device;struct accfg_group *group; -char dev_name[MAX_DEV_LEN ], group_name[MAX_DEV_LEN ]; - -if (strstr (argv[i],"group" ) ==NULL ) { -fprintf (stderr,"need to provide group name\n" ); -return -EINVAL ; - } -/* walk through group */ -if (sscanf (argv[i],"%[^/]/group%u.%u" , dev_name, &dev_id, &group_id) - !=3 ) { +if (parse_group_name (ctx, argv[i],NULL , &group)) {fprintf (stderr, -"'%s' is not a valid group name\n" , argv[i]); -return -EINVAL ; +"%s is not a valid group name\n" , argv[i]); +continue ; } -if (!accfg_device_type_validate (dev_name)) -return -EINVAL ; - rc =sprintf (group_name,"group%u.%u" , dev_id, group_id); + rc =accel_config_parse_group_attribs (group, &group_param);if (rc <0 )return rc; - - accfg_device_foreach(ctx, device) { -if (!util_device_filter (device, dev_name)) -continue ; - - accfg_group_foreach(device, group) { -if (!util_group_filter (group, group_name)) -continue ; - - rc =accel_config_parse_group_attribs (group, - &group_param); -if (rc <0 ) -return rc; - } - } }return 0 ;
@@ -418,7 +389,6 @@ int cmd_config_group(int argc, const char **argv, void *ctx) int cmd_config_wq(int argc, const char **argv, void *ctx) { int i, rc = 0; - unsigned int dev_id = 0, wq_id = 0; const struct option options[] = { OPT_INTEGER('g', "group-id", &wq_param.group_id,
@@ -466,40 +436,16 @@ int cmd_config_wq(int argc, const char **argv, void *ctx)for (i =0 ; i < argc; i++) {struct accfg_device *device;struct accfg_wq *wq; -char dev_name[MAX_DEV_LEN ], wq_name[MAX_DEV_LEN ]; - -/* walk through wq */ -if (strstr (argv[i],"wq" ) !=NULL ) { -if (sscanf (argv[i],"%[^/]/wq%u.%u" , - dev_name, &dev_id, &wq_id) !=3 ) { -fprintf (stderr, -"'%s' is not a valid wq name\n" , - argv[i]); -return -EINVAL ; - } - } -if (!accfg_device_type_validate (dev_name)) -return -EINVAL ; +if (parse_wq_name (ctx, argv[i], &device, &wq)) { +fprintf (stderr, +"%s is not a valid workqueue name\n" , argv[i]); +continue ; + } - rc =sprintf (wq_name,"wq%u.%u" , dev_id, wq_id); + rc =accel_config_parse_wq_attribs (device, wq, &wq_param);if (rc <0 )return rc; - - accfg_device_foreach(ctx, device) { -if (!util_device_filter (device, dev_name)) -continue ; - - accfg_wq_foreach(device, wq) { -if (!util_wq_filter (wq, wq_name)) -continue ; - - rc =accel_config_parse_wq_attribs (device, wq, - &wq_param); -if (rc <0 ) -return rc; - } - } }return 0 ;
@@ -508,7 +454,6 @@ int cmd_config_wq(int argc, const char **argv, void *ctx) int cmd_config_engine(int argc, const char **argv, void *ctx) { int i, rc = 0; - unsigned int dev_id = 0, engine_id = 0; const struct option options[] = { OPT_INTEGER('g', "group-id", &engine_param.group_id,
@@ -538,41 +483,19 @@ int cmd_config_engine(int argc, const char **argv, void *ctx)for (i =0 ; i < argc; i++) {struct accfg_device *device;struct accfg_engine *engine; -char dev_name[MAX_DEV_LEN ], engine_name[MAX_DEV_LEN ]; - -if (strstr (argv[i],"engine" ) !=NULL ) { -if (sscanf (argv[i],"%[^/]/engine%u.%u" , dev_name, &dev_id, - &engine_id) !=3 ) { -fprintf (stderr, -"'%s' is not a valid engine name\n" , - argv[i]); -return -EINVAL ; - } - } -/* walk through engine */ -if (!accfg_device_type_validate (dev_name)) -return -EINVAL ; +if (parse_engine_name (ctx, argv[i], &device, &engine)) { +fprintf (stderr, +"%s is not a valid engine name\n" , argv[i]); +continue ; + } - rc =sprintf (engine_name,"engine%u.%u" , dev_id, engine_id); -if (rc <0 ) + rc =accel_config_parse_engine_attribs (device, + engine, &engine_param); +if (rc !=0 ) { +fprintf (stderr, +"accel_config_parse_engine_attribs failed\n" );return rc; - - accfg_device_foreach(ctx, device) { -if (!util_device_filter (device, dev_name)) -continue ; - - accfg_engine_foreach(device, engine) { -if (!util_engine_filter (engine, engine_name)) -continue ; - rc =accel_config_parse_engine_attribs (device, - engine, &engine_param); -if (rc !=0 ) { -fprintf (stderr, -"accel_config_parse_engine_attribs failed\n" ); -return rc; - } - } } }
accfg/enable.c +36 -66
128 lines not on this page · raw message
Signature · 1 line
2.26.3
ramesh.thomas at intel.com
PATCH 6/8 accel-config: Skip negative fields in listings
In reply to ramesh.thomas at intel.comFrom: Ramesh Thomas <ramesh.thomas(a)intel.com>
Skip printing cdev_minor and group_id if they have negative values indicating they are invalid or are not initialized.
--- util/json.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
util/json.c +12 -8
@@ -429,9 +429,11 @@ struct json_object *util_wq_to_json(struct accfg_wq *wq,json_object_object_add (jaccfg,"size" , jobj); } - jobj =json_object_new_int (accfg_wq_get_group_id (wq)); -if (jobj) -json_object_object_add (jaccfg,"group_id" , jobj); +if (accfg_wq_get_group_id (wq) >=0 ) { + jobj =json_object_new_int (accfg_wq_get_group_id (wq)); +if (jobj) +json_object_object_add (jaccfg,"group_id" , jobj); + } int_val =accfg_wq_get_priority (wq);if (int_val >=0 ) {
@@ -452,7 +454,7 @@ struct json_object *util_wq_to_json(struct accfg_wq *wq,if (jobj)json_object_object_add (jaccfg,"max_transfer_size" , jobj); -if (!(flags &UTIL_JSON_SAVE )) { +if (!(flags &UTIL_JSON_SAVE ) &&accfg_wq_get_cdev_minor (wq) >=0 ) { jobj =json_object_new_int (accfg_wq_get_cdev_minor (wq));if (jobj)json_object_object_add (jaccfg,"cdev_minor" , jobj);
@@ -517,10 +519,12 @@ struct json_object *util_engine_to_json(struct accfg_engine *engine, goto err;json_object_object_add (jaccfg,"dev" , jobj); - jobj =json_object_new_int (accfg_engine_get_group_id (engine)); -if (!jobj) - goto err; -json_object_object_add (jaccfg,"group_id" , jobj); +if (accfg_engine_get_group_id (engine) >=0 ) { + jobj =json_object_new_int (accfg_engine_get_group_id (engine)); +if (!jobj) + goto err; +json_object_object_add (jaccfg,"group_id" , jobj); + }return jaccfg; err:
Signature · 1 line
2.26.3
ramesh.thomas at intel.com
PATCH 7/8 accel-config: Return error if no args
In reply to ramesh.thomas at intel.comFrom: Ramesh Thomas <ramesh.thomas(a)intel.com>
Return an error after displaying an help message if accel-config was run without any argument.
--- accfg/accel-config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accfg/accel-config.c +1 -1
@@ -118,7 +118,7 @@ int main(int argc, const char **argv)/* The user didn't specify a command; give them help */ printf ("\n usage: %s\n\n" , accfg_usage_string);printf ("\n %s\n\n" , accfg_more_info_string); -return 0 ; +return -EINVAL ; } rc =idxd_kmod_init (&kmod_ctx, &mod);
Signature · 1 line
2.26.3
ramesh.thomas at intel.com
PATCH 8/8 accel-config: Do not return error if help was specifically called
In reply to ramesh.thomas at intel.comFrom: Ramesh Thomas <ramesh.thomas(a)intel.com>
Return success when help was specifically requested in commands using the -h and --list-cmds options.
--- util/parse-options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
util/parse-options.c +3 -3
@@ -495,7 +495,7 @@ static int parse_options_subcommand_prefix(int argc, const char **argv,parse_options_start (&ctx, argc, argv, prefix, flags);switch (parse_options_step (&ctx, options, usagestr)) {case PARSE_OPT_HELP : -exit (129 ); +exit (0 );case PARSE_OPT_DONE :break ;case PARSE_OPT_LIST_OPTS :
@@ -503,12 +503,12 @@ static int parse_options_subcommand_prefix(int argc, const char **argv,printf ("--%s " , options->long_name); options++; } -exit (130 ); +exit (0 );case PARSE_OPT_LIST_SUBCMDS :if (subcommands)for (int i =0 ; subcommands[i]; i++)printf ("%s " , subcommands[i]); -exit (130 ); +exit (0 );default :/* PARSE_OPT_UNKNOWN */ if (ctx.argv[0 ][1 ] =='-' ) {error ("unknown option `%s'" , ctx.argv[0 ] +2 );
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>
These patches fixes many of the bugs that were seen due to the addition of iax. While fixing the reqported issues found that the existing code was using assumptions that are obsolete. Many parts of the filter, list, config and enable/disable areas have been rewritten considering latest design changes. This simplifies the implementation and would make future maintenance easier.
More deletion than add. Nice!
Quoted 22 lines
Ramesh Thomas (8):
accel-config: Fix some indentation and coding convention errors
accel-config: Fix wrong return values in functions
accel-config: Rewrite filter functions
accel-config: Rewrite listing functions
accel-config: Rewrite device selection using new filter functions
accel-config: Skip negative fields in listings
accel-config: Return error if no args
accel-config: Do not return error if help was specifically calledaccfg/accel-config.c | 2 +- accfg/config_attr.c | 154 +++++------------- accfg/enable.c | 106 +++++------- accfg/list.c | 278 +++++++++++++++---------------- util/filter.c | 379 +++++++++++++++++++++---------------------- util/filter.h | 42 ++--- util/json.c | 36 ++-- util/json.h | 1 - util/parse-options.c | 6 +- 9 files changed, 436 insertions(+), 568 deletions(-)