Skip to content

Commit

Permalink
add --enable-bound-port-transfer config option
Browse files Browse the repository at this point in the history
This uses gcc extensions to remove one level of indirection from the
virtual function calls done by push/pull.  I have not actually seen a
measurable performance improvement from this (in my very limited
testing).  I am curious if anyone else sees any performance win from
it though.

This work was sponsored by Meraki, Inc.

Signed-off-by: Cliff Frey <cliff@meraki.com>
  • Loading branch information
Cliff Frey committed Jan 5, 2011
1 parent 6e5677a commit cd08cd8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
21 changes: 20 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ enable_experimental
enable_skip_elements
with_freebsd
enable_int64
enable_bound_port_transfer
enable_nanotimestamp
enable_tools
enable_dynamic_linking
Expand Down Expand Up @@ -1450,6 +1451,7 @@ Optional Features:
--enable-experimental enable experimental elements in normal groups
--enable-skip-elements=ELTS disable comma-separated elements
--disable-int64 disable 64-bit integer support
--enable-bound-port-transfer enable port transfer function ptr optimization
--enable-nanotimestamp enable nanosecond timestamps
--enable-tools=WHERE enable tools (host/build/mixed/no) [mixed]
--disable-dynamic-linking disable dynamic linking
Expand Down Expand Up @@ -7014,7 +7016,7 @@ else

ac_cv_endian=0
cat > conftest.$ac_ext <<EOF
#line 7017 "configure"
#line 7019 "configure"
#include "confdefs.h"
#include <$endian_hdr>
#ifdef __BYTE_ORDER
Expand Down Expand Up @@ -7638,6 +7640,23 @@ $as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h
fi




# Check whether --enable-bound-port-transfer was given.
if test "${enable_bound_port_transfer+set}" = set; then :
enableval=$enable_bound_port_transfer; :
else
enable_bound_port_transfer=no
fi


if test "$enable_bound_port_transfer" = yes; then

$as_echo "#define HAVE_BOUND_PORT_TRANSFER 1" >>confdefs.h

CXXFLAGS="$CXXFLAGS -Wno-pmf-conversions"
fi

# Check whether --enable-nanotimestamp was given.
if test "${enable_nanotimestamp+set}" = set; then :
enableval=$enable_nanotimestamp;
Expand Down
14 changes: 14 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,20 @@ if test "x$have_timespec" = xyes; then
fi
CLICK_CHECK_POSIX_CLOCKS


dnl
dnl check forms of port transfer
dnl

AC_ARG_ENABLE(bound-port-transfer,
[[ --enable-bound-port-transfer enable port transfer function ptr optimization]],
:, enable_bound_port_transfer=no)

if test "$enable_bound_port_transfer" = yes; then
AC_DEFINE([HAVE_BOUND_PORT_TRANSFER], [1], [Define if Port::push/Port::pull should use bound function pointers.])
CXXFLAGS="$CXXFLAGS -Wno-pmf-conversions"
fi

AC_ARG_ENABLE(nanotimestamp, [ --enable-nanotimestamp enable nanosecond timestamps])
# Default to nanosecond-precision timestamps if clock_gettime is available.
if test "x$enable_nanotimestamp" = x -a "x$have_clock_gettime" = xyes; then
Expand Down
33 changes: 33 additions & 0 deletions include/click/element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ class Element { public:

Element* _e;
int _port;
#if HAVE_BOUND_PORT_TRANSFER
union {
void (*push)(Element *e, int port, Packet *p);
Packet *(*pull)(Element *e, int port);
} _bound;
#endif

#if CLICK_STATS >= 1
mutable unsigned _packets; // How many packets have we moved?
Expand Down Expand Up @@ -509,6 +515,17 @@ Element::Port::assign(Element *owner, Element *e, int port, bool isoutput)
_e = e;
_port = port;
(void) isoutput;
#if HAVE_BOUND_PORT_TRANSFER
if (e) {
if (isoutput) {
void (Element::*pusher)(int, Packet *) = &Element::push;
_bound.push = (void (*)(Element *, int, Packet *)) (e->*pusher);
} else {
Packet *(Element::*puller)(int) = &Element::pull;
_bound.pull = (Packet *(*)(Element *, int)) (e->*puller);
}
}
#endif
}

/** @brief Returns whether this port is active (a push output or a pull input).
Expand Down Expand Up @@ -570,13 +587,21 @@ Element::Port::push(Packet* p) const
#if CLICK_STATS >= 2
++_e->input(_port)._packets;
click_cycles_t c0 = click_get_cycles();
# if HAVE_BOUND_PORT_TRANSFER
_bound.push(_e, _port, p);
# else
_e->push(_port, p);
# endif
click_cycles_t x = click_get_cycles() - c0;
++_e->_calls;
_e->_self_cycles += x;
_owner->_child_cycles += x;
#else
# if HAVE_BOUND_PORT_TRANSFER
_bound.push(_e, _port, p);
# else
_e->push(_port, p);
# endif
#endif
}

Expand All @@ -602,15 +627,23 @@ Element::Port::pull() const
assert(_e);
#if CLICK_STATS >= 2
click_cycles_t c0 = click_get_cycles();
# if HAVE_BOUND_PORT_TRANSFER
Packet *p = _bound.pull(_e, _port);
# else
Packet *p = _e->pull(_port);
# endif
click_cycles_t x = click_get_cycles() - c0;
++_e->_calls;
_e->_self_cycles += x;
_owner->_child_cycles += x;
if (p)
++_e->output(_port)._packets;
#else
# if HAVE_BOUND_PORT_TRANSFER
Packet *p = _bound.pull(_e, _port);
# else
Packet *p = _e->pull(_port);
# endif
#endif
#if CLICK_STATS >= 1
if (p)
Expand Down

0 comments on commit cd08cd8

Please sign in to comment.