Revision: 477 http://vde.svn.sourceforge.net/vde/?rev=477&view=rev Author: rd235 Date: 2011-03-14 15:21:50 +0000 (Mon, 14 Mar 2011)
Log Message: ----------- rd235 experimental branch: ppoll+timespec+dynamic delays for packet queues (tnx Simone Abbakus) Modified Paths: -------------- branches/rd235/vde-2/include/vde.h branches/rd235/vde-2/src/kvde_switch/kvde_switch.c branches/rd235/vde-2/src/vde_switch/Makefile.am branches/rd235/vde-2/src/vde_switch/packetq.c branches/rd235/vde-2/src/vde_switch/packetq.h branches/rd235/vde-2/src/vde_switch/vde_switch.c Modified: branches/rd235/vde-2/include/vde.h =================================================================== --- branches/rd235/vde-2/include/vde.h 2011-03-14 14:18:59 UTC (rev 476) +++ branches/rd235/vde-2/include/vde.h 2011-03-14 15:21:50 UTC (rev 477) @@ -23,5 +23,7 @@ * (expecially with Darwin and other BSDs) */ #define VDE_PQ +#define VDE_PQ_PPOLL +#define VDE_PQ_DYNAMIC #endif Modified: branches/rd235/vde-2/src/kvde_switch/kvde_switch.c =================================================================== --- branches/rd235/vde-2/src/kvde_switch/kvde_switch.c 2011-03-14 14:18:59 UTC (rev 476) +++ branches/rd235/vde-2/src/kvde_switch/kvde_switch.c 2011-03-14 15:21:50 UTC (rev 477) @@ -27,11 +27,6 @@ #include "../vde_switch/switch.h" #include "consmgmt.h" #include "datasock.h" -#undef VDE_PQ -#undef OPTPOLL -#ifdef VDE_PQ -#include <packetq.h> -#endif time_t starting_time; static struct swmodule *swmh; @@ -203,11 +198,7 @@ time_t now; register int n,i; while(1) { -#ifdef VDE_PQ - n=poll(fds,nfds,packetq_timeout); -#else n=poll(fds,nfds,-1); -#endif now=time(NULL); if(n < 0){ if(errno != EINTR) @@ -223,25 +214,7 @@ break; /* PERFORMANCE it is faster returning to poll */ } /* optimization: most used descriptors migrate to the head of the poll array */ -#ifdef OPTPOLL - else - { - if (i < nfds && i > 0 && i != nprio) { - register int i_1=i-1; - if (fdpp[i]->timestamp > fdpp[i_1]->timestamp) { - struct pollfd tfds; - struct pollplus *tfdpp; - tfds=fds[i];fds[i]=fds[i_1];fds[i_1]=tfds; - tfdpp=fdpp[i];fdpp[i]=fdpp[i_1];fdpp[i_1]=tfdpp; - } - } - } -#endif } -#ifdef VDE_PQ - if (packetq_timeout > 0) - packetq_try(); -#endif } } } Modified: branches/rd235/vde-2/src/vde_switch/Makefile.am =================================================================== --- branches/rd235/vde-2/src/vde_switch/Makefile.am 2011-03-14 14:18:59 UTC (rev 476) +++ branches/rd235/vde-2/src/vde_switch/Makefile.am 2011-03-14 15:21:50 UTC (rev 477) @@ -22,7 +22,7 @@ tuntap.c \ tuntap.h -vde_switch_LDADD = $(top_builddir)/src/common/libvdecommon.la +vde_switch_LDADD = $(top_builddir)/src/common/libvdecommon.la -lrt AM_CPPFLAGS = -I$(top_srcdir)/include AM_CFLAGS = -Wall Modified: branches/rd235/vde-2/src/vde_switch/packetq.c =================================================================== --- branches/rd235/vde-2/src/vde_switch/packetq.c 2011-03-14 14:18:59 UTC (rev 476) +++ branches/rd235/vde-2/src/vde_switch/packetq.c 2011-03-14 15:21:50 UTC (rev 477) @@ -1,7 +1,8 @@ /* * packetq - packet queue management. try to send packets several times before discarding. - * Copyright 2005 Renzo Davoli + * Copyright 2005,...,2011 Renzo Davoli * Licensed under the GPLv2 + * 2011 Thanks to Simone Abbakus for the idea of dynamic delay */ #include <stdlib.h> @@ -20,15 +21,38 @@ #include "consmgmt.h" +#define TIMES 10 +#define MAXQLEN 4192 + #ifdef VDE_PQ #include "packetq.h" +#include <time.h> +#ifdef VDE_PQ_PPOLL + +#ifdef CLOCK_MONOTONIC_RAW +#define CLOCK_TYPE CLOCK_MONOTONIC_RAW +#else +#define CLOCK_TYPE CLOCK_MONOTONIC +#endif +struct timespec *packetq_timeout; +static struct timespec packetq_timeout_value; +#ifdef VDE_PQ_DYNAMIC +#define TIMEOUT_MAX 10000000 //Upper bound 10ms +#define TIMEOUT_MIN 1000000 //Lower bound 1ms +#define TIMEOUT_MEAN ((TIMEOUT_MAX + TIMEOUT_MIN) / 2) +#define TIMEOUT_STEP ((TIMEOUT_MAX - TIMEOUT_MIN) / MAXQLEN) +#else +#define TIMEOUT_NS 5000000 +#endif +#else + int packetq_timeout= -1; -static int countq; #define TIMEOUT 5 -#define TIMES 10 -#define MAXQLEN 4192 +#endif +static int countq; + struct packetqq { int (*sender)(int fd, int fd_ctl, void *packet, int len, void *data, int port); int fd; @@ -43,7 +67,11 @@ static struct packetqq *pqh=NULL; static struct packetqq *pqt=NULL; +#ifdef VDE_PQ_PPOLL +static struct timespec last_try; +#else static struct timeval last_try; +#endif void packetq_add(int (*sender)(int fd, int fd_ctl, void *packet, int len, void *data, int port), int fd, int fd_ctl, void *packet, int len, void *data, int port) @@ -64,8 +92,18 @@ new->times=TIMES; new->next=NULL; if (pqh==NULL) { +#ifdef VDE_PQ_PPOLL + clock_gettime(CLOCK_TYPE,&last_try); +#ifdef VDE_PQ_DYNAMIC + packetq_timeout_value.tv_nsec=TIMEOUT_MEAN; +#else + packetq_timeout_value.tv_nsec=TIMEOUT_NS; +#endif + packetq_timeout=&packetq_timeout_value; +#else gettimeofday(&last_try,NULL); packetq_timeout=TIMEOUT; +#endif pqh=pqt=new; } else { pqt->next=new; @@ -104,6 +142,27 @@ void packetq_try(void) { if (pqh != NULL) { +#ifdef VDE_PQ_PPOLL + struct timespec this_try; + long remaining_nsecs; + clock_gettime(CLOCK_TYPE,&this_try); + /* TIMEOUT should never exceed 2.1 secs! */ + remaining_nsecs = packetq_timeout_value.tv_nsec - ((this_try.tv_sec-last_try.tv_sec) * 1000000000 + (this_try.tv_nsec-last_try.tv_nsec)); + if (remaining_nsecs <= 0) { + fd_set fds; + FD_ZERO(&fds); + pqh=packetq_scantry(pqh,&pqt,&fds); + if (pqh != NULL) { + clock_gettime(CLOCK_TYPE,&last_try); +#ifdef VDE_PQ_DYNAMIC + packetq_timeout_value.tv_nsec = TIMEOUT_MAX - TIMEOUT_STEP * countq; +#else + packetq_timeout_value.tv_nsec = TIMEOUT_NS; +#endif + } else + packetq_timeout = NULL; + } +#else struct timeval this_try; gettimeofday(&this_try,NULL); packetq_timeout=TIMEOUT - ((this_try.tv_sec-last_try.tv_sec) * 1000 + @@ -118,6 +177,7 @@ } else packetq_timeout = -1; } +#endif } } @@ -143,7 +203,11 @@ { pqh=packetq_scandelfd(fd,pqh,&pqt); if (pqh == NULL) +#ifdef VDE_PQ_PPOLL + packetq_timeout = NULL; +#else packetq_timeout = -1; +#endif } int packetq_count() Modified: branches/rd235/vde-2/src/vde_switch/packetq.h =================================================================== --- branches/rd235/vde-2/src/vde_switch/packetq.h 2011-03-14 14:18:59 UTC (rev 476) +++ branches/rd235/vde-2/src/vde_switch/packetq.h 2011-03-14 15:21:50 UTC (rev 477) @@ -7,8 +7,13 @@ #ifdef VDE_PQ #ifndef _PACKETQ_H #define _PACKETQ_H +#include <time.h> +#ifdef VDE_PQ_PPOLL +extern struct timespec *packetq_timeout; +#else extern int packetq_timeout; +#endif void packetq_add(int (*sender)(int fd, int fd_ctl, void *packet, int len, void *data, int port), int fd, int fd_ctl, void *packet, int len, void *data, int port); Modified: branches/rd235/vde-2/src/vde_switch/vde_switch.c =================================================================== --- branches/rd235/vde-2/src/vde_switch/vde_switch.c 2011-03-14 14:18:59 UTC (rev 476) +++ branches/rd235/vde-2/src/vde_switch/vde_switch.c 2011-03-14 15:21:50 UTC (rev 477) @@ -5,8 +5,8 @@ * Modified by Ludovico Gardenghi 2005 */ +#define _GNU_SOURCE #include <unistd.h> -#define _GNU_SOURCE #include <getopt.h> #include <stdlib.h> #include <stdio.h> @@ -34,6 +34,7 @@ #ifdef VDE_PQ #include "packetq.h" +#include <poll.h> #endif static struct swmodule *swmh; @@ -207,7 +208,11 @@ register int n,i; while(1) { #ifdef VDE_PQ +#ifdef VDE_PQ_PPOLL + n=ppoll(fds,nfds,packetq_timeout,NULL); +#else n=poll(fds,nfds,packetq_timeout); +#endif #else n=poll(fds,nfds,-1); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d _______________________________________________ vde-users mailing list vde-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vde-users