Skip to content

Commit 8834b3b

Browse files
authored
Merge pull request #526 from NetSys/gcc7
GCC 7 Support
2 parents 54cf79d + 5ccefa6 commit 8834b3b

11 files changed

Lines changed: 85 additions & 36 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ env:
2525
- VER_CXX=g++-5 DEBUG=1
2626
- VER_CXX=g++-5 TAG_SUFFIX=_32 # 32bit build
2727
- VER_CXX=g++-6
28+
- VER_CXX=g++-7
2829

2930
before_install:
3031
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test

core/Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ $(shell mkdir -p $(DEPDIR)/hooks >/dev/null)
1818
# 'clang' or 'g++'
1919
CXXCOMPILER := $(shell expr $(word 1, $(shell $(CXX) --version)) : '\(clang\|g++\)')
2020

21-
# e.g., 4.9.3 -> 40903. For clang it is always 40201
22-
CXXVERSION := $(shell $(CXX) -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/')
21+
CXXVERSION := $(shell $(CXX) -dumpversion)
2322

24-
ifeq "$(shell expr $(CXXCOMPILER) = g++ \& $(CXXVERSION) \< 40800)" "1"
23+
ifeq "$(CXXCOMPILER)" "g++"
24+
ifneq "$(shell printf '$(CXXVERSION)\n4.7' | sort -V | head -n1)" "4.7"
2525
$(error g++ 4.8 or higher is required)
2626
endif
27+
endif
2728

2829
RTE_SDK ?= $(abspath ../deps/dpdk-17.05)
2930
RTE_TARGET ?= $(shell uname -m)-native-linuxapp-gcc
@@ -44,7 +45,7 @@ else ifeq ($(words $(MAKECMDGOALS)),1)
4445
endif
4546

4647
CXXARCHFLAGS ?= -march=native
47-
CXXFLAGS += -std=gnu++11 -g3 -ggdb3 $(CXXARCHFLAGS) \
48+
CXXFLAGS += -std=c++11 -g3 -ggdb3 $(CXXARCHFLAGS) \
4849
-Werror -isystem $(DPDK_INC_DIR) -isystem . -D_GNU_SOURCE \
4950
-Wall -Wextra -Wcast-align
5051

core/kmod/llring.h

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@
6666
#ifndef _LLRING_H_
6767
#define _LLRING_H_
6868

69+
#if defined(__has_cpp_attribute)
70+
#if __has_cpp_attribute(fallthrough)
71+
#define FALLTHROUGH [[fallthrough]]
72+
#elif __has_cpp_attribute(clang::fallthrough)
73+
#define FALLTHROUGH [[clang::fallthrough]]
74+
#else
75+
#define FALLTHROUGH
76+
#endif
77+
#else
78+
#define FALLTHROUGH
79+
#endif
80+
6981
/**
7082
* Note: the ring implementation is not preemptable. A producer must not
7183
* be interrupted by another producer that uses the same ring.
@@ -111,14 +123,14 @@ static inline void llring_pause(void) { _mm_pause(); }
111123

112124
#endif
113125

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.
126+
/* llring can be used between execution contexts having different address
127+
* widths. In such circumstances, use phys_addr_t rather than void *, whose size
128+
* would be different in 32 bit versus 64 bit contexts.
117129
*/
118130
#ifdef __LLRING_USE_PHYS_ADDR__
119131
typedef phys_addr_t llring_addr_t;
120132
#else
121-
typedef void * llring_addr_t;
133+
typedef void *llring_addr_t;
122134
#endif
123135

124136
/* dummy assembly operation to prevent compiler re-ordering of instructions */
@@ -210,10 +222,11 @@ struct llring {
210222
/* it seems to help */
211223
char _pad[LLRING_CACHELINE_SIZE];
212224

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 */
225+
llring_addr_t ring[0] __llring_cache_aligned; /**< Memory space of ring
226+
* starts here. not
227+
* volatile so need to be
228+
* careful about compiler
229+
* re-ordering */
217230
} __llring_cache_aligned;
218231

219232
#define RING_QUOT_EXCEED (1 << 31) /**< Quota exceed for burst ops */
@@ -236,7 +249,9 @@ struct llring {
236249
r->stats[__lcore_id].name##_bulk += 1; \
237250
} while (0)
238251
#else
239-
#define __RING_STAT_ADD(r, name, n) do {} while(0)
252+
#define __RING_STAT_ADD(r, name, n) \
253+
do { \
254+
} while (0)
240255
#endif
241256

242257
static inline int llring_bytes_with_slots(unsigned int slots)
@@ -324,8 +339,10 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
324339
switch (n & 0x3) { \
325340
case 3: \
326341
r->ring[idx++] = obj_table[i++]; \
342+
FALLTHROUGH; \
327343
case 2: \
328344
r->ring[idx++] = obj_table[i++]; \
345+
FALLTHROUGH; \
329346
case 1: \
330347
r->ring[idx++] = obj_table[i++]; \
331348
} \
@@ -355,8 +372,10 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
355372
switch (n & 0x3) { \
356373
case 3: \
357374
obj_table[i++] = r->ring[idx++]; \
375+
FALLTHROUGH; \
358376
case 2: \
359377
obj_table[i++] = r->ring[idx++]; \
378+
FALLTHROUGH; \
360379
case 1: \
361380
obj_table[i++] = r->ring[idx++]; \
362381
} \
@@ -395,8 +414,8 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
395414
* - n: Actual number of objects enqueued.
396415
*/
397416
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)
417+
__llring_mp_do_enqueue(struct llring *r, llring_addr_t const *obj_table,
418+
unsigned n, enum llring_queue_behavior behavior)
400419
{
401420
uint32_t prod_head, prod_next;
402421
uint32_t cons_tail, free_entries;
@@ -491,8 +510,8 @@ __llring_mp_do_enqueue(struct llring *r, llring_addr_t const *obj_table, unsigne
491510
* - n: Actual number of objects enqueued.
492511
*/
493512
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)
513+
__llring_sp_do_enqueue(struct llring *r, llring_addr_t const *obj_table,
514+
unsigned n, enum llring_queue_behavior behavior)
496515
{
497516
uint32_t prod_head, cons_tail;
498517
uint32_t prod_next, free_entries;
@@ -723,19 +742,22 @@ __llring_sc_do_dequeue(struct llring *r, llring_addr_t *obj_table, unsigned n,
723742
* enqueued.
724743
*/
725744
static inline int __attribute__((always_inline))
726-
llring_mp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table, unsigned n)
745+
llring_mp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table,
746+
unsigned n)
727747
{
728748
return __llring_mp_do_enqueue(r, obj_table, n, LLRING_QUEUE_FIXED);
729749
}
730750

731751
static inline int __attribute__((always_inline))
732-
llring_sp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table, unsigned n)
752+
llring_sp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table,
753+
unsigned n)
733754
{
734755
return __llring_sp_do_enqueue(r, obj_table, n, LLRING_QUEUE_FIXED);
735756
}
736757

737758
static inline int __attribute__((always_inline))
738-
llring_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table, unsigned n)
759+
llring_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table,
760+
unsigned n)
739761
{
740762
if (r->common.sp_enqueue)
741763
return llring_sp_enqueue_bulk(r, obj_table, n);
@@ -1057,7 +1079,8 @@ llring_sp_enqueue_burst(struct llring *r, llring_addr_t const *obj_table,
10571079
* - n: Actual number of objects enqueued.
10581080
*/
10591081
static inline int __attribute__((always_inline))
1060-
llring_enqueue_burst(struct llring *r, llring_addr_t const *obj_table, unsigned n)
1082+
llring_enqueue_burst(struct llring *r, llring_addr_t const *obj_table,
1083+
unsigned n)
10611084
{
10621085
if (r->common.sp_enqueue)
10631086
return llring_sp_enqueue_burst(r, obj_table, n);

core/message.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define BESS_MESSAGE_H_
33

44
#include <cstdarg>
5+
#include <functional>
56

67
#include "bess_msg.pb.h"
78
#include "error.pb.h"

core/module_test.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,15 @@ DEF_MODULE(AcmeModule, "acme_module", "foo bar");
3737

3838
class AcmeModuleWithTask : public Module {
3939
public:
40-
AcmeModuleWithTask() : Module() {
41-
is_task_ = true;
42-
}
40+
AcmeModuleWithTask() : Module() { is_task_ = true; }
4341

4442
static const gate_idx_t kNumIGates = 1;
4543
static const gate_idx_t kNumOGates = 2;
4644

47-
CommandResponse Init(const bess::pb::EmptyArg &) {
48-
return CommandResponse();
49-
}
45+
CommandResponse Init(const bess::pb::EmptyArg &) { return CommandResponse(); }
5046

5147
struct task_result RunTask(void *) override {
52-
struct task_result ret;
53-
return ret;
48+
return task_result();
5449
}
5550
};
5651

@@ -305,4 +300,4 @@ TEST_F(ModuleTester, GenerateTCGraph) {
305300
EXPECT_EQ(0, t3->parent_tasks().size());
306301
EXPECT_EQ(0, t4->parent_tasks().size());
307302
}
308-
} // namespace (unnamed)
303+
} // namespace

core/modules/rewrite.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Rewrite final : public Module {
3636

3737
size_t num_templates_;
3838
uint16_t template_size_[kNumSlots];
39-
unsigned char templates_[kNumSlots][kMaxTemplateSize] __ymm_aligned;
39+
unsigned char templates_[kNumSlots][kMaxTemplateSize];
4040
};
4141

4242
#endif // BESS_MODULES_REWRITE_H_

core/utils/copy.h

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

4-
#include <cstring>
4+
#if defined(__has_cpp_attribute)
5+
#if __has_cpp_attribute(fallthrough)
6+
#define FALLTHROUGH [[fallthrough]]
7+
#elif __has_cpp_attribute(clang::fallthrough)
8+
#define FALLTHROUGH [[clang::fallthrough]]
9+
#else
10+
#define FALLTHROUGH
11+
#endif
12+
#else
13+
#define FALLTHROUGH
14+
#endif
515

16+
#include <glog/logging.h>
617
#include <x86intrin.h>
718

8-
#include <glog/logging.h>
19+
#include <cstring>
920

1021
#include "common.h"
1122

@@ -34,7 +45,7 @@ static inline void Copy32(void *__restrict__ dst,
3445
// Copy exactly "bytes" (<= 64). Works best if size is a compile-time constant.
3546
static inline void CopySmall(void *__restrict__ dst,
3647
const void *__restrict__ src, size_t bytes) {
37-
DCHECK(bytes <= 64);
48+
DCHECK_LE(bytes, 64);
3849

3950
auto *d = reinterpret_cast<char *__restrict__>(dst);
4051
auto *s = reinterpret_cast<const char *__restrict__>(src);
@@ -79,6 +90,7 @@ static inline void CopySmall(void *__restrict__ dst,
7990
break;
8091
case 9:
8192
memcpy(d + 8, s + 8, 1);
93+
FALLTHROUGH;
8294
case 8:
8395
memcpy(d, s, 8);
8496
break;
@@ -91,11 +103,13 @@ static inline void CopySmall(void *__restrict__ dst,
91103
break;
92104
case 5:
93105
memcpy(d + 4, s + 4, 1);
106+
FALLTHROUGH;
94107
case 4:
95108
memcpy(d, s, 4);
96109
break;
97110
case 3:
98111
memcpy(d + 2, s + 2, 1);
112+
FALLTHROUGH;
99113
case 2:
100114
memcpy(d, s, 2);
101115
break;
@@ -169,16 +183,22 @@ static inline void CopyInlined(void *__restrict__ dst,
169183
switch (leftover_blocks) {
170184
case 7:
171185
copy_block(d + 6, s + 6);
186+
FALLTHROUGH;
172187
case 6:
173188
copy_block(d + 5, s + 5);
189+
FALLTHROUGH;
174190
case 5:
175191
copy_block(d + 4, s + 4);
192+
FALLTHROUGH;
176193
case 4:
177194
copy_block(d + 3, s + 3);
195+
FALLTHROUGH;
178196
case 3:
179197
copy_block(d + 2, s + 2);
198+
FALLTHROUGH;
180199
case 2:
181200
copy_block(d + 1, s + 1);
201+
FALLTHROUGH;
182202
case 1:
183203
copy_block(d + 0, s + 0);
184204
}

core/utils/cuckoo_map.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <functional>
1313
#include <limits>
1414
#include <stack>
15+
#include <type_traits>
1516
#include <utility>
1617
#include <vector>
1718

@@ -180,7 +181,9 @@ class CuckooMap {
180181
Entry* Find(const K& key, const H& hasher = H(), const E& eq = E()) {
181182
// Blame Effective C++ for this
182183
return const_cast<Entry*>(
183-
static_cast<const typeof(*this)&>(*this).Find(key, hasher, eq));
184+
static_cast<
185+
const typename std::remove_reference<decltype(*this)>::type&>(*this)
186+
.Find(key, hasher, eq));
184187
}
185188

186189
// const version of Find()

env/Dockerfile.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ RUN cd /build && \
2121
git clone -b ${BESS_DPDK_BRANCH} https://github.com/netsys/bess && \
2222
cd /build/bess && \
2323
setarch ${DPDK_ARCH} ./build.py dpdk && \
24-
mv /build/bess/deps/dpdk-17.02 /build/dpdk-17.02 && \
24+
mv /build/bess/deps/dpdk-17.05 /build/dpdk-17.05 && \
2525
rm -rf /build/bess
2626

2727
WORKDIR /build/bess

env/packages.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- g++-4.8
1515
- g++-5
1616
- g++-6
17+
- g++-7
1718
- g++
1819
- clang-3.8
1920
- autoconf
@@ -70,6 +71,9 @@
7071

7172
- name: Compile gRPC and its dependencies
7273
shell: make -j{{ ansible_processor_vcpus }} chdir=/tmp/grpc
74+
environment:
75+
- CC: gcc-6
76+
- CXX: g++-6
7377

7478
- name: Install gRPC
7579
shell: make install chdir=/tmp/grpc

0 commit comments

Comments
 (0)