accel-config: Replace unsigned long with uint64_t
ramesh.thomas at intel.com
PATCH 1/1 accel-config: Replace unsigned long with uint64_t
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
Makes 64 bit data type portable across 32 bit and 62 bit targets. This fixes compilation errors reported by 32 bit compilers.
---
***Please subscribe to mailing list***
A server error is not allowing me to authorize postings from non-subsribers.
Subsribe here -
https://lists.01.org/postorius/lists/accel-config.lists.01.org/
accfg/config.c | 12 ++++++------ accfg/config_attr.c | 2 +- accfg/enable.c | 2 +- accfg/lib/libaccfg.c | 38 +++++++++++++++++++------------------- accfg/lib/private.h | 10 +++++----- accfg/libaccel_config.h | 18 +++++++++--------- accfg/list.c | 8 ++++---- ccan/endian/endian.h | 2 +- util/bitmap.c | 34 +++++++++++++++++----------------- util/bitmap.h | 18 +++++++++--------- util/filter.h | 2 +- util/json.c | 32 ++++++++++++++++---------------- util/json.h | 18 +++++++++--------- util/size.c | 6 +++--- util/size.h | 12 +++++++----- 15 files changed, 108 insertions(+), 106 deletions(-)
accfg/config.c +6 -6
@@ -32,9 +32,9 @@ static struct config {char *buf; } config; -static unsigned long config_opts_to_flags (void ) +static uint64_t config_opts_to_flags (void ) { -unsigned long flags =0 ; +uint64_t flags =0 ;return flags; }
@@ -47,7 +47,7 @@ struct device_set_table {struct wq_set_table {char *name;int (*set_int_func)(struct accfg_wq *wq,int val); -int (*set_long_func)(struct accfg_wq *wq,unsigned long val); +int (*set_long_func)(struct accfg_wq *wq,uint64_t val);int (*set_str_func)(struct accfg_wq *wq,const char *val);bool (*is_writable)(struct accfg_wq *wq,int val); };
@@ -259,7 +259,7 @@ static int wq_json_set_val(struct accfg_wq *wq, json_object *jobj, char *key)return 0 ; }else if (wq_table[i].set_long_func) { -unsigned long val =json_object_get_int64 (jobj); +uint64_t val =json_object_get_int64 (jobj);if ((val ==0 ) && (errno ==EINVAL ))return -errno;
@@ -563,7 +563,7 @@ static int configure_json_value(struct accfg_ctx *ctx, }static struct json_object *config_group_to_json (struct accfg_group *group, -unsigned long flags) +uint64_t flags) {struct json_object *jgroup =json_object_new_object ();struct json_object *jobj =NULL ;
@@ -819,7 +819,7 @@ static bool filter_group(struct accfg_group *group,struct list_filter_arg *lfa = ctx->list;struct json_object *jgroup;struct json_object *container = lfa->jdevice; -unsigned long group_id; +uint64_t group_id;struct accfg_device *dev =accfg_group_get_device (group);int max_groups =accfg_device_get_max_groups (dev);struct accfg_json_container *jc =NULL , *iter;
accfg/config_attr.c +1 -1
@@ -134,7 +134,7 @@ static int accel_config_parse_wq_attribs(struct accfg_device *device, struct accfg_wq *wq, struct wq_parameters *wq_params) { unsigned int max_groups, max_wq_size, max_batch_size; -unsigned long max_transfer_size; +uint64_t max_transfer_size;int rc =0 ;if (wq_params->mode) {
accfg/enable.c +1 -1
@@ -237,7 +237,7 @@ static int wq_action(int argc, const char **argv, const char *usage, usage, NULL }; -unsigned long dev_id, wq_id; +uint64_t dev_id, wq_id;int i, rc =0 , success =0 , fail =0 , fail_reason =0 ;const char *all ="all" ;enum accfg_wq_state state;
accfg/lib/libaccfg.c +19 -19
@@ -109,7 +109,7 @@ static long accfg_get_param_long(struct accfg_ctx *ctx, int dfd, char *name)return strtol (buf,NULL ,0 ); } -static unsigned long long accfg_get_param_unsigned_llong ( +static uint64_t accfg_get_param_unsigned_llong (struct accfg_ctx *ctx,int dfd,char *name) {int fd =openat (dfd, name,O_RDONLY );
@@ -317,13 +317,13 @@ ACCFG_EXPORT int accfg_new(struct accfg_ctx **ctx) env =secure_getenv ("ACCFG_TIMEOUT" );if (env !=NULL ) { -unsigned long tmo; +uint64_t tmo;char *end; tmo =strtoul (env, &end,0 );if (tmo <ULONG_MAX && !end) c->timeout = tmo; -dbg (c,"timeout = %ld\n" , tmo); +dbg (c,"timeout = %" PRIu64"\n" , tmo); }return 0 ;
@@ -642,7 +642,7 @@ static void *add_wq(void *parent, int id, const char *wq_base,struct accfg_ctx *ctx;char *path;char *wq_base_string; -unsigned long device_id, wq_id; +uint64_t device_id, wq_id;int dfd;char *wq_type;
@@ -678,7 +678,7 @@ static void *add_wq(void *parent, int id, const char *wq_base, }if (sscanf (basename (wq_base_string), -"wq%ld.%ld" , &device_id, &wq_id) !=2 ) { +"wq%" PRIu64".%" PRIu64, &device_id, &wq_id) !=2 ) {close (dfd); goto err_wq; }
@@ -739,7 +739,7 @@ static void *add_group(void *parent, int id, const char *group_base,char *path;char *group_base_string;int dfd; -unsigned long device_id, group_id; +uint64_t device_id, group_id;if (!device)return NULL ;
@@ -770,7 +770,7 @@ static void *add_group(void *parent, int id, const char *group_base, goto err_group; }if (sscanf (basename (group_base_string), -"group%ld.%ld" , &device_id, &group_id) !=2 ) { +"group%" PRIu64".%" PRIu64, &device_id, &group_id) !=2 ) {free (group);close (dfd); goto err_group;
@@ -828,7 +828,7 @@ static void *add_engine(void *parent, int id, const char *engine_base,char *path;char *engine_base_string;int dfd; -unsigned long device_id, engine_id; +uint64_t device_id, engine_id;if (!device)return NULL ;
@@ -861,7 +861,7 @@ static void *add_engine(void *parent, int id, const char *engine_base, goto err_engine; }if (sscanf (basename (engine_base_string), -"engine%ld.%ld" , &device_id, &engine_id) !=2 ) { +"engine%" PRIu64".%" PRIu64, &device_id, &engine_id) !=2 ) {close (dfd);free (path);free (engine);
@@ -1205,19 +1205,19 @@ ACCFG_EXPORT unsigned int accfg_device_get_max_batch_size(return device->max_batch_size; } -ACCFG_EXPORT unsigned long accfg_device_get_max_transfer_size ( +ACCFG_EXPORT uint64_t accfg_device_get_max_transfer_size(struct accfg_device *device) {return device->max_transfer_size; } -ACCFG_EXPORT unsigned long accfg_device_get_op_cap ( +ACCFG_EXPORT uint64_t accfg_device_get_op_cap(struct accfg_device *device) {return device->opcap; } -ACCFG_EXPORT unsigned long accfg_device_get_gen_cap (struct accfg_device *device) +ACCFG_EXPORT uint64_t accfg_device_get_gen_cap(struct accfg_device *device) {return device->gencap; }
@@ -1257,7 +1257,7 @@ ACCFG_EXPORT int accfg_device_get_errors(struct accfg_device *device,return -errno; read_error =accfg_get_param_str (ctx, dfd,"errors" );close (dfd); - rc =sscanf (read_error,"%lx %lx %lx %lx" , + rc =sscanf (read_error,"%" PRIx64" %" PRIx64" %" PRIx64" %" PRIx64, &error->val[0 ], &error->val[1 ], &error->val[2 ], &error->val[3 ]);if (rc <0 ) {
@@ -1626,12 +1626,12 @@ ACCFG_EXPORT const char *accfg_group_get_devname(struct accfg_group *group)return devpath_to_devname (group->group_path); } -ACCFG_EXPORT unsigned long accfg_group_get_size (struct accfg_group *group) +ACCFG_EXPORT uint64_t accfg_group_get_size(struct accfg_group *group) {return group->size; } -ACCFG_EXPORT unsigned long accfg_group_get_available_size ( +ACCFG_EXPORT uint64_t accfg_group_get_available_size(struct accfg_group *group) {struct accfg_ctx *ctx =accfg_group_get_ctx (group);
@@ -1799,7 +1799,7 @@ ACCFG_EXPORT const char *accfg_wq_get_type_name(struct accfg_wq *wq)return wq->name; } -ACCFG_EXPORT unsigned long accfg_wq_get_size (struct accfg_wq *wq) +ACCFG_EXPORT uint64_t accfg_wq_get_size(struct accfg_wq *wq) {return wq->size; }
@@ -1809,7 +1809,7 @@ ACCFG_EXPORT unsigned int accfg_wq_get_max_batch_size(struct accfg_wq *wq)return wq->max_batch_size; } -ACCFG_EXPORT unsigned long accfg_wq_get_max_transfer_size (struct accfg_wq *wq) +ACCFG_EXPORT uint64_t accfg_wq_get_max_transfer_size(struct accfg_wq *wq) {return wq->max_transfer_size; }
@@ -2096,7 +2096,7 @@ accfg_wq_set_field(wq, val, max_batch_size)#define accfg_wq_set_long_field (wq, val, field) \ ACCFG_EXPORT int accfg_wq_set_##field( \ - struct accfg_wq *wq, unsigned long val) \ + struct accfg_wq *wq, uint64_t val) \ { \ struct accfg_ctx *ctx = accfg_wq_get_ctx(wq); \ char *path = wq->wq_buf; \
@@ -2105,7 +2105,7 @@ ACCFG_EXPORT int accfg_wq_set_##field( \ rc = sprintf(wq->wq_buf, "%s/%s", wq->wq_path, #field); \if (rc <0 ) \return -errno; \ -if (sprintf (buf,"%ld" , val) <0 ) { \ +if (sprintf (buf,"%" PRId64, val) <0 ) { \err (ctx,"%s: sprintf to buf failed: %s\n" , \accfg_wq_get_devname (wq), \strerror (errno)); \
accfg/lib/private.h +5 -5
@@ -51,9 +51,9 @@ struct accfg_device {unsigned int token_limit;unsigned int cdev_major;unsigned int version; -unsigned long max_transfer_size; -unsigned long opcap; -unsigned long gencap; +uint64_t max_transfer_size; +uint64_t opcap; +uint64_t gencap;char *pasid_enabled; };
@@ -124,7 +124,7 @@ struct accfg_wq {enum accfg_wq_type type;char *state;unsigned int max_batch_size; -unsigned long max_transfer_size; +uint64_t max_transfer_size; };#define ACCFG_EXPORT __attribute__ ((visibility("default")))
@@ -144,7 +144,7 @@ struct accfg_ctx {int devices_init;int groups_init;struct list_head devices; -unsigned long timeout; +uint64_t timeout;void *private_data; };
accfg/libaccel_config.h +9 -9
@@ -102,7 +102,7 @@ struct wq_parameters {unsigned int priority;int block_on_fault;unsigned int max_batch_size; -unsigned long max_transfer_size; +uint64_t max_transfer_size;const char *mode;const char *type;const char *name;
@@ -167,9 +167,9 @@ unsigned int accfg_device_get_max_work_queues_size(struct accfg_device *device);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); -unsigned long accfg_device_get_max_transfer_size (struct accfg_device *device); -unsigned long accfg_device_get_op_cap (struct accfg_device *device); -unsigned long accfg_device_get_gen_cap (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);bool accfg_device_get_mdev_enabled (struct accfg_device *device);
@@ -213,8 +213,8 @@ struct accfg_group *accfg_device_group_get_by_id(struct accfg_device *device, int id);int accfg_group_get_device_id (struct accfg_group *group);const char *accfg_group_get_devname (struct accfg_group *group); -unsigned long accfg_group_get_size (struct accfg_group *group); -unsigned long accfg_group_get_available_size (struct accfg_group *group); +uint64_t accfg_group_get_size (struct accfg_group *group); +uint64_t accfg_group_get_available_size (struct accfg_group *group);struct accfg_device *accfg_group_get_device (struct accfg_group *group);struct accfg_ctx *accfg_group_get_ctx (struct accfg_group *group);int accfg_group_get_tokens_reserved (struct accfg_group *group);
@@ -247,7 +247,7 @@ struct accfg_wq *accfg_device_wq_get_by_id(struct accfg_device *device, int id);const char *accfg_wq_get_devname (struct accfg_wq *wq);enum accfg_wq_mode accfg_wq_get_mode (struct accfg_wq *wq); -unsigned long accfg_wq_get_size (struct accfg_wq *wq); +uint64_t accfg_wq_get_size (struct accfg_wq *wq);int accfg_wq_get_group_id (struct accfg_wq *wq);int accfg_wq_get_priority (struct accfg_wq *wq);unsigned int accfg_wq_get_priv (struct accfg_wq *wq);
@@ -257,7 +257,7 @@ int accfg_wq_get_cdev_minor(struct accfg_wq *wq);const char *accfg_wq_get_type_name (struct accfg_wq *wq);enum accfg_wq_type accfg_wq_get_type (struct accfg_wq *wq);unsigned int accfg_wq_get_max_batch_size (struct accfg_wq *wq); -unsigned long accfg_wq_get_max_transfer_size (struct accfg_wq *wq); +uint64_t accfg_wq_get_max_transfer_size (struct accfg_wq *wq);int accfg_wq_get_threshold (struct accfg_wq *wq);int accfg_wq_get_clients (struct accfg_wq *wq);int accfg_wq_is_enabled (struct accfg_wq *wq);
@@ -267,7 +267,7 @@ int accfg_wq_set_group_id(struct accfg_wq *wq, int val);int accfg_wq_set_threshold (struct accfg_wq *wq,int val);int accfg_wq_set_block_on_fault (struct accfg_wq *wq,int val);int accfg_wq_set_max_batch_size (struct accfg_wq *wq,int val); -int accfg_wq_set_max_transfer_size (struct accfg_wq *wq,unsigned long val); +int accfg_wq_set_max_transfer_size (struct accfg_wq *wq,uint64_t val);int accfg_wq_set_str_mode (struct accfg_wq *wq,const char * val);int accfg_wq_set_mode (struct accfg_wq *wq,enum accfg_wq_mode mode);int accfg_wq_set_str_type (struct accfg_wq *wq,const char * val);
accfg/list.c +4 -4
@@ -25,9 +25,9 @@ static struct {bool save_conf; } list; -static unsigned long listopts_to_flags (void ) +static uint64_t listopts_to_flags (void ) { -unsigned long flags =0 ; +uint64_t flags =0 ;if (list.idle) flags |=UTIL_JSON_IDLE ;
@@ -50,7 +50,7 @@ do { \ }while (0 ) static struct json_object *group_to_json(struct accfg_group *group, -unsigned long flags) +uint64_t flags) {struct json_object *jgroup =json_object_new_object ();struct json_object *jobj =NULL ;
@@ -249,7 +249,7 @@ static bool filter_engine(struct accfg_engine *engine,static bool filter_group (struct accfg_group *group,struct util_filter_ctx *ctx) { -unsigned long group_id; +uint64_t group_id;struct list_filter_arg *lfa = ctx->list;struct json_object *jgroup;struct json_object *container = lfa->jdevice;
ccan/endian/endian.h +1 -1
@@ -95,7 +95,7 @@ static inline uint32_t bswap_32(uint32_t val)* Example: * // Output contains "1024 is 1125899906842624 as eight bytes reversed" * printf("1024 is %llu as eight bytes reversed\n", -* (unsigned long long)bswap_64(1024)); +* (uint64_t long)bswap_64(1024)); */ static inline uint64_t bswap_64 (uint64_t val) {
util/bitmap.c +17 -17
@@ -22,17 +22,17 @@#include <ccan/minmax/minmax.h> #include <ccan/short_types/short_types.h> -unsigned long *bitmap_alloc (unsigned long nbits) +uint64_t *bitmap_alloc (uint64_t nbits) { -return calloc (BITS_TO_LONGS (nbits),sizeof (unsigned long )); +return calloc (BITS_TO_LONGS (nbits),sizeof (uint64_t )); } -void bitmap_set (unsigned long *map,unsigned int start,int len) +void bitmap_set (uint64_t *map,unsigned int start,int len) { -unsigned long *p = map +BIT_WORD (start); +uint64_t *p = map +BIT_WORD (start);const unsigned int size = start + len;int bits_to_set =BITS_PER_LONG - (start %BITS_PER_LONG ); -unsigned long mask_to_set =BITMAP_FIRST_WORD_MASK (start); +uint64_t mask_to_set =BITMAP_FIRST_WORD_MASK (start);while (len - bits_to_set >=0 ) { *p |= mask_to_set;
@@ -47,12 +47,12 @@ void bitmap_set(unsigned long *map, unsigned int start, int len) } } -void bitmap_clear (unsigned long *map,unsigned int start,int len) +void bitmap_clear (uint64_t *map,unsigned int start,int len) { -unsigned long *p = map +BIT_WORD (start); +uint64_t *p = map +BIT_WORD (start);const unsigned int size = start + len;int bits_to_clear =BITS_PER_LONG - (start %BITS_PER_LONG ); -unsigned long mask_to_clear =BITMAP_FIRST_WORD_MASK (start); +uint64_t mask_to_clear =BITMAP_FIRST_WORD_MASK (start);while (len - bits_to_clear >=0 ) { *p &= ~mask_to_clear;
@@ -72,7 +72,7 @@ void bitmap_clear(unsigned long *map, unsigned int start, int len)* @nr: bit number to test * @addr: Address to start counting from */ -int test_bit (unsigned int nr,const volatile unsigned long *addr) +int test_bit (unsigned int nr,const volatile uint64_t *addr) {return 1UL & (addr[BIT_WORD (nr)] >> (nr & (BITS_PER_LONG -1 ))); }
@@ -82,10 +82,10 @@ int test_bit(unsigned int nr, const volatile unsigned long *addr)* find_next_zero_bit. The difference is the "invert" argument, which * is XORed with each fetched word before searching it for one bits. */ -static unsigned long _find_next_bit (const unsigned long *addr, -unsigned long nbits,unsigned long start,unsigned long invert) +static uint64_t _find_next_bit (const uint64_t *addr, +uint64_t nbits,uint64_t start,uint64_t invert) { -unsigned long tmp; +uint64_t tmp;if (!nbits || start >= nbits)return nbits;
@@ -110,19 +110,19 @@ static unsigned long _find_next_bit(const unsigned long *addr,/* * Find the next set bit in a memory region. */ -unsigned long find_next_bit (const unsigned long *addr,unsigned long size, -unsigned long offset) +uint64_t find_next_bit (const uint64_t *addr,uint64_t size, +uint64_t offset) {return _find_next_bit (addr, size, offset,0UL ); } -unsigned long find_next_zero_bit (const unsigned long *addr,unsigned long size, -unsigned long offset) +uint64_t find_next_zero_bit (const uint64_t *addr,uint64_t size, +uint64_t offset) {return _find_next_bit (addr, size, offset, ~0UL ); } -int bitmap_full (const unsigned long *src,unsigned int nbits) +int bitmap_full (const uint64_t *src,unsigned int nbits) {if (small_const_nbits (nbits))return ! (~(*src) &BITMAP_LAST_WORD_MASK (nbits));
util/bitmap.h +9 -9
@@ -21,15 +21,15 @@#define small_const_nbits (nbits) \ (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) -unsigned long *bitmap_alloc (unsigned long nbits); -void bitmap_set (unsigned long *map,unsigned int start,int len); -void bitmap_clear (unsigned long *map,unsigned int start,int len); -int test_bit (unsigned int nr,const volatile unsigned long *addr); -unsigned long find_next_bit (const unsigned long *addr,unsigned long size, -unsigned long offset); -unsigned long find_next_zero_bit (const unsigned long *addr,unsigned long size, -unsigned long offset); -int bitmap_full (const unsigned long *src,unsigned int nbits); +uint64_t *bitmap_alloc (uint64_t nbits); +void bitmap_set (uint64_t *map,unsigned int start,int len); +void bitmap_clear (uint64_t *map,unsigned int start,int len); +int test_bit (unsigned int nr,const volatile uint64_t *addr); +uint64_t find_next_bit (const uint64_t *addr,uint64_t size, +uint64_t offset); +uint64_t find_next_zero_bit (const uint64_t *addr,uint64_t size, +uint64_t offset); +int bitmap_full (const uint64_t *src,unsigned int nbits);#endif /* _ACCFG_BITMAP_H_ */
util/filter.h +1 -1
@@ -62,7 +62,7 @@ struct list_filter_arg {/* linked list node for each list_filter_arg */ struct list_node list;/* flags to indicate command options */ -unsigned long flags; +uint64_t flags;/* track device number during walk-through */ int dev_num;/* track group_num during walk-through */
util/json.c +16 -16
@@ -27,7 +27,7 @@ static const char *wq_type_str[] = {static int display_size (struct json_object *jobj,struct printbuf *pbuf,int level,int flags) { -unsigned long long bytes =json_object_get_int64 (jobj); +uint64_t bytes =json_object_get_int64 (jobj);static char buf[128 ];int c;
@@ -43,7 +43,7 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,*/ if (bytes <5000 *1024 ) -snprintf (buf,sizeof (buf),"%lld" , bytes); +snprintf (buf,sizeof (buf),"%" PRId64, bytes);else {/* IEC */ if (bytes <2 *1024LL *1024LL *1024LL ) {
@@ -78,14 +78,14 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,static int display_hex (struct json_object *jobj,struct printbuf *pbuf,int level,int flags) { -unsigned long long val =json_object_get_int64 (jobj); +uint64_t val =json_object_get_int64 (jobj);static char buf[32 ]; -snprintf (buf,sizeof (buf),"\"%#llx\"" , val); +snprintf (buf,sizeof (buf),"\"%#" PRIx64"\"" , val);return printbuf_memappend (pbuf, buf,strlen (buf)); } -struct json_object *util_json_object_size (unsigned long long size, -unsigned long flags) +struct json_object *util_json_object_size (uint64_t size, +uint64_t flags) {struct json_object *jobj =json_object_new_int64 (size);
@@ -94,8 +94,8 @@ struct json_object *util_json_object_size(unsigned long long size,return jobj; } -struct json_object *util_json_object_hex (unsigned long long val, -unsigned long flags) +struct json_object *util_json_object_hex (uint64_t val, +uint64_t flags) {struct json_object *jobj =json_object_new_int64 (val);
@@ -106,7 +106,7 @@ struct json_object *util_json_object_hex(unsigned long long val,/* API used to output json object display to console */ void util_display_json_array (FILE * f_out,struct json_object *jarray, -unsigned long flags) +uint64_t flags) {int len =json_object_array_length (jarray);int jflag =JSON_C_TO_STRING_PRETTY ;
@@ -125,7 +125,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, -unsigned long flags) +uint64_t flags) {int len =json_object_array_length (jarray);int jflag =JSON_C_TO_STRING_PRETTY ;
@@ -143,15 +143,15 @@ void __util_display_json_array(FILE * fd, struct json_object *jarray, }struct json_object *util_device_to_json (struct accfg_device *device, -unsigned long flags) +uint64_t flags) {struct json_object *jdevice =json_object_new_object ();struct json_object *jobj;struct accfg_error *error;enum accfg_device_state dev_state;int int_val; -unsigned long ulong_val; -unsigned long long ullong_val; +uint64_t ulong_val; +uint64_t ullong_val;bool new_bool;struct accfg_device_mdev *mdev;struct json_object *json_uuid;
@@ -386,11 +386,11 @@ err: }struct json_object *util_wq_to_json (struct accfg_wq *wq, -unsigned long flags) +uint64_t flags) {struct json_object *jaccfg =json_object_new_object ();struct json_object *jobj =NULL ; -unsigned long size =ULLONG_MAX ; +uint64_t size =ULLONG_MAX ;enum accfg_wq_mode wq_mode;enum accfg_wq_state wq_state;int int_val;
@@ -501,7 +501,7 @@ err: }struct json_object *util_engine_to_json (struct accfg_engine *engine, -unsigned long flags) +uint64_t flags) {struct json_object *jaccfg =json_object_new_object ();struct json_object *jobj =NULL ;
util/json.h +9 -9
@@ -17,17 +17,17 @@ enum util_json_flags {struct json_object ;void util_display_json_array (FILE *f_out,struct json_object *jarray, -unsigned long flags); +uint64_t flags);void __util_display_json_array (FILE *fd,struct json_object *jarray, -unsigned long flags); +uint64_t flags);struct json_object *util_device_to_json (struct accfg_device *device, -unsigned long flags); +uint64_t flags);struct json_object *util_wq_to_json (struct accfg_wq *accfg_wq, -unsigned long flags); +uint64_t flags);struct json_object *util_engine_to_json (struct accfg_engine *accfg_engine, -unsigned long flags); -struct json_object *util_json_object_size (unsigned long long size, -unsigned long flags); -struct json_object *util_json_object_hex (unsigned long long val, -unsigned long flags); +uint64_t flags); +struct json_object *util_json_object_size (uint64_t size, +uint64_t flags); +struct json_object *util_json_object_hex (uint64_t val, +uint64_t flags);#endif /* __ACCFG_JSON_H__ */
util/size.c +3 -3
@@ -5,9 +5,9 @@#include <limits.h> #include <util/size.h> -unsigned long long __parse_size64 (const char *str,unsigned long long *units) +uint64_t __parse_size64 (const char *str,uint64_t *units) { -unsigned long long val, check; +uint64_t val, check;char *end; val =strtoull (str, &end,0 );
@@ -54,7 +54,7 @@ unsigned long long __parse_size64(const char *str, unsigned long long *units)return val; } -unsigned long long parse_size64 (const char *str) +uint64_t parse_size64 (const char *str) {return __parse_size64 (str,NULL ); }
util/size.h +7 -5
@@ -4,6 +4,8 @@#ifndef _ACCFG_SIZE_H_#define _ACCFG_SIZE_H_ +#include <stdint.h> +#define SZ_1K 0x00000400#define SZ_4K 0x00001000#define SZ_1M 0x00100000
@@ -14,12 +16,12 @@#define SZ_1G 0x40000000#define SZ_1T 0x10000000000ULL -unsigned long long parse_size64 (const char *str); -unsigned long long __parse_size64 (const char *str,unsigned long long *units); +uint64_t parse_size64 (const char *str); +uint64_t __parse_size64 (const char *str,uint64_t *units); -#define ALIGN (x, a) ((((unsigned long long) x) + (a - 1)) & ~(a - 1)) -#define ALIGN_DOWN (x, a) (((((unsigned long long) x) + a) & ~(a - 1)) - a) -#define BITS_PER_LONG (sizeof(unsigned long) * 8) +#define ALIGN (x, a) ((((uint64_t) x) + (a - 1)) & ~(a - 1)) +#define ALIGN_DOWN (x, a) (((((uint64_t) x) + a) & ~(a - 1)) - a) +#define BITS_PER_LONG (sizeof(uint64_t) * 8)#define HPAGE_SIZE (2 << 20)#endif /* _ACCFG_SIZE_H_ */
Signature · 1 line
2.26.2
Dave Jiang
Reviewed-by on v1 1/1Quoted 8 lines · ramesh.thomas(a)intel.com
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
Makes 64 bit data type portable across 32 bit and 62 bit targets. This fixes compilation errors reported by 32 bit compilers.
Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>Reported-by Libor Pecháček <lpechacek(a)gmx.com>Reported-by Yunying Sun <yunying.sun(a)intel.com>
Quoted 746 lines
---
***Please subscribe to mailing list***
A server error is not allowing me to authorize postings from non-subsribers.
Subsribe here -
https://lists.01.org/postorius/lists/accel-config.lists.01.org/accfg/config.c | 12 ++++++------ accfg/config_attr.c | 2 +- accfg/enable.c | 2 +- accfg/lib/libaccfg.c | 38 +++++++++++++++++++------------------- accfg/lib/private.h | 10 +++++----- accfg/libaccel_config.h | 18 +++++++++--------- accfg/list.c | 8 ++++---- ccan/endian/endian.h | 2 +- util/bitmap.c | 34 +++++++++++++++++----------------- util/bitmap.h | 18 +++++++++--------- util/filter.h | 2 +- util/json.c | 32 ++++++++++++++++---------------- util/json.h | 18 +++++++++--------- util/size.c | 6 +++--- util/size.h | 12 +++++++----- 15 files changed, 108 insertions(+), 106 deletions(-)accfg/config.c +6
-6@@ -32,9 +32,9 @@ static struct config {char *buf; } config; -static unsigned long config_opts_to_flags (void ) +static uint64_t config_opts_to_flags (void ) { -unsigned long flags =0 ; +uint64_t flags =0 ;return flags; }@@ -47,7 +47,7 @@ struct device_set_table {struct wq_set_table {char *name;int (*set_int_func)(struct accfg_wq *wq,int val); -int (*set_long_func)(struct accfg_wq *wq,unsigned long val); +int (*set_long_func)(struct accfg_wq *wq,uint64_t val);int (*set_str_func)(struct accfg_wq *wq,const char *val);bool (*is_writable)(struct accfg_wq *wq,int val); };@@ -259,7 +259,7 @@ static int wq_json_set_val(struct accfg_wq *wq, json_object *jobj, char *key)return 0 ; }else if (wq_table[i].set_long_func) { -unsigned long val =json_object_get_int64 (jobj); +uint64_t val =json_object_get_int64 (jobj);if ((val ==0 ) && (errno ==EINVAL ))return -errno;@@ -563,7 +563,7 @@ static int configure_json_value(struct accfg_ctx *ctx, }static struct json_object *config_group_to_json (struct accfg_group *group, -unsigned long flags) +uint64_t flags) {struct json_object *jgroup =json_object_new_object ();struct json_object *jobj =NULL ;@@ -819,7 +819,7 @@ static bool filter_group(struct accfg_group *group,struct list_filter_arg *lfa = ctx->list;struct json_object *jgroup;struct json_object *container = lfa->jdevice; -unsigned long group_id; +uint64_t group_id;struct accfg_device *dev =accfg_group_get_device (group);int max_groups =accfg_device_get_max_groups (dev);struct accfg_json_container *jc =NULL , *iter;accfg/config_attr.c +1
-1@@ -134,7 +134,7 @@ static int accel_config_parse_wq_attribs(struct accfg_device *device, struct accfg_wq *wq, struct wq_parameters *wq_params) { unsigned int max_groups, max_wq_size, max_batch_size; -unsigned long max_transfer_size; +uint64_t max_transfer_size;int rc =0 ;if (wq_params->mode) {accfg/enable.c +1
-1@@ -237,7 +237,7 @@ static int wq_action(int argc, const char **argv, const char *usage, usage, NULL }; -unsigned long dev_id, wq_id; +uint64_t dev_id, wq_id;int i, rc =0 , success =0 , fail =0 , fail_reason =0 ;const char *all ="all" ;enum accfg_wq_state state;accfg/lib/libaccfg.c +19
-19@@ -109,7 +109,7 @@ static long accfg_get_param_long(struct accfg_ctx *ctx, int dfd, char *name)return strtol (buf,NULL ,0 ); } -static unsigned long long accfg_get_param_unsigned_llong ( +static uint64_t accfg_get_param_unsigned_llong (struct accfg_ctx *ctx,int dfd,char *name) {int fd =openat (dfd, name,O_RDONLY );@@ -317,13 +317,13 @@ ACCFG_EXPORT int accfg_new(struct accfg_ctx **ctx) env =secure_getenv ("ACCFG_TIMEOUT" );if (env !=NULL ) { -unsigned long tmo; +uint64_t tmo;char *end; tmo =strtoul (env, &end,0 );if (tmo <ULONG_MAX && !end) c->timeout = tmo; -dbg (c,"timeout = %ld\n" , tmo); +dbg (c,"timeout = %" PRIu64"\n" , tmo); }return 0 ;@@ -642,7 +642,7 @@ static void *add_wq(void *parent, int id, const char *wq_base,struct accfg_ctx *ctx;char *path;char *wq_base_string; -unsigned long device_id, wq_id; +uint64_t device_id, wq_id;int dfd;char *wq_type;@@ -678,7 +678,7 @@ static void *add_wq(void *parent, int id, const char *wq_base, }if (sscanf (basename (wq_base_string), -"wq%ld.%ld" , &device_id, &wq_id) !=2 ) { +"wq%" PRIu64".%" PRIu64, &device_id, &wq_id) !=2 ) {close (dfd); goto err_wq; }@@ -739,7 +739,7 @@ static void *add_group(void *parent, int id, const char *group_base,char *path;char *group_base_string;int dfd; -unsigned long device_id, group_id; +uint64_t device_id, group_id;if (!device)return NULL ;@@ -770,7 +770,7 @@ static void *add_group(void *parent, int id, const char *group_base, goto err_group; }if (sscanf (basename (group_base_string), -"group%ld.%ld" , &device_id, &group_id) !=2 ) { +"group%" PRIu64".%" PRIu64, &device_id, &group_id) !=2 ) {free (group);close (dfd); goto err_group;@@ -828,7 +828,7 @@ static void *add_engine(void *parent, int id, const char *engine_base,char *path;char *engine_base_string;int dfd; -unsigned long device_id, engine_id; +uint64_t device_id, engine_id;if (!device)return NULL ;@@ -861,7 +861,7 @@ static void *add_engine(void *parent, int id, const char *engine_base, goto err_engine; }if (sscanf (basename (engine_base_string), -"engine%ld.%ld" , &device_id, &engine_id) !=2 ) { +"engine%" PRIu64".%" PRIu64, &device_id, &engine_id) !=2 ) {close (dfd);free (path);free (engine);@@ -1205,19 +1205,19 @@ ACCFG_EXPORT unsigned int accfg_device_get_max_batch_size(return device->max_batch_size; } -ACCFG_EXPORT unsigned long accfg_device_get_max_transfer_size ( +ACCFG_EXPORT uint64_t accfg_device_get_max_transfer_size(struct accfg_device *device) {return device->max_transfer_size; } -ACCFG_EXPORT unsigned long accfg_device_get_op_cap ( +ACCFG_EXPORT uint64_t accfg_device_get_op_cap(struct accfg_device *device) {return device->opcap; } -ACCFG_EXPORT unsigned long accfg_device_get_gen_cap (struct accfg_device *device) +ACCFG_EXPORT uint64_t accfg_device_get_gen_cap(struct accfg_device *device) {return device->gencap; }@@ -1257,7 +1257,7 @@ ACCFG_EXPORT int accfg_device_get_errors(struct accfg_device *device,return -errno; read_error =accfg_get_param_str (ctx, dfd,"errors" );close (dfd); - rc =sscanf (read_error,"%lx %lx %lx %lx" , + rc =sscanf (read_error,"%" PRIx64" %" PRIx64" %" PRIx64" %" PRIx64, &error->val[0 ], &error->val[1 ], &error->val[2 ], &error->val[3 ]);if (rc <0 ) {@@ -1626,12 +1626,12 @@ ACCFG_EXPORT const char *accfg_group_get_devname(struct accfg_group *group)return devpath_to_devname (group->group_path); } -ACCFG_EXPORT unsigned long accfg_group_get_size (struct accfg_group *group) +ACCFG_EXPORT uint64_t accfg_group_get_size(struct accfg_group *group) {return group->size; } -ACCFG_EXPORT unsigned long accfg_group_get_available_size ( +ACCFG_EXPORT uint64_t accfg_group_get_available_size(struct accfg_group *group) {struct accfg_ctx *ctx =accfg_group_get_ctx (group);@@ -1799,7 +1799,7 @@ ACCFG_EXPORT const char *accfg_wq_get_type_name(struct accfg_wq *wq)return wq->name; } -ACCFG_EXPORT unsigned long accfg_wq_get_size (struct accfg_wq *wq) +ACCFG_EXPORT uint64_t accfg_wq_get_size(struct accfg_wq *wq) {return wq->size; }@@ -1809,7 +1809,7 @@ ACCFG_EXPORT unsigned int accfg_wq_get_max_batch_size(struct accfg_wq *wq)return wq->max_batch_size; } -ACCFG_EXPORT unsigned long accfg_wq_get_max_transfer_size (struct accfg_wq *wq) +ACCFG_EXPORT uint64_t accfg_wq_get_max_transfer_size(struct accfg_wq *wq) {return wq->max_transfer_size; }@@ -2096,7 +2096,7 @@ accfg_wq_set_field(wq, val, max_batch_size)#define accfg_wq_set_long_field (wq, val, field) \ ACCFG_EXPORT int accfg_wq_set_##field( \ - struct accfg_wq *wq, unsigned long val) \ + struct accfg_wq *wq, uint64_t val) \ { \ struct accfg_ctx *ctx = accfg_wq_get_ctx(wq); \ char *path = wq->wq_buf; \@@ -2105,7 +2105,7 @@ ACCFG_EXPORT int accfg_wq_set_##field( \ rc = sprintf(wq->wq_buf, "%s/%s", wq->wq_path, #field); \if (rc <0 ) \return -errno; \ -if (sprintf (buf,"%ld" , val) <0 ) { \ +if (sprintf (buf,"%" PRId64, val) <0 ) { \err (ctx,"%s: sprintf to buf failed: %s\n" , \accfg_wq_get_devname (wq), \strerror (errno)); \accfg/lib/private.h +5
-5@@ -51,9 +51,9 @@ struct accfg_device {unsigned int token_limit;unsigned int cdev_major;unsigned int version; -unsigned long max_transfer_size; -unsigned long opcap; -unsigned long gencap; +uint64_t max_transfer_size; +uint64_t opcap; +uint64_t gencap;char *pasid_enabled; };@@ -124,7 +124,7 @@ struct accfg_wq {enum accfg_wq_type type;char *state;unsigned int max_batch_size; -unsigned long max_transfer_size; +uint64_t max_transfer_size; };#define ACCFG_EXPORT __attribute__ ((visibility("default")))@@ -144,7 +144,7 @@ struct accfg_ctx {int devices_init;int groups_init;struct list_head devices; -unsigned long timeout; +uint64_t timeout;void *private_data; };accfg/libaccel_config.h +9
-9@@ -102,7 +102,7 @@ struct wq_parameters {unsigned int priority;int block_on_fault;unsigned int max_batch_size; -unsigned long max_transfer_size; +uint64_t max_transfer_size;const char *mode;const char *type;const char *name;@@ -167,9 +167,9 @@ unsigned int accfg_device_get_max_work_queues_size(struct accfg_device *device);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); -unsigned long accfg_device_get_max_transfer_size (struct accfg_device *device); -unsigned long accfg_device_get_op_cap (struct accfg_device *device); -unsigned long accfg_device_get_gen_cap (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);bool accfg_device_get_mdev_enabled (struct accfg_device *device);@@ -213,8 +213,8 @@ struct accfg_group *accfg_device_group_get_by_id(struct accfg_device *device, int id);int accfg_group_get_device_id (struct accfg_group *group);const char *accfg_group_get_devname (struct accfg_group *group); -unsigned long accfg_group_get_size (struct accfg_group *group); -unsigned long accfg_group_get_available_size (struct accfg_group *group); +uint64_t accfg_group_get_size (struct accfg_group *group); +uint64_t accfg_group_get_available_size (struct accfg_group *group);struct accfg_device *accfg_group_get_device (struct accfg_group *group);struct accfg_ctx *accfg_group_get_ctx (struct accfg_group *group);int accfg_group_get_tokens_reserved (struct accfg_group *group);@@ -247,7 +247,7 @@ struct accfg_wq *accfg_device_wq_get_by_id(struct accfg_device *device, int id);const char *accfg_wq_get_devname (struct accfg_wq *wq);enum accfg_wq_mode accfg_wq_get_mode (struct accfg_wq *wq); -unsigned long accfg_wq_get_size (struct accfg_wq *wq); +uint64_t accfg_wq_get_size (struct accfg_wq *wq);int accfg_wq_get_group_id (struct accfg_wq *wq);int accfg_wq_get_priority (struct accfg_wq *wq);unsigned int accfg_wq_get_priv (struct accfg_wq *wq);@@ -257,7 +257,7 @@ int accfg_wq_get_cdev_minor(struct accfg_wq *wq);const char *accfg_wq_get_type_name (struct accfg_wq *wq);enum accfg_wq_type accfg_wq_get_type (struct accfg_wq *wq);unsigned int accfg_wq_get_max_batch_size (struct accfg_wq *wq); -unsigned long accfg_wq_get_max_transfer_size (struct accfg_wq *wq); +uint64_t accfg_wq_get_max_transfer_size (struct accfg_wq *wq);int accfg_wq_get_threshold (struct accfg_wq *wq);int accfg_wq_get_clients (struct accfg_wq *wq);int accfg_wq_is_enabled (struct accfg_wq *wq);@@ -267,7 +267,7 @@ int accfg_wq_set_group_id(struct accfg_wq *wq, int val);int accfg_wq_set_threshold (struct accfg_wq *wq,int val);int accfg_wq_set_block_on_fault (struct accfg_wq *wq,int val);int accfg_wq_set_max_batch_size (struct accfg_wq *wq,int val); -int accfg_wq_set_max_transfer_size (struct accfg_wq *wq,unsigned long val); +int accfg_wq_set_max_transfer_size (struct accfg_wq *wq,uint64_t val);int accfg_wq_set_str_mode (struct accfg_wq *wq,const char * val);int accfg_wq_set_mode (struct accfg_wq *wq,enum accfg_wq_mode mode);int accfg_wq_set_str_type (struct accfg_wq *wq,const char * val);accfg/list.c +4
-4@@ -25,9 +25,9 @@ static struct {bool save_conf; } list; -static unsigned long listopts_to_flags (void ) +static uint64_t listopts_to_flags (void ) { -unsigned long flags =0 ; +uint64_t flags =0 ;if (list.idle) flags |=UTIL_JSON_IDLE ;@@ -50,7 +50,7 @@ do { \ }while (0 ) static struct json_object *group_to_json(struct accfg_group *group, -unsigned long flags) +uint64_t flags) {struct json_object *jgroup =json_object_new_object ();struct json_object *jobj =NULL ;@@ -249,7 +249,7 @@ static bool filter_engine(struct accfg_engine *engine,static bool filter_group (struct accfg_group *group,struct util_filter_ctx *ctx) { -unsigned long group_id; +uint64_t group_id;struct list_filter_arg *lfa = ctx->list;struct json_object *jgroup;struct json_object *container = lfa->jdevice;ccan/endian/endian.h +1
-1@@ -95,7 +95,7 @@ static inline uint32_t bswap_32(uint32_t val)* Example: * // Output contains "1024 is 1125899906842624 as eight bytes reversed" * printf("1024 is %llu as eight bytes reversed\n", -* (unsigned long long)bswap_64(1024)); +* (uint64_t long)bswap_64(1024)); */ static inline uint64_t bswap_64 (uint64_t val) {util/bitmap.c +17
-17@@ -22,17 +22,17 @@#include <ccan/minmax/minmax.h> #include <ccan/short_types/short_types.h> -unsigned long *bitmap_alloc (unsigned long nbits) +uint64_t *bitmap_alloc (uint64_t nbits) { -return calloc (BITS_TO_LONGS (nbits),sizeof (unsigned long )); +return calloc (BITS_TO_LONGS (nbits),sizeof (uint64_t )); } -void bitmap_set (unsigned long *map,unsigned int start,int len) +void bitmap_set (uint64_t *map,unsigned int start,int len) { -unsigned long *p = map +BIT_WORD (start); +uint64_t *p = map +BIT_WORD (start);const unsigned int size = start + len;int bits_to_set =BITS_PER_LONG - (start %BITS_PER_LONG ); -unsigned long mask_to_set =BITMAP_FIRST_WORD_MASK (start); +uint64_t mask_to_set =BITMAP_FIRST_WORD_MASK (start);while (len - bits_to_set >=0 ) { *p |= mask_to_set;@@ -47,12 +47,12 @@ void bitmap_set(unsigned long *map, unsigned int start, int len) } } -void bitmap_clear (unsigned long *map,unsigned int start,int len) +void bitmap_clear (uint64_t *map,unsigned int start,int len) { -unsigned long *p = map +BIT_WORD (start); +uint64_t *p = map +BIT_WORD (start);const unsigned int size = start + len;int bits_to_clear =BITS_PER_LONG - (start %BITS_PER_LONG ); -unsigned long mask_to_clear =BITMAP_FIRST_WORD_MASK (start); +uint64_t mask_to_clear =BITMAP_FIRST_WORD_MASK (start);while (len - bits_to_clear >=0 ) { *p &= ~mask_to_clear;@@ -72,7 +72,7 @@ void bitmap_clear(unsigned long *map, unsigned int start, int len)* @nr: bit number to test * @addr: Address to start counting from */ -int test_bit (unsigned int nr,const volatile unsigned long *addr) +int test_bit (unsigned int nr,const volatile uint64_t *addr) {return 1UL & (addr[BIT_WORD (nr)] >> (nr & (BITS_PER_LONG -1 ))); }@@ -82,10 +82,10 @@ int test_bit(unsigned int nr, const volatile unsigned long *addr)* find_next_zero_bit. The difference is the "invert" argument, which * is XORed with each fetched word before searching it for one bits. */ -static unsigned long _find_next_bit (const unsigned long *addr, -unsigned long nbits,unsigned long start,unsigned long invert) +static uint64_t _find_next_bit (const uint64_t *addr, +uint64_t nbits,uint64_t start,uint64_t invert) { -unsigned long tmp; +uint64_t tmp;if (!nbits || start >= nbits)return nbits;@@ -110,19 +110,19 @@ static unsigned long _find_next_bit(const unsigned long *addr,/* * Find the next set bit in a memory region. */ -unsigned long find_next_bit (const unsigned long *addr,unsigned long size, -unsigned long offset) +uint64_t find_next_bit (const uint64_t *addr,uint64_t size, +uint64_t offset) {return _find_next_bit (addr, size, offset,0UL ); } -unsigned long find_next_zero_bit (const unsigned long *addr,unsigned long size, -unsigned long offset) +uint64_t find_next_zero_bit (const uint64_t *addr,uint64_t size, +uint64_t offset) {return _find_next_bit (addr, size, offset, ~0UL ); } -int bitmap_full (const unsigned long *src,unsigned int nbits) +int bitmap_full (const uint64_t *src,unsigned int nbits) {if (small_const_nbits (nbits))return ! (~(*src) &BITMAP_LAST_WORD_MASK (nbits));util/bitmap.h +9
-9@@ -21,15 +21,15 @@#define small_const_nbits (nbits) \ (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) -unsigned long *bitmap_alloc (unsigned long nbits); -void bitmap_set (unsigned long *map,unsigned int start,int len); -void bitmap_clear (unsigned long *map,unsigned int start,int len); -int test_bit (unsigned int nr,const volatile unsigned long *addr); -unsigned long find_next_bit (const unsigned long *addr,unsigned long size, -unsigned long offset); -unsigned long find_next_zero_bit (const unsigned long *addr,unsigned long size, -unsigned long offset); -int bitmap_full (const unsigned long *src,unsigned int nbits); +uint64_t *bitmap_alloc (uint64_t nbits); +void bitmap_set (uint64_t *map,unsigned int start,int len); +void bitmap_clear (uint64_t *map,unsigned int start,int len); +int test_bit (unsigned int nr,const volatile uint64_t *addr); +uint64_t find_next_bit (const uint64_t *addr,uint64_t size, +uint64_t offset); +uint64_t find_next_zero_bit (const uint64_t *addr,uint64_t size, +uint64_t offset); +int bitmap_full (const uint64_t *src,unsigned int nbits);#endif /* _ACCFG_BITMAP_H_ */ util/filter.h +1
-1@@ -62,7 +62,7 @@ struct list_filter_arg {/* linked list node for each list_filter_arg */ struct list_node list;/* flags to indicate command options */ -unsigned long flags; +uint64_t flags;/* track device number during walk-through */ int dev_num;/* track group_num during walk-through */ util/json.c +16
-16@@ -27,7 +27,7 @@ static const char *wq_type_str[] = {static int display_size (struct json_object *jobj,struct printbuf *pbuf,int level,int flags) { -unsigned long long bytes =json_object_get_int64 (jobj); +uint64_t bytes =json_object_get_int64 (jobj);static char buf[128 ];int c;@@ -43,7 +43,7 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,*/ if (bytes <5000 *1024 ) -snprintf (buf,sizeof (buf),"%lld" , bytes); +snprintf (buf,sizeof (buf),"%" PRId64, bytes);else {/* IEC */ if (bytes <2 *1024LL *1024LL *1024LL ) {@@ -78,14 +78,14 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,static int display_hex (struct json_object *jobj,struct printbuf *pbuf,int level,int flags) { -unsigned long long val =json_object_get_int64 (jobj); +uint64_t val =json_object_get_int64 (jobj);static char buf[32 ]; -snprintf (buf,sizeof (buf),"\"%#llx\"" , val); +snprintf (buf,sizeof (buf),"\"%#" PRIx64"\"" , val);return printbuf_memappend (pbuf, buf,strlen (buf)); } -struct json_object *util_json_object_size (unsigned long long size, -unsigned long flags) +struct json_object *util_json_object_size (uint64_t size, +uint64_t flags) {struct json_object *jobj =json_object_new_int64 (size);@@ -94,8 +94,8 @@ struct json_object *util_json_object_size(unsigned long long size,return jobj; } -struct json_object *util_json_object_hex (unsigned long long val, -unsigned long flags) +struct json_object *util_json_object_hex (uint64_t val, +uint64_t flags) {struct json_object *jobj =json_object_new_int64 (val);@@ -106,7 +106,7 @@ struct json_object *util_json_object_hex(unsigned long long val,/* API used to output json object display to console */ void util_display_json_array (FILE * f_out,struct json_object *jarray, -unsigned long flags) +uint64_t flags) {int len =json_object_array_length (jarray);int jflag =JSON_C_TO_STRING_PRETTY ;@@ -125,7 +125,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, -unsigned long flags) +uint64_t flags) {int len =json_object_array_length (jarray);int jflag =JSON_C_TO_STRING_PRETTY ;@@ -143,15 +143,15 @@ void __util_display_json_array(FILE * fd, struct json_object *jarray, }struct json_object *util_device_to_json (struct accfg_device *device, -unsigned long flags) +uint64_t flags) {struct json_object *jdevice =json_object_new_object ();struct json_object *jobj;struct accfg_error *error;enum accfg_device_state dev_state;int int_val; -unsigned long ulong_val; -unsigned long long ullong_val; +uint64_t ulong_val; +uint64_t ullong_val;bool new_bool;struct accfg_device_mdev *mdev;struct json_object *json_uuid;@@ -386,11 +386,11 @@ err: }struct json_object *util_wq_to_json (struct accfg_wq *wq, -unsigned long flags) +uint64_t flags) {struct json_object *jaccfg =json_object_new_object ();struct json_object *jobj =NULL ; -unsigned long size =ULLONG_MAX ; +uint64_t size =ULLONG_MAX ;enum accfg_wq_mode wq_mode;enum accfg_wq_state wq_state;int int_val;@@ -501,7 +501,7 @@ err: }struct json_object *util_engine_to_json (struct accfg_engine *engine, -unsigned long flags) +uint64_t flags) {struct json_object *jaccfg =json_object_new_object ();struct json_object *jobj =NULL ;util/json.h +9
-9@@ -17,17 +17,17 @@ enum util_json_flags {struct json_object ;void util_display_json_array (FILE *f_out,struct json_object *jarray, -unsigned long flags); +uint64_t flags);void __util_display_json_array (FILE *fd,struct json_object *jarray, -unsigned long flags); +uint64_t flags);struct json_object *util_device_to_json (struct accfg_device *device, -unsigned long flags); +uint64_t flags);struct json_object *util_wq_to_json (struct accfg_wq *accfg_wq, -unsigned long flags); +uint64_t flags);struct json_object *util_engine_to_json (struct accfg_engine *accfg_engine, -unsigned long flags); -struct json_object *util_json_object_size (unsigned long long size, -unsigned long flags); -struct json_object *util_json_object_hex (unsigned long long val, -unsigned long flags); +uint64_t flags); +struct json_object *util_json_object_size (uint64_t size, +uint64_t flags); +struct json_object *util_json_object_hex (uint64_t val, +uint64_t flags);#endif /* __ACCFG_JSON_H__ */ util/size.c +3
-3@@ -5,9 +5,9 @@#include <limits.h> #include <util/size.h> -unsigned long long __parse_size64 (const char *str,unsigned long long *units) +uint64_t __parse_size64 (const char *str,uint64_t *units) { -unsigned long long val, check; +uint64_t val, check;char *end; val =strtoull (str, &end,0 );@@ -54,7 +54,7 @@ unsigned long long __parse_size64(const char *str, unsigned long long *units)return val; } -unsigned long long parse_size64 (const char *str) +uint64_t parse_size64 (const char *str) {return __parse_size64 (str,NULL ); }util/size.h +7
-5@@ -4,6 +4,8 @@#ifndef _ACCFG_SIZE_H_#define _ACCFG_SIZE_H_ +#include <stdint.h> +#define SZ_1K 0x00000400#define SZ_4K 0x00001000#define SZ_1M 0x00100000@@ -14,12 +16,12 @@#define SZ_1G 0x40000000#define SZ_1T 0x10000000000ULL -unsigned long long parse_size64 (const char *str); -unsigned long long __parse_size64 (const char *str,unsigned long long *units); +uint64_t parse_size64 (const char *str); +uint64_t __parse_size64 (const char *str,uint64_t *units); -#define ALIGN (x, a) ((((unsigned long long) x) + (a - 1)) & ~(a - 1)) -#define ALIGN_DOWN (x, a) (((((unsigned long long) x) + a) & ~(a - 1)) - a) -#define BITS_PER_LONG (sizeof(unsigned long) * 8) +#define ALIGN (x, a) ((((uint64_t) x) + (a - 1)) & ~(a - 1)) +#define ALIGN_DOWN (x, a) (((((uint64_t) x) + a) & ~(a - 1)) - a) +#define BITS_PER_LONG (sizeof(uint64_t) * 8)#define HPAGE_SIZE (2 << 20)#endif /* _ACCFG_SIZE_H_ */
Libor Pechacek
Acked-by Libor Pecháček on v1 1/1Thanks for CCing me on the patch, Ramesh!
Quoted 7 lines · ramesh.thomas(a)intel.com
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
Makes 64 bit data type portable across 32 bit and 62 bit targets. This fixes compilation errors reported by 32 bit compilers.
Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>Reported-by Libor Pecháček <lpechacek(a)gmx.com>
Feel free to use my lpechacek(a)suse.cz address in this patch. I'm using the GMX one for my spare-time opensource involvement.
[...]
Review static void *add_wq(void *parent, int id, const char *wq_base, · line 681
Quoted 6 lines
(quoted diff) +1
-1@@ -678,7 +678,7 @@ static void *add_wq(void *parent, int id, const char *wq_base, } if (sscanf(basename(wq_base_string), - "wq%ld.%ld", &device_id, &wq_id) != 2) { + "wq%" PRIu64 ".%" PRIu64, &device_id, &wq_id) != 2) {
^^^^^^
Just a nit. I know that the resulting format string is the same in this case but aren't SCN* macros intended for use with *scanf functions?
In addition, GCC 10 on openSUSE reported about a few more places which would benefit from the portable formatting strings. Otherwise,
Thanks!
Libor
accfg/config_attr.c +2 -1
@@ -3,6 +3,7 @@#include <stdio.h> #include <errno.h> +#include <inttypes.h> #include <stdlib.h> #include <time.h> #include <json-c/json.h>
@@ -184,7 +185,7 @@ static int accel_config_parse_wq_attribs || wq_params->max_transfer_size > max_transfer_size) && (wq_params->max_transfer_size != INT_MAX)) {fprintf (stderr, -"valid max-transfer-size should be 1 to %ld\n" , max_transfer_size); +"valid max-transfer-size should be 1 to %" PRIu64"\n" , max_transfer_size);return -EINVAL ; }
accfg/enable.c +3 -2
@@ -3,6 +3,7 @@#include <stdio.h> #include <errno.h> +#include <inttypes.h> #include <stdlib.h> #include <time.h> #include <json-c/json.h>
@@ -263,7 +264,7 @@ static int wq_action(int argc, const chachar dev_name[MAX_DEV_LEN ], wq_name[MAX_DEV_LEN ];int found =0 ; -if (sscanf (argv[i],"%[^/]/wq%lu.%lu" , dev_name, &dev_id, &wq_id) !=3 ) { +if (sscanf (argv[i],"%[^/]/wq%" SCNu64".%" SCNu64, dev_name, &dev_id, &wq_id) !=3 ) {fprintf (stderr,"'%s' is not a valid wq name\n" , argv[i]);return -EINVAL ;
@@ -272,7 +273,7 @@ static int wq_action(int argc, const chaif (!accfg_device_type_validate (dev_name))return -EINVAL ; - rc =sprintf (wq_name,"wq%lu.%lu" , dev_id, wq_id); + rc =sprintf (wq_name,"wq%" PRIu64".%" PRIu64, dev_id, wq_id);if (rc <0 )return errno;
Signature · 2 lines
Libor Pechacek SUSE Labs Remember to have fun...
Thomas
Hi Libor,
Thanks for reviewing. I will change to "SCN" in sscanfs as well as change the places that were missed.
-Ramesh
Quoted 91 lines · Libor Pechacek
Thanks for CCing me on the patch, Ramesh!
Quoted 7 lines · ramesh.thomas(a)intel.com
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
Makes 64 bit data type portable across 32 bit and 62 bit targets. This fixes compilation errors reported by 32 bit compilers.
Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>Reported-by Libor Pecháček <lpechacek(a)gmx.com>Feel free to use my lpechacek(a)suse.cz address in this patch. I'm using the GMX one for my spare-time opensource involvement.
[...]
Review static void *add_wq(void *parent, int id, const char *wq_base, · line 681
Quoted 6 lines
(quoted diff) +1
-1@@ -678,7 +678,7 @@ static void *add_wq(void *parent, int id, const char *wq_base, } if (sscanf(basename(wq_base_string), - "wq%ld.%ld", &device_id, &wq_id) != 2) { + "wq%" PRIu64 ".%" PRIu64, &device_id, &wq_id) != 2) {^^^^^^Just a nit. I know that the resulting format string is the same in this case but aren't SCN* macros intended for use with *scanf functions?
In addition, GCC 10 on openSUSE reported about a few more places which would benefit from the portable formatting strings. Otherwise,
Acked-by Libor Pecháček <lpechacek(a)suse.cz>Thanks!
Libor
Index:
idxd-config-accel-config-v3.0.1/accfg/config_attr.c
===================================================================accfg/config_attr.c +2
-1@@ -3,6 +3,7 @@#include <stdio.h> #include <errno.h> +#include <inttypes.h> #include <stdlib.h> #include <time.h> #include <json-c/json.h> @@ -184,7 +185,7 @@ static int accel_config_parse_wq_attribs || wq_params->max_transfer_size > max_transfer_size) && (wq_params->max_transfer_size != INT_MAX)) {fprintf (stderr, -"valid max-transfer-size should be 1 to %ld\n" , max_transfer_size); +"valid max-transfer-size should be 1 to %" PRIu64"\n" , max_transfer_size);return -EINVAL ; }Index:
idxd-config-accel-config-v3.0.1/accfg/enable.c
===================================================================accfg/enable.c +2
-1@@ -3,6 +3,7 @@#include <stdio.h> #include <errno.h> +#include <inttypes.h> #include <stdlib.h> #include <time.h> #include <json-c/json.h> @@ -263,7 +264,7 @@ static int wq_action(int argc, const chachar dev_name[MAX_DEV_LEN ], wq_name[MAX_DEV_LEN ];int found =0 ; -if (sscanf (argv[i],"%[^/]/wq%lu.%lu" , dev_name, &dev_id, &wq_id) !=3 ) { +if (sscanf (argv[i],"%[^/]/wq%" SCNu64".%" SCNu64, dev_name, &dev_id, &wq_id) !=3 ) {fprintf (stderr,"'%s' is not a valid wq name\n" , argv[i]);accfg/enable.c +1
-2return -EINVAL ;@@ -272,7 +273,7 @@ static int wq_action(int argc, const chaif (!accfg_device_type_validate (dev_name))return -EINVAL ; - rc =sprintf (wq_name,"wq%lu.%lu" , dev_id, wq_id); + rc =sprintf (wq_name,"wq%" PRIu64".%" PRIu64, dev_id, wq_id);if (rc <0 )return errno; --Libor Pechacek
SUSE Labs Remember to have fun...