Skip to content

Commit 5aa8dbb

Browse files
committed
Merge branch 'tipc-next'
Jon Maloy says: ==================== tipc: Merge port and socket layer code After the removal of the TIPC native interface, there is no reason to keep a distinction between a "generic" port layer and a "specific" socket layer in the code. Throughout the last months, we have posted several series that aimed at facilitating removal of the port layer, and in particular the port_lock spinlock, which in reality duplicates the role normally kept by lock_sock()/bh_lock_sock(). In this series, we finalize this work, by making a significant number of changes to the link, node, port and socket code, all with the aim of reducing dependencies between the layers. In the final commits, we then remove the port spinlock, port.c and port.h altogether. After this series, we have a socket layer that has only few dependencies to the rest of the stack, so that it should be possible to continue cleanups of its code without significantly affecting other code. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents f9474dd + 301bae5 commit 5aa8dbb

File tree

20 files changed

+956
-1301
lines changed

20 files changed

+956
-1301
lines changed

net/tipc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ obj-$(CONFIG_TIPC) := tipc.o
77
tipc-y += addr.o bcast.o bearer.o config.o \
88
core.o link.o discover.o msg.o \
99
name_distr.o subscr.o name_table.o net.o \
10-
netlink.o node.o node_subscr.o port.o ref.o \
10+
netlink.o node.o node_subscr.o \
1111
socket.o log.o eth_media.o server.o
1212

1313
tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o

net/tipc/bcast.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
#include "core.h"
3939
#include "link.h"
40-
#include "port.h"
4140
#include "socket.h"
4241
#include "msg.h"
4342
#include "bcast.h"
@@ -300,8 +299,8 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)
300299
tipc_link_push_queue(bcl);
301300
bclink_set_last_sent();
302301
}
303-
if (unlikely(released && !list_empty(&bcl->waiting_ports)))
304-
tipc_link_wakeup_ports(bcl, 0);
302+
if (unlikely(released && !skb_queue_empty(&bcl->waiting_sks)))
303+
bclink->node.action_flags |= TIPC_WAKEUP_USERS;
305304
exit:
306305
tipc_bclink_unlock();
307306
}
@@ -840,9 +839,10 @@ int tipc_bclink_init(void)
840839
sprintf(bcbearer->media.name, "tipc-broadcast");
841840

842841
spin_lock_init(&bclink->lock);
843-
INIT_LIST_HEAD(&bcl->waiting_ports);
842+
__skb_queue_head_init(&bcl->waiting_sks);
844843
bcl->next_out_no = 1;
845844
spin_lock_init(&bclink->node.lock);
845+
__skb_queue_head_init(&bclink->node.waiting_sks);
846846
bcl->owner = &bclink->node;
847847
bcl->max_pkt = MAX_PKT_DEFAULT_MCAST;
848848
tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT);

net/tipc/config.c

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

3737
#include "core.h"
38-
#include "port.h"
38+
#include "socket.h"
3939
#include "name_table.h"
4040
#include "config.h"
4141
#include "server.h"
@@ -266,7 +266,7 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
266266
rep_tlv_buf = tipc_media_get_names();
267267
break;
268268
case TIPC_CMD_SHOW_PORTS:
269-
rep_tlv_buf = tipc_port_get_ports();
269+
rep_tlv_buf = tipc_sk_socks_show();
270270
break;
271271
case TIPC_CMD_SHOW_STATS:
272272
rep_tlv_buf = tipc_show_stats();

net/tipc/core.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@
3535
*/
3636

3737
#include "core.h"
38-
#include "ref.h"
3938
#include "name_table.h"
4039
#include "subscr.h"
4140
#include "config.h"
42-
#include "port.h"
41+
#include "socket.h"
4342

4443
#include <linux/module.h>
4544

@@ -85,7 +84,7 @@ static void tipc_core_stop(void)
8584
tipc_netlink_stop();
8685
tipc_subscr_stop();
8786
tipc_nametbl_stop();
88-
tipc_ref_table_stop();
87+
tipc_sk_ref_table_stop();
8988
tipc_socket_stop();
9089
tipc_unregister_sysctl();
9190
}
@@ -99,7 +98,7 @@ static int tipc_core_start(void)
9998

10099
get_random_bytes(&tipc_random, sizeof(tipc_random));
101100

102-
err = tipc_ref_table_init(tipc_max_ports, tipc_random);
101+
err = tipc_sk_ref_table_init(tipc_max_ports, tipc_random);
103102
if (err)
104103
goto out_reftbl;
105104

@@ -139,7 +138,7 @@ static int tipc_core_start(void)
139138
out_netlink:
140139
tipc_nametbl_stop();
141140
out_nametbl:
142-
tipc_ref_table_stop();
141+
tipc_sk_ref_table_stop();
143142
out_reftbl:
144143
return err;
145144
}

net/tipc/core.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,11 @@ static inline void k_term_timer(struct timer_list *timer)
187187

188188
struct tipc_skb_cb {
189189
void *handle;
190-
bool deferred;
191190
struct sk_buff *tail;
191+
bool deferred;
192+
bool wakeup_pending;
193+
u16 chain_sz;
194+
u16 chain_imp;
192195
};
193196

194197
#define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0]))

net/tipc/link.c

Lines changed: 54 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#include "core.h"
3838
#include "link.h"
39-
#include "port.h"
4039
#include "socket.h"
4140
#include "name_distr.h"
4241
#include "discover.h"
@@ -275,7 +274,7 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
275274
link_init_max_pkt(l_ptr);
276275

277276
l_ptr->next_out_no = 1;
278-
INIT_LIST_HEAD(&l_ptr->waiting_ports);
277+
__skb_queue_head_init(&l_ptr->waiting_sks);
279278

280279
link_reset_statistics(l_ptr);
281280

@@ -322,66 +321,47 @@ void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down)
322321
}
323322

324323
/**
325-
* link_schedule_port - schedule port for deferred sending
326-
* @l_ptr: pointer to link
327-
* @origport: reference to sending port
328-
* @sz: amount of data to be sent
329-
*
330-
* Schedules port for renewed sending of messages after link congestion
331-
* has abated.
324+
* link_schedule_user - schedule user for wakeup after congestion
325+
* @link: congested link
326+
* @oport: sending port
327+
* @chain_sz: size of buffer chain that was attempted sent
328+
* @imp: importance of message attempted sent
329+
* Create pseudo msg to send back to user when congestion abates
332330
*/
333-
static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz)
331+
static bool link_schedule_user(struct tipc_link *link, u32 oport,
332+
uint chain_sz, uint imp)
334333
{
335-
struct tipc_port *p_ptr;
336-
struct tipc_sock *tsk;
334+
struct sk_buff *buf;
337335

338-
spin_lock_bh(&tipc_port_list_lock);
339-
p_ptr = tipc_port_lock(origport);
340-
if (p_ptr) {
341-
if (!list_empty(&p_ptr->wait_list))
342-
goto exit;
343-
tsk = tipc_port_to_sock(p_ptr);
344-
tsk->link_cong = 1;
345-
p_ptr->waiting_pkts = 1 + ((sz - 1) / l_ptr->max_pkt);
346-
list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports);
347-
l_ptr->stats.link_congs++;
348-
exit:
349-
tipc_port_unlock(p_ptr);
350-
}
351-
spin_unlock_bh(&tipc_port_list_lock);
352-
return -ELINKCONG;
336+
buf = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0, tipc_own_addr,
337+
tipc_own_addr, oport, 0, 0);
338+
if (!buf)
339+
return false;
340+
TIPC_SKB_CB(buf)->chain_sz = chain_sz;
341+
TIPC_SKB_CB(buf)->chain_imp = imp;
342+
__skb_queue_tail(&link->waiting_sks, buf);
343+
link->stats.link_congs++;
344+
return true;
353345
}
354346

355-
void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all)
347+
/**
348+
* link_prepare_wakeup - prepare users for wakeup after congestion
349+
* @link: congested link
350+
* Move a number of waiting users, as permitted by available space in
351+
* the send queue, from link wait queue to node wait queue for wakeup
352+
*/
353+
static void link_prepare_wakeup(struct tipc_link *link)
356354
{
357-
struct tipc_port *p_ptr;
358-
struct tipc_sock *tsk;
359-
struct tipc_port *temp_p_ptr;
360-
int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size;
361-
362-
if (all)
363-
win = 100000;
364-
if (win <= 0)
365-
return;
366-
if (!spin_trylock_bh(&tipc_port_list_lock))
367-
return;
368-
if (link_congested(l_ptr))
369-
goto exit;
370-
list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports,
371-
wait_list) {
372-
if (win <= 0)
355+
struct sk_buff_head *wq = &link->waiting_sks;
356+
struct sk_buff *buf;
357+
uint pend_qsz = link->out_queue_size;
358+
359+
for (buf = skb_peek(wq); buf; buf = skb_peek(wq)) {
360+
if (pend_qsz >= link->queue_limit[TIPC_SKB_CB(buf)->chain_imp])
373361
break;
374-
tsk = tipc_port_to_sock(p_ptr);
375-
list_del_init(&p_ptr->wait_list);
376-
spin_lock_bh(p_ptr->lock);
377-
tsk->link_cong = 0;
378-
tipc_sock_wakeup(tsk);
379-
win -= p_ptr->waiting_pkts;
380-
spin_unlock_bh(p_ptr->lock);
362+
pend_qsz += TIPC_SKB_CB(buf)->chain_sz;
363+
__skb_queue_tail(&link->owner->waiting_sks, __skb_dequeue(wq));
381364
}
382-
383-
exit:
384-
spin_unlock_bh(&tipc_port_list_lock);
385365
}
386366

387367
/**
@@ -423,6 +403,7 @@ void tipc_link_reset(struct tipc_link *l_ptr)
423403
u32 prev_state = l_ptr->state;
424404
u32 checkpoint = l_ptr->next_in_no;
425405
int was_active_link = tipc_link_is_active(l_ptr);
406+
struct tipc_node *owner = l_ptr->owner;
426407

427408
msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
428409

@@ -450,9 +431,10 @@ void tipc_link_reset(struct tipc_link *l_ptr)
450431
kfree_skb(l_ptr->proto_msg_queue);
451432
l_ptr->proto_msg_queue = NULL;
452433
kfree_skb_list(l_ptr->oldest_deferred_in);
453-
if (!list_empty(&l_ptr->waiting_ports))
454-
tipc_link_wakeup_ports(l_ptr, 1);
455-
434+
if (!skb_queue_empty(&l_ptr->waiting_sks)) {
435+
skb_queue_splice_init(&l_ptr->waiting_sks, &owner->waiting_sks);
436+
owner->action_flags |= TIPC_WAKEUP_USERS;
437+
}
456438
l_ptr->retransm_queue_head = 0;
457439
l_ptr->retransm_queue_size = 0;
458440
l_ptr->last_out = NULL;
@@ -688,19 +670,23 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
688670
static int tipc_link_cong(struct tipc_link *link, struct sk_buff *buf)
689671
{
690672
struct tipc_msg *msg = buf_msg(buf);
691-
uint psz = msg_size(msg);
692673
uint imp = tipc_msg_tot_importance(msg);
693674
u32 oport = msg_tot_origport(msg);
694675

695-
if (likely(imp <= TIPC_CRITICAL_IMPORTANCE)) {
696-
if (!msg_errcode(msg) && !msg_reroute_cnt(msg)) {
697-
link_schedule_port(link, oport, psz);
698-
return -ELINKCONG;
699-
}
700-
} else {
676+
if (unlikely(imp > TIPC_CRITICAL_IMPORTANCE)) {
701677
pr_warn("%s<%s>, send queue full", link_rst_msg, link->name);
702678
tipc_link_reset(link);
679+
goto drop;
703680
}
681+
if (unlikely(msg_errcode(msg)))
682+
goto drop;
683+
if (unlikely(msg_reroute_cnt(msg)))
684+
goto drop;
685+
if (TIPC_SKB_CB(buf)->wakeup_pending)
686+
return -ELINKCONG;
687+
if (link_schedule_user(link, oport, TIPC_SKB_CB(buf)->chain_sz, imp))
688+
return -ELINKCONG;
689+
drop:
704690
kfree_skb_list(buf);
705691
return -EHOSTUNREACH;
706692
}
@@ -1202,8 +1188,10 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
12021188
if (unlikely(l_ptr->next_out))
12031189
tipc_link_push_queue(l_ptr);
12041190

1205-
if (unlikely(!list_empty(&l_ptr->waiting_ports)))
1206-
tipc_link_wakeup_ports(l_ptr, 0);
1191+
if (released && !skb_queue_empty(&l_ptr->waiting_sks)) {
1192+
link_prepare_wakeup(l_ptr);
1193+
l_ptr->owner->action_flags |= TIPC_WAKEUP_USERS;
1194+
}
12071195

12081196
/* Process the incoming packet */
12091197
if (unlikely(!link_working_working(l_ptr))) {

net/tipc/link.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* net/tipc/link.h: Include file for TIPC link code
33
*
4-
* Copyright (c) 1995-2006, 2013, Ericsson AB
4+
* Copyright (c) 1995-2006, 2013-2014, Ericsson AB
55
* Copyright (c) 2004-2005, 2010-2011, Wind River Systems
66
* All rights reserved.
77
*
@@ -133,7 +133,7 @@ struct tipc_stats {
133133
* @retransm_queue_size: number of messages to retransmit
134134
* @retransm_queue_head: sequence number of first message to retransmit
135135
* @next_out: ptr to first unsent outbound message in queue
136-
* @waiting_ports: linked list of ports waiting for link congestion to abate
136+
* @waiting_sks: linked list of sockets waiting for link congestion to abate
137137
* @long_msg_seq_no: next identifier to use for outbound fragmented messages
138138
* @reasm_buf: head of partially reassembled inbound message fragments
139139
* @stats: collects statistics regarding link activity
@@ -194,7 +194,7 @@ struct tipc_link {
194194
u32 retransm_queue_size;
195195
u32 retransm_queue_head;
196196
struct sk_buff *next_out;
197-
struct list_head waiting_ports;
197+
struct sk_buff_head waiting_sks;
198198

199199
/* Fragmentation/reassembly */
200200
u32 long_msg_seq_no;
@@ -235,7 +235,6 @@ void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int prob,
235235
void tipc_link_push_queue(struct tipc_link *l_ptr);
236236
u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail,
237237
struct sk_buff *buf);
238-
void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all);
239238
void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window);
240239
void tipc_link_retransmit(struct tipc_link *l_ptr,
241240
struct sk_buff *start, u32 retransmits);

0 commit comments

Comments
 (0)