Commit ae245557 authored by Parthasarathy Bhuvaragan's avatar Parthasarathy Bhuvaragan Committed by David S. Miller

tipc: donot create timers if subscription timeout = TIPC_WAIT_FOREVER

Until now, we create timers even for the subscription requests
with timeout = TIPC_WAIT_FOREVER.
This can be improved by avoiding timer creation when the timeout
is set to TIPC_WAIT_FOREVER.

In this commit, we introduce a check to creates timers only
when timeout != TIPC_WAIT_FOREVER.
Acked-by: default avatarYing Xue <ying.xue@windriver.com>
Reviewed-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarParthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f3ad288c
...@@ -188,12 +188,14 @@ static struct tipc_subscriber *tipc_subscrb_create(int conid) ...@@ -188,12 +188,14 @@ static struct tipc_subscriber *tipc_subscrb_create(int conid)
static void tipc_subscrb_delete(struct tipc_subscriber *subscriber) static void tipc_subscrb_delete(struct tipc_subscriber *subscriber)
{ {
struct tipc_subscription *sub, *temp; struct tipc_subscription *sub, *temp;
u32 timeout;
spin_lock_bh(&subscriber->lock); spin_lock_bh(&subscriber->lock);
/* Destroy any existing subscriptions for subscriber */ /* Destroy any existing subscriptions for subscriber */
list_for_each_entry_safe(sub, temp, &subscriber->subscrp_list, list_for_each_entry_safe(sub, temp, &subscriber->subscrp_list,
subscrp_list) { subscrp_list) {
if (del_timer(&sub->timer)) { timeout = htohl(sub->evt.s.timeout, sub->swap);
if ((timeout == TIPC_WAIT_FOREVER) || del_timer(&sub->timer)) {
tipc_subscrp_delete(sub); tipc_subscrp_delete(sub);
tipc_subscrb_put(subscriber); tipc_subscrb_put(subscriber);
} }
...@@ -217,13 +219,16 @@ static void tipc_subscrp_cancel(struct tipc_subscr *s, ...@@ -217,13 +219,16 @@ static void tipc_subscrp_cancel(struct tipc_subscr *s,
struct tipc_subscriber *subscriber) struct tipc_subscriber *subscriber)
{ {
struct tipc_subscription *sub, *temp; struct tipc_subscription *sub, *temp;
u32 timeout;
spin_lock_bh(&subscriber->lock); spin_lock_bh(&subscriber->lock);
/* Find first matching subscription, exit if not found */ /* Find first matching subscription, exit if not found */
list_for_each_entry_safe(sub, temp, &subscriber->subscrp_list, list_for_each_entry_safe(sub, temp, &subscriber->subscrp_list,
subscrp_list) { subscrp_list) {
if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) { if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) {
if (del_timer(&sub->timer)) { timeout = htohl(sub->evt.s.timeout, sub->swap);
if ((timeout == TIPC_WAIT_FOREVER) ||
del_timer(&sub->timer)) {
tipc_subscrp_delete(sub); tipc_subscrp_delete(sub);
tipc_subscrb_put(subscriber); tipc_subscrb_put(subscriber);
} }
...@@ -267,7 +272,6 @@ static struct tipc_subscription *tipc_subscrp_create(struct net *net, ...@@ -267,7 +272,6 @@ static struct tipc_subscription *tipc_subscrp_create(struct net *net,
sub->swap = swap; sub->swap = swap;
memcpy(&sub->evt.s, s, sizeof(*s)); memcpy(&sub->evt.s, s, sizeof(*s));
atomic_inc(&tn->subscription_count); atomic_inc(&tn->subscription_count);
setup_timer(&sub->timer, tipc_subscrp_timeout, (unsigned long)sub);
return sub; return sub;
} }
...@@ -290,6 +294,10 @@ static void tipc_subscrp_subscribe(struct net *net, struct tipc_subscr *s, ...@@ -290,6 +294,10 @@ static void tipc_subscrp_subscribe(struct net *net, struct tipc_subscr *s,
spin_unlock_bh(&subscriber->lock); spin_unlock_bh(&subscriber->lock);
timeout = htohl(sub->evt.s.timeout, swap); timeout = htohl(sub->evt.s.timeout, swap);
if (timeout == TIPC_WAIT_FOREVER)
return;
setup_timer(&sub->timer, tipc_subscrp_timeout, (unsigned long)sub);
mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout)); mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment