batman-adv: Replace bitarray operations with bitmap [aka. lets break batman-av]
RFC 1/1 batman-adv: Replace bitarray operations with bitmap [aka. lets break batman-av]
bitarray.c consists mostly of functionality that is already available as part of the standard kernel API. batman-adv could use architecture optimized code and reduce the binary size by switching to the standard functions.
--
This patch is completely untested. Simon and I just talked about standard kernel bit operations and noticed that we hadn't fulfilled our promise to remove the code that is already available in the linux kernel. So this is just a reminder and should not be seen as a finished patch.
bat_iv_ogm.c | 5 ++- bitarray.c | 92 +++++---------------------------------------------------- bitarray.h | 5 --- main.h | 2 +- routing.c | 2 +- types.h | 4 +- 6 files changed, 15 insertions(+), 95 deletions(-)
bat_iv_ogm.c +3 -2
@@ -874,7 +874,8 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, seq_diff, set_mark); tmp_neigh_node->real_packet_count = -bit_packet_count (tmp_neigh_node->real_bits); +bitmap_weight (tmp_neigh_node->real_bits, +TQ_LOCAL_WINDOW_SIZE ); }rcu_read_unlock ();
@@ -1013,7 +1014,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr, if_incoming_seqno - batman_ogm_packet->seqno - 2); orig_neigh_node->bcast_own_sum[if_incoming->if_num] = -bit_packet_count (word); +bitmap_weight (word,TQ_LOCAL_WINDOW_SIZE );spin_unlock_bh (&orig_neigh_node->ogm_cnt_lock); }
bitarray.c +8 -84
133 lines not on this page · raw message
bitarray.h +0 -5
@@ -22,8 +22,6 @@#ifndef _NET_BATMAN_ADV_BITARRAY_H_#define _NET_BATMAN_ADV_BITARRAY_H_ -#define WORD_BIT_SIZE (sizeof(unsigned long) * 8) -/* returns true if the corresponding bit in the given seq_bits indicates true * and curr_seqno is within range of last_seqno */ int get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
@@ -38,7 +36,4 @@ void bit_mark(unsigned long *seq_bits, int32_t n);int bit_get_packet (void *priv,unsigned long *seq_bits,int32_t seq_num_diff,int set_mark); -/* count the hamming weight, how many good packets did we receive? */ -int bit_packet_count (const unsigned long *seq_bits); -#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */
main.h +1 -1
@@ -65,7 +65,7 @@#define NULL_IFINDEX 0/* dummy ifindex used to avoid iface checks */ -#define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE) +#define NUM_WORDS BITS_TO_LONGS(TQ_LOCAL_WINDOW_SIZE)#define LOG_BUF_LEN 8192/* has to be a power of 2 */
routing.c +1 -1
@@ -52,7 +52,7 @@ void slide_own_bcast_window(struct hard_iface *hard_iface)bit_get_packet (bat_priv, word,1 ,0 ); orig_node->bcast_own_sum[hard_iface->if_num] = -bit_packet_count (word); +bitmap_weight (word,TQ_LOCAL_WINDOW_SIZE );spin_unlock_bh (&orig_node->ogm_cnt_lock); }rcu_read_unlock ();
types.h +2 -2
@@ -90,7 +90,7 @@ struct orig_node {bool tt_poss_change;uint32_t last_real_seqno;uint8_t last_ttl; -unsigned long bcast_bits[NUM_WORDS ]; +DECLARE_BITMAP (bcast_bits,TQ_LOCAL_WINDOW_SIZE );uint32_t last_bcast_seqno;struct hlist_head neigh_list;struct list_head frag_list;
@@ -132,7 +132,7 @@ struct neigh_node {uint8_t last_ttl;struct list_head bonding_list;unsigned long last_valid; -unsigned long real_bits[NUM_WORDS ]; +DECLARE_BITMAP (real_bits,TQ_LOCAL_WINDOW_SIZE );atomic_t refcount;struct rcu_head rcu;struct orig_node *orig_node;
Signature · 1 line
1.7.7.3
Hi,
Quoted 4 lines
bitarray.cconsists mostly of functionality that is already available as part of the standard kernel API. batman-adv could use architecture optimized code and reduce the binary size by switching to the standard functions.
it took some time to read about the kernel bit functions but I think this is the right way to go. From my end it looks pretty solid. Though I have 2 comments:
* get_bit_status()/bit_mark()/bit_shift() now are wrapper functions of the
linux kernel functions with an additional check. How about we follow the kernel naming convention plus a small prefix ? For example:
bat_test_bit()/bat_set_bit()/bat_bitmap_shift_left() ? We probably could also inline those 3 functions since they don't do much.
* Am I right assuming that you did not find something nice / handy for our
bitarrays bcast_own/bcast_own_sum ? At the moment we deal with them in a "manual" fashion ..
Cheers,
Marek
RFC v2 1/1 batman-adv: Replace bitarray operations with bitmap
In reply to Sven Eckelmannbitarray.c consists mostly of functionality that is already available as part of the standard kernel API. batman-adv could use architecture optimized code and reduce the binary size by switching to the standard functions.
---
Just renamed all functions to bat_xxx where xxx is the name of the function used in the wrapper. Also all wrapper functions can now be inlined.
And yes, I didn't find a good way to deal with the bcast_own/bcast_own_sum bitarray monster.
bat_iv_ogm.c | 15 ++++--- bitarray.c | 118 ++++----------------------------------------------------- bitarray.h | 26 +++++++++---- main.h | 2 +- routing.c | 6 +- types.h | 4 +- 6 files changed, 41 insertions(+), 130 deletions(-)
bat_iv_ogm.c +8 -7
@@ -858,9 +858,9 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,hlist_for_each_entry_rcu (tmp_neigh_node, node, &orig_node->neigh_list, list) { - is_duplicate |=get_bit_status (tmp_neigh_node->real_bits, - orig_node->last_real_seqno, - batman_ogm_packet->seqno); + is_duplicate |=bat_test_bit (tmp_neigh_node->real_bits, + orig_node->last_real_seqno, + batman_ogm_packet->seqno);if (compare_eth (tmp_neigh_node->addr, ethhdr->h_source) && (tmp_neigh_node->if_incoming == if_incoming))
@@ -874,7 +874,8 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, seq_diff, set_mark); tmp_neigh_node->real_packet_count = -bit_packet_count (tmp_neigh_node->real_bits); +bitmap_weight (tmp_neigh_node->real_bits, +TQ_LOCAL_WINDOW_SIZE ); }rcu_read_unlock ();
@@ -1009,11 +1010,11 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,spin_lock_bh (&orig_neigh_node->ogm_cnt_lock); word = &(orig_neigh_node->bcast_own[offset]); -bit_mark (word, - if_incoming_seqno - +bat_set_bit (word, + if_incoming_seqno - batman_ogm_packet->seqno -2 ); orig_neigh_node->bcast_own_sum[if_incoming->if_num] = -bit_packet_count (word); +bitmap_weight (word,TQ_LOCAL_WINDOW_SIZE );spin_unlock_bh (&orig_neigh_node->ogm_cnt_lock); }
bitarray.c +9 -109
160 lines not on this page · raw message
bitarray.h +18 -8
@@ -22,23 +22,33 @@#ifndef _NET_BATMAN_ADV_BITARRAY_H_#define _NET_BATMAN_ADV_BITARRAY_H_ -#define WORD_BIT_SIZE (sizeof(unsigned long) * 8) -/* returns true if the corresponding bit in the given seq_bits indicates true * and curr_seqno is within range of last_seqno */ -int get_bit_status (const unsigned long *seq_bits,uint32_t last_seqno, -uint32_t curr_seqno); +static inline int bat_test_bit (const unsigned long *seq_bits, +uint32_t last_seqno,uint32_t curr_seqno) +{ +int32_t diff; + + diff = last_seqno - curr_seqno; +if (diff <0 || diff >=TQ_LOCAL_WINDOW_SIZE ) +return 0 ; +else +return test_bit (diff, seq_bits); +}/* turn corresponding bit on, so we can remember that we got the packet */ -void bit_mark (unsigned long *seq_bits,int32_t n); +static inline void bat_set_bit (unsigned long *seq_bits,int32_t n) +{ +/* if too old, just drop it */ +if (n <0 || n >=TQ_LOCAL_WINDOW_SIZE ) +return ; +set_bit (n, seq_bits);/* turn the position on */ +}/* receive and process one packet, returns 1 if received seq_num is considered * new, 0 if old */ int bit_get_packet (void *priv,unsigned long *seq_bits,int32_t seq_num_diff,int set_mark); -/* count the hamming weight, how many good packets did we receive? */ -int bit_packet_count (const unsigned long *seq_bits); -#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */
main.h +1 -1
@@ -65,7 +65,7 @@#define NULL_IFINDEX 0/* dummy ifindex used to avoid iface checks */ -#define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE) +#define NUM_WORDS BITS_TO_LONGS(TQ_LOCAL_WINDOW_SIZE)#define LOG_BUF_LEN 8192/* has to be a power of 2 */
routing.c +3 -3
@@ -52,7 +52,7 @@ void slide_own_bcast_window(struct hard_iface *hard_iface)bit_get_packet (bat_priv, word,1 ,0 ); orig_node->bcast_own_sum[hard_iface->if_num] = -bit_packet_count (word); +bitmap_weight (word,TQ_LOCAL_WINDOW_SIZE );spin_unlock_bh (&orig_node->ogm_cnt_lock); }rcu_read_unlock ();
@@ -1049,8 +1049,8 @@ int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if)spin_lock_bh (&orig_node->bcast_seqno_lock);/* check whether the packet is a duplicate */ -if (get_bit_status (orig_node->bcast_bits, orig_node->last_bcast_seqno, -ntohl (bcast_packet->seqno))) +if (bat_test_bit (orig_node->bcast_bits, orig_node->last_bcast_seqno, +ntohl (bcast_packet->seqno))) goto spin_unlock; seq_diff =ntohl (bcast_packet->seqno) - orig_node->last_bcast_seqno;
types.h +2 -2
@@ -90,7 +90,7 @@ struct orig_node {bool tt_poss_change;uint32_t last_real_seqno;uint8_t last_ttl; -unsigned long bcast_bits[NUM_WORDS ]; +DECLARE_BITMAP (bcast_bits,TQ_LOCAL_WINDOW_SIZE );uint32_t last_bcast_seqno;struct hlist_head neigh_list;struct list_head frag_list;
@@ -132,7 +132,7 @@ struct neigh_node {uint8_t last_ttl;struct list_head bonding_list;unsigned long last_valid; -unsigned long real_bits[NUM_WORDS ]; +DECLARE_BITMAP (real_bits,TQ_LOCAL_WINDOW_SIZE );atomic_t refcount;struct rcu_head rcu;struct orig_node *orig_node;
Signature · 1 line
1.7.8.3
Marek Lindner
AppliedRe: [B.A.T.M.A.N.] [RFCv2] batman-adv: Replace bitarray operations with bitmap
Quoted 4 lines · On Sunday, February 05, 2012 00:34:52 Sven Eckelmann wrote:
bitarray.cconsists mostly of functionality that is already available as part of the standard kernel API. batman-adv could use architecture optimized code and reduce the binary size by switching to the standard functions.
Applied in revision a9f0721.
Thanks,
Marek