Skip to content

Commit

Permalink
chore: update and run clang
Browse files Browse the repository at this point in the history
Signed-off-by: Maryam Tahhan <[email protected]>
  • Loading branch information
maryamtahhan committed Nov 25, 2024
1 parent c75b1ff commit 8173595
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: DoozyX/[email protected]
- uses: DoozyX/[email protected].1.1
with:
source: '.'
exclude: 'examples/vpp-plugin'
extensions: 'h,cpp,c,cc'
clangFormatVersion: 17
clangFormatVersion: 18.1.8
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
hooks:
- id: yamllint
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.4
rev: v18.1.1
hooks:
- id: clang-format
types_or: [c++, c]
Expand Down
2 changes: 1 addition & 1 deletion lib/core/hash/cne_hash_crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static const uint32_t crc32c_tables[8][256] = {{
// clang-format on

#define CRC32_UPD(crc, n) \
(crc32c_tables[(n)][(crc) & 0xFF] ^ crc32c_tables[(n)-1][((crc) >> 8) & 0xFF])
(crc32c_tables[(n)][(crc) & 0xFF] ^ crc32c_tables[(n) - 1][((crc) >> 8) & 0xFF])

static inline uint32_t
crc32c_1byte(uint8_t data, uint32_t init_val)
Expand Down
2 changes: 1 addition & 1 deletion lib/core/ring/cne_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "ring_private.h" // for cne_ring, cne_ring_headtail, CNE_...

/* true if x is a power of 2 */
#define POWEROF2(x) ((((x)-1) & (x)) == 0)
#define POWEROF2(x) ((((x) - 1) & (x)) == 0)
#define RING_DFLT_ELEM_SZ sizeof(void *) /** The default ring element size*/

ssize_t
Expand Down
20 changes: 11 additions & 9 deletions lib/include/cne_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ typedef uint16_t unaligned_uint16_t;
*/
#define CNE_SET_USED(x) (void)(x)

#define cne_roundup(_x, _y) ((((_x) + ((_y)-1)) / (_y)) * (_y))
#define cne_roundup(_x, _y) ((((_x) + ((_y) - 1)) / (_y)) * (_y))
#define cne_ctz(_v) __builtin_ctz(_v)
#define cne_prefixbits(_v) ((__typeof__(_v))(sizeof(_v) * 8) - cne_ctz(_v))
#define cne_numbytes(_v) ((cne_prefixbits(_v) + 7) / 8)
Expand Down Expand Up @@ -269,7 +269,7 @@ typedef uint16_t unaligned_uint16_t;
* bigger than the first parameter. Second parameter must be a
* power-of-two value.
*/
#define CNE_ALIGN_FLOOR(val, align) (typeof(val))((val) & (~((typeof(val))((align)-1))))
#define CNE_ALIGN_FLOOR(val, align) (typeof(val))((val) & (~((typeof(val))((align) - 1))))

/**
* Macro to align a pointer to a given power-of-two. The resultant
Expand All @@ -278,15 +278,15 @@ typedef uint16_t unaligned_uint16_t;
* must be a power-of-two value.
*/
#define CNE_PTR_ALIGN_CEIL(ptr, align) \
CNE_PTR_ALIGN_FLOOR((typeof(ptr))CNE_PTR_ADD(ptr, (align)-1), align)
CNE_PTR_ALIGN_FLOOR((typeof(ptr))CNE_PTR_ADD(ptr, (align) - 1), align)

/**
* Macro to align a value to a given power-of-two. The resultant value
* will be of the same type as the first parameter, and will be no lower
* than the first parameter. Second parameter must be a power-of-two
* value.
*/
#define CNE_ALIGN_CEIL(val, align) CNE_ALIGN_FLOOR(((val) + ((typeof(val))(align)-1)), align)
#define CNE_ALIGN_CEIL(val, align) CNE_ALIGN_FLOOR(((val) + ((typeof(val))(align) - 1)), align)

/**
* Macro to align a pointer to a given power-of-two. The resultant
Expand All @@ -312,7 +312,7 @@ typedef uint16_t unaligned_uint16_t;
* than the first parameter.
*/
#define CNE_ALIGN_MUL_CEIL(v, mul) \
(((v + (typeof(v))(mul)-1) / ((typeof(v))(mul))) * (typeof(v))(mul))
(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))

/**
* Macro to align a value to the multiple of given value. The resultant
Expand Down Expand Up @@ -397,7 +397,7 @@ __extension__ typedef uint64_t CNE_MARKER64[0];

/** Physical address */
typedef uint64_t phys_addr_t;
#define CNE_BAD_PHYS_ADDR ((phys_addr_t)-1)
#define CNE_BAD_PHYS_ADDR ((phys_addr_t) - 1)

/**
* IO virtual address type.
Expand All @@ -407,7 +407,7 @@ typedef uint64_t phys_addr_t;
* Otherwise, in virtual mode (IOVA as VA), an IOMMU may do the translation.
*/
typedef uint64_t cne_iova_t;
#define CNE_BAD_IOVA ((cne_iova_t)-1)
#define CNE_BAD_IOVA ((cne_iova_t) - 1)

/**
* Combines 32b inputs most significant set bits into the least
Expand Down Expand Up @@ -459,7 +459,7 @@ cne_combine64ms1b(uint64_t v)
/**
* Macro to return 1 if n is a power of 2, 0 otherwise
*/
#define CNE_IS_POWER_OF_2(n) ((n) && !(((n)-1) & (n)))
#define CNE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))

/**
* Returns true if n is a power of 2
Expand Down Expand Up @@ -773,7 +773,9 @@ cne_log2_u64(uint64_t v)
#define CNE_FMT_TAIL(fmt, ...) __VA_ARGS__

/** Mask value of type "tp" for the first "ln" bit set. */
#define CNE_LEN2MASK(ln, tp) ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
// clang-format off
#define CNE_LEN2MASK(ln, tp) ((tp)((uint64_t) - 1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
// clang-format on

/** Number of elements in the array. */
#define CNE_DIM(a) (int)(sizeof(a) / sizeof((a)[0]))
Expand Down
8 changes: 4 additions & 4 deletions lib/usr/app/cli/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,25 @@ struct cli_cmd {
const char *name; /**< Name of command */
cli_cfunc_t cfunc; /**< Function pointer */
const char *short_desc; /**< Short description */
}; /**< List of commands for cli_add_cmds() */
}; /**< List of commands for cli_add_cmds() */

struct cli_alias {
const char *name; /**< Name of command */
const char *alias_atr; /**< Alias string */
const char *short_desc; /**< Short description */
}; /**< List of alias for cli_add_aliases() */
}; /**< List of alias for cli_add_aliases() */

struct cli_file {
const char *name; /**< Name of command */
cli_ffunc_t ffunc; /**< Read/Write function pointer */
const char *short_desc; /**< Short description */
}; /**< List of alias for cli_add_aliases() */
}; /**< List of alias for cli_add_aliases() */

struct cli_str {
const char *name; /**< Name of command */
cli_sfunc_t sfunc; /**< Function pointer */
const char *string; /**< Default string */
}; /**< List of commands for cli_add_str() */
}; /**< List of commands for cli_add_str() */

struct cli_tree {
node_type_t type; /**< type of node to create */
Expand Down
2 changes: 1 addition & 1 deletion lib/usr/clib/acl/cne_acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ enum {
};

#define CNE_ACL_MASKLEN_TO_BITMASK(v, s) \
((v) == 0 ? (v) : (typeof(v))((uint64_t)-1 << ((s) * CHAR_BIT - (v))))
((v) == 0 ? (v) : (typeof(v))((uint64_t) - 1 << ((s) * CHAR_BIT - (v))))

/**
* Miscellaneous data for ACL rule.
Expand Down
12 changes: 8 additions & 4 deletions lib/usr/clib/cthread/cthread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ _qnode_pool_insert(struct qnode_pool *p, struct qnode *n)
* @return
* NULL on error or qnode pointer
*/
static inline struct qnode *__attribute__((always_inline)) _pool_remove(struct qnode_pool *p)
static inline struct qnode *__attribute__((always_inline))
_pool_remove(struct qnode_pool *p)
{
struct qnode *head;
struct qnode *tail = p->tail;
Expand Down Expand Up @@ -212,7 +213,8 @@ static inline struct qnode *__attribute__((always_inline)) _pool_remove(struct q
* @return
* The qnode removed from queue or NULL on error
*/
static inline struct qnode *__attribute__((always_inline)) _qnode_pool_remove(struct qnode_pool *p)
static inline struct qnode *__attribute__((always_inline))
_qnode_pool_remove(struct qnode_pool *p)
{
struct qnode *n;

Expand All @@ -230,7 +232,8 @@ static inline struct qnode *__attribute__((always_inline)) _qnode_pool_remove(st
* Allocate a node from the pool
* If the pool is empty add mode nodes
*/
static inline struct qnode *__attribute__((always_inline)) _qnode_alloc(void)
static inline struct qnode *__attribute__((always_inline))
_qnode_alloc(void)
{
struct qnode_pool *p = (THIS_SCHED)->qnode_pool;
int prealloc_size = p->pre_alloc;
Expand Down Expand Up @@ -263,7 +266,8 @@ static inline struct qnode *__attribute__((always_inline)) _qnode_alloc(void)
/*
* free a queue node to the per scheduler pool from which it came
*/
static inline void __attribute__((always_inline)) _qnode_free(struct qnode *n)
static inline void __attribute__((always_inline))
_qnode_free(struct qnode *n)
{
struct qnode_pool *p = n->pool;

Expand Down
9 changes: 6 additions & 3 deletions lib/usr/clib/cthread/cthread_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,16 @@ _sched_now(void)
return 1;
}

static inline void __attribute__((always_inline)) _affinitize(void)
static inline void __attribute__((always_inline))
_affinitize(void)
{
struct cthread *ct = THIS_CTHREAD;

cthread_switch(&(THIS_SCHED)->ctx, &ct->ctx);
}

static inline void __attribute__((always_inline)) _suspend(void)
static inline void __attribute__((always_inline))
_suspend(void)
{
struct cthread *ct = THIS_CTHREAD;

Expand All @@ -117,7 +119,8 @@ static inline void __attribute__((always_inline)) _suspend(void)
(THIS_SCHED)->nb_blocked_threads--;
}

static inline void __attribute__((always_inline)) _reschedule(void)
static inline void __attribute__((always_inline))
_reschedule(void)
{
struct cthread *ct = THIS_CTHREAD;

Expand Down
4 changes: 2 additions & 2 deletions lib/usr/clib/utils/crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
extern const uint32_t crc32_tab[];

#define rounddown(x, y) (((x) / (y)) * (y))
#define rounddown2(x, y) ((x) & (~((y)-1))) /* if y is power of two */
#define roundup2(x, y) (((x) + ((y)-1)) & (~((y)-1))) /* if y is power of two */
#define rounddown2(x, y) ((x) & (~((y) - 1))) /* if y is power of two */
#define roundup2(x, y) (((x) + ((y) - 1)) & (~((y) - 1))) /* if y is power of two */

static __inline uint32_t
crc32_raw(const void *buf, size_t size, uint32_t crc)
Expand Down

0 comments on commit 8173595

Please sign in to comment.