Skip to content

Commit

Permalink
net: add option to enable error queue packets waking select
Browse files Browse the repository at this point in the history
Currently, when a socket receives something on the error queue it only wakes up
the socket on select if it is in the "read" list, that is the socket has
something to read. It is useful also to wake the socket if it is in the error
list, which would enable software to wait on error queue packets without waking
up for regular data on the socket. The main use case is for receiving
timestamped transmit packets which return the timestamp to the socket via the
error queue. This enables an application to select on the socket for the error
queue only instead of for the regular traffic.

-v2-
* Added the SO_SELECT_ERR_QUEUE socket option to every architechture specific file
* Modified every socket poll function that checks error queue

Signed-off-by: Jacob Keller <[email protected]>
Cc: Jeffrey Kirsher <[email protected]>
Cc: Richard Cochran <[email protected]>
Cc: Matthew Vick <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jacob-keller authored and davem330 committed Mar 31, 2013
1 parent 4eb0614 commit 7d4c04f
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 6 deletions.
2 changes: 2 additions & 0 deletions arch/alpha/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _UAPI_ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/avr32/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* __ASM_AVR32_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/cris/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _ASM_SOCKET_H */


2 changes: 2 additions & 0 deletions arch/frv/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _ASM_SOCKET_H */

2 changes: 2 additions & 0 deletions arch/h8300/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/ia64/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _ASM_IA64_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/m32r/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _ASM_M32R_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/mips/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _UAPI_ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/mn10300/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/parisc/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@

#define SO_LOCK_FILTER 0x4025

#define SO_SELECT_ERR_QUEUE 0x4026

/* O_NONBLOCK clashes with the bits used for socket types. Therefore we
* have to define SOCK_NONBLOCK to a different value here.
*/
Expand Down
2 changes: 2 additions & 0 deletions arch/powerpc/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _ASM_POWERPC_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/s390/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/sparc/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@

#define SO_LOCK_FILTER 0x0028

#define SO_SELECT_ERR_QUEUE 0x0029

/* Security levels - as per NRL IPv6 - don't actually do anything */
#define SO_SECURITY_AUTHENTICATION 0x5001
#define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002
Expand Down
2 changes: 2 additions & 0 deletions arch/xtensa/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* _XTENSA_SOCKET_H */
1 change: 1 addition & 0 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ enum sock_flags {
* user-space instead.
*/
SOCK_FILTER_LOCKED, /* Filter cannot be changed anymore */
SOCK_SELECT_ERR_QUEUE, /* Wake select on error queue */
};

static inline void sock_copy_flags(struct sock *nsk, struct sock *osk)
Expand Down
2 changes: 2 additions & 0 deletions include/uapi/asm-generic/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@

#define SO_LOCK_FILTER 44

#define SO_SELECT_ERR_QUEUE 45

#endif /* __ASM_GENERIC_SOCKET_H */
3 changes: 2 additions & 1 deletion net/bluetooth/af_bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ unsigned int bt_sock_poll(struct file *file, struct socket *sock,
return bt_accept_poll(sk);

if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
mask |= POLLERR;
mask |= POLLERR |
sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? POLLPRI : 0;

if (sk->sk_shutdown & RCV_SHUTDOWN)
mask |= POLLRDHUP | POLLIN | POLLRDNORM;
Expand Down
4 changes: 3 additions & 1 deletion net/core/datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,9 @@ unsigned int datagram_poll(struct file *file, struct socket *sock,

/* exceptional events? */
if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
mask |= POLLERR;
mask |= POLLERR |
sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? POLLPRI : 0;

if (sk->sk_shutdown & RCV_SHUTDOWN)
mask |= POLLRDHUP | POLLIN | POLLRDNORM;
if (sk->sk_shutdown == SHUTDOWN_MASK)
Expand Down
8 changes: 8 additions & 0 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,10 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
sock_valbool_flag(sk, SOCK_NOFCS, valbool);
break;

case SO_SELECT_ERR_QUEUE:
sock_valbool_flag(sk, SOCK_SELECT_ERR_QUEUE, valbool);
break;

default:
ret = -ENOPROTOOPT;
break;
Expand Down Expand Up @@ -1160,6 +1164,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
v.val = sock_flag(sk, SOCK_FILTER_LOCKED);
break;

case SO_SELECT_ERR_QUEUE:
v.val = sock_flag(sk, SOCK_SELECT_ERR_QUEUE);
break;

default:
return -ENOPROTOOPT;
}
Expand Down
3 changes: 2 additions & 1 deletion net/iucv/af_iucv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,8 @@ unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
return iucv_accept_poll(sk);

if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
mask |= POLLERR;
mask |= POLLERR |
sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? POLLPRI : 0;

if (sk->sk_shutdown & RCV_SHUTDOWN)
mask |= POLLRDHUP;
Expand Down
3 changes: 2 additions & 1 deletion net/nfc/llcp/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ static unsigned int llcp_sock_poll(struct file *file, struct socket *sock,
return llcp_accept_poll(sk);

if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
mask |= POLLERR;
mask |= POLLERR |
sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? POLLPRI : 0;

if (!skb_queue_empty(&sk->sk_receive_queue))
mask |= POLLIN | POLLRDNORM;
Expand Down
3 changes: 2 additions & 1 deletion net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -6185,7 +6185,8 @@ unsigned int sctp_poll(struct file *file, struct socket *sock, poll_table *wait)

/* Is there any exceptional events? */
if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
mask |= POLLERR;
mask |= POLLERR |
sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? POLLPRI : 0;
if (sk->sk_shutdown & RCV_SHUTDOWN)
mask |= POLLRDHUP | POLLIN | POLLRDNORM;
if (sk->sk_shutdown == SHUTDOWN_MASK)
Expand Down
4 changes: 3 additions & 1 deletion net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,9 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,

/* exceptional events? */
if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
mask |= POLLERR;
mask |= POLLERR |
sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? POLLPRI : 0;

if (sk->sk_shutdown & RCV_SHUTDOWN)
mask |= POLLRDHUP | POLLIN | POLLRDNORM;
if (sk->sk_shutdown == SHUTDOWN_MASK)
Expand Down

0 comments on commit 7d4c04f

Please sign in to comment.