Page MenuHomeFreeBSD

Enable the ability to load multiple versions of the same TCP stack
ClosedPublic

Authored by jtl on Jun 7 2017, 11:15 PM.

Details

Summary

This patch enables the ability to load multiple versions of the same TCP stack.

It lets us write simple Makefiles like this:

#
# $FreeBSD$
#

STACKNAME=      bbr_17q22
KMOD=   tcp_${STACKNAME}
SRCS=   bbr.c sack_filter.c

#
# Enable full debugging
#
#CFLAGS += -g

CFLAGS+=        -DMODNAME=${KMOD}
CFLAGS+=        -DSTACKNAME=${STACKNAME}
PREFIX_SYMS=    ${KMOD}_

.include <bsd.kmod.mk>

In the code, we can register non-conflicting module names like this:

MODULE_VERSION(MODNAME, 1);
DECLARE_MODULE(MODNAME, tcp_bbr, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);

We can enable multiple stack names like this:

static const char *my_stack_names[] = {
        __XSTRING(STACKNAME),
#ifdef STACKALIAS
        __XSTRING(STACKALIAS),
#endif
};
...
                num_stacks = nitems(my_stack_names);
                err = register_tcp_functions_as_names(&__tcp_mystack, M_WAITOK,
                    my_stack_names, &num_stacks);

To do this, it:

  • Supports symbol mangling to avoid overlapping symbols between the multiple modules.
  • Lets us use a macro as the module name in the DECLARE_MACRO() and MACRO_VERSION() macros.
  • Lets us register stack aliases (e.g. both a generic name ["default"] and version-specific name ["default_v1"]).

We can then create a new version of the module just by changing the STACKNAME variable.

Test Plan

This is in use in Netflix.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

jtl created this revision.Jun 7 2017, 11:15 PM
jtl edited the summary of this revision. (Show Details)Jun 7 2017, 11:17 PM
sjg edited edge metadata.Jun 8 2017, 12:02 AM

makefile changes look ok, thought the number of ${OBJCOPY} invocations might be getting out of hand.
Since they all work the same it would be possible to accumulate the output of all the awk commands in one file, and then feed that to xargs -J% ${OBJCOPY} % ${.TARGET}

sjg added a comment.Jun 8 2017, 12:17 AM

never mind, objcopy -J% is going to be invoked once per line anyway

sjg accepted this revision.Jun 8 2017, 12:19 AM

so makefiles ok

gnn accepted this revision.Jun 8 2017, 12:25 AM
This revision is now accepted and ready to land.Jun 8 2017, 12:25 AM
This revision was automatically updated to reflect the committed changes.