Skip to content

Commit c6552d9

Browse files
Tyler Retzlaffdavid-marchand
Tyler Retzlaff
authored andcommitted
lib: move alignment attribute on types for MSVC
The current location used for __rte_aligned(a) for alignment of types is not compatible with MSVC. There is only a single location accepted by both toolchains. The standard offers no alignment facility that compatibly interoperates with C and C++ but it may be achieved by relocating the placement of __rte_aligned(a) to the aforementioned location accepted by all currently supported toolchains. To allow alignment for both compilers, do the following: * Expand __rte_aligned(a) to __declspec(align(a)) when building with MSVC. * Move __rte_aligned from the end of {struct,union} definitions to be between {struct,union} and tag. The placement between {struct,union} and the tag allows the desired alignment to be imparted on the type regardless of the toolchain being used for all of GCC, LLVM, MSVC compilers building both C and C++. Note: this move has an additional benefit as Doxygen is not confused anymore like for the rte_event_vector struct definition. Signed-off-by: Tyler Retzlaff <[email protected]> Acked-by: Morten Brørup <[email protected]> Acked-by: Bruce Richardson <[email protected]> Acked-by: Konstantin Ananyev <[email protected]> Acked-by: Chengwen Feng <[email protected]> Reviewed-by: Maxime Coquelin <[email protected]> Signed-off-by: David Marchand <[email protected]>
1 parent 45f1004 commit c6552d9

File tree

81 files changed

+281
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+281
-259
lines changed

devtools/checkpatches.sh

+23
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,21 @@ check_internal_tags() { # <patch>
336336
return $res
337337
}
338338

339+
check_aligned_attributes() { # <patch>
340+
res=0
341+
342+
for token in __rte_aligned __rte_cache_aligned __rte_cache_min_aligned; do
343+
if [ $(grep -E '^\+.*\<'$token'\>' "$1" | \
344+
grep -vE '\<(struct|union)[[:space:]]*'$token'\>' | \
345+
wc -l) != 0 ]; then
346+
echo "Please use $token only for struct or union types alignment."
347+
res=1
348+
fi
349+
done
350+
351+
return $res
352+
}
353+
339354
check_release_notes() { # <patch>
340355
rel_notes_prefix=doc/guides/rel_notes/release_
341356
IFS=. read year month release < VERSION
@@ -445,6 +460,14 @@ check () { # <patch-file> <commit>
445460
ret=1
446461
fi
447462

463+
! $verbose || printf '\nChecking alignment attributes:\n'
464+
report=$(check_aligned_attributes "$tmpinput")
465+
if [ $? -ne 0 ] ; then
466+
$headline_printed || print_headline "$subject"
467+
printf '%s\n' "$report"
468+
ret=1
469+
fi
470+
448471
! $verbose || printf '\nChecking release notes updates:\n'
449472
report=$(check_release_notes "$tmpinput")
450473
if [ $? -ne 0 ] ; then

lib/acl/acl_run.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ struct acl_flow_data {
5555
* Structure to maintain running results for
5656
* a single packet (up to 4 tries).
5757
*/
58-
struct completion {
58+
struct __rte_aligned(XMM_SIZE) completion {
5959
uint32_t *results; /* running results. */
6060
int32_t priority[RTE_ACL_MAX_CATEGORIES]; /* running priorities. */
6161
uint32_t count; /* num of remaining tries */
6262
/* true for allocated struct */
63-
} __rte_aligned(XMM_SIZE);
63+
};
6464

6565
/*
6666
* One parms structure for each slot in the search engine.

lib/bpf/bpf_pkt.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* information about installed BPF rx/tx callback
2424
*/
2525

26-
struct bpf_eth_cbi {
26+
struct __rte_cache_aligned bpf_eth_cbi {
2727
/* used by both data & control path */
2828
RTE_ATOMIC(uint32_t) use; /*usage counter */
2929
const struct rte_eth_rxtx_callback *cb; /* callback handle */
@@ -33,7 +33,7 @@ struct bpf_eth_cbi {
3333
LIST_ENTRY(bpf_eth_cbi) link;
3434
uint16_t port;
3535
uint16_t queue;
36-
} __rte_cache_aligned;
36+
};
3737

3838
/*
3939
* Odd number means that callback is used by datapath.

lib/compressdev/rte_comp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ struct rte_comp_xform {
356356
* Comp operations are enqueued and dequeued in comp PMDs using the
357357
* rte_compressdev_enqueue_burst() / rte_compressdev_dequeue_burst() APIs
358358
*/
359-
struct rte_comp_op {
359+
struct __rte_cache_aligned rte_comp_op {
360360
enum rte_comp_op_type op_type;
361361
union {
362362
void *private_xform;
@@ -478,7 +478,7 @@ struct rte_comp_op {
478478
* will be set to RTE_COMP_OP_STATUS_SUCCESS after operation
479479
* is successfully processed by a PMD
480480
*/
481-
} __rte_cache_aligned;
481+
};
482482

483483
/**
484484
* Creates an operation pool

lib/compressdev/rte_compressdev_internal.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ typedef uint16_t (*compressdev_enqueue_pkt_burst_t)(void *qp,
6969
struct rte_comp_op **ops, uint16_t nb_ops);
7070

7171
/** The data structure associated with each comp device. */
72-
struct rte_compressdev {
72+
struct __rte_cache_aligned rte_compressdev {
7373
compressdev_dequeue_pkt_burst_t dequeue_burst;
7474
/**< Pointer to PMD receive function */
7575
compressdev_enqueue_pkt_burst_t enqueue_burst;
@@ -87,7 +87,7 @@ struct rte_compressdev {
8787
__extension__
8888
uint8_t attached : 1;
8989
/**< Flag indicating the device is attached */
90-
} __rte_cache_aligned;
90+
};
9191

9292
/**
9393
*
@@ -96,7 +96,7 @@ struct rte_compressdev {
9696
* This structure is safe to place in shared memory to be common among
9797
* different processes in a multi-process configuration.
9898
*/
99-
struct rte_compressdev_data {
99+
struct __rte_cache_aligned rte_compressdev_data {
100100
uint8_t dev_id;
101101
/**< Compress device identifier */
102102
int socket_id;
@@ -115,7 +115,7 @@ struct rte_compressdev_data {
115115

116116
void *dev_private;
117117
/**< PMD-specific private data */
118-
} __rte_cache_aligned;
118+
};
119119

120120
#ifdef __cplusplus
121121
}

lib/cryptodev/cryptodev_pmd.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct rte_cryptodev_pmd_init_params {
6161
* This structure is safe to place in shared memory to be common among
6262
* different processes in a multi-process configuration.
6363
*/
64-
struct rte_cryptodev_data {
64+
struct __rte_cache_aligned rte_cryptodev_data {
6565
/** Device ID for this instance */
6666
uint8_t dev_id;
6767
/** Socket ID where memory is allocated */
@@ -82,10 +82,10 @@ struct rte_cryptodev_data {
8282

8383
/** PMD-specific private data */
8484
void *dev_private;
85-
} __rte_cache_aligned;
85+
};
8686

8787
/** @internal The data structure associated with each crypto device. */
88-
struct rte_cryptodev {
88+
struct __rte_cache_aligned rte_cryptodev {
8989
/** Pointer to PMD dequeue function. */
9090
dequeue_pkt_burst_t dequeue_burst;
9191
/** Pointer to PMD enqueue function. */
@@ -117,7 +117,7 @@ struct rte_cryptodev {
117117
struct rte_cryptodev_cb_rcu *enq_cbs;
118118
/** User application callback for post dequeue processing */
119119
struct rte_cryptodev_cb_rcu *deq_cbs;
120-
} __rte_cache_aligned;
120+
};
121121

122122
/** Global structure used for maintaining state of allocated crypto devices */
123123
struct rte_cryptodev_global {

lib/cryptodev/rte_cryptodev_core.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct rte_cryptodev_qpdata {
4040
struct rte_cryptodev_cb_rcu *deq_cb;
4141
};
4242

43-
struct rte_crypto_fp_ops {
43+
struct __rte_cache_aligned rte_crypto_fp_ops {
4444
/** PMD enqueue burst function. */
4545
enqueue_pkt_burst_t enqueue_burst;
4646
/** PMD dequeue burst function. */
@@ -49,7 +49,7 @@ struct rte_crypto_fp_ops {
4949
struct rte_cryptodev_qpdata qp;
5050
/** Reserved for future ops. */
5151
uintptr_t reserved[3];
52-
} __rte_cache_aligned;
52+
};
5353

5454
extern struct rte_crypto_fp_ops rte_crypto_fp_ops[RTE_CRYPTO_MAX_DEVS];
5555

lib/dispatcher/rte_dispatcher.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ struct rte_dispatcher_finalizer {
4141
void *finalize_data;
4242
};
4343

44-
struct rte_dispatcher_lcore {
44+
struct __rte_cache_aligned rte_dispatcher_lcore {
4545
uint8_t num_ports;
4646
uint16_t num_handlers;
4747
int32_t prio_count;
4848
struct rte_dispatcher_lcore_port ports[EVD_MAX_PORTS_PER_LCORE];
4949
struct rte_dispatcher_handler handlers[EVD_MAX_HANDLERS];
5050
struct rte_dispatcher_stats stats;
5151
RTE_CACHE_GUARD;
52-
} __rte_cache_aligned;
52+
};
5353

5454
struct rte_dispatcher {
5555
uint8_t event_dev_id;

lib/distributor/distributor_private.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@
5353
* the next cache line to worker 0, we pad this out to three cache lines.
5454
* Only 64-bits of the memory is actually used though.
5555
*/
56-
union rte_distributor_buffer_single {
56+
union __rte_cache_aligned rte_distributor_buffer_single {
5757
volatile RTE_ATOMIC(int64_t) bufptr64;
5858
char pad[RTE_CACHE_LINE_SIZE*3];
59-
} __rte_cache_aligned;
59+
};
6060

6161
/*
6262
* Transfer up to 8 mbufs at a time to/from workers, and
6363
* flow matching algorithm optimized for 8 flow IDs at a time
6464
*/
6565
#define RTE_DIST_BURST_SIZE 8
6666

67-
struct rte_distributor_backlog {
67+
struct __rte_cache_aligned rte_distributor_backlog {
6868
unsigned int start;
6969
unsigned int count;
7070
alignas(RTE_CACHE_LINE_SIZE) int64_t pkts[RTE_DIST_BURST_SIZE];
7171
uint16_t *tags; /* will point to second cacheline of inflights */
72-
} __rte_cache_aligned;
72+
};
7373

7474

7575
struct rte_distributor_returned_pkts {

lib/dmadev/rte_dmadev_core.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ typedef uint16_t (*rte_dma_burst_capacity_t)(const void *dev_private, uint16_t v
6161
* The 'dev_private' field was placed in the first cache line to optimize
6262
* performance because the PMD mainly depends on this field.
6363
*/
64-
struct rte_dma_fp_object {
64+
struct __rte_cache_aligned rte_dma_fp_object {
6565
/** PMD-specific private data. The driver should copy
6666
* rte_dma_dev.data->dev_private to this field during initialization.
6767
*/
@@ -73,7 +73,7 @@ struct rte_dma_fp_object {
7373
rte_dma_completed_t completed;
7474
rte_dma_completed_status_t completed_status;
7575
rte_dma_burst_capacity_t burst_capacity;
76-
} __rte_cache_aligned;
76+
};
7777

7878
extern struct rte_dma_fp_object *rte_dma_fp_objs;
7979

lib/dmadev/rte_dmadev_pmd.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct rte_dma_dev_ops {
9494
*
9595
* @see struct rte_dma_dev::data
9696
*/
97-
struct rte_dma_dev_data {
97+
struct __rte_cache_aligned rte_dma_dev_data {
9898
char dev_name[RTE_DEV_NAME_MAX_LEN]; /**< Unique identifier name */
9999
int16_t dev_id; /**< Device [external] identifier. */
100100
int16_t numa_node; /**< Local NUMA memory ID. -1 if unknown. */
@@ -103,7 +103,7 @@ struct rte_dma_dev_data {
103103
__extension__
104104
uint8_t dev_started : 1; /**< Device state: STARTED(1)/STOPPED(0). */
105105
uint64_t reserved[2]; /**< Reserved for future fields */
106-
} __rte_cache_aligned;
106+
};
107107

108108
/**
109109
* Possible states of a DMA device.
@@ -122,7 +122,7 @@ enum rte_dma_dev_state {
122122
* @internal
123123
* The generic data structure associated with each DMA device.
124124
*/
125-
struct rte_dma_dev {
125+
struct __rte_cache_aligned rte_dma_dev {
126126
/** Device info which supplied during device initialization. */
127127
struct rte_device *device;
128128
struct rte_dma_dev_data *data; /**< Pointer to shared device data. */
@@ -132,7 +132,7 @@ struct rte_dma_dev {
132132
const struct rte_dma_dev_ops *dev_ops;
133133
enum rte_dma_dev_state state; /**< Flag indicating the device state. */
134134
uint64_t reserved[2]; /**< Reserved for future fields. */
135-
} __rte_cache_aligned;
135+
};
136136

137137
/**
138138
* @internal

lib/eal/arm/include/rte_vect.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ typedef int32x4_t xmm_t;
2424
#define XMM_SIZE (sizeof(xmm_t))
2525
#define XMM_MASK (XMM_SIZE - 1)
2626

27-
typedef union rte_xmm {
27+
typedef union __rte_aligned(16) rte_xmm {
2828
xmm_t x;
2929
uint8_t u8[XMM_SIZE / sizeof(uint8_t)];
3030
uint16_t u16[XMM_SIZE / sizeof(uint16_t)];
3131
uint32_t u32[XMM_SIZE / sizeof(uint32_t)];
3232
uint64_t u64[XMM_SIZE / sizeof(uint64_t)];
3333
double pd[XMM_SIZE / sizeof(double)];
34-
} __rte_aligned(16) rte_xmm_t;
34+
} rte_xmm_t;
3535

3636
#if defined(RTE_ARCH_ARM) && defined(RTE_ARCH_32)
3737
/* NEON intrinsic vqtbl1q_u8() is not supported in ARMv7-A(AArch32) */

lib/eal/common/malloc_elem.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum elem_state {
2020
ELEM_PAD /* element is a padding-only header */
2121
};
2222

23-
struct malloc_elem {
23+
struct __rte_cache_aligned malloc_elem {
2424
struct malloc_heap *heap;
2525
struct malloc_elem *volatile prev;
2626
/**< points to prev elem in memseg */
@@ -48,7 +48,7 @@ struct malloc_elem {
4848
size_t user_size;
4949
uint64_t asan_cookie[2]; /* must be next to header_cookie */
5050
#endif
51-
} __rte_cache_aligned;
51+
};
5252

5353
static const unsigned int MALLOC_ELEM_HEADER_LEN = sizeof(struct malloc_elem);
5454

lib/eal/common/malloc_heap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct malloc_elem;
2121
/**
2222
* Structure to hold malloc heap
2323
*/
24-
struct malloc_heap {
24+
struct __rte_cache_aligned malloc_heap {
2525
rte_spinlock_t lock;
2626
LIST_HEAD(, malloc_elem) free_head[RTE_HEAP_NUM_FREELISTS];
2727
struct malloc_elem *volatile first;
@@ -31,7 +31,7 @@ struct malloc_heap {
3131
unsigned int socket_id;
3232
size_t total_size;
3333
char name[RTE_HEAP_NAME_MAX_LEN];
34-
} __rte_cache_aligned;
34+
};
3535

3636
void *
3737
malloc_heap_alloc(const char *type, size_t size, int socket, unsigned int flags,

lib/eal/common/rte_random.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
#include <rte_lcore.h>
1414
#include <rte_random.h>
1515

16-
struct rte_rand_state {
16+
struct __rte_cache_aligned rte_rand_state {
1717
uint64_t z1;
1818
uint64_t z2;
1919
uint64_t z3;
2020
uint64_t z4;
2121
uint64_t z5;
2222
RTE_CACHE_GUARD;
23-
} __rte_cache_aligned;
23+
};
2424

2525
/* One instance each for every lcore id-equipped thread, and one
2626
* additional instance to be shared by all others threads (i.e., all

lib/eal/common/rte_service.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define RUNSTATE_RUNNING 1
3333

3434
/* internal representation of a service */
35-
struct rte_service_spec_impl {
35+
struct __rte_cache_aligned rte_service_spec_impl {
3636
/* public part of the struct */
3737
struct rte_service_spec spec;
3838

@@ -53,15 +53,15 @@ struct rte_service_spec_impl {
5353
* on currently.
5454
*/
5555
RTE_ATOMIC(uint32_t) num_mapped_cores;
56-
} __rte_cache_aligned;
56+
};
5757

5858
struct service_stats {
5959
RTE_ATOMIC(uint64_t) calls;
6060
RTE_ATOMIC(uint64_t) cycles;
6161
};
6262

6363
/* the internal values of a service core */
64-
struct core_state {
64+
struct __rte_cache_aligned core_state {
6565
/* map of services IDs are run on this core */
6666
uint64_t service_mask;
6767
RTE_ATOMIC(uint8_t) runstate; /* running or stopped */
@@ -71,7 +71,7 @@ struct core_state {
7171
RTE_ATOMIC(uint64_t) loops;
7272
RTE_ATOMIC(uint64_t) cycles;
7373
struct service_stats service_stats[RTE_SERVICE_NUM_MAX];
74-
} __rte_cache_aligned;
74+
};
7575

7676
static uint32_t rte_service_count;
7777
static struct rte_service_spec_impl *rte_services;

lib/eal/include/generic/rte_atomic.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ static inline void rte_atomic64_clear(rte_atomic64_t *v)
10941094
/**
10951095
* 128-bit integer structure.
10961096
*/
1097-
typedef struct {
1097+
typedef struct __rte_aligned(16) {
10981098
union {
10991099
uint64_t val[2];
11001100
#ifdef RTE_ARCH_64
@@ -1103,7 +1103,7 @@ typedef struct {
11031103
#endif
11041104
#endif
11051105
};
1106-
} __rte_aligned(16) rte_int128_t;
1106+
} rte_int128_t;
11071107

11081108
#ifdef __DOXYGEN__
11091109

0 commit comments

Comments
 (0)