Skip to content

Commit e3eea1e

Browse files
Jon Paul Maloydavem330
authored andcommitted
tipc: clean up handling of message priorities
Messages transferred by TIPC are assigned an "importance priority", -an integer value indicating how to treat the message when there is link or destination socket congestion. There is no separate header field for this value. Instead, the message user values have been chosen in ascending order according to perceived importance, so that the message user field can be used for this. This is not a good solution. First, we have many more users than the needed priority levels, so we end up with treating more priority levels than necessary. Second, the user field cannot always accurately reflect the priority of the message. E.g., a message fragment packet should really have the priority of the enveloped user data message, and not the priority of the MSG_FRAGMENTER user. Until now, we have been working around this problem in different ways, but it is now time to implement a consistent way of handling such priorities, although still within the constraint that we cannot allocate any more bits in the regular data message header for this. In this commit, we define a new priority level, TIPC_SYSTEM_IMPORTANCE, that will be the only one used apart from the four (lower) user data levels. All non-data messages map down to this priority. Furthermore, we take some free bits from the MSG_FRAGMENTER header and allocate them to store the priority of the enveloped message. We then adjust the functions msg_importance()/msg_set_importance() so that they read/set the correct header fields depending on user type. This small protocol change is fully compatible, because the code at the receiving end of a link currently reads the importance level only from user data messages, where there is no change. Reviewed-by: Erik Hugne <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 05dcc5a commit e3eea1e

File tree

4 files changed

+50
-61
lines changed

4 files changed

+50
-61
lines changed

net/tipc/bcast.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ int tipc_bclink_xmit(struct net *net, struct sk_buff_head *list)
383383
__skb_queue_purge(list);
384384
return -EHOSTUNREACH;
385385
}
386-
387386
/* Broadcast to all nodes */
388387
if (likely(bclink)) {
389388
tipc_bclink_lock(net);

net/tipc/link.c

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*/
3636

3737
#include "core.h"
38+
#include "subscr.h"
3839
#include "link.h"
3940
#include "bcast.h"
4041
#include "socket.h"
@@ -305,12 +306,10 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
305306
msg_set_session(msg, (tn->random & 0xffff));
306307
msg_set_bearer_id(msg, b_ptr->identity);
307308
strcpy((char *)msg_data(msg), if_name);
308-
309-
l_ptr->priority = b_ptr->priority;
310-
tipc_link_set_queue_limits(l_ptr, b_ptr->window);
311-
312309
l_ptr->net_plane = b_ptr->net_plane;
313310
link_init_max_pkt(l_ptr);
311+
l_ptr->priority = b_ptr->priority;
312+
tipc_link_set_queue_limits(l_ptr, b_ptr->window);
314313

315314
l_ptr->next_out_no = 1;
316315
__skb_queue_head_init(&l_ptr->transmq);
@@ -708,7 +707,7 @@ static int tipc_link_cong(struct tipc_link *link, struct sk_buff_head *list)
708707
{
709708
struct sk_buff *skb = skb_peek(list);
710709
struct tipc_msg *msg = buf_msg(skb);
711-
uint imp = tipc_msg_tot_importance(msg);
710+
int imp = msg_importance(msg);
712711
u32 oport = msg_tot_origport(msg);
713712

714713
if (unlikely(imp > TIPC_CRITICAL_IMPORTANCE)) {
@@ -745,7 +744,7 @@ int __tipc_link_xmit(struct net *net, struct tipc_link *link,
745744
{
746745
struct tipc_msg *msg = buf_msg(skb_peek(list));
747746
unsigned int maxwin = link->window;
748-
uint imp = tipc_msg_tot_importance(msg);
747+
unsigned int imp = msg_importance(msg);
749748
uint mtu = link->max_pkt;
750749
uint ack = mod(link->next_in_no - 1);
751750
uint seqno = link->next_out_no;
@@ -755,7 +754,7 @@ int __tipc_link_xmit(struct net *net, struct tipc_link *link,
755754
struct sk_buff_head *backlogq = &link->backlogq;
756755
struct sk_buff *skb, *tmp;
757756

758-
/* Match queue limits against msg importance: */
757+
/* Match queue limit against msg importance: */
759758
if (unlikely(skb_queue_len(backlogq) >= link->queue_limit[imp]))
760759
return tipc_link_cong(link, list);
761760

@@ -1811,25 +1810,16 @@ static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tol)
18111810
l_ptr->abort_limit = tol / (jiffies_to_msecs(l_ptr->cont_intv) / 4);
18121811
}
18131812

1814-
void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window)
1813+
void tipc_link_set_queue_limits(struct tipc_link *l, u32 win)
18151814
{
1816-
l_ptr->window = window;
1817-
1818-
/* Data messages from this node, inclusive FIRST_FRAGM */
1819-
l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window;
1820-
l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4;
1821-
l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5;
1822-
l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6;
1823-
/* Transiting data messages,inclusive FIRST_FRAGM */
1824-
l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300;
1825-
l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600;
1826-
l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900;
1827-
l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200;
1828-
l_ptr->queue_limit[CONN_MANAGER] = 1200;
1829-
l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500;
1830-
l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000;
1831-
/* FRAGMENT and LAST_FRAGMENT packets */
1832-
l_ptr->queue_limit[MSG_FRAGMENTER] = 4000;
1815+
int max_bulk = TIPC_MAX_PUBLICATIONS / (l->max_pkt / ITEM_SIZE);
1816+
1817+
l->window = win;
1818+
l->queue_limit[TIPC_LOW_IMPORTANCE] = win / 2;
1819+
l->queue_limit[TIPC_MEDIUM_IMPORTANCE] = win;
1820+
l->queue_limit[TIPC_HIGH_IMPORTANCE] = win / 2 * 3;
1821+
l->queue_limit[TIPC_CRITICAL_IMPORTANCE] = win * 2;
1822+
l->queue_limit[TIPC_SYSTEM_IMPORTANCE] = max_bulk;
18331823
}
18341824

18351825
/* tipc_link_find_owner - locate owner node of link by link's name

net/tipc/msg.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m,
272272
FIRST_FRAGMENT, INT_H_SIZE, msg_destnode(mhdr));
273273
msg_set_size(&pkthdr, pktmax);
274274
msg_set_fragm_no(&pkthdr, pktno);
275+
msg_set_importance(&pkthdr, msg_importance(mhdr));
275276

276277
/* Prepare first fragment */
277278
skb = tipc_buf_acquire(pktmax);
@@ -467,7 +468,6 @@ bool tipc_msg_reverse(u32 own_addr, struct sk_buff *buf, u32 *dnode,
467468
int err)
468469
{
469470
struct tipc_msg *msg = buf_msg(buf);
470-
uint imp = msg_importance(msg);
471471
struct tipc_msg ohdr;
472472
uint rdsz = min_t(uint, msg_data_sz(msg), MAX_FORWARD_SIZE);
473473

@@ -479,9 +479,6 @@ bool tipc_msg_reverse(u32 own_addr, struct sk_buff *buf, u32 *dnode,
479479
if (msg_errcode(msg))
480480
goto exit;
481481
memcpy(&ohdr, msg, msg_hdr_sz(msg));
482-
imp = min_t(uint, imp + 1, TIPC_CRITICAL_IMPORTANCE);
483-
if (msg_isdata(msg))
484-
msg_set_importance(msg, imp);
485482
msg_set_errcode(msg, err);
486483
msg_set_origport(msg, msg_destport(&ohdr));
487484
msg_set_destport(msg, msg_origport(&ohdr));

net/tipc/msg.h

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct plist;
5454
* - TIPC_HIGH_IMPORTANCE
5555
* - TIPC_CRITICAL_IMPORTANCE
5656
*/
57+
#define TIPC_SYSTEM_IMPORTANCE 4
58+
5759

5860
/*
5961
* Payload message types
@@ -63,6 +65,19 @@ struct plist;
6365
#define TIPC_NAMED_MSG 2
6466
#define TIPC_DIRECT_MSG 3
6567

68+
/*
69+
* Internal message users
70+
*/
71+
#define BCAST_PROTOCOL 5
72+
#define MSG_BUNDLER 6
73+
#define LINK_PROTOCOL 7
74+
#define CONN_MANAGER 8
75+
#define CHANGEOVER_PROTOCOL 10
76+
#define NAME_DISTRIBUTOR 11
77+
#define MSG_FRAGMENTER 12
78+
#define LINK_CONFIG 13
79+
#define SOCK_WAKEUP 14 /* pseudo user */
80+
6681
/*
6782
* Message header sizes
6883
*/
@@ -170,16 +185,6 @@ static inline void msg_set_user(struct tipc_msg *m, u32 n)
170185
msg_set_bits(m, 0, 25, 0xf, n);
171186
}
172187

173-
static inline u32 msg_importance(struct tipc_msg *m)
174-
{
175-
return msg_bits(m, 0, 25, 0xf);
176-
}
177-
178-
static inline void msg_set_importance(struct tipc_msg *m, u32 i)
179-
{
180-
msg_set_user(m, i);
181-
}
182-
183188
static inline u32 msg_hdr_sz(struct tipc_msg *m)
184189
{
185190
return msg_bits(m, 0, 21, 0xf) << 2;
@@ -336,6 +341,25 @@ static inline void msg_set_seqno(struct tipc_msg *m, u32 n)
336341
/*
337342
* Words 3-10
338343
*/
344+
static inline u32 msg_importance(struct tipc_msg *m)
345+
{
346+
if (unlikely(msg_user(m) == MSG_FRAGMENTER))
347+
return msg_bits(m, 5, 13, 0x7);
348+
if (likely(msg_isdata(m) && !msg_errcode(m)))
349+
return msg_user(m);
350+
return TIPC_SYSTEM_IMPORTANCE;
351+
}
352+
353+
static inline void msg_set_importance(struct tipc_msg *m, u32 i)
354+
{
355+
if (unlikely(msg_user(m) == MSG_FRAGMENTER))
356+
msg_set_bits(m, 5, 13, 0x7, i);
357+
else if (likely(i < TIPC_SYSTEM_IMPORTANCE))
358+
msg_set_user(m, i);
359+
else
360+
pr_warn("Trying to set illegal importance in message\n");
361+
}
362+
339363
static inline u32 msg_prevnode(struct tipc_msg *m)
340364
{
341365
return msg_word(m, 3);
@@ -457,20 +481,6 @@ static inline struct tipc_msg *msg_get_wrapped(struct tipc_msg *m)
457481
* Constants and routines used to read and write TIPC internal message headers
458482
*/
459483

460-
/*
461-
* Internal message users
462-
*/
463-
#define BCAST_PROTOCOL 5
464-
#define MSG_BUNDLER 6
465-
#define LINK_PROTOCOL 7
466-
#define CONN_MANAGER 8
467-
#define ROUTE_DISTRIBUTOR 9 /* obsoleted */
468-
#define CHANGEOVER_PROTOCOL 10
469-
#define NAME_DISTRIBUTOR 11
470-
#define MSG_FRAGMENTER 12
471-
#define LINK_CONFIG 13
472-
#define SOCK_WAKEUP 14 /* pseudo user */
473-
474484
/*
475485
* Connection management protocol message types
476486
*/
@@ -743,13 +753,6 @@ static inline void msg_set_link_tolerance(struct tipc_msg *m, u32 n)
743753
msg_set_bits(m, 9, 0, 0xffff, n);
744754
}
745755

746-
static inline u32 tipc_msg_tot_importance(struct tipc_msg *m)
747-
{
748-
if ((msg_user(m) == MSG_FRAGMENTER) && (msg_type(m) == FIRST_FRAGMENT))
749-
return msg_importance(msg_get_wrapped(m));
750-
return msg_importance(m);
751-
}
752-
753756
static inline u32 msg_tot_origport(struct tipc_msg *m)
754757
{
755758
if ((msg_user(m) == MSG_FRAGMENTER) && (msg_type(m) == FIRST_FRAGMENT))

0 commit comments

Comments
 (0)