Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gk: convert all batched lookups into coroutines #370

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ SRCS-y := main/main.c
SRCS-y += config/static.c config/dynamic.c
SRCS-y += cps/main.c cps/kni.c cps/elf.c
SRCS-y += ggu/main.c
SRCS-y += gk/main.c gk/fib.c gk/bpf.c
SRCS-y += gk/main.c gk/fib.c gk/bpf.c gk/co.c
SRCS-y += gt/main.c gt/lua_lpm.c
SRCS-y += lls/main.c lls/cache.c lls/arp.c lls/nd.c
SRCS-y += sol/main.c

# Libraries.
SRCS-y += lib/mailbox.c lib/net.c lib/flow.c lib/ipip.c \
lib/luajit-ffi-cdata.c lib/launch.c lib/lpm.c lib/acl.c lib/varip.c \
lib/l2.c lib/ratelimit.c lib/memblock.c lib/log_ratelimit.c
lib/l2.c lib/ratelimit.c lib/memblock.c lib/log_ratelimit.c lib/coro.c

LDLIBS += $(LDIR) -Bstatic -lluajit-5.1 -Bdynamic -lm -lmnl -lkmod
CFLAGS += $(WERROR_FLAGS) -I${GATEKEEPER}/include -I/usr/local/include/luajit-2.0/
EXTRA_CFLAGS += -O3 -g -Wfatal-errors -DALLOW_EXPERIMENTAL_API \
-Wno-deprecated-declarations
-Wno-deprecated-declarations -DCORO_ASM

include $(RTE_SDK)/mk/rte.extapp.mk

Expand Down
36 changes: 23 additions & 13 deletions gk/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ static const struct rte_bpf_xsym flow_handler_init_xsym[] = {
};

struct gk_bpf_pkt_frame {
uint64_t password;
struct flow_entry *fe;
struct ipacket *packet;
struct gk_config *gk_conf;
bool ready_to_tx;
struct gk_bpf_pkt_ctx ctx;
uint64_t password;
struct flow_entry *fe;
struct ipacket *packet;
struct gk_co *this_co;
bool pkt_part2_prefetched;
bool ready_to_tx;
struct gk_bpf_pkt_ctx ctx;
};

static const uint64_t pkt_password = 0xa2e329ba8b15af05;
Expand Down Expand Up @@ -199,6 +200,7 @@ gk_bpf_prep_for_tx(struct gk_bpf_pkt_ctx *ctx, int priority,
int direct_if_possible)
{
int ret;
struct gatekeeper_if *back;
struct gk_bpf_pkt_frame *frame = pkt_ctx_to_frame(ctx);
if (unlikely(frame == NULL))
return -EINVAL;
Expand All @@ -208,11 +210,18 @@ gk_bpf_prep_for_tx(struct gk_bpf_pkt_ctx *ctx, int priority,
if (unlikely(priority < 0 || priority > PRIORITY_MAX))
return -EINVAL;

/* Prepare packet for transmission if needed. */
if (likely(!frame->pkt_part2_prefetched)) {
frame->pkt_part2_prefetched = true;
if (likely(rte_mbuf_prefetch_part2_non_temporal(
frame->packet->pkt)))
gk_yield_next(frame->this_co);
}

back = &frame->this_co->work->gk_conf->net->back;
ret = (direct_if_possible != 0 && priority == PRIORITY_GRANTED)
? update_pkt_priority(frame->packet, priority,
&frame->gk_conf->net->back)
: encapsulate(frame->packet->pkt, priority,
&frame->gk_conf->net->back,
? update_pkt_priority(frame->packet, priority, back)
: encapsulate(frame->packet->pkt, priority, back,
&frame->fe->grantor_fib->u.grantor.gt_addr);

frame->ready_to_tx = ret == 0;
Expand Down Expand Up @@ -486,23 +495,24 @@ parse_packet_further(struct ipacket *packet, struct gk_bpf_pkt_ctx *ctx)
}

int
gk_bpf_decide_pkt(struct gk_config *gk_conf, uint8_t program_index,
gk_bpf_decide_pkt(struct gk_co *this_co, uint8_t program_index,
struct flow_entry *fe, struct ipacket *packet, uint64_t now,
uint64_t *p_bpf_ret)
{
struct gk_bpf_pkt_frame frame = {
.password = pkt_password,
.fe = fe,
.packet = packet,
.gk_conf = gk_conf,
.this_co = this_co,
.pkt_part2_prefetched = false,
.ready_to_tx = false,
.ctx = {
.now = now,
.expire_at = fe->u.bpf.expire_at,
},
};
const struct gk_bpf_flow_handler *handler =
&gk_conf->flow_handlers[program_index];
&this_co->work->gk_conf->flow_handlers[program_index];

if (unlikely(handler->f_pkt == NULL)) {
GK_LOG(WARNING,
Expand Down
3 changes: 2 additions & 1 deletion gk/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define _GATEKEEPER_GK_BPF_H_

#include "gatekeeper_gk.h"
#include "co.h"

/*
* Load the BPF program that handles flows into @gk_conf at
Expand All @@ -32,7 +33,7 @@
int gk_load_bpf_flow_handler(struct gk_config *gk_conf, unsigned int index,
const char *filename, int jit);

int gk_bpf_decide_pkt(struct gk_config *gk_conf, uint8_t program_index,
int gk_bpf_decide_pkt(struct gk_co *this_co, uint8_t program_index,
struct flow_entry *fe, struct ipacket *packet, uint64_t now,
uint64_t *p_bpf_ret);

Expand Down
Loading