* [B.A.T.M.A.N.] [PATCH] batman-adv: Move is_out_of_time() to main.c for general use @ 2011-12-02 14:15 Martin Hundebøll 2011-12-02 14:37 ` Martin Hundebøll 2011-12-02 14:39 ` [B.A.T.M.A.N.] [PATCH] batman-adv: Rm trailing whitespace from is_my_mac() in main.c Martin Hundebøll 0 siblings, 2 replies; 13+ messages in thread From: Martin Hundebøll @ 2011-12-02 14:15 UTC (permalink / raw) To: b.a.t.m.a.n Both translation tables and network coding use timeouts to do house keeping, so we might as well share the function used to compare a timestamp+timeout with current time. Also, this patch removes a trailing newline in is_my_mac() to satisfy checkpatch Signed-off-by: Martin Hundebøll <martin@hundeboll.net> --- main.c | 4 ++++ main.h | 1 + translation-table.c | 8 -------- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index fb87bdc..0930bb4 100644 --- a/main.c +++ b/main.c @@ -170,7 +170,11 @@ int is_my_mac(const uint8_t *addr) } rcu_read_unlock(); return 0; +} +bool is_out_of_time(unsigned long timestamp, unsigned long timeout) +{ + return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout)); } module_init(batman_init); diff --git a/main.h b/main.h index 464439f..92eb37b 100644 --- a/main.h +++ b/main.h @@ -159,6 +159,7 @@ void mesh_free(struct net_device *soft_iface); void inc_module_count(void); void dec_module_count(void); int is_my_mac(const uint8_t *addr); +bool is_out_of_time(unsigned long timestamp, unsigned long timeout); #ifdef CONFIG_BATMAN_ADV_DEBUG int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3); diff --git a/translation-table.c b/translation-table.c index 7a7df4a..b22f8d9 100644 --- a/translation-table.c +++ b/translation-table.c @@ -108,14 +108,6 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, } -static bool is_out_of_time(unsigned long starting_time, unsigned long timeout) -{ - unsigned long deadline; - deadline = starting_time + msecs_to_jiffies(timeout); - - return time_after(jiffies, deadline); -} - static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) { if (atomic_dec_and_test(&tt_local_entry->common.refcount)) -- 1.7.7.4 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [B.A.T.M.A.N.] [PATCH] batman-adv: Move is_out_of_time() to main.c for general use 2011-12-02 14:15 [B.A.T.M.A.N.] [PATCH] batman-adv: Move is_out_of_time() to main.c for general use Martin Hundebøll @ 2011-12-02 14:37 ` Martin Hundebøll 2011-12-03 7:36 ` Marek Lindner 2011-12-02 14:39 ` [B.A.T.M.A.N.] [PATCH] batman-adv: Rm trailing whitespace from is_my_mac() in main.c Martin Hundebøll 1 sibling, 1 reply; 13+ messages in thread From: Martin Hundebøll @ 2011-12-02 14:37 UTC (permalink / raw) To: b.a.t.m.a.n; +Cc: Martin Hundebøll Both translation tables and network coding use timeouts to do house keeping, so we might as well share the function used to compare a timestamp+timeout with current time. Signed-off-by: Martin Hundebøll <martin@hundeboll.net> --- main.c | 5 +++++ main.h | 1 + translation-table.c | 8 -------- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index 71b56cf..0930bb4 100644 --- a/main.c +++ b/main.c @@ -172,6 +172,11 @@ int is_my_mac(const uint8_t *addr) return 0; } +bool is_out_of_time(unsigned long timestamp, unsigned long timeout) +{ + return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout)); +} + module_init(batman_init); module_exit(batman_exit); diff --git a/main.h b/main.h index 464439f..92eb37b 100644 --- a/main.h +++ b/main.h @@ -159,6 +159,7 @@ void mesh_free(struct net_device *soft_iface); void inc_module_count(void); void dec_module_count(void); int is_my_mac(const uint8_t *addr); +bool is_out_of_time(unsigned long timestamp, unsigned long timeout); #ifdef CONFIG_BATMAN_ADV_DEBUG int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3); diff --git a/translation-table.c b/translation-table.c index 7a7df4a..b22f8d9 100644 --- a/translation-table.c +++ b/translation-table.c @@ -108,14 +108,6 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, } -static bool is_out_of_time(unsigned long starting_time, unsigned long timeout) -{ - unsigned long deadline; - deadline = starting_time + msecs_to_jiffies(timeout); - - return time_after(jiffies, deadline); -} - static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) { if (atomic_dec_and_test(&tt_local_entry->common.refcount)) -- 1.7.7.4 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Move is_out_of_time() to main.c for general use 2011-12-02 14:37 ` Martin Hundebøll @ 2011-12-03 7:36 ` Marek Lindner 2011-12-03 15:41 ` Martin Hundebøll 0 siblings, 1 reply; 13+ messages in thread From: Marek Lindner @ 2011-12-03 7:36 UTC (permalink / raw) To: The list for a Better Approach To Mobile Ad-hoc Networking On Friday, December 02, 2011 22:37:31 Martin Hundebøll wrote: > Both translation tables and network coding use timeouts to do house > keeping, so we might as well share the function used to compare a > timestamp+timeout with current time. > > Signed-off-by: Martin Hundebøll <martin@hundeboll.net> > --- > main.c | 5 +++++ > main.h | 1 + > translation-table.c | 8 -------- > 3 files changed, 6 insertions(+), 8 deletions(-) > > diff --git a/main.c b/main.c > index 71b56cf..0930bb4 100644 > --- a/main.c > +++ b/main.c > @@ -172,6 +172,11 @@ int is_my_mac(const uint8_t *addr) > return 0; > } > > +bool is_out_of_time(unsigned long timestamp, unsigned long timeout) > +{ > + return time_is_before_jiffies(timestamp + > msecs_to_jiffies(timeout)); > +} Since it is a simple one-liner you could make it a define or at least static inline (in main.h). How about a more descriptive name like "reached_timeout()" or "has_timed_out()" ? We could use it in other parts of the code too. You might also want to add a few words about the fact that you did not only move the function but also changed time_after() to time_is_before_jiffies() at the same time. Regards, Marek ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Move is_out_of_time() to main.c for general use 2011-12-03 7:36 ` Marek Lindner @ 2011-12-03 15:41 ` Martin Hundebøll 2011-12-03 15:46 ` Marek Lindner 0 siblings, 1 reply; 13+ messages in thread From: Martin Hundebøll @ 2011-12-03 15:41 UTC (permalink / raw) To: b.a.t.m.a.n On 2011-12-03 08:36, Marek Lindner wrote: > Since it is a simple one-liner you could make it a define or at least static > inline (in main.h). Correct. Maybe the correct solution is to remove the function and just call time_is_before_jiffies() directly instead? -- Kind regards Martin Hundebøll +45 61 65 54 61 martin@hundeboll.net Nordborggade 57, 2. tv 8000 Aarhus C Denmark ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Move is_out_of_time() to main.c for general use 2011-12-03 15:41 ` Martin Hundebøll @ 2011-12-03 15:46 ` Marek Lindner 2011-12-03 15:54 ` Martin Hundebøll 0 siblings, 1 reply; 13+ messages in thread From: Marek Lindner @ 2011-12-03 15:46 UTC (permalink / raw) To: The list for a Better Approach To Mobile Ad-hoc Networking On Saturday, December 03, 2011 23:41:38 Martin Hundebøll wrote: > On 2011-12-03 08:36, Marek Lindner wrote: > > Since it is a simple one-liner you could make it a define or at least > > static inline (in main.h). > > Correct. Maybe the correct solution is to remove the function and just call > time_is_before_jiffies() directly instead? Guess you misread me. I like the idea of having this easy to read wrapper. Before you moved it to main.c it was a static function. The compiler could better optimize it. Cheers, Marek ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Move is_out_of_time() to main.c for general use 2011-12-03 15:46 ` Marek Lindner @ 2011-12-03 15:54 ` Martin Hundebøll 2011-12-08 12:32 ` [B.A.T.M.A.N.] [PATCHv2] batman-adv: Move is_out_of_time() to main.h " Martin Hundebøll 0 siblings, 1 reply; 13+ messages in thread From: Martin Hundebøll @ 2011-12-03 15:54 UTC (permalink / raw) To: b.a.t.m.a.n On 2011-12-03 16:46, Marek Lindner wrote: > On Saturday, December 03, 2011 23:41:38 Martin Hundebøll wrote: >> On 2011-12-03 08:36, Marek Lindner wrote: >>> Since it is a simple one-liner you could make it a define or at least >>> static inline (in main.h). >> >> Correct. Maybe the correct solution is to remove the function and just call >> time_is_before_jiffies() directly instead? > > Guess you misread me. I like the idea of having this easy to read wrapper. > Before you moved it to main.c it was a static function. The compiler could > better optimize it. OK. Didn't misread you; just tried to think :) I'll send a patch with moving it to an inline function in main.h. -- Kind regards Martin Hundebøll +45 61 65 54 61 martin@hundeboll.net Nordborggade 57, 2. tv 8000 Aarhus C Denmark ^ permalink raw reply [flat|nested] 13+ messages in thread
* [B.A.T.M.A.N.] [PATCHv2] batman-adv: Move is_out_of_time() to main.h for general use 2011-12-03 15:54 ` Martin Hundebøll @ 2011-12-08 12:32 ` Martin Hundebøll 2011-12-10 9:28 ` Marek Lindner 0 siblings, 1 reply; 13+ messages in thread From: Martin Hundebøll @ 2011-12-08 12:32 UTC (permalink / raw) To: b.a.t.m.a.n; +Cc: Martin Hundebøll Both translation tables and network coding use timeouts to do house keeping, so we might as well share the function used to compare a timestamp+timeout with current time. For readability and simplicity, the function is renamed to has_timed_out() and uses time_is_before_jiffies() instead of time_after(). Signed-off-by: Martin Hundebøll <martin@hundeboll.net> --- main.h | 5 +++++ translation-table.c | 32 ++++++++++++-------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/main.h b/main.h index 464439f..838bba0 100644 --- a/main.h +++ b/main.h @@ -204,6 +204,11 @@ static inline int compare_eth(const void *data1, const void *data2) return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); } +/* Returns true if current time (jiffies) is after timestamp + timeout */ +static inline bool has_timed_out(unsigned long timestamp, unsigned long timeout) +{ + return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout)); +} #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) diff --git a/translation-table.c b/translation-table.c index 20d6628..d542b9d 100644 --- a/translation-table.c +++ b/translation-table.c @@ -108,14 +108,6 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, } -static bool is_out_of_time(unsigned long starting_time, unsigned long timeout) -{ - unsigned long deadline; - deadline = starting_time + msecs_to_jiffies(timeout); - - return time_after(jiffies, deadline); -} - static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) { if (atomic_dec_and_test(&tt_local_entry->common.refcount)) @@ -420,8 +412,8 @@ static void tt_local_purge(struct bat_priv *bat_priv) if (tt_local_entry->common.flags & TT_CLIENT_PENDING) continue; - if (!is_out_of_time(tt_local_entry->last_seen, - TT_LOCAL_TIMEOUT * 1000)) + if (!has_timed_out(tt_local_entry->last_seen, + TT_LOCAL_TIMEOUT * 1000)) continue; tt_local_set_pending(bat_priv, tt_local_entry, @@ -758,8 +750,8 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv) common); if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM)) continue; - if (!is_out_of_time(tt_global_entry->roam_at, - TT_CLIENT_ROAM_TIMEOUT * 1000)) + if (!has_timed_out(tt_global_entry->roam_at, + TT_CLIENT_ROAM_TIMEOUT * 1000)) continue; bat_dbg(DBG_TT, bat_priv, "Deleting global " @@ -978,8 +970,8 @@ static void tt_req_purge(struct bat_priv *bat_priv) spin_lock_bh(&bat_priv->tt_req_list_lock); list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { - if (is_out_of_time(node->issued_at, - TT_REQUEST_TIMEOUT * 1000)) { + if (has_timed_out(node->issued_at, + TT_REQUEST_TIMEOUT * 1000)) { list_del(&node->list); kfree(node); } @@ -997,8 +989,8 @@ static struct tt_req_node *new_tt_req_node(struct bat_priv *bat_priv, spin_lock_bh(&bat_priv->tt_req_list_lock); list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) { if (compare_eth(tt_req_node_tmp, orig_node) && - !is_out_of_time(tt_req_node_tmp->issued_at, - TT_REQUEST_TIMEOUT * 1000)) + !has_timed_out(tt_req_node_tmp->issued_at, + TT_REQUEST_TIMEOUT * 1000)) goto unlock; } @@ -1591,8 +1583,8 @@ static void tt_roam_purge(struct bat_priv *bat_priv) spin_lock_bh(&bat_priv->tt_roam_list_lock); list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { - if (!is_out_of_time(node->first_time, - ROAMING_MAX_TIME * 1000)) + if (!has_timed_out(node->first_time, + ROAMING_MAX_TIME * 1000)) continue; list_del(&node->list); @@ -1619,8 +1611,8 @@ static bool tt_check_roam_count(struct bat_priv *bat_priv, if (!compare_eth(tt_roam_node->addr, client)) continue; - if (is_out_of_time(tt_roam_node->first_time, - ROAMING_MAX_TIME * 1000)) + if (has_timed_out(tt_roam_node->first_time, + ROAMING_MAX_TIME * 1000)) continue; if (!atomic_dec_not_zero(&tt_roam_node->counter)) -- 1.7.8 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCHv2] batman-adv: Move is_out_of_time() to main.h for general use 2011-12-08 12:32 ` [B.A.T.M.A.N.] [PATCHv2] batman-adv: Move is_out_of_time() to main.h " Martin Hundebøll @ 2011-12-10 9:28 ` Marek Lindner 0 siblings, 0 replies; 13+ messages in thread From: Marek Lindner @ 2011-12-10 9:28 UTC (permalink / raw) To: The list for a Better Approach To Mobile Ad-hoc Networking On Thursday, December 08, 2011 20:32:41 Martin Hundebøll wrote: > Both translation tables and network coding use timeouts to do house > keeping, so we might as well share the function used to compare a > timestamp+timeout with current time. > > For readability and simplicity, the function is renamed to > has_timed_out() and uses time_is_before_jiffies() instead of > time_after(). Applied in revision 7ee2219. Thanks, Marek ^ permalink raw reply [flat|nested] 13+ messages in thread
* [B.A.T.M.A.N.] [PATCH] batman-adv: Rm trailing whitespace from is_my_mac() in main.c 2011-12-02 14:15 [B.A.T.M.A.N.] [PATCH] batman-adv: Move is_out_of_time() to main.c for general use Martin Hundebøll 2011-12-02 14:37 ` Martin Hundebøll @ 2011-12-02 14:39 ` Martin Hundebøll 2011-12-03 7:27 ` Marek Lindner 1 sibling, 1 reply; 13+ messages in thread From: Martin Hundebøll @ 2011-12-02 14:39 UTC (permalink / raw) To: b.a.t.m.a.n; +Cc: Martin Hundebøll Signed-off-by: Martin Hundebøll <martin@hundeboll.net> --- main.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/main.c b/main.c index fb87bdc..71b56cf 100644 --- a/main.c +++ b/main.c @@ -170,7 +170,6 @@ int is_my_mac(const uint8_t *addr) } rcu_read_unlock(); return 0; - } module_init(batman_init); -- 1.7.7.4 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Rm trailing whitespace from is_my_mac() in main.c 2011-12-02 14:39 ` [B.A.T.M.A.N.] [PATCH] batman-adv: Rm trailing whitespace from is_my_mac() in main.c Martin Hundebøll @ 2011-12-03 7:27 ` Marek Lindner 2011-12-03 15:39 ` Martin Hundebøll 0 siblings, 1 reply; 13+ messages in thread From: Marek Lindner @ 2011-12-03 7:27 UTC (permalink / raw) To: The list for a Better Approach To Mobile Ad-hoc Networking On Friday, December 02, 2011 22:39:07 Martin Hundebøll wrote: > Signed-off-by: Martin Hundebøll <martin@hundeboll.net> > --- > main.c | 1 - > 1 files changed, 0 insertions(+), 1 deletions(-) > > diff --git a/main.c b/main.c > index fb87bdc..71b56cf 100644 > --- a/main.c > +++ b/main.c > @@ -170,7 +170,6 @@ int is_my_mac(const uint8_t *addr) > } > rcu_read_unlock(); > return 0; > - > } > > module_init(batman_init); I don't have a trailing whitespace space there and you are removing an entire (empty) line. Not just a whitespace ? My checkpatch also does not complain about your first patch. Where did you get your checkpatch from ? Regards, Marek ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Rm trailing whitespace from is_my_mac() in main.c 2011-12-03 7:27 ` Marek Lindner @ 2011-12-03 15:39 ` Martin Hundebøll 2011-12-08 11:48 ` [B.A.T.M.A.N.] [PATCHv2] batman-adv: Rm empty line " Martin Hundebøll 0 siblings, 1 reply; 13+ messages in thread From: Martin Hundebøll @ 2011-12-03 15:39 UTC (permalink / raw) To: b.a.t.m.a.n On 2011-12-03 08:27, Marek Lindner wrote: > I don't have a trailing whitespace space there and you are removing an entire > (empty) line. Not just a whitespace ? Yes, sorry. The commit should say "empty line" instead of "whitespace". The empty line is also present on git.open-mesh.org: http://git.open-mesh.org/?p=batman-adv.git;a=blob;f=main.c;h=fb87bdc2ce9bdba9b551f90fcdcada42fdc594a4;hb=refs/heads/master#l173 > My checkpatch also does not complain about your first patch. Where did you get > your checkpatch from ? Downloaded it from git.kernel.org: http://git.kernel.org/?p=linux/kernel/git/apw/checkpatch.git;a=blob;f=scripts/checkpatch.pl;h=e29eeea86388d88d7c878383186318632ddac6eb;hb=HEAD Also tried to download the file from 3.1-tagged tree, which make the same complaints as I mentioned on IRC: Patch: http://dpaste.com/664910/ checkpatch.pl complaints: http://paste.pocoo.org/show/515753/ I will make a patch v2 with a corrected commit message. -- Kind regards Martin Hundebøll +45 61 65 54 61 martin@hundeboll.net Nordborggade 57, 2. tv 8000 Aarhus C Denmark ^ permalink raw reply [flat|nested] 13+ messages in thread
* [B.A.T.M.A.N.] [PATCHv2] batman-adv: Rm empty line from is_my_mac() in main.c 2011-12-03 15:39 ` Martin Hundebøll @ 2011-12-08 11:48 ` Martin Hundebøll 2011-12-10 9:18 ` Marek Lindner 0 siblings, 1 reply; 13+ messages in thread From: Martin Hundebøll @ 2011-12-08 11:48 UTC (permalink / raw) To: b.a.t.m.a.n; +Cc: Martin Hundebøll Signed-off-by: Martin Hundebøll <martin@hundeboll.net> --- main.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/main.c b/main.c index fb87bdc..71b56cf 100644 --- a/main.c +++ b/main.c @@ -170,7 +170,6 @@ int is_my_mac(const uint8_t *addr) } rcu_read_unlock(); return 0; - } module_init(batman_init); -- 1.7.8 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCHv2] batman-adv: Rm empty line from is_my_mac() in main.c 2011-12-08 11:48 ` [B.A.T.M.A.N.] [PATCHv2] batman-adv: Rm empty line " Martin Hundebøll @ 2011-12-10 9:18 ` Marek Lindner 0 siblings, 0 replies; 13+ messages in thread From: Marek Lindner @ 2011-12-10 9:18 UTC (permalink / raw) To: The list for a Better Approach To Mobile Ad-hoc Networking On Thursday, December 08, 2011 19:48:26 Martin Hundebøll wrote: > Signed-off-by: Martin Hundebøll <martin@hundeboll.net> > --- > main.c | 1 - > 1 files changed, 0 insertions(+), 1 deletions(-) Applied in revision f742a64. Thanks, Marek ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2011-12-10 9:28 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-12-02 14:15 [B.A.T.M.A.N.] [PATCH] batman-adv: Move is_out_of_time() to main.c for general use Martin Hundebøll 2011-12-02 14:37 ` Martin Hundebøll 2011-12-03 7:36 ` Marek Lindner 2011-12-03 15:41 ` Martin Hundebøll 2011-12-03 15:46 ` Marek Lindner 2011-12-03 15:54 ` Martin Hundebøll 2011-12-08 12:32 ` [B.A.T.M.A.N.] [PATCHv2] batman-adv: Move is_out_of_time() to main.h " Martin Hundebøll 2011-12-10 9:28 ` Marek Lindner 2011-12-02 14:39 ` [B.A.T.M.A.N.] [PATCH] batman-adv: Rm trailing whitespace from is_my_mac() in main.c Martin Hundebøll 2011-12-03 7:27 ` Marek Lindner 2011-12-03 15:39 ` Martin Hundebøll 2011-12-08 11:48 ` [B.A.T.M.A.N.] [PATCHv2] batman-adv: Rm empty line " Martin Hundebøll 2011-12-10 9:18 ` Marek Lindner
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox