From a2ff67c3dc61144b2472bbdd5a6ad153e0b078c3 Mon Sep 17 00:00:00 2001 From: Gianfranco Costamagna Date: Tue, 7 Jan 2014 09:52:51 +0100 Subject: [PATCH] Improve throughput by reducing calls to stats --- include/ec_globals.h | 1 + share/etter.conf.v4 | 1 + share/etter.conf.v6 | 1 + src/ec_conf.c | 3 ++- src/ec_decode.c | 22 +++++++++++++++------- src/ec_dispatcher.c | 24 +++++++++++++++++------- 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/include/ec_globals.h b/include/ec_globals.h index 780185238..c40c9146d 100644 --- a/include/ec_globals.h +++ b/include/ec_globals.h @@ -46,6 +46,7 @@ struct ec_conf { int connection_buffer; int connect_timeout; int sampling_rate; + int packet_update_count; int close_on_eof; int aggressive_dissectors; int skip_forwarded; diff --git a/share/etter.conf.v4 b/share/etter.conf.v4 index 4c954b9d6..f2965a430 100644 --- a/share/etter.conf.v4 +++ b/share/etter.conf.v4 @@ -37,6 +37,7 @@ connect_timeout = 5 # seconds [stats] sampling_rate = 50 # number of packets +packet_update_count = 50 # number of packets [misc] close_on_eof = 1 # boolean value diff --git a/share/etter.conf.v6 b/share/etter.conf.v6 index cef5f395b..4f5a42eb8 100644 --- a/share/etter.conf.v6 +++ b/share/etter.conf.v6 @@ -43,6 +43,7 @@ connect_timeout = 5 # seconds [stats] sampling_rate = 50 # number of packets +packet_update_count = 50 # number of packets [misc] close_on_eof = 1 # boolean value diff --git a/src/ec_conf.c b/src/ec_conf.c index 0c6de5133..da34a9397 100644 --- a/src/ec_conf.c +++ b/src/ec_conf.c @@ -69,6 +69,7 @@ static struct conf_entry connections[] = { static struct conf_entry stats[] = { { "sampling_rate", NULL }, + { "packet_update_count", NULL }, { NULL, NULL }, }; @@ -184,12 +185,12 @@ static void init_structures(void) set_pointer(mitm, "ndp_poison_equal_mac", &EC_GBL_CONF->ndp_poison_equal_mac); set_pointer(mitm, "icmp6_probe_delay", &EC_GBL_CONF->icmp6_probe_delay); #endif - set_pointer(connections, "connection_timeout", &EC_GBL_CONF->connection_timeout); set_pointer(connections, "connection_idle", &EC_GBL_CONF->connection_idle); set_pointer(connections, "connection_buffer", &EC_GBL_CONF->connection_buffer); set_pointer(connections, "connect_timeout", &EC_GBL_CONF->connect_timeout); set_pointer(stats, "sampling_rate", &EC_GBL_CONF->sampling_rate); + set_pointer(stats, "packet_update_count", &EC_GBL_CONF->packet_update_count); set_pointer(misc, "close_on_eof", &EC_GBL_CONF->close_on_eof); set_pointer(misc, "store_profiles", &EC_GBL_CONF->store_profiles); set_pointer(misc, "aggressive_dissectors", &EC_GBL_CONF->aggressive_dissectors); diff --git a/src/ec_decode.c b/src/ec_decode.c index c59bbf54b..d4aaef18b 100644 --- a/src/ec_decode.c +++ b/src/ec_decode.c @@ -39,6 +39,7 @@ /* globals */ +static int count = 0; static struct dec_entry *protocols_table; static unsigned protocols_num; static bool table_sorted = false; @@ -86,9 +87,13 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk CANCELLATION_POINT(); - /* start the timer for the stats */ - stats_half_start(&EC_GBL_STATS->bh); - + count++; + if(count == 1) + { + /* start the timer for the stats */ + stats_half_start(&EC_GBL_STATS->bh); + } + /* XXX -- remove this */ #if 0 if (!EC_GBL_OPTIONS->quiet) @@ -233,10 +238,13 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk /* free the structure */ packet_destroy_object(&po); - - /* calculate the stats */ - stats_half_end(&EC_GBL_STATS->bh, pkthdr->caplen); - + if(count == EC_GBL_CONF->packet_update_count) + { + /* calculate the stats */ + stats_half_end(&EC_GBL_STATS->bh, pkthdr->caplen); + count = 0; + } + CANCELLATION_POINT(); return; diff --git a/src/ec_dispatcher.c b/src/ec_dispatcher.c index 9f74cee92..7cfb1f796 100644 --- a/src/ec_dispatcher.c +++ b/src/ec_dispatcher.c @@ -25,6 +25,8 @@ #include #include +/* globals */ +static int count = 0; /* this is the PO queue from bottom to top half */ struct po_queue_entry { @@ -97,10 +99,14 @@ EC_THREAD_FUNC(top_half) ec_usleep(1); // 1µs continue; } - - /* start the counter for the TopHalf */ - stats_half_start(&EC_GBL_STATS->th); - + + count++; + if(count == 1) + { + /* start the counter for the TopHalf */ + stats_half_start(&EC_GBL_STATS->th); + } + /* remove the packet form the queue */ STAILQ_REMOVE_HEAD(&po_queue, e, next); @@ -140,9 +146,13 @@ EC_THREAD_FUNC(top_half) packet_destroy_object(e->po); SAFE_FREE(e->po); SAFE_FREE(e); - - /* start the counter for the TopHalf */ - stats_half_end(&EC_GBL_STATS->th, pck_len); + + if(count == EC_GBL_CONF->packet_update_count) + { + /* start the counter for the TopHalf */ + stats_half_end(&EC_GBL_STATS->th, pck_len); + count = 0; + } } return NULL;