Skip to content

Commit d6dfee9

Browse files
committed
Explicit fallthrough
1 parent b6a2565 commit d6dfee9

2 files changed

Lines changed: 40 additions & 21 deletions

File tree

core/kmod/llring.h

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ static inline void llring_pause(void) { _mm_pause(); }
111111

112112
#endif
113113

114-
/* llring can be used between execution contexts having different address widths.
115-
* In such circumstances, use phys_addr_t rather than void *, whose size would
116-
* be different in 32 bit versus 64 bit contexts.
114+
/* llring can be used between execution contexts having different address
115+
* widths. In such circumstances, use phys_addr_t rather than void *, whose size
116+
* would be different in 32 bit versus 64 bit contexts.
117117
*/
118118
#ifdef __LLRING_USE_PHYS_ADDR__
119119
typedef phys_addr_t llring_addr_t;
120120
#else
121-
typedef void * llring_addr_t;
121+
typedef void *llring_addr_t;
122122
#endif
123123

124124
/* dummy assembly operation to prevent compiler re-ordering of instructions */
@@ -210,10 +210,11 @@ struct llring {
210210
/* it seems to help */
211211
char _pad[LLRING_CACHELINE_SIZE];
212212

213-
llring_addr_t ring[0]
214-
__llring_cache_aligned; /**< Memory space of ring starts here.
215-
* not volatile so need to be careful
216-
* about compiler re-ordering */
213+
llring_addr_t ring[0] __llring_cache_aligned; /**< Memory space of ring
214+
* starts here. not
215+
* volatile so need to be
216+
* careful about compiler
217+
* re-ordering */
217218
} __llring_cache_aligned;
218219

219220
#define RING_QUOT_EXCEED (1 << 31) /**< Quota exceed for burst ops */
@@ -236,7 +237,9 @@ struct llring {
236237
r->stats[__lcore_id].name##_bulk += 1; \
237238
} while (0)
238239
#else
239-
#define __RING_STAT_ADD(r, name, n) do {} while(0)
240+
#define __RING_STAT_ADD(r, name, n) \
241+
do { \
242+
} while (0)
240243
#endif
241244

242245
static inline int llring_bytes_with_slots(unsigned int slots)
@@ -324,8 +327,10 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
324327
switch (n & 0x3) { \
325328
case 3: \
326329
r->ring[idx++] = obj_table[i++]; \
330+
[[gnu::fallthrough]]; \
327331
case 2: \
328332
r->ring[idx++] = obj_table[i++]; \
333+
[[gnu::fallthrough]]; \
329334
case 1: \
330335
r->ring[idx++] = obj_table[i++]; \
331336
} \
@@ -355,8 +360,10 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
355360
switch (n & 0x3) { \
356361
case 3: \
357362
obj_table[i++] = r->ring[idx++]; \
363+
[[gnu::fallthrough]]; \
358364
case 2: \
359365
obj_table[i++] = r->ring[idx++]; \
366+
[[gnu::fallthrough]]; \
360367
case 1: \
361368
obj_table[i++] = r->ring[idx++]; \
362369
} \
@@ -395,8 +402,8 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
395402
* - n: Actual number of objects enqueued.
396403
*/
397404
static inline int __attribute__((always_inline))
398-
__llring_mp_do_enqueue(struct llring *r, llring_addr_t const *obj_table, unsigned n,
399-
enum llring_queue_behavior behavior)
405+
__llring_mp_do_enqueue(struct llring *r, llring_addr_t const *obj_table,
406+
unsigned n, enum llring_queue_behavior behavior)
400407
{
401408
uint32_t prod_head, prod_next;
402409
uint32_t cons_tail, free_entries;
@@ -491,8 +498,8 @@ __llring_mp_do_enqueue(struct llring *r, llring_addr_t const *obj_table, unsigne
491498
* - n: Actual number of objects enqueued.
492499
*/
493500
static inline int __attribute__((always_inline))
494-
__llring_sp_do_enqueue(struct llring *r, llring_addr_t const *obj_table, unsigned n,
495-
enum llring_queue_behavior behavior)
501+
__llring_sp_do_enqueue(struct llring *r, llring_addr_t const *obj_table,
502+
unsigned n, enum llring_queue_behavior behavior)
496503
{
497504
uint32_t prod_head, cons_tail;
498505
uint32_t prod_next, free_entries;
@@ -723,19 +730,22 @@ __llring_sc_do_dequeue(struct llring *r, llring_addr_t *obj_table, unsigned n,
723730
* enqueued.
724731
*/
725732
static inline int __attribute__((always_inline))
726-
llring_mp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table, unsigned n)
733+
llring_mp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table,
734+
unsigned n)
727735
{
728736
return __llring_mp_do_enqueue(r, obj_table, n, LLRING_QUEUE_FIXED);
729737
}
730738

731739
static inline int __attribute__((always_inline))
732-
llring_sp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table, unsigned n)
740+
llring_sp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table,
741+
unsigned n)
733742
{
734743
return __llring_sp_do_enqueue(r, obj_table, n, LLRING_QUEUE_FIXED);
735744
}
736745

737746
static inline int __attribute__((always_inline))
738-
llring_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table, unsigned n)
747+
llring_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table,
748+
unsigned n)
739749
{
740750
if (r->common.sp_enqueue)
741751
return llring_sp_enqueue_bulk(r, obj_table, n);
@@ -1057,7 +1067,8 @@ llring_sp_enqueue_burst(struct llring *r, llring_addr_t const *obj_table,
10571067
* - n: Actual number of objects enqueued.
10581068
*/
10591069
static inline int __attribute__((always_inline))
1060-
llring_enqueue_burst(struct llring *r, llring_addr_t const *obj_table, unsigned n)
1070+
llring_enqueue_burst(struct llring *r, llring_addr_t const *obj_table,
1071+
unsigned n)
10611072
{
10621073
if (r->common.sp_enqueue)
10631074
return llring_sp_enqueue_burst(r, obj_table, n);

core/utils/copy.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#ifndef BESS_UTILS_COPY_H_
22
#define BESS_UTILS_COPY_H_
33

4-
#include <cstring>
5-
4+
#include <glog/logging.h>
65
#include <x86intrin.h>
76

8-
#include <glog/logging.h>
7+
#include <cstring>
98

109
#include "common.h"
1110

@@ -34,7 +33,7 @@ static inline void Copy32(void *__restrict__ dst,
3433
// Copy exactly "bytes" (<= 64). Works best if size is a compile-time constant.
3534
static inline void CopySmall(void *__restrict__ dst,
3635
const void *__restrict__ src, size_t bytes) {
37-
DCHECK(bytes <= 64);
36+
DCHECK_LE(bytes, 64);
3837

3938
auto *d = reinterpret_cast<char *__restrict__>(dst);
4039
auto *s = reinterpret_cast<const char *__restrict__>(src);
@@ -79,6 +78,7 @@ static inline void CopySmall(void *__restrict__ dst,
7978
break;
8079
case 9:
8180
memcpy(d + 8, s + 8, 1);
81+
[[gnu::fallthrough]];
8282
case 8:
8383
memcpy(d, s, 8);
8484
break;
@@ -91,11 +91,13 @@ static inline void CopySmall(void *__restrict__ dst,
9191
break;
9292
case 5:
9393
memcpy(d + 4, s + 4, 1);
94+
[[gnu::fallthrough]];
9495
case 4:
9596
memcpy(d, s, 4);
9697
break;
9798
case 3:
9899
memcpy(d + 2, s + 2, 1);
100+
[[gnu::fallthrough]];
99101
case 2:
100102
memcpy(d, s, 2);
101103
break;
@@ -169,16 +171,22 @@ static inline void CopyInlined(void *__restrict__ dst,
169171
switch (leftover_blocks) {
170172
case 7:
171173
copy_block(d + 6, s + 6);
174+
[[gnu::fallthrough]];
172175
case 6:
173176
copy_block(d + 5, s + 5);
177+
[[gnu::fallthrough]];
174178
case 5:
175179
copy_block(d + 4, s + 4);
180+
[[gnu::fallthrough]];
176181
case 4:
177182
copy_block(d + 3, s + 3);
183+
[[gnu::fallthrough]];
178184
case 3:
179185
copy_block(d + 2, s + 2);
186+
[[gnu::fallthrough]];
180187
case 2:
181188
copy_block(d + 1, s + 1);
189+
[[gnu::fallthrough]];
182190
case 1:
183191
copy_block(d + 0, s + 0);
184192
}

0 commit comments

Comments
 (0)