Skip to content

Commit

Permalink
tipc: eliminate redundant lookups in registry
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Ying Xue <[email protected]>
Reviewed-by: Erik Hugne <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jon Paul Maloy authored and davem330 committed Mar 12, 2014
1 parent 58ed944 commit 5c31142
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 64 deletions.
39 changes: 19 additions & 20 deletions net/tipc/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,18 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg)
* tipc_port_mcast_xmit - send a multicast message to local and remote
* destinations
*/
int tipc_port_mcast_xmit(u32 ref, struct tipc_name_seq const *seq,
struct iovec const *msg_sect, unsigned int len)
int tipc_port_mcast_xmit(struct tipc_port *oport,
struct tipc_name_seq const *seq,
struct iovec const *msg_sect,
unsigned int len)
{
struct tipc_msg *hdr;
struct sk_buff *buf;
struct sk_buff *ibuf = NULL;
struct tipc_port_list dports = {0, NULL, };
struct tipc_port *oport = tipc_port_deref(ref);
int ext_targets;
int res;

if (unlikely(!oport))
return -EINVAL;

/* Create multicast message */
hdr = &oport->phdr;
msg_set_type(hdr, TIPC_MCAST_MSG);
Expand Down Expand Up @@ -807,14 +805,14 @@ static int tipc_port_iovec_rcv(struct tipc_port *sender,
/**
* tipc_send - send message sections on connection
*/
int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len)
int tipc_send(struct tipc_port *p_ptr,
struct iovec const *msg_sect,
unsigned int len)
{
struct tipc_port *p_ptr;
u32 destnode;
int res;

p_ptr = tipc_port_deref(ref);
if (!p_ptr || !p_ptr->connected)
if (!p_ptr->connected)
return -EINVAL;

p_ptr->congested = 1;
Expand Down Expand Up @@ -843,17 +841,18 @@ int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len)
/**
* tipc_send2name - send message sections to port name
*/
int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
struct iovec const *msg_sect, unsigned int len)
int tipc_send2name(struct tipc_port *p_ptr,
struct tipc_name const *name,
unsigned int domain,
struct iovec const *msg_sect,
unsigned int len)
{
struct tipc_port *p_ptr;
struct tipc_msg *msg;
u32 destnode = domain;
u32 destport;
int res;

p_ptr = tipc_port_deref(ref);
if (!p_ptr || p_ptr->connected)
if (p_ptr->connected)
return -EINVAL;

msg = &p_ptr->phdr;
Expand Down Expand Up @@ -892,15 +891,15 @@ int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
/**
* tipc_send2port - send message sections to port identity
*/
int tipc_send2port(u32 ref, struct tipc_portid const *dest,
struct iovec const *msg_sect, unsigned int len)
int tipc_send2port(struct tipc_port *p_ptr,
struct tipc_portid const *dest,
struct iovec const *msg_sect,
unsigned int len)
{
struct tipc_port *p_ptr;
struct tipc_msg *msg;
int res;

p_ptr = tipc_port_deref(ref);
if (!p_ptr || p_ptr->connected)
if (p_ptr->connected)
return -EINVAL;

msg = &p_ptr->phdr;
Expand Down
43 changes: 26 additions & 17 deletions net/tipc/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void tipc_port_destroy(struct tipc_port *p_ptr);

int tipc_publish(struct tipc_port *p_ptr, unsigned int scope,
struct tipc_name_seq const *name_seq);

int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope,
struct tipc_name_seq const *name_seq);

Expand All @@ -134,20 +135,33 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg);
* TIPC messaging routines
*/
int tipc_port_rcv(struct sk_buff *buf);
int tipc_send(u32 portref, struct iovec const *msg_sect, unsigned int len);

int tipc_send2name(u32 portref, struct tipc_name const *name, u32 domain,
struct iovec const *msg_sect, unsigned int len);

int tipc_send2port(u32 portref, struct tipc_portid const *dest,
struct iovec const *msg_sect, unsigned int len);

int tipc_port_mcast_xmit(u32 portref, struct tipc_name_seq const *seq,
struct iovec const *msg, unsigned int len);

int tipc_port_iovec_reject(struct tipc_port *p_ptr, struct tipc_msg *hdr,
struct iovec const *msg_sect, unsigned int len,
int tipc_send(struct tipc_port *port,
struct iovec const *msg_sect,
unsigned int len);

int tipc_send2name(struct tipc_port *port,
struct tipc_name const *name,
u32 domain,
struct iovec const *msg_sect,
unsigned int len);

int tipc_send2port(struct tipc_port *port,
struct tipc_portid const *dest,
struct iovec const *msg_sect,
unsigned int len);

int tipc_port_mcast_xmit(struct tipc_port *port,
struct tipc_name_seq const *seq,
struct iovec const *msg,
unsigned int len);

int tipc_port_iovec_reject(struct tipc_port *p_ptr,
struct tipc_msg *hdr,
struct iovec const *msg_sect,
unsigned int len,
int err);

struct sk_buff *tipc_port_get_ports(void);
void tipc_port_proto_rcv(struct sk_buff *buf);
void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp);
Expand All @@ -171,11 +185,6 @@ static inline void tipc_port_unlock(struct tipc_port *p_ptr)
spin_unlock_bh(p_ptr->lock);
}

static inline struct tipc_port *tipc_port_deref(u32 ref)
{
return (struct tipc_port *)tipc_ref_deref(ref);
}

static inline int tipc_port_congested(struct tipc_port *p_ptr)
{
return (p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2);
Expand Down
17 changes: 0 additions & 17 deletions net/tipc/ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,3 @@ void *tipc_ref_lock(u32 ref)
}
return NULL;
}


/**
* tipc_ref_deref - return pointer referenced object (without locking it)
*/
void *tipc_ref_deref(u32 ref)
{
if (likely(tipc_ref_table.entries)) {
struct reference *entry;

entry = &tipc_ref_table.entries[ref &
tipc_ref_table.index_mask];
if (likely(entry->ref == ref))
return entry->object;
}
return NULL;
}
1 change: 0 additions & 1 deletion net/tipc/ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock);
void tipc_ref_discard(u32 ref);

void *tipc_ref_lock(u32 ref);
void *tipc_ref_deref(u32 ref);

#endif
14 changes: 5 additions & 9 deletions net/tipc/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
{
struct sock *sk = sock->sk;
struct tipc_sock *tsk = tipc_sk(sk);
struct tipc_port *port = &tsk->port;
DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
int needs_conn;
long timeo;
u32 ref = tsk->port.ref;
int res = -EINVAL;

if (unlikely(!dest))
Expand Down Expand Up @@ -646,13 +646,13 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
res = dest_name_check(dest, m);
if (res)
break;
res = tipc_send2name(ref,
res = tipc_send2name(port,
&dest->addr.name.name,
dest->addr.name.domain,
m->msg_iov,
total_len);
} else if (dest->addrtype == TIPC_ADDR_ID) {
res = tipc_send2port(ref,
res = tipc_send2port(port,
&dest->addr.id,
m->msg_iov,
total_len);
Expand All @@ -664,7 +664,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
res = dest_name_check(dest, m);
if (res)
break;
res = tipc_port_mcast_xmit(ref,
res = tipc_port_mcast_xmit(port,
&dest->addr.nameseq,
m->msg_iov,
total_len);
Expand Down Expand Up @@ -754,7 +754,7 @@ static int tipc_send_packet(struct kiocb *iocb, struct socket *sock,

timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
do {
res = tipc_send(tsk->port.ref, m->msg_iov, total_len);
res = tipc_send(&tsk->port, m->msg_iov, total_len);
if (likely(res != -ELINKCONG))
break;
res = tipc_wait_for_sndpkt(sock, &timeo);
Expand Down Expand Up @@ -881,10 +881,6 @@ static int auto_connect(struct tipc_sock *tsk, struct tipc_msg *msg)
peer.ref = msg_origport(msg);
peer.node = msg_orignode(msg);

port = tipc_port_deref(port->ref);
if (!port)
return -EINVAL;

__tipc_port_connect(port->ref, port, &peer);

if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE)
Expand Down

0 comments on commit 5c31142

Please sign in to comment.