Skip to content

Commit

Permalink
Merge pull request #526 from NetSys/gcc7
Browse files Browse the repository at this point in the history
GCC 7 Support
  • Loading branch information
sangjinhan authored Jun 20, 2017
2 parents 54cf79d + 5ccefa6 commit 8834b3b
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 36 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ env:
- VER_CXX=g++-5 DEBUG=1
- VER_CXX=g++-5 TAG_SUFFIX=_32 # 32bit build
- VER_CXX=g++-6
- VER_CXX=g++-7

before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
Expand Down
9 changes: 5 additions & 4 deletions core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ $(shell mkdir -p $(DEPDIR)/hooks >/dev/null)
# 'clang' or 'g++'
CXXCOMPILER := $(shell expr $(word 1, $(shell $(CXX) --version)) : '\(clang\|g++\)')

# e.g., 4.9.3 -> 40903. For clang it is always 40201
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/')
CXXVERSION := $(shell $(CXX) -dumpversion)

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

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

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

Expand Down
57 changes: 40 additions & 17 deletions core/kmod/llring.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
#ifndef _LLRING_H_
#define _LLRING_H_

#if defined(__has_cpp_attribute)
#if __has_cpp_attribute(fallthrough)
#define FALLTHROUGH [[fallthrough]]
#elif __has_cpp_attribute(clang::fallthrough)
#define FALLTHROUGH [[clang::fallthrough]]
#else
#define FALLTHROUGH
#endif
#else
#define FALLTHROUGH
#endif

/**
* Note: the ring implementation is not preemptable. A producer must not
* be interrupted by another producer that uses the same ring.
Expand Down Expand Up @@ -111,14 +123,14 @@ static inline void llring_pause(void) { _mm_pause(); }

#endif

/* llring can be used between execution contexts having different address widths.
* In such circumstances, use phys_addr_t rather than void *, whose size would
* be different in 32 bit versus 64 bit contexts.
/* llring can be used between execution contexts having different address
* widths. In such circumstances, use phys_addr_t rather than void *, whose size
* would be different in 32 bit versus 64 bit contexts.
*/
#ifdef __LLRING_USE_PHYS_ADDR__
typedef phys_addr_t llring_addr_t;
#else
typedef void * llring_addr_t;
typedef void *llring_addr_t;
#endif

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

llring_addr_t ring[0]
__llring_cache_aligned; /**< Memory space of ring starts here.
* not volatile so need to be careful
* about compiler re-ordering */
llring_addr_t ring[0] __llring_cache_aligned; /**< Memory space of ring
* starts here. not
* volatile so need to be
* careful about compiler
* re-ordering */
} __llring_cache_aligned;

#define RING_QUOT_EXCEED (1 << 31) /**< Quota exceed for burst ops */
Expand All @@ -236,7 +249,9 @@ struct llring {
r->stats[__lcore_id].name##_bulk += 1; \
} while (0)
#else
#define __RING_STAT_ADD(r, name, n) do {} while(0)
#define __RING_STAT_ADD(r, name, n) \
do { \
} while (0)
#endif

static inline int llring_bytes_with_slots(unsigned int slots)
Expand Down Expand Up @@ -324,8 +339,10 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
switch (n & 0x3) { \
case 3: \
r->ring[idx++] = obj_table[i++]; \
FALLTHROUGH; \
case 2: \
r->ring[idx++] = obj_table[i++]; \
FALLTHROUGH; \
case 1: \
r->ring[idx++] = obj_table[i++]; \
} \
Expand Down Expand Up @@ -355,8 +372,10 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
switch (n & 0x3) { \
case 3: \
obj_table[i++] = r->ring[idx++]; \
FALLTHROUGH; \
case 2: \
obj_table[i++] = r->ring[idx++]; \
FALLTHROUGH; \
case 1: \
obj_table[i++] = r->ring[idx++]; \
} \
Expand Down Expand Up @@ -395,8 +414,8 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
* - n: Actual number of objects enqueued.
*/
static inline int __attribute__((always_inline))
__llring_mp_do_enqueue(struct llring *r, llring_addr_t const *obj_table, unsigned n,
enum llring_queue_behavior behavior)
__llring_mp_do_enqueue(struct llring *r, llring_addr_t const *obj_table,
unsigned n, enum llring_queue_behavior behavior)
{
uint32_t prod_head, prod_next;
uint32_t cons_tail, free_entries;
Expand Down Expand Up @@ -491,8 +510,8 @@ __llring_mp_do_enqueue(struct llring *r, llring_addr_t const *obj_table, unsigne
* - n: Actual number of objects enqueued.
*/
static inline int __attribute__((always_inline))
__llring_sp_do_enqueue(struct llring *r, llring_addr_t const *obj_table, unsigned n,
enum llring_queue_behavior behavior)
__llring_sp_do_enqueue(struct llring *r, llring_addr_t const *obj_table,
unsigned n, enum llring_queue_behavior behavior)
{
uint32_t prod_head, cons_tail;
uint32_t prod_next, free_entries;
Expand Down Expand Up @@ -723,19 +742,22 @@ __llring_sc_do_dequeue(struct llring *r, llring_addr_t *obj_table, unsigned n,
* enqueued.
*/
static inline int __attribute__((always_inline))
llring_mp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table, unsigned n)
llring_mp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table,
unsigned n)
{
return __llring_mp_do_enqueue(r, obj_table, n, LLRING_QUEUE_FIXED);
}

static inline int __attribute__((always_inline))
llring_sp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table, unsigned n)
llring_sp_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table,
unsigned n)
{
return __llring_sp_do_enqueue(r, obj_table, n, LLRING_QUEUE_FIXED);
}

static inline int __attribute__((always_inline))
llring_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table, unsigned n)
llring_enqueue_bulk(struct llring *r, llring_addr_t const *obj_table,
unsigned n)
{
if (r->common.sp_enqueue)
return llring_sp_enqueue_bulk(r, obj_table, n);
Expand Down Expand Up @@ -1057,7 +1079,8 @@ llring_sp_enqueue_burst(struct llring *r, llring_addr_t const *obj_table,
* - n: Actual number of objects enqueued.
*/
static inline int __attribute__((always_inline))
llring_enqueue_burst(struct llring *r, llring_addr_t const *obj_table, unsigned n)
llring_enqueue_burst(struct llring *r, llring_addr_t const *obj_table,
unsigned n)
{
if (r->common.sp_enqueue)
return llring_sp_enqueue_burst(r, obj_table, n);
Expand Down
1 change: 1 addition & 0 deletions core/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define BESS_MESSAGE_H_

#include <cstdarg>
#include <functional>

#include "bess_msg.pb.h"
#include "error.pb.h"
Expand Down
13 changes: 4 additions & 9 deletions core/module_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,15 @@ DEF_MODULE(AcmeModule, "acme_module", "foo bar");

class AcmeModuleWithTask : public Module {
public:
AcmeModuleWithTask() : Module() {
is_task_ = true;
}
AcmeModuleWithTask() : Module() { is_task_ = true; }

static const gate_idx_t kNumIGates = 1;
static const gate_idx_t kNumOGates = 2;

CommandResponse Init(const bess::pb::EmptyArg &) {
return CommandResponse();
}
CommandResponse Init(const bess::pb::EmptyArg &) { return CommandResponse(); }

struct task_result RunTask(void *) override {
struct task_result ret;
return ret;
return task_result();
}
};

Expand Down Expand Up @@ -305,4 +300,4 @@ TEST_F(ModuleTester, GenerateTCGraph) {
EXPECT_EQ(0, t3->parent_tasks().size());
EXPECT_EQ(0, t4->parent_tasks().size());
}
} // namespace (unnamed)
} // namespace
2 changes: 1 addition & 1 deletion core/modules/rewrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Rewrite final : public Module {

size_t num_templates_;
uint16_t template_size_[kNumSlots];
unsigned char templates_[kNumSlots][kMaxTemplateSize] __ymm_aligned;
unsigned char templates_[kNumSlots][kMaxTemplateSize];
};

#endif // BESS_MODULES_REWRITE_H_
26 changes: 23 additions & 3 deletions core/utils/copy.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#ifndef BESS_UTILS_COPY_H_
#define BESS_UTILS_COPY_H_

#include <cstring>
#if defined(__has_cpp_attribute)
#if __has_cpp_attribute(fallthrough)
#define FALLTHROUGH [[fallthrough]]
#elif __has_cpp_attribute(clang::fallthrough)
#define FALLTHROUGH [[clang::fallthrough]]
#else
#define FALLTHROUGH
#endif
#else
#define FALLTHROUGH
#endif

#include <glog/logging.h>
#include <x86intrin.h>

#include <glog/logging.h>
#include <cstring>

#include "common.h"

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

auto *d = reinterpret_cast<char *__restrict__>(dst);
auto *s = reinterpret_cast<const char *__restrict__>(src);
Expand Down Expand Up @@ -79,6 +90,7 @@ static inline void CopySmall(void *__restrict__ dst,
break;
case 9:
memcpy(d + 8, s + 8, 1);
FALLTHROUGH;
case 8:
memcpy(d, s, 8);
break;
Expand All @@ -91,11 +103,13 @@ static inline void CopySmall(void *__restrict__ dst,
break;
case 5:
memcpy(d + 4, s + 4, 1);
FALLTHROUGH;
case 4:
memcpy(d, s, 4);
break;
case 3:
memcpy(d + 2, s + 2, 1);
FALLTHROUGH;
case 2:
memcpy(d, s, 2);
break;
Expand Down Expand Up @@ -169,16 +183,22 @@ static inline void CopyInlined(void *__restrict__ dst,
switch (leftover_blocks) {
case 7:
copy_block(d + 6, s + 6);
FALLTHROUGH;
case 6:
copy_block(d + 5, s + 5);
FALLTHROUGH;
case 5:
copy_block(d + 4, s + 4);
FALLTHROUGH;
case 4:
copy_block(d + 3, s + 3);
FALLTHROUGH;
case 3:
copy_block(d + 2, s + 2);
FALLTHROUGH;
case 2:
copy_block(d + 1, s + 1);
FALLTHROUGH;
case 1:
copy_block(d + 0, s + 0);
}
Expand Down
5 changes: 4 additions & 1 deletion core/utils/cuckoo_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <functional>
#include <limits>
#include <stack>
#include <type_traits>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -180,7 +181,9 @@ class CuckooMap {
Entry* Find(const K& key, const H& hasher = H(), const E& eq = E()) {
// Blame Effective C++ for this
return const_cast<Entry*>(
static_cast<const typeof(*this)&>(*this).Find(key, hasher, eq));
static_cast<
const typename std::remove_reference<decltype(*this)>::type&>(*this)
.Find(key, hasher, eq));
}

// const version of Find()
Expand Down
2 changes: 1 addition & 1 deletion env/Dockerfile.m4
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN cd /build && \
git clone -b ${BESS_DPDK_BRANCH} https://github.com/netsys/bess && \
cd /build/bess && \
setarch ${DPDK_ARCH} ./build.py dpdk && \
mv /build/bess/deps/dpdk-17.02 /build/dpdk-17.02 && \
mv /build/bess/deps/dpdk-17.05 /build/dpdk-17.05 && \
rm -rf /build/bess

WORKDIR /build/bess
4 changes: 4 additions & 0 deletions env/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- g++-4.8
- g++-5
- g++-6
- g++-7
- g++
- clang-3.8
- autoconf
Expand Down Expand Up @@ -70,6 +71,9 @@

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

- name: Install gRPC
shell: make install chdir=/tmp/grpc
Expand Down
1 change: 1 addition & 0 deletions env/rebuild_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ def main(argv):

return 0


if __name__ == '__main__':
sys.exit(main(sys.argv))

0 comments on commit 8834b3b

Please sign in to comment.