From 7bbc116cf2dbfcd7c0a15ebb4fefa7b2c0bae4c6 Mon Sep 17 00:00:00 2001 From: Michael Blizek Date: Sat, 5 Feb 2011 11:09:28 +0100 Subject: [PATCH] per conn neighbor stall timeout removal --- net/cor/common.c | 7 --- net/cor/cor.h | 17 +------- net/cor/cpacket_parse.c | 34 --------------- net/cor/neighbor.c | 112 ++++++++++++++++++++++-------------------------- net/cor/settings.h | 5 +-- 5 files changed, 53 insertions(+), 122 deletions(-) diff --git a/net/cor/common.c b/net/cor/common.c index 3bc84b9cc5c..3e37a2cf829 100644 --- a/net/cor/common.c +++ b/net/cor/common.c @@ -427,7 +427,6 @@ int conn_init_out(struct conn *rconn, struct neighbor *nb) { int rc = 0; struct conn *sconn = rconn->reversedir; - __u32 stall_timeout_ms = rconn->target.unconnected.stall_timeout_ms; mutex_lock(&(sconn->rcv_lock)); @@ -448,7 +447,6 @@ int conn_init_out(struct conn *rconn, struct neighbor *nb) kref_get(&(nb->ref)); kref_get(&(nb->ref)); - rconn->target.out.stall_timeout_ms = stall_timeout_ms; skb_queue_head_init(&(sconn->source.in.reorder_queue)); atomic_set(&(sconn->source.in.pong_awaiting), 0); @@ -542,11 +540,6 @@ struct conn* alloc_conn(gfp_t allocflags) rconn->crate_forward = ((1 << 31) - (((__u32) 1 << 31) / 10)); sconn->crate_forward = ((1 << 31) - (((__u32) 1 << 31) / 10)); - rconn->target.unconnected.stall_timeout_ms = - CONN_STALL_DEFAULT_TIMEOUT_MS; - sconn->target.unconnected.stall_timeout_ms = - CONN_STALL_DEFAULT_TIMEOUT_MS; - databuf_init(rconn); databuf_init(sconn); diff --git a/net/cor/cor.h b/net/cor/cor.h index 1b6eebe440d..c4d2075408f 100644 --- a/net/cor/cor.h +++ b/net/cor/cor.h @@ -210,23 +210,12 @@ struct cor_sockaddr { * offset[1-4] */ #define CD_LIST_NEIGH 3 -/* - * CD_SET_(FORWARD|BACKWARD)_TIMEOUT[2] length[1-4] timeout_ms[4] - * - * If there is no successful communication with the previous or neighbor for - * this period, the connection will be reset. This value must be between - * NB_STALL_TIME and NB_KILL_TIME. Otherwise it will silently behave as if it - * was set to exactly one of these limits. - */ -#define CD_SET_FORWARD_TIMEOUT 4 -#define CD_SET_BACKWARD_TIMEOUT 5 - /* * CD_SET_TOS[2] length[1-4] forward_tos[1] backward_tos[1] * Only 2 bits of the tos flags are used, the highers 6 bits are ignored. */ -#define CD_SET_TOS 6 +#define CD_SET_TOS 4 #define TOS_NORMAL 0 #define TOS_LATENCY 1 @@ -641,8 +630,6 @@ struct conn{ __u8 in_buffer_wait_list; struct list_head buffer_wait_list; - - __u32 stall_timeout_ms; }unconnected; struct{ @@ -666,8 +653,6 @@ struct conn{ struct resume_block rb; - __u32 stall_timeout_ms; - /* credit rate */ long jiffies_crate_send; __u32 crate_out_raw; diff --git a/net/cor/cpacket_parse.c b/net/cor/cpacket_parse.c index 2e8fa2e5e7c..1c9f0b25230 100644 --- a/net/cor/cpacket_parse.c +++ b/net/cor/cpacket_parse.c @@ -350,36 +350,6 @@ static void parse_set_tos(struct conn *rconn) rconn->reversedir->tos = (rconn->target.unconnected.cmdparams[1]) & 3; } -#warning todo remove??? -static void parse_set_timeout(struct conn *rconn, int backwards) -{ - __u32 timeout; - - if (unlikely(rconn->target.unconnected.paramlen < 4)) { - send_resp_failed(rconn, CDR_EXECFAILED_CMD_TOO_SHORT); - return; - } - - ((char *)&timeout)[0] = rconn->target.unconnected.cmdparams[0]; - ((char *)&timeout)[1] = rconn->target.unconnected.cmdparams[1]; - ((char *)&timeout)[2] = rconn->target.unconnected.cmdparams[2]; - ((char *)&timeout)[3] = rconn->target.unconnected.cmdparams[3]; - - timeout = be32_to_cpu(timeout); - - if (backwards) { - if (rconn->reversedir->targettype != TARGET_OUT) { - send_resp_failed(rconn, CDR_EXECFAILED_ILLEGAL_COMMAND); - return; - } - rconn->reversedir->target.out.stall_timeout_ms = timeout; - } else { - rconn->target.unconnected.stall_timeout_ms = timeout; - } - - send_resp_ok(rconn); -} - static void parse_list_neigh(struct conn *rconn) { __u32 limit; @@ -529,10 +499,6 @@ static void parse_cmd(struct conn *rconn) parse_connect_port(rconn); } else if (code == CD_LIST_NEIGH) { parse_list_neigh(rconn); - } else if (code == CD_SET_FORWARD_TIMEOUT) { - parse_set_timeout(rconn, 0); - } else if (code == CD_SET_BACKWARD_TIMEOUT) { - parse_set_timeout(rconn, 1); } else if (code == CD_SET_TOS) { parse_set_tos(rconn); } else { diff --git a/net/cor/neighbor.c b/net/cor/neighbor.c index a8f254230e0..fc9941b535b 100644 --- a/net/cor/neighbor.c +++ b/net/cor/neighbor.c @@ -411,35 +411,30 @@ present2: } } -static void reset_stall_conns(struct neighbor *nb, - int stall_time_ms, int resetall) +static void reset_all_conns(struct neighbor *nb) { - struct list_head *currlh; - -start: - mutex_lock(&(nb->conn_list_lock)); - currlh = nb->snd_conn_list.next; + while (1) { + struct conn *sconn; - while (currlh != &(nb->snd_conn_list)) { - struct conn *sconn = container_of(currlh, struct conn, - target.out.nb_list); - BUG_ON(sconn->targettype != TARGET_OUT); + mutex_lock(&(nb->conn_list_lock)); - if (resetall || stall_time_ms >= - sconn->target.out.stall_timeout_ms) { - /** - * reset_conn must not be called with conn_list_lock - * held - */ + if (list_empty(&(nb->snd_conn_list))) { + BUG_ON(nb->num_send_conns != 0); mutex_unlock(&(nb->conn_list_lock)); - reset_conn(sconn); - goto start; + break; } - currlh = currlh->next; - } - BUG_ON(list_empty(&(nb->snd_conn_list)) && nb->num_send_conns != 0); - mutex_unlock(&(nb->conn_list_lock)); + sconn = container_of(nb->snd_conn_list.next, struct conn, + target.out.nb_list); + BUG_ON(sconn->targettype != TARGET_OUT); + + /** + * reset_conn must not be called with conn_list_lock + * held + */ + mutex_unlock(&(nb->conn_list_lock)); + reset_conn(sconn); + } } static void stall_timer(struct work_struct *work) @@ -450,54 +445,53 @@ static void stall_timer(struct work_struct *work) int stall_time_ms; __u8 nbstate; - int resetall; - unsigned long iflags; spin_lock_irqsave( &(nb->state_lock), iflags ); stall_time_ms = jiffies_to_msecs(jiffies - nb->state_time.last_roundtrip); nbstate = nb->state; + if (unlikely(nbstate != NEIGHBOR_STATE_STALLED)) + nb->str_timer_pending = 0; + spin_unlock_irqrestore( &(nb->state_lock), iflags ); if (unlikely(nbstate != NEIGHBOR_STATE_STALLED)) { - nb->str_timer_pending = 0; kref_put(&(nb->ref), neighbor_free); return; } - resetall = (stall_time_ms > NB_KILL_TIME_MS); - - /*if(resetall) - printk(KERN_ERR "reset_all");*/ + if (stall_time_ms < NB_KILL_TIME_MS) { + INIT_DELAYED_WORK(&(nb->stalltimeout_timer), stall_timer); + schedule_delayed_work(&(nb->stalltimeout_timer), + msecs_to_jiffies(NB_KILL_TIME_MS - + stall_time_ms)); + return; + } - reset_stall_conns(nb, stall_time_ms, resetall); + printk(KERN_ERR "reset_all"); - if (resetall) { - spin_lock_irqsave( &(nb->state_lock), iflags ); - nb->state = NEIGHBOR_STATE_KILLED; - spin_unlock_irqrestore( &(nb->state_lock), iflags ); + reset_all_conns(nb); - mutex_lock(&neighbor_operation_lock); - list_del(&(nb->nb_list)); - refresh_initial_debitsrate(); - mutex_unlock(&neighbor_operation_lock); - kref_put(&(nb->ref), neighbor_free); /* nb_list */ + spin_lock_irqsave( &(nb->state_lock), iflags ); + nb->state = NEIGHBOR_STATE_KILLED; + spin_unlock_irqrestore( &(nb->state_lock), iflags ); - kref_put(&(nb->ref), neighbor_free); /* stall_timer */ + mutex_lock(&neighbor_operation_lock); + list_del(&(nb->nb_list)); + refresh_initial_debitsrate(); + mutex_unlock(&neighbor_operation_lock); - } else { - INIT_DELAYED_WORK(&(nb->stalltimeout_timer), stall_timer); - schedule_delayed_work(&(nb->stalltimeout_timer), - msecs_to_jiffies(STALL_TIMER_INTERVAL_MS)); - } + kref_put(&(nb->ref), neighbor_free); /* nb_list */ + kref_put(&(nb->ref), neighbor_free); /* stall_timer */ } int get_neigh_state(struct neighbor *nb) { int ret; - int switchedtostalled = 0; unsigned long iflags; + int starttimer = 0; + int stall_time_ms; BUG_ON(nb == 0); @@ -509,7 +503,9 @@ int get_neigh_state(struct neighbor *nb) nb->ping_intransit >= NB_STALL_MINPINGS || nb->ping_intransit >= PING_COOKIES_PER_NEIGH)))) { nb->state = NEIGHBOR_STATE_STALLED; - switchedtostalled = 1; + starttimer = (nb->str_timer_pending == 0); + stall_time_ms = jiffies - nb->state_time.last_roundtrip; + nb->str_timer_pending = 1; printk(KERN_ERR "switched to stalled"); BUG_ON(nb->ping_intransit > PING_COOKIES_PER_NEIGH); } @@ -518,19 +514,13 @@ int get_neigh_state(struct neighbor *nb) spin_unlock_irqrestore( &(nb->state_lock), iflags ); - if (unlikely(switchedtostalled)) { - /*printk(KERN_ERR "switched to stalled");*/ - int pending; - spin_lock_irqsave( &(nb->state_lock), iflags ); - pending = nb->str_timer_pending; - spin_unlock_irqrestore( &(nb->state_lock), iflags ); - - if (pending == 0) { - kref_get(&(nb->ref)); - INIT_DELAYED_WORK(&(nb->stalltimeout_timer), - stall_timer); - schedule_delayed_work(&(nb->stalltimeout_timer), 1); - } + + if (unlikely(starttimer)) { + kref_get(&(nb->ref)); + INIT_DELAYED_WORK(&(nb->stalltimeout_timer), + stall_timer); + schedule_delayed_work(&(nb->stalltimeout_timer), + NB_KILL_TIME_MS - stall_time_ms); } return ret; diff --git a/net/cor/settings.h b/net/cor/settings.h index d485b4ddb0f..e54f0897756 100644 --- a/net/cor/settings.h +++ b/net/cor/settings.h @@ -33,10 +33,7 @@ #define NB_STALL_MINPINGS 10 #define NB_STALL_TIME_MS 10000 -#define NB_KILL_TIME_MS 300000 -#define CONN_STALL_DEFAULT_TIMEOUT_MS 30000 - -#define STALL_TIMER_INTERVAL_MS 1000 +#define NB_KILL_TIME_MS 30000 #define CREDIT_RATE_INITIAL 10000 #define MAX_CREDITRATE_SOCK 268435465 -- 2.11.4.GIT