The following commit has been merged in the master branch: commit 09b9c9a8f02c0e5259da9aaff338fc97b6b49dd4 Author: Marek Lindner lindner_marek@yahoo.de Date: Sat Mar 10 01:14:15 2007 +0100
internal cpu profiler added
diff --git a/Makefile b/Makefile index 870c0a2..b3c6b9f 100644 --- a/Makefile +++ b/Makefile @@ -31,23 +31,23 @@ LDFLAGS = -lpthread UNAME=$(shell uname)
ifeq ($(UNAME),Linux) -OS_OBJ= orginator.o schedule.o posix-specific.o posix.o linux-specific.o linux.o allocate.o bitarray.o hash.o +OS_OBJ= orginator.o schedule.o posix-specific.o posix.o linux-specific.o linux.o allocate.o bitarray.o hash.o profile.o endif
ifeq ($(UNAME),Darwin) -OS_OBJ= orginator.o schedule.o posix-specific.o posix.o bsd.o allocate.o bitarray.o hash.o +OS_OBJ= orginator.o schedule.o posix-specific.o posix.o bsd.o allocate.o bitarray.o hash.o profile.o endif
ifeq ($(UNAME),FreeBSD) -OS_OBJ= orginator.o schedule.o posix-specific.o posix.o bsd.o allocate.o bitarray.o hash.o +OS_OBJ= orginator.o schedule.o posix-specific.o posix.o bsd.o allocate.o bitarray.o hash.o profile.o endif
ifeq ($(UNAME),OpenBSD) -OS_OBJ= orginator.o schedule.o posix-specific.o posix.o bsd.o allocate.o bitarray.o hash.o +OS_OBJ= orginator.o schedule.o posix-specific.o posix.o bsd.o allocate.o bitarray.o hash.o profile.o endif
-LINUX_SRC_C= batman.c orginator.c schedule.c posix-specific.c posix.c linux-specific.c linux.c allocate.c bitarray.c hash.c -LINUX_SRC_H= batman.h orginator.h schedule.h batman-specific.h list.h os.h allocate.h bitarray.h hash.h +LINUX_SRC_C= batman.c orginator.c schedule.c posix-specific.c posix.c linux-specific.c linux.c allocate.c bitarray.c hash.c profile.c +LINUX_SRC_H= batman.h orginator.h schedule.h batman-specific.h list.h os.h allocate.h bitarray.h hash.h profile.h
all: batmand
diff --git a/allocate.c b/allocate.c index 46e4164..fab9849 100644 --- a/allocate.c +++ b/allocate.c @@ -26,7 +26,7 @@ #include "allocate.h"
#define DEBUG_MALLOC -/*#define MEMORY_USAGE*/ +#define MEMORY_USAGE
#define MAGIC_NUMBER 0x12345678
diff --git a/batman.c b/batman.c index 9188dd9..e89535e 100644 --- a/batman.c +++ b/batman.c @@ -211,15 +211,20 @@ void add_del_hna( struct orig_node *orig_node, int8_t del ) {
void choose_gw() {
+ prof_start( PROF_choose_gw ); struct list_head *pos; struct gw_node *gw_node, *tmp_curr_gw = NULL; uint8_t max_gw_class = 0, max_packets = 0, max_gw_factor = 0; static char orig_str[ADDR_STR_LEN];
- if ( routing_class == 0 ) + if ( routing_class == 0 ) { + + prof_stop( PROF_choose_gw ); return;
+ } + if ( list_empty(&gw_list) ) {
if ( curr_gateway != NULL ) { @@ -230,6 +235,7 @@ void choose_gw() {
}
+ prof_stop( PROF_choose_gw ); return;
} @@ -316,12 +322,15 @@ void choose_gw() {
}
+ prof_stop( PROF_choose_gw ); + }
void update_routes( struct orig_node *orig_node, struct neigh_node *neigh_node, unsigned char *hna_recv_buff, int16_t hna_buff_len ) {
+ prof_start( PROF_update_routes ); static char orig_str[ADDR_STR_LEN], next_str[ADDR_STR_LEN];
@@ -406,12 +415,15 @@ void update_routes( struct orig_node *orig_node, struct neigh_node *neigh_node,
}
+ prof_stop( PROF_update_routes ); + }
void update_gw_list( struct orig_node *orig_node, uint8_t new_gwflags ) {
+ prof_start( PROF_update_gw_list ); struct list_head *gw_pos, *gw_pos_tmp; struct gw_node *gw_node; static char orig_str[ADDR_STR_LEN]; @@ -438,6 +450,7 @@ void update_gw_list( struct orig_node *orig_node, uint8_t new_gwflags ) {
}
+ prof_stop( PROF_update_gw_list ); choose_gw(); return;
@@ -458,6 +471,8 @@ void update_gw_list( struct orig_node *orig_node, uint8_t new_gwflags ) {
list_add_tail( &gw_node->list, &gw_list );
+ prof_stop( PROF_update_gw_list ); + choose_gw();
} @@ -466,6 +481,7 @@ void update_gw_list( struct orig_node *orig_node, uint8_t new_gwflags ) {
int isDuplicate( struct orig_node *orig_node, uint16_t seqno ) {
+ prof_start( PROF_is_duplicate ); struct list_head *neigh_pos; struct neigh_node *neigh_node;
@@ -473,11 +489,17 @@ int isDuplicate( struct orig_node *orig_node, uint16_t seqno ) {
neigh_node = list_entry( neigh_pos, struct neigh_node, list );
- if ( get_bit_status( neigh_node->seq_bits, orig_node->last_seqno, seqno ) ) + if ( get_bit_status( neigh_node->seq_bits, orig_node->last_seqno, seqno ) ) { + + prof_stop( PROF_is_duplicate ); return 1;
+ } + }
+ prof_stop( PROF_is_duplicate ); + return 0;
} @@ -551,6 +573,17 @@ int8_t batman() { if ( NULL == ( orig_hash = hash_new( 128, orig_comp, orig_choose ) ) ) return(-1);
+ /* for profiling the functions */ + prof_init( PROF_choose_gw, "choose_gw" ); + prof_init( PROF_update_routes, "update_routes" ); + prof_init( PROF_update_gw_list, "update_gw_list" ); + prof_init( PROF_is_duplicate, "isDuplicate" ); + prof_init( PROF_get_orig_node, "get_orig_node" ); + prof_init( PROF_update_originator, "update_originator" ); + prof_init( PROF_purge_orginator, "purge_orginator" ); + prof_init( PROF_schedule_forward_packet, "schedule_forward_packet" ); + prof_init( PROF_send_outstanding_packets, "send_outstanding_packets" ); + if ( !( list_empty( &hna_list ) ) ) {
list_for_each( hna_pos, &hna_list ) { diff --git a/batman.h b/batman.h index 134eb23..4edf79b 100644 --- a/batman.h +++ b/batman.h @@ -28,10 +28,11 @@ #include "bitarray.h" #include "hash.h" #include "allocate.h" +#include "profile.h"
-#define SOURCE_VERSION "0.2 alpha" +#define SOURCE_VERSION "0.2 alpha (debug)" #define COMPAT_VERSION 2 #define PORT 1966 #define UNIDIRECTIONAL 0x80 @@ -40,6 +41,8 @@
#define UNIX_PATH "/var/run/batmand.socket"
+#define PROFILE_DATA +
/* * No configuration files or fancy command line switches yet diff --git a/hash.c b/hash.c index 067fe39..84f7ffd 100644 --- a/hash.c +++ b/hash.c @@ -1,5 +1,6 @@ /* Copyright (C) 2006 B.A.T.M.A.N. contributors: - * Simon Wunderlich + * Simon Wunderlich, Marek Lindner + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. diff --git a/hash.h b/hash.h index 8a05514..71b4c8c 100644 --- a/hash.h +++ b/hash.h @@ -1,5 +1,6 @@ /* Copyright (C) 2006 B.A.T.M.A.N. contributors: - * Simon Wunderlich + * Simon Wunderlich, Marek Lindner + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. diff --git a/orginator.c b/orginator.c index f4d59ca..d720c87 100644 --- a/orginator.c +++ b/orginator.c @@ -61,14 +61,19 @@ int orig_choose(void *data, int32_t size) { /* this function finds or creates an originator entry for the given address if it does not exits */ struct orig_node *get_orig_node( uint32_t addr ) {
+ prof_start( PROF_get_orig_node ); struct orig_node *orig_node;
orig_node = ((struct orig_node *)hash_find( orig_hash, &addr ));
- if ( orig_node != NULL ) + if ( orig_node != NULL ) { + + prof_stop( PROF_get_orig_node ); return orig_node;
+ } +
debug_output( 4, "Creating new originator\n" );
@@ -95,6 +100,8 @@ struct orig_node *get_orig_node( uint32_t addr ) {
}
+ prof_stop( PROF_get_orig_node ); + return orig_node;
} @@ -103,6 +110,7 @@ struct orig_node *get_orig_node( uint32_t addr ) {
void update_originator( struct orig_node *orig_node, struct packet *in, uint32_t neigh, struct batman_if *if_incoming, unsigned char *hna_recv_buff, int16_t hna_buff_len ) {
+ prof_start( PROF_update_originator ); struct list_head *neigh_pos; struct neigh_node *neigh_node = NULL, *tmp_neigh_node, *best_neigh_node; uint8_t max_packet_count = 0, is_new_seqno = 0; @@ -185,12 +193,15 @@ void update_originator( struct orig_node *orig_node, struct packet *in, uint32_t
orig_node->gwflags = in->gwflags;
+ prof_stop( PROF_update_originator ); + }
void purge_orginator( uint32_t curr_time ) {
+ prof_start( PROF_purge_orginator ); struct hash_it_t *hashit = NULL; struct list_head *neigh_pos, *neigh_temp; struct list_head *gw_pos, *gw_pos_tmp; @@ -286,6 +297,8 @@ void purge_orginator( uint32_t curr_time ) { if ( gw_purged ) choose_gw();
+ prof_stop( PROF_purge_orginator ); + }
@@ -396,6 +409,9 @@ void debug_orginator() {
}
+ if ( debug_clients.clients_num[2] > 0 ) + prof_print(); + }
diff --git a/profile.c b/profile.c new file mode 100644 index 0000000..64e6e6c --- /dev/null +++ b/profile.c @@ -0,0 +1,101 @@ +/* Copyright (C) 2006 B.A.T.M.A.N. contributors: + * Simon Wunderlich, Marek Lindner + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA + * + */ + + + +#include "batman.h" + + + +#if defined PROFILE_DATA + + +static struct prof_container prof_container[PROF_COUNT]; + + + +void prof_init( int32_t index, char *name ) { + + prof_container[index].total_time = 0; + prof_container[index].calls = 0; + prof_container[index].name = name; + +} + + + +void prof_start( int32_t index ) { + + prof_container[index].start_time = clock(); + +} + + + +void prof_stop( int32_t index ) { + + prof_container[index].calls++; + prof_container[index].total_time += clock() - prof_container[index].start_time; + +} + + +void prof_print() { + + int32_t index; + + debug_output( 3, "\nProfile data:\n" ); + + for ( index = 0; index < PROF_COUNT; index++ ) { + + debug_output( 3, " %''30s: cpu time = %10.3f, calls = %i\n", prof_container[index].name, (float)prof_container[index].total_time/CLOCKS_PER_SEC, prof_container[index].calls ); + + } + + debug_output( 3, "\n" ); + +} + + +#else + + +void prof_init( int32_t index, char *name ) { + +} + + + +void prof_start( int32_t index ) { + +} + + + +void prof_stop( int32_t index ) { + +} + + +void prof_print() { + +} + + +#endif diff --git a/orginator.h b/profile.h similarity index 61% copy from orginator.h copy to profile.h index ece749b..653c7f4 100644 --- a/orginator.h +++ b/profile.h @@ -19,10 +19,33 @@
-int orig_comp(void *data1, void *data2); -int orig_choose(void *data, int32_t size); -struct orig_node *get_orig_node( uint32_t addr ); -void update_originator( struct orig_node *orig_node, struct packet *in, uint32_t neigh, struct batman_if *if_incoming, unsigned char *hna_recv_buff, int16_t hna_buff_len ); -void purge_orginator( uint32_t curr_time ); -void debug_orginator(); +enum {
+ PROF_choose_gw, + PROF_update_routes, + PROF_update_gw_list, + PROF_is_duplicate, + PROF_get_orig_node, + PROF_update_originator, + PROF_purge_orginator, + PROF_schedule_forward_packet, + PROF_send_outstanding_packets, + PROF_COUNT + +}; + + +struct prof_container { + + clock_t start_time; + clock_t total_time; + char *name; + uint32_t calls; + +}; + + +void prof_init( int32_t index, char *name ); +void prof_start( int32_t index ); +void prof_stop( int32_t index ); +void prof_print(); diff --git a/schedule.c b/schedule.c index 2fdb92f..0ea0136 100644 --- a/schedule.c +++ b/schedule.c @@ -78,6 +78,7 @@ void schedule_own_packet( struct batman_if *batman_if ) {
void schedule_forward_packet( struct packet *in, uint8_t unidirectional, uint8_t directlink, unsigned char *hna_recv_buff, int16_t hna_buff_len, struct batman_if *if_outgoing ) {
+ prof_start( PROF_schedule_forward_packet ); struct forw_node *forw_node_new;
debug_output( 4, "schedule_forward_packet(): \n" ); @@ -132,12 +133,15 @@ void schedule_forward_packet( struct packet *in, uint8_t unidirectional, uint8_t
}
+ prof_stop( PROF_schedule_forward_packet ); + }
void send_outstanding_packets() {
+ prof_start( PROF_send_outstanding_packets ); struct forw_node *forw_node; struct list_head *forw_pos, *if_pos, *temp; struct batman_if *batman_if; @@ -251,6 +255,8 @@ void send_outstanding_packets() {
}
+ prof_stop( PROF_send_outstanding_packets ); + }