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

Force expensive packet reallocation #418

Open
wants to merge 2 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
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
/* Define for Click memory allocation debugging. */
#undef CLICK_DMALLOC

/* Define for forcing expensive packet operations. */
#undef CLICK_FORCE_EXPENSIVE

/* Define to generate smaller object files. */
#undef CLICK_OPTIMIZE_SIZE

Expand Down
32 changes: 19 additions & 13 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,6 @@ infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
Expand Down Expand Up @@ -850,6 +849,7 @@ enable_stats
enable_stride
enable_task_heap
enable_dmalloc
enable_force_expensive
enable_valgrind
enable_schedule_debugging
enable_intel_cpu
Expand Down Expand Up @@ -908,7 +908,6 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
Expand Down Expand Up @@ -1161,15 +1160,6 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;

-runstatedir | --runstatedir | --runstatedi | --runstated \
| --runstate | --runstat | --runsta | --runst | --runs \
| --run | --ru | --r)
ac_prev=runstatedir ;;
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
| --run=* | --ru=* | --r=*)
runstatedir=$ac_optarg ;;

-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
Expand Down Expand Up @@ -1307,7 +1297,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir runstatedir
libdir localedir mandir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
Expand Down Expand Up @@ -1460,7 +1450,6 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
Expand Down Expand Up @@ -1552,6 +1541,8 @@ Optional Features:
--disable-stride disable stride scheduler
--enable-task-heap use heap for task list
--enable-dmalloc enable debugging malloc
--enable-force-expensive
force expensive packet operations
--enable-valgrind extra support for debugging with valgrind
--enable-schedule-debugging[=WHAT] enable Click scheduler debugging
(no/yes/extra) [yes]
Expand Down Expand Up @@ -10279,6 +10270,21 @@ fi



# Check whether --enable-force-expensive was given.
if test "${enable_force_expensive+set}" = set; then :
enableval=$enable_force_expensive; :
else
enable_force_expensive=no
fi

if test $enable_force_expensive = yes; then

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

fi



# Check whether --enable-valgrind was given.
if test "${enable_valgrind+set}" = set; then :
enableval=$enable_valgrind; :
Expand Down
8 changes: 8 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,14 @@ if test $enable_dmalloc = yes; then
fi


dnl debug by forcing expensive operations

AC_ARG_ENABLE([force-expensive], [AS_HELP_STRING([--enable-force-expensive], [force expensive packet operations])], :, enable_force_expensive=no)
if test $enable_force_expensive = yes; then
AC_DEFINE([CLICK_FORCE_EXPENSIVE], [1], [Define for forcing expensive packet operations])
fi


dnl valgrind debugging support

AC_ARG_ENABLE([valgrind], [AS_HELP_STRING([--enable-valgrind], [extra support for debugging with valgrind])], :, enable_valgrind=no)
Expand Down
27 changes: 26 additions & 1 deletion include/click/packet.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ Packet::kill()
b->list = 0;
# endif
skbmgr_recycle_skbs(b);
#elif HAVE_CLICK_PACKET_POOL
#elif HAVE_CLICK_PACKET_POOL && !defined(CLICK_FORCE_EXPENSIVE)
if (_use_count.dec_and_test())
WritablePacket::recycle(static_cast<WritablePacket *>(this));
#else
Expand Down Expand Up @@ -1536,6 +1536,19 @@ Packet::shared() const
#endif
}

class PacketRef {
public:
PacketRef(Packet* p) : _p(p->clone()) { }
~PacketRef() { if (_p) _p->kill(); }
Packet* release() {
Packet* tmp = _p;
_p = NULL;
return tmp;
}
private:
Packet* _p;
};

/** @brief Return an unshared packet containing this packet's data.
* @return the unshared packet, which is writable
*
Expand All @@ -1562,6 +1575,9 @@ Packet::shared() const
inline WritablePacket *
Packet::uniqueify()
{
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
if (!shared())
return static_cast<WritablePacket *>(this);
else
Expand All @@ -1571,6 +1587,9 @@ Packet::uniqueify()
inline WritablePacket *
Packet::push(uint32_t len)
{
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
if (headroom() >= len && !shared()) {
WritablePacket *q = (WritablePacket *)this;
#if CLICK_LINUXMODULE /* Linux kernel module */
Expand Down Expand Up @@ -1629,6 +1648,9 @@ Packet::pull(uint32_t len)
inline WritablePacket *
Packet::put(uint32_t len)
{
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
if (tailroom() >= len && !shared()) {
WritablePacket *q = (WritablePacket *)this;
#if CLICK_LINUXMODULE /* Linux kernel module */
Expand Down Expand Up @@ -1830,6 +1852,9 @@ Packet::clear_mac_header()
inline WritablePacket *
Packet::push_mac_header(uint32_t len)
{
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
WritablePacket *q;
if (headroom() >= len && !shared()) {
q = (WritablePacket *)this;
Expand Down
3 changes: 3 additions & 0 deletions lib/packet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,9 @@ Packet::expensive_put(uint32_t nbytes)
Packet *
Packet::shift_data(int offset, bool free_on_failure)
{
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
if (offset == 0)
return this;

Expand Down