aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2014-03-12 11:31:13 -0400
committerDavid S. Miller <davem@davemloft.net>2014-03-12 15:53:49 -0400
commit5c311421a28051036a114aec972d36c72114ed4c (patch)
treeb8210cd9a14a3fc205ca254d33de80bf185f2a0c /net/tipc
parent58ed944241794087df1edadfa66795c966bf1604 (diff)
tipc: eliminate redundant lookups in registry
As an artefact from the native interface, the message sending functions in the port takes a port ref as first parameter, and then looks up in the registry to find the corresponding port pointer. This despite the fact that the only currently existing caller, tipc_sock, already knows this pointer. We change the signature of these functions to take a struct tipc_port* argument, and remove the redundant lookups. We also remove an unmotivated extra lookup in the function socket.c:auto_connect(), and, as the lookup functions tipc_port_deref() and ref_deref() now become unused, we remove these two functions. Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Reviewed-by: Erik Hugne <erik.hugne@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/port.c39
-rw-r--r--net/tipc/port.h43
-rw-r--r--net/tipc/ref.c17
-rw-r--r--net/tipc/ref.h1
-rw-r--r--net/tipc/socket.c14
5 files changed, 50 insertions, 64 deletions
diff --git a/net/tipc/port.c b/net/tipc/port.c
index 894c0d9fbe0f..5c14c7801ee6 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -80,20 +80,18 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg)
80 * tipc_port_mcast_xmit - send a multicast message to local and remote 80 * tipc_port_mcast_xmit - send a multicast message to local and remote
81 * destinations 81 * destinations
82 */ 82 */
83int tipc_port_mcast_xmit(u32 ref, struct tipc_name_seq const *seq, 83int tipc_port_mcast_xmit(struct tipc_port *oport,
84 struct iovec const *msg_sect, unsigned int len) 84 struct tipc_name_seq const *seq,
85 struct iovec const *msg_sect,
86 unsigned int len)
85{ 87{
86 struct tipc_msg *hdr; 88 struct tipc_msg *hdr;
87 struct sk_buff *buf; 89 struct sk_buff *buf;
88 struct sk_buff *ibuf = NULL; 90 struct sk_buff *ibuf = NULL;
89 struct tipc_port_list dports = {0, NULL, }; 91 struct tipc_port_list dports = {0, NULL, };
90 struct tipc_port *oport = tipc_port_deref(ref);
91 int ext_targets; 92 int ext_targets;
92 int res; 93 int res;
93 94
94 if (unlikely(!oport))
95 return -EINVAL;
96
97 /* Create multicast message */ 95 /* Create multicast message */
98 hdr = &oport->phdr; 96 hdr = &oport->phdr;
99 msg_set_type(hdr, TIPC_MCAST_MSG); 97 msg_set_type(hdr, TIPC_MCAST_MSG);
@@ -807,14 +805,14 @@ static int tipc_port_iovec_rcv(struct tipc_port *sender,
807/** 805/**
808 * tipc_send - send message sections on connection 806 * tipc_send - send message sections on connection
809 */ 807 */
810int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len) 808int tipc_send(struct tipc_port *p_ptr,
809 struct iovec const *msg_sect,
810 unsigned int len)
811{ 811{
812 struct tipc_port *p_ptr;
813 u32 destnode; 812 u32 destnode;
814 int res; 813 int res;
815 814
816 p_ptr = tipc_port_deref(ref); 815 if (!p_ptr->connected)
817 if (!p_ptr || !p_ptr->connected)
818 return -EINVAL; 816 return -EINVAL;
819 817
820 p_ptr->congested = 1; 818 p_ptr->congested = 1;
@@ -843,17 +841,18 @@ int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len)
843/** 841/**
844 * tipc_send2name - send message sections to port name 842 * tipc_send2name - send message sections to port name
845 */ 843 */
846int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain, 844int tipc_send2name(struct tipc_port *p_ptr,
847 struct iovec const *msg_sect, unsigned int len) 845 struct tipc_name const *name,
846 unsigned int domain,
847 struct iovec const *msg_sect,
848 unsigned int len)
848{ 849{
849 struct tipc_port *p_ptr;
850 struct tipc_msg *msg; 850 struct tipc_msg *msg;
851 u32 destnode = domain; 851 u32 destnode = domain;
852 u32 destport; 852 u32 destport;
853 int res; 853 int res;
854 854
855 p_ptr = tipc_port_deref(ref); 855 if (p_ptr->connected)
856 if (!p_ptr || p_ptr->connected)
857 return -EINVAL; 856 return -EINVAL;
858 857
859 msg = &p_ptr->phdr; 858 msg = &p_ptr->phdr;
@@ -892,15 +891,15 @@ int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
892/** 891/**
893 * tipc_send2port - send message sections to port identity 892 * tipc_send2port - send message sections to port identity
894 */ 893 */
895int tipc_send2port(u32 ref, struct tipc_portid const *dest, 894int tipc_send2port(struct tipc_port *p_ptr,
896 struct iovec const *msg_sect, unsigned int len) 895 struct tipc_portid const *dest,
896 struct iovec const *msg_sect,
897 unsigned int len)
897{ 898{
898 struct tipc_port *p_ptr;
899 struct tipc_msg *msg; 899 struct tipc_msg *msg;
900 int res; 900 int res;
901 901
902 p_ptr = tipc_port_deref(ref); 902 if (p_ptr->connected)
903 if (!p_ptr || p_ptr->connected)
904 return -EINVAL; 903 return -EINVAL;
905 904
906 msg = &p_ptr->phdr; 905 msg = &p_ptr->phdr;
diff --git a/net/tipc/port.h b/net/tipc/port.h
index 53ec5f06422f..a00397393bd1 100644
--- a/net/tipc/port.h
+++ b/net/tipc/port.h
@@ -111,6 +111,7 @@ void tipc_port_destroy(struct tipc_port *p_ptr);
111 111
112int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, 112int tipc_publish(struct tipc_port *p_ptr, unsigned int scope,
113 struct tipc_name_seq const *name_seq); 113 struct tipc_name_seq const *name_seq);
114
114int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope, 115int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope,
115 struct tipc_name_seq const *name_seq); 116 struct tipc_name_seq const *name_seq);
116 117
@@ -134,20 +135,33 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg);
134 * TIPC messaging routines 135 * TIPC messaging routines
135 */ 136 */
136int tipc_port_rcv(struct sk_buff *buf); 137int tipc_port_rcv(struct sk_buff *buf);
137int tipc_send(u32 portref, struct iovec const *msg_sect, unsigned int len);
138
139int tipc_send2name(u32 portref, struct tipc_name const *name, u32 domain,
140 struct iovec const *msg_sect, unsigned int len);
141
142int tipc_send2port(u32 portref, struct tipc_portid const *dest,
143 struct iovec const *msg_sect, unsigned int len);
144
145int tipc_port_mcast_xmit(u32 portref, struct tipc_name_seq const *seq,
146 struct iovec const *msg, unsigned int len);
147 138
148int tipc_port_iovec_reject(struct tipc_port *p_ptr, struct tipc_msg *hdr, 139int tipc_send(struct tipc_port *port,
149 struct iovec const *msg_sect, unsigned int len, 140 struct iovec const *msg_sect,
141 unsigned int len);
142
143int tipc_send2name(struct tipc_port *port,
144 struct tipc_name const *name,
145 u32 domain,
146 struct iovec const *msg_sect,
147 unsigned int len);
148
149int tipc_send2port(struct tipc_port *port,
150 struct tipc_portid const *dest,
151 struct iovec const *msg_sect,
152 unsigned int len);
153
154int tipc_port_mcast_xmit(struct tipc_port *port,
155 struct tipc_name_seq const *seq,
156 struct iovec const *msg,
157 unsigned int len);
158
159int tipc_port_iovec_reject(struct tipc_port *p_ptr,
160 struct tipc_msg *hdr,
161 struct iovec const *msg_sect,
162 unsigned int len,
150 int err); 163 int err);
164
151struct sk_buff *tipc_port_get_ports(void); 165struct sk_buff *tipc_port_get_ports(void);
152void tipc_port_proto_rcv(struct sk_buff *buf); 166void tipc_port_proto_rcv(struct sk_buff *buf);
153void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp); 167void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp);
@@ -171,11 +185,6 @@ static inline void tipc_port_unlock(struct tipc_port *p_ptr)
171 spin_unlock_bh(p_ptr->lock); 185 spin_unlock_bh(p_ptr->lock);
172} 186}
173 187
174static inline struct tipc_port *tipc_port_deref(u32 ref)
175{
176 return (struct tipc_port *)tipc_ref_deref(ref);
177}
178
179static inline int tipc_port_congested(struct tipc_port *p_ptr) 188static inline int tipc_port_congested(struct tipc_port *p_ptr)
180{ 189{
181 return (p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2); 190 return (p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2);
diff --git a/net/tipc/ref.c b/net/tipc/ref.c
index 67176b5e14f3..3d4ecd754eee 100644
--- a/net/tipc/ref.c
+++ b/net/tipc/ref.c
@@ -264,20 +264,3 @@ void *tipc_ref_lock(u32 ref)
264 } 264 }
265 return NULL; 265 return NULL;
266} 266}
267
268
269/**
270 * tipc_ref_deref - return pointer referenced object (without locking it)
271 */
272void *tipc_ref_deref(u32 ref)
273{
274 if (likely(tipc_ref_table.entries)) {
275 struct reference *entry;
276
277 entry = &tipc_ref_table.entries[ref &
278 tipc_ref_table.index_mask];
279 if (likely(entry->ref == ref))
280 return entry->object;
281 }
282 return NULL;
283}
diff --git a/net/tipc/ref.h b/net/tipc/ref.h
index 5bc8e7ab84de..d01aa1df63b8 100644
--- a/net/tipc/ref.h
+++ b/net/tipc/ref.h
@@ -44,6 +44,5 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock);
44void tipc_ref_discard(u32 ref); 44void tipc_ref_discard(u32 ref);
45 45
46void *tipc_ref_lock(u32 ref); 46void *tipc_ref_lock(u32 ref);
47void *tipc_ref_deref(u32 ref);
48 47
49#endif 48#endif
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 9cea92ee6c82..2a89bdb331b5 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -600,10 +600,10 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
600{ 600{
601 struct sock *sk = sock->sk; 601 struct sock *sk = sock->sk;
602 struct tipc_sock *tsk = tipc_sk(sk); 602 struct tipc_sock *tsk = tipc_sk(sk);
603 struct tipc_port *port = &tsk->port;
603 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 604 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
604 int needs_conn; 605 int needs_conn;
605 long timeo; 606 long timeo;
606 u32 ref = tsk->port.ref;
607 int res = -EINVAL; 607 int res = -EINVAL;
608 608
609 if (unlikely(!dest)) 609 if (unlikely(!dest))
@@ -646,13 +646,13 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
646 res = dest_name_check(dest, m); 646 res = dest_name_check(dest, m);
647 if (res) 647 if (res)
648 break; 648 break;
649 res = tipc_send2name(ref, 649 res = tipc_send2name(port,
650 &dest->addr.name.name, 650 &dest->addr.name.name,
651 dest->addr.name.domain, 651 dest->addr.name.domain,
652 m->msg_iov, 652 m->msg_iov,
653 total_len); 653 total_len);
654 } else if (dest->addrtype == TIPC_ADDR_ID) { 654 } else if (dest->addrtype == TIPC_ADDR_ID) {
655 res = tipc_send2port(ref, 655 res = tipc_send2port(port,
656 &dest->addr.id, 656 &dest->addr.id,
657 m->msg_iov, 657 m->msg_iov,
658 total_len); 658 total_len);
@@ -664,7 +664,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
664 res = dest_name_check(dest, m); 664 res = dest_name_check(dest, m);
665 if (res) 665 if (res)
666 break; 666 break;
667 res = tipc_port_mcast_xmit(ref, 667 res = tipc_port_mcast_xmit(port,
668 &dest->addr.nameseq, 668 &dest->addr.nameseq,
669 m->msg_iov, 669 m->msg_iov,
670 total_len); 670 total_len);
@@ -754,7 +754,7 @@ static int tipc_send_packet(struct kiocb *iocb, struct socket *sock,
754 754
755 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); 755 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
756 do { 756 do {
757 res = tipc_send(tsk->port.ref, m->msg_iov, total_len); 757 res = tipc_send(&tsk->port, m->msg_iov, total_len);
758 if (likely(res != -ELINKCONG)) 758 if (likely(res != -ELINKCONG))
759 break; 759 break;
760 res = tipc_wait_for_sndpkt(sock, &timeo); 760 res = tipc_wait_for_sndpkt(sock, &timeo);
@@ -881,10 +881,6 @@ static int auto_connect(struct tipc_sock *tsk, struct tipc_msg *msg)
881 peer.ref = msg_origport(msg); 881 peer.ref = msg_origport(msg);
882 peer.node = msg_orignode(msg); 882 peer.node = msg_orignode(msg);
883 883
884 port = tipc_port_deref(port->ref);
885 if (!port)
886 return -EINVAL;
887
888 __tipc_port_connect(port->ref, port, &peer); 884 __tipc_port_connect(port->ref, port, &peer);
889 885
890 if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE) 886 if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE)