From patchwork Fri Feb 17 07:18:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 1533 Return-Path: Received: from nm3-vm0.bullet.mail.ukl.yahoo.com (nm3-vm0.bullet.mail.ukl.yahoo.com [217.146.183.228]) by open-mesh.org (Postfix) with SMTP id CA2E1600872 for ; Fri, 17 Feb 2012 08:19:18 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@yahoo.de; dkim-adsp=none Received: from [217.146.183.216] by nm3.bullet.mail.ukl.yahoo.com with NNFMP; 17 Feb 2012 07:19:18 -0000 Received: from [217.146.182.88] by tm9.bullet.mail.ukl.yahoo.com with NNFMP; 17 Feb 2012 07:19:18 -0000 Received: from [127.0.0.1] by smtp151.mail.ukl.yahoo.com with NNFMP; 17 Feb 2012 07:19:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1329463158; bh=F5PuSl64qpXar2h7VHz8IbEFThwjbxLC0TJefw+NRF8=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding; b=cYrGldEEHIB7CjjNs82AY3mkLxFLCizElsusmdpC5G3sNrOtBpyT/f114+sddvf+l1UGpG1LXoRFh9fJo5u5zlmL+3s5+qiLI/oQvlfNTroe9fu+0BZXYHHhHJpPqXEpaGIe9q9L0b3pV4YwxtMmvws4O+gETISlITBJx/qFkbM= X-Yahoo-Newman-Id: 292125.18154.bm@smtp151.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: tBX9dIAVM1kvCFhn1F0UJ4G7xv5WzX05aQvM9MtFuTXnGs6 5J30kltI3hkYuLwIlln7xMHuvZvw1qdLsADY0Wy5Zh.j2i1RO4geZtSuMGMA jI.2ZPD0k0JcFfTzR2kmBm_rKGIbCcBgSfKh_LXUPeFKfY_gWk.Mwsj6IEhJ xoww.ydJyXd_0QdaT30A_6fqjcqkZvbj9F8LAsT4vDfJFwAu6beEWpXGh5d. VDH_3Jze4Dmt3XP7ZQJajaR34tHsleuiwNUko.jUO2tZXzyk0immWRBPUHBB M9q2nbYJKBgp4M4Ea_m7znPpxUZAmFp1LL4ahuOy5I42Zkk.WdiPSaFcKtKT .KypC_NOnOr8Qfeez8X..TAovgQ9N7Ci0JnoDkgqeJnyEvXAtNpvMzpRTudV gyQ-- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@210.177.7.38 with plain) by smtp151.mail.ukl.yahoo.com with SMTP; 16 Feb 2012 23:19:16 -0800 PST From: Marek Lindner To: davem@davemloft.net Date: Fri, 17 Feb 2012 15:18:25 +0800 Message-Id: <1329463110-856-6-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.9 In-Reply-To: <1329463110-856-1-git-send-email-lindner_marek@yahoo.de> References: <1329463110-856-1-git-send-email-lindner_marek@yahoo.de> MIME-Version: 1.0 Cc: netdev@vger.kernel.org, =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= , b.a.t.m.a.n@lists.open-mesh.org, Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 05/10] batman-adv: Move is_out_of_time() to main.h for general use X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Feb 2012 07:19:19 -0000 From: 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 Signed-off-by: Marek Lindner --- net/batman-adv/main.h | 11 +++++++++++ net/batman-adv/translation-table.c | 32 ++++++++++++-------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h index 86354e0..f9c659b 100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h @@ -202,6 +202,17 @@ static inline int compare_eth(const void *data1, const void *data2) return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); } +/** + * has_timed_out - compares current time (jiffies) and timestamp + timeout + * @timestamp: base value to compare with (in jiffies) + * @timeout: added to base value before comparing (in milliseconds) + * + * Returns true if current time is after timestamp + timeout + */ +static inline bool has_timed_out(unsigned long timestamp, unsigned int 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/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index bc518fc..a84e804 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/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))