Skip to content

Commit 333ef69

Browse files
Jon Paul Maloydavem330
authored andcommitted
tipc: simplify link timer implementation
We create a second, simpler, link timer function, tipc_link_timeout(). The new function makes use of the new FSM function introduced in the previous commit, and just like it, takes a buffer queue as parameter. It returns an event bit field and potentially a link protocol packet to the caller. The existing timer function, link_timeout(), is still needed for a while, so we redesign it to become a wrapper around the new function. Reviewed-by: Ying Xue <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6ab30f9 commit 333ef69

File tree

2 files changed

+72
-45
lines changed

2 files changed

+72
-45
lines changed

net/tipc/link.c

Lines changed: 71 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -193,60 +193,30 @@ int tipc_link_is_active(struct tipc_link *l)
193193

194194
/**
195195
* link_timeout - handle expiration of link timer
196-
* @l_ptr: pointer to link
197196
*/
198197
static void link_timeout(unsigned long data)
199198
{
200-
struct tipc_link *l_ptr = (struct tipc_link *)data;
199+
struct tipc_link *l = (struct tipc_link *)data;
200+
struct sk_buff_head xmitq;
201201
struct sk_buff *skb;
202+
int rc;
202203

203-
tipc_node_lock(l_ptr->owner);
204+
__skb_queue_head_init(&xmitq);
204205

205-
/* update counters used in statistical profiling of send traffic */
206-
l_ptr->stats.accu_queue_sz += skb_queue_len(&l_ptr->transmq);
207-
l_ptr->stats.queue_sz_counts++;
206+
tipc_node_lock(l->owner);
208207

209-
skb = skb_peek(&l_ptr->transmq);
210-
if (skb) {
211-
struct tipc_msg *msg = buf_msg(skb);
212-
u32 length = msg_size(msg);
213-
214-
if ((msg_user(msg) == MSG_FRAGMENTER) &&
215-
(msg_type(msg) == FIRST_FRAGMENT)) {
216-
length = msg_size(msg_get_wrapped(msg));
217-
}
218-
if (length) {
219-
l_ptr->stats.msg_lengths_total += length;
220-
l_ptr->stats.msg_length_counts++;
221-
if (length <= 64)
222-
l_ptr->stats.msg_length_profile[0]++;
223-
else if (length <= 256)
224-
l_ptr->stats.msg_length_profile[1]++;
225-
else if (length <= 1024)
226-
l_ptr->stats.msg_length_profile[2]++;
227-
else if (length <= 4096)
228-
l_ptr->stats.msg_length_profile[3]++;
229-
else if (length <= 16384)
230-
l_ptr->stats.msg_length_profile[4]++;
231-
else if (length <= 32768)
232-
l_ptr->stats.msg_length_profile[5]++;
233-
else
234-
l_ptr->stats.msg_length_profile[6]++;
235-
}
236-
}
208+
rc = tipc_link_timeout(l, &xmitq);
237209

238-
/* do all other link processing performed on a periodic basis */
239-
if (l_ptr->silent_intv_cnt)
240-
link_state_event(l_ptr, SILENCE_EVT);
241-
else if (link_working(l_ptr) && tipc_bclink_acks_missing(l_ptr->owner))
242-
tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0);
210+
if (rc & TIPC_LINK_DOWN_EVT)
211+
tipc_link_reset(l);
243212

244-
l_ptr->silent_intv_cnt++;
245-
if (skb_queue_len(&l_ptr->backlogq))
246-
tipc_link_push_packets(l_ptr);
247-
link_set_timer(l_ptr, l_ptr->keepalive_intv);
248-
tipc_node_unlock(l_ptr->owner);
249-
tipc_link_put(l_ptr);
213+
skb = __skb_dequeue(&xmitq);
214+
if (skb)
215+
tipc_bearer_send(l->owner->net, l->bearer_id,
216+
skb, &l->media_addr);
217+
link_set_timer(l, l->keepalive_intv);
218+
tipc_node_unlock(l->owner);
219+
tipc_link_put(l);
250220
}
251221

252222
static void link_set_timer(struct tipc_link *link, unsigned long time)
@@ -499,6 +469,62 @@ static int tipc_link_fsm_evt(struct tipc_link *l, int evt,
499469
return rc;
500470
}
501471

472+
/* link_profile_stats - update statistical profiling of traffic
473+
*/
474+
static void link_profile_stats(struct tipc_link *l)
475+
{
476+
struct sk_buff *skb;
477+
struct tipc_msg *msg;
478+
int length;
479+
480+
/* Update counters used in statistical profiling of send traffic */
481+
l->stats.accu_queue_sz += skb_queue_len(&l->transmq);
482+
l->stats.queue_sz_counts++;
483+
484+
skb = skb_peek(&l->transmq);
485+
if (!skb)
486+
return;
487+
msg = buf_msg(skb);
488+
length = msg_size(msg);
489+
490+
if (msg_user(msg) == MSG_FRAGMENTER) {
491+
if (msg_type(msg) != FIRST_FRAGMENT)
492+
return;
493+
length = msg_size(msg_get_wrapped(msg));
494+
}
495+
l->stats.msg_lengths_total += length;
496+
l->stats.msg_length_counts++;
497+
if (length <= 64)
498+
l->stats.msg_length_profile[0]++;
499+
else if (length <= 256)
500+
l->stats.msg_length_profile[1]++;
501+
else if (length <= 1024)
502+
l->stats.msg_length_profile[2]++;
503+
else if (length <= 4096)
504+
l->stats.msg_length_profile[3]++;
505+
else if (length <= 16384)
506+
l->stats.msg_length_profile[4]++;
507+
else if (length <= 32768)
508+
l->stats.msg_length_profile[5]++;
509+
else
510+
l->stats.msg_length_profile[6]++;
511+
}
512+
513+
/* tipc_link_timeout - perform periodic task as instructed from node timeout
514+
*/
515+
int tipc_link_timeout(struct tipc_link *l, struct sk_buff_head *xmitq)
516+
{
517+
int rc = 0;
518+
519+
link_profile_stats(l);
520+
if (l->silent_intv_cnt)
521+
rc = tipc_link_fsm_evt(l, SILENCE_EVT, xmitq);
522+
else if (link_working(l) && tipc_bclink_acks_missing(l->owner))
523+
tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, xmitq);
524+
l->silent_intv_cnt++;
525+
return rc;
526+
}
527+
502528
/**
503529
* link_schedule_user - schedule a message sender for wakeup after congestion
504530
* @link: congested link

net/tipc/link.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ int tipc_nl_link_set(struct sk_buff *skb, struct genl_info *info);
245245
int tipc_nl_link_reset_stats(struct sk_buff *skb, struct genl_info *info);
246246
int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[]);
247247
void link_prepare_wakeup(struct tipc_link *l);
248+
int tipc_link_timeout(struct tipc_link *l, struct sk_buff_head *xmitq);
248249

249250
static inline u32 link_own_addr(struct tipc_link *l)
250251
{

0 commit comments

Comments
 (0)