Skip to content

Commit

Permalink
dp-core: Add dynamic offload module registration
Browse files Browse the repository at this point in the history
Extend the paravirtualized per-host type offloads with infrastructure
that allows arbitrary modules to plug into the framework. This closely
resembles the offload register/unregister callbacks that were present in
versions R3.1 and R4.1, with the addition of dpdk support (under Linux).

RCU is used to ensure integrity of the offload structure upon
plugging/unplugging. The registration interface exposes symbols when
building the vrouter kernel module. A framework for user space plugging
is not yet available, but dynamic loading could be used to achieve this.

Change-Id: Ifa2ea8af5b0abfeb4e732a4f68d48cf42bd8739f
Depends-On: Ieb451b6374918ef4ad2476610ba013b80aa83ce0
Partial-Bug: #1767107
Signed-off-by: Frik Botha <frederick.botha@netronome.com>
  • Loading branch information
fjbotha committed Dec 6, 2018
1 parent 6f0477e commit 923c988
Show file tree
Hide file tree
Showing 18 changed files with 599 additions and 261 deletions.
2 changes: 1 addition & 1 deletion dp-core/vr_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "vr_ip_mtrie.h"
#include "vr_bridge.h"

#include "vr_offloads.h"
#include "vr_offloads_dp.h"

#define VR_NUM_FLOW_TABLES 1

Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "vr_btable.h"
#include "vr_route.h"
#include "vr_ip_mtrie.h"
#include "vr_offloads.h"
#include "vr_offloads_dp.h"

unsigned int vr_interfaces = VR_MAX_INTERFACES;

Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "vr_sandesh.h"
#include "vr_message.h"
#include "vr_mirror.h"
#include "vr_offloads.h"
#include "vr_offloads_dp.h"

struct vr_mirror_entry *
vrouter_get_mirror(unsigned int rid, unsigned int index)
Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "vr_bridge.h"
#include "vr_datapath.h"
#include "vr_btable.h"
#include "vr_offloads.h"
#include "vr_offloads_dp.h"

unsigned int vr_mpls_labels = VR_DEF_LABELS;

Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "vr_route.h"
#include "vr_hash.h"
#include "vr_mirror.h"
#include "vr_offloads.h"
#include "vr_offloads_dp.h"

extern bool vr_has_to_fragment(struct vr_interface *, struct vr_packet *,
unsigned int);
Expand Down
90 changes: 83 additions & 7 deletions dp-core/vr_offloads.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2018 Mellanox Technologies, Ltd
*/
#include <vrouter.h>
#include <vr_offloads.h>
#include <vr_offloads_dp.h>
#include <vr_btable.h>
#include <vr_packet.h>

Expand Down Expand Up @@ -357,13 +357,25 @@ int
vr_offloads_init(struct vrouter *router)
{
unsigned int entry_size;
struct vr_offload_ops *offload;

if (!datapath_offloads)
return 0;

/* Do not initialize twice. E.g. a soft reset would not have unregistered
* the offloads. */
offload = vr_rcu_dereference(offload_ops);
if (offload)
return 0;

if (!vr_offload_flow_destroy || !vr_offload_flow_create ||
!vr_offload_prepare)
return -ENOSYS;
!vr_offload_prepare) {
/* Not an error necessarily. Offloads are not implemented for this host
* type, so don't register anything. External implementation can still
* be registered after initialization. */
vr_printf("offload: no built-in offload implementation for current context\n");
return 0;
}

if (!offload_tags) {
/* Round up to the next divisor */
Expand All @@ -387,14 +399,14 @@ vr_offloads_init(struct vrouter *router)
}
}

offload_ops = &vr_offload_ops;
vr_offload_register(&vr_offload_ops);

return 0;

}

void
vr_offloads_exit(struct vrouter *router, bool soft_reset)
static void
_vr_offloads_exit(struct vrouter *router, bool soft_reset)
{
struct vr_offload_flow *oflow;
struct vr_offload_tag *otag;
Expand Down Expand Up @@ -443,7 +455,6 @@ vr_offloads_exit(struct vrouter *router, bool soft_reset)

pvif = NULL;
host_ip = 0;
offload_ops = NULL;
}

inline struct vr_offload_flow *
Expand All @@ -458,3 +469,68 @@ vr_offloads_flow_get(unsigned int index)

return oflow;
}

/*
* Called by an external offload module to register itself with vrouter.
*/
int
vr_offload_register(const struct vr_offload_ops *new_handler)
{
struct vr_offload_ops *offload;

if (!datapath_offloads || !new_handler)
return -EINVAL;

offload = vr_rcu_dereference(offload_ops);
if (offload)
return -EBUSY;

offload = vr_malloc(sizeof(*offload), VR_MALLOC_OBJECT);
if (!offload)
return -ENOMEM;
*offload = *new_handler;
vr_rcu_assign_pointer(offload_ops, offload);
vr_synchronize_rcu();

return 0;
}
#if defined(__linux__) && defined(__KERNEL__)
EXPORT_SYMBOL(vr_offload_register);
#endif

/*
* Called by an external offload module to unregister itself with vrouter.
*/
static void
_vr_offload_unregister(void)
{
struct vr_offload_ops *offload = vr_rcu_dereference(offload_ops);

if (offload) {
vr_rcu_assign_pointer(offload_ops, NULL);
vr_synchronize_rcu();
vr_free(offload, VR_MALLOC_OBJECT);
}
}

int
vr_offload_unregister(void)
{
struct vrouter *router = vrouter_get(0);

_vr_offloads_exit(router, false);
_vr_offload_unregister();

return 0;
}
#if defined(__linux__) && defined(__KERNEL__)
EXPORT_SYMBOL(vr_offload_unregister);
#endif

void
vr_offloads_exit(struct vrouter *router, bool soft_reset)
{
_vr_offloads_exit(router, soft_reset);
if (!soft_reset)
_vr_offload_unregister();
}
2 changes: 1 addition & 1 deletion dp-core/vr_qos.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "vr_interface.h"
#include "vr_datapath.h"
#include "vr_qos.h"
#include "vr_offloads.h"
#include "vr_offloads_dp.h"

unsigned int vr_qos_map_entries = VR_DEF_QOS_MAP_ENTRIES;
unsigned int vr_fc_map_entries = VR_DEF_FC_MAP_ENTRIES;
Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vr_route.h>
#include "vr_message.h"
#include "vr_sandesh.h"
#include "vr_offloads.h"
#include "vr_offloads_dp.h"

unsigned int vr_vrfs = VR_DEF_VRFS;

Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <vr_os.h>
#include <vr_types.h>
#include <vr_packet.h>
#include <vr_offloads.h>
#include <vr_offloads_dp.h>
#include "vr_message.h"
#include "vr_btable.h"

Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_vrf_assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "vr_message.h"
#include "vr_sandesh.h"
#include "vr_packet.h"
#include "vr_offloads.h"
#include "vr_offloads_dp.h"
#include <vr_interface.h>
#include <vr_response.h>

Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "vr_vxlan.h"
#include "vr_bridge.h"
#include "vr_datapath.h"
#include "vr_offloads.h"
#include "vr_offloads_dp.h"

int
vr_vxlan_input(struct vrouter *router, struct vr_packet *pkt,
Expand Down
2 changes: 1 addition & 1 deletion dp-core/vrouter.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <vr_mirror.h>
#include <vr_vxlan.h>
#include <vr_qos.h>
#include <vr_offloads.h>
#include <vr_offloads_dp.h>

static struct vrouter router;
struct host_os *vrouter_host;
Expand Down
2 changes: 1 addition & 1 deletion dpdk/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env.Append(LIBPATH = ['../host', '../sandesh', '../dp-core'])

# Libraries
env.Replace(LIBS = ['dp_core', 'dp_sandesh_c', 'dp_core', 'sandesh-c'])
env.Append(LIBS = ['rt', 'dl', 'pthread', 'urcu-qsbr'])
env.Append(LIBS = ['rt', 'dl', 'pthread', 'urcu-qsbr', 'urcu-bp'])
env.Append(LINKFLAGS = env['DPDK_LINKFLAGS'])

dpdk_objs = env.Object(Glob('*.c'))
Expand Down
Loading

0 comments on commit 923c988

Please sign in to comment.