[Olsr-dev] CCC-Camp07 Results

Hannes Gredler (spam-protected)
Thu Aug 16 19:07:43 CEST 2007


looks good - go for it ! - /hannes

On Thu, Aug 16, 2007 at 06:56:13PM +0200, Bernd Petrovitsch wrote:
| On Wed, 2007-08-15 at 08:57 +0200, Sven-Ola Tuecke wrote:
| [...] 
| > while attending the 2007 CCC's summer camp in Finowfurt, I investigated a
| > bit the wireless terrain. Situation was unique, because we normally do not
| > have ~ 30..40 OLSR nodes in near range.
| 
| Cool:-)
| 
| [...] 
| > http://download-master.berlin.freifunk.net/sven-ola/gmon.txt
| > 
| > To my interpretation, olsr_input_lq_tc() is a good candidate for further
| 
| JftSoC: Since (sufficient recent) gccs automatically inline functions
| called only once (if they are defined before the call),
| deserialize_lq_tc(), process_lq_tc() and destroy_lq_tc() cannot be found
| in the above file.
| 
| > optimization. Every incoming LQ_TC will trigger a lot of mallocs (in this
| > situation for each neighbour included in the message one malloc). After
| > sending the unpacked LQ_TC through processing, the data is freed again.
| 
| Uuugh, it's even worse;-):
| - In deserialize_lq_tc() we malloc a list of "struct lq_tc_neighbor".
| - In process_lq_tc() we malloc a list of "struct tc_mpr_addr" and fill
|   it with the (almost the whole) contents of the former "struct
|   lq_tc_neighbor".
| - And in destroy_lq_tc() we free the "struct lq_tc_neighbor" list again.
| 
| Given the copying of the list elements in process_lq_tc(), 
| struct lq_tc_neighbor and struct tc_mpr_addr are identical except for
| the name of the fields.
| 
| So the obvious first thing to do (earning at least the low hanging
| fruits) and save approx. 50% of the malloc()s and the same number of
| free()s of course and remove some useless code is to kill "struct
| lq_tc_neighbor" and create immediately the final list (of "struct
| tc_mpr_addr"s) in deserialize_lq_tc() as in the attched patch.
| It works for me!
| 
| 	Bernd
| -- 
| Firmix Software GmbH                   http://www.firmix.at/
| mobil: +43 664 4416156                 fax: +43 1 7890849-55
|           Embedded Linux Development and Services

| Index: src/lq_packet.c
| ===================================================================
| RCS file: /cvsroot/olsrd/olsrd-current/src/lq_packet.c,v
| retrieving revision 1.24
| diff -d --unified -r1.24 lq_packet.c
| --- src/lq_packet.c	2 Aug 2007 22:07:19 -0000	1.24
| +++ src/lq_packet.c	16 Aug 2007 16:51:03 -0000
| @@ -147,7 +147,7 @@
|  static void
|  create_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
|  {
| -  struct lq_tc_neighbor *neigh;
| +  struct tc_mpr_addr *neigh;
|    int i;
|    struct neighbor_entry *walker;
|    static int ttl_list[] = { 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, MAX_TTL-1, 0};
| @@ -218,15 +218,15 @@
|  
|            // allocate a neighbour entry
|            
| -          neigh = olsr_malloc(sizeof (struct lq_tc_neighbor), "Build LQ_TC");
| +          neigh = olsr_malloc(sizeof (struct tc_mpr_addr), "Build LQ_TC");
|  		
|            // set the entry's main address
|  
| -          COPY_IP(&neigh->main, &walker->neighbor_main_addr);
| +          COPY_IP(&neigh->address, &walker->neighbor_main_addr);
|  
|            // set the entry's link quality
|  
| -          lnk = get_best_link_to_neighbor(&neigh->main);
| +          lnk = get_best_link_to_neighbor(&neigh->address);
|  
|            if (lnk) {
|              neigh->link_quality = lnk->loss_link_quality;
| @@ -244,7 +244,7 @@
|  static void
|  destroy_lq_tc(struct lq_tc_message *lq_tc)
|  {
| -  struct lq_tc_neighbor *walker, *aux;
| +  struct tc_mpr_addr *walker, *aux;
|  
|    // loop through the queued neighbour entries and free them
|  
| @@ -471,7 +471,7 @@
|  {
|    int off, rem, size;
|    struct lq_tc_header *head;
| -  struct lq_tc_neighbor *neigh;
| +  struct tc_mpr_addr *neigh;
|    unsigned char *buff;
|  
|    if (lq_tc == NULL || outif == NULL)
| @@ -545,7 +545,7 @@
|  
|        // add the current neighbor's IP address
|  
| -      COPY_IP(buff + size, &neigh->main);
| +      COPY_IP(buff + size, &neigh->address);
|        size += olsr_cnf->ipsize;
|  
|        // add the corresponding link quality
| @@ -674,7 +674,7 @@
|    struct lq_tc_header *head;
|    union olsr_ip_addr *addr;
|    unsigned char *curr, *limit;
| -  struct lq_tc_neighbor *neigh;
| +  struct tc_mpr_addr *neigh;
|  
|    lq_tc->neigh = NULL;
|  
| @@ -705,15 +705,21 @@
|  
|    while (curr < limit)
|      {
| -      neigh = olsr_malloc(sizeof (struct lq_tc_neighbor),
| +      // Sven-Ola: Also check the neighbours
| +      if(!olsr_validate_address((union olsr_ip_addr *)curr)) {
| +        curr += olsr_cnf->ipsize;
| +        curr += 2;
| +        continue;
| +      }
| +
| +      neigh = olsr_malloc(sizeof (struct tc_mpr_addr),
|                            "LQ_TC deserialization");
|  
| -      COPY_IP(&neigh->main, curr);
| +      COPY_IP(&neigh->address, curr);
|        curr += olsr_cnf->ipsize;
|  
|        neigh->link_quality = (double)*curr++ / 255.0;
|        neigh->neigh_link_quality = (double)*curr++ / 255.0;
| -
|        curr += 2;
|  
|        neigh->next = lq_tc->neigh;
| @@ -858,8 +864,6 @@
|                union olsr_ip_addr *from, union olsr_message *ser)
|  {
|    struct tc_message tc;
| -  struct lq_tc_neighbor *neigh;
| -  struct tc_mpr_addr *new_neigh;
|  
|    // Sven-Ola: Check the message source addr
|    if(!olsr_validate_address(&lq_tc->from)||!olsr_validate_address(&lq_tc->comm.orig))
| @@ -867,8 +871,6 @@
|        return;
|      }
|  
| -  // XXX - translation is ugly; everybody should use lq_tc_message :-)
| -
|    // move the static fields from LQ_TC to TC
|  
|    tc.vtime = lq_tc->comm.vtime;
| @@ -881,32 +883,8 @@
|    tc.ttl = lq_tc->comm.ttl;
|    tc.ansn = lq_tc->ansn;
|  
| -  tc.multipoint_relay_selector_address = NULL;
| -
|    // move all LQ_TC neighbours to TC
| -
| -  for (neigh = lq_tc->neigh; neigh != NULL; neigh = neigh->next)
| -    {
| -      // Sven-Ola: Also check the neighbours
| -      if(!olsr_validate_address(&neigh->main)) continue;
| -      
| -      // allocate TC neighbour
| -
| -      new_neigh = olsr_malloc(sizeof (struct tc_mpr_addr),
| -                              "LQ_TC translation");
| -
| -      // copy fields
| -
| -      new_neigh->link_quality = neigh->link_quality;
| -      new_neigh->neigh_link_quality = neigh->neigh_link_quality;
| -
| -      COPY_IP(&new_neigh->address, &neigh->main);
| -
| -      // queue TC neighbour
| -
| -      new_neigh->next = tc.multipoint_relay_selector_address;
| -      tc.multipoint_relay_selector_address = new_neigh;
| -    }
| +  tc.multipoint_relay_selector_address = lq_tc->neigh;
|  
|    olsr_tc_tap(&tc, inif, from, ser);
|  }
| @@ -944,8 +922,4 @@
|    // process internal format
|  
|    process_lq_tc(&lq_tc, inif, from, ser);
| -
| -  // destroy internal format
| -
| -  destroy_lq_tc(&lq_tc);
|  }
| Index: src/lq_packet.h
| ===================================================================
| RCS file: /cvsroot/olsrd/olsrd-current/src/lq_packet.h,v
| retrieving revision 1.6
| diff -d --unified -r1.6 lq_packet.h
| --- src/lq_packet.h	20 Feb 2005 18:52:18 -0000	1.6
| +++ src/lq_packet.h	16 Aug 2007 16:51:03 -0000
| @@ -43,6 +43,7 @@
|  #define _OLSR_LQ_PACKET_H
|  
|  #include "olsr_types.h"
| +#include "packet.h"
|  
|  #define LQ_HELLO_MESSAGE      201
|  #define LQ_TC_MESSAGE         202
| @@ -124,20 +125,12 @@
|  
|  // deserialized LQ_TC
|  
| -struct lq_tc_neighbor
| -{
| -  double                link_quality;
| -  double                neigh_link_quality;
| -  union olsr_ip_addr    main;
| -  struct lq_tc_neighbor *next;
| -};
| -
|  struct lq_tc_message
|  {
|    struct olsr_common    comm;
|    union olsr_ip_addr    from;
|    olsr_u16_t            ansn;
| -  struct lq_tc_neighbor *neigh;
| +  struct tc_mpr_addr   *neigh;
|  };
|  
|  // serialized LQ_TC

| -- 
| Olsr-dev mailing list
| (spam-protected)
| http://lists.olsr.org/mailman/listinfo/olsr-dev




More information about the Olsr-dev mailing list