From 9fa00629eb8184f54e525605812191ed9c29398f Mon Sep 17 00:00:00 2001 From: Michael Blizek Date: Sun, 17 Apr 2011 08:04:44 +0200 Subject: [PATCH] function conts attributes, log tables check --- net/cor/common.c | 33 ++++++++++++++++++++++++++------- net/cor/cor.h | 16 ++++++++-------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/net/cor/common.c b/net/cor/common.c index 631dc74d750..4e5fd82eb1c 100644 --- a/net/cor/common.c +++ b/net/cor/common.c @@ -371,8 +371,7 @@ static const __u64 log_300_24_table[] = {0LL, 1920609120652954LL, 1976887263605976LL}; -#warning todo add constant keyword -__u8 enc_log_64_11(__u32 value) +__u8 __attribute__((const)) enc_log_64_11(__u32 value) { int i; BUG_ON(log_64_11_table[255] != 571789581); @@ -384,14 +383,22 @@ __u8 enc_log_64_11(__u32 value) return (__u8)(i-1); /* round down */ } -__u32 dec_log_64_11(__u8 value) +__u32 __attribute__((const)) dec_log_64_11(__u8 value) { BUG_ON(log_64_11_table[255] != 571789581); return log_64_11_table[value]; } -#warning todo table checks (only ascending) -__u16 enc_log_300_24(__u64 value) +static void check_log_64_11_table(void) +{ + int i; + BUG_ON(log_64_11_table[0] != 0); + for (i=1;i<256;i++) { + BUG_ON(log_64_11_table[i] <= log_64_11_table[i-1]); + } +} + +__u16 __attribute__((const)) enc_log_300_24(__u64 value) { int i; BUG_ON(log_300_24_table[1023] != 1976887263605976LL); @@ -403,13 +410,22 @@ __u16 enc_log_300_24(__u64 value) return (__u16)(i-1); /* round down */ } -__u64 dec_log_300_24(__u16 value) +__u64 __attribute__((const)) dec_log_300_24(__u16 value) { BUG_ON(value >= 1024); BUG_ON(log_300_24_table[1023] != 1976887263605976LL); return log_300_24_table[value]; } +static void check_log_300_24_table(void) +{ + int i; + BUG_ON(log_300_24_table[0] != 0); + for (i=1;i<1024;i++) { + BUG_ON(log_300_24_table[i] <= log_300_24_table[i-1]); + } +} + static inline __u64 mul_saturated(__u64 a, __u64 b) { __u64 res = a*b; @@ -428,7 +444,7 @@ static inline int numdigits(__u64 value) } /* approximate (a*b) / c without overflowing a*b */ -__u64 multiply_div(__u64 a, __u64 b, __u64 c) +__u64 __attribute__((const)) multiply_div(__u64 a, __u64 b, __u64 c) { int alen = numdigits(a); int blen = numdigits(b); @@ -1241,6 +1257,9 @@ static int __init cor_common_init(void) struct conn c; + check_log_64_11_table(); + check_log_300_24_table(); + printk(KERN_ERR "sizeof conn: %d", sizeof(c)); printk(KERN_ERR " conn.source: %d", sizeof(c.source)); printk(KERN_ERR " conn.target: %d", sizeof(c.target)); diff --git a/net/cor/cor.h b/net/cor/cor.h index 96ceef5ca9c..3847ff2b293 100644 --- a/net/cor/cor.h +++ b/net/cor/cor.h @@ -763,15 +763,15 @@ struct sock_buffertracker { /* common.c */ extern atomic_t num_conns; -extern __u8 enc_log_64_11(__u32 window_bytes); +extern __u8 __attribute__((const)) enc_log_64_11(__u32 window_bytes); -extern __u32 dec_log_64_11(__u8 window); +extern __u32 __attribute__((const)) dec_log_64_11(__u8 window); -extern __u16 enc_log_300_24(__u64 value); +extern __u16 __attribute__((const)) enc_log_300_24(__u64 value); -extern __u64 dec_log_300_24(__u16 value); +extern __u64 __attribute__((const)) dec_log_300_24(__u16 value); -extern __u64 multiply_div(__u64 a, __u64 b, __u64 c); +extern __u64 __attribute__((const)) multiply_div(__u64 a, __u64 b, __u64 c); extern char *htable_get(struct htable *ht, __u32 key, void *searcheditem); @@ -827,7 +827,7 @@ extern void set_conn_in_decaytime(struct conn *rconn, __u8 decaytime_seqno, extern void connreset_credits(struct conn *conn); -extern void credits_init(void); +extern void __init credits_init(void); /* neighbor.c */ extern void neighbor_free(struct kref *ref); @@ -928,7 +928,7 @@ extern void send_connid_unknown(struct control_msg_out *cm, __u32 conn_id); extern void send_ping_all_conns(struct neighbor *nb); -extern void cor_kgen_init(void); +extern void __init cor_kgen_init(void); /* cpacket_parse.c */ extern void free_cpacket_buffer(__s32 amount); @@ -1011,7 +1011,7 @@ extern int receive_skb(struct conn *rconn, struct sk_buff *skb); extern void wake_sender(struct conn *rconn); -extern void forward_init(void); +extern void __init forward_init(void); /* sock.c */ extern struct mutex sock_bufferlimits_lock; -- 2.11.4.GIT