net: add option to enable error queue packets waking select
Subsystems (16)
RFC PATCH v2 1/1 net: add option to enable error queue packets waking select
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
--- arch/alpha/include/uapi/asm/socket.h | 2 ++ arch/avr32/include/uapi/asm/socket.h | 2 ++ arch/cris/include/uapi/asm/socket.h | 2 ++ arch/frv/include/uapi/asm/socket.h | 2 ++ arch/h8300/include/uapi/asm/socket.h | 2 ++ arch/ia64/include/uapi/asm/socket.h | 2 ++ arch/m32r/include/uapi/asm/socket.h | 2 ++ arch/mips/include/uapi/asm/socket.h | 2 ++ arch/mn10300/include/uapi/asm/socket.h | 2 ++ arch/parisc/include/uapi/asm/socket.h | 2 ++ arch/powerpc/include/uapi/asm/socket.h | 2 ++ arch/s390/include/uapi/asm/socket.h | 2 ++ arch/sparc/include/uapi/asm/socket.h | 2 ++ arch/xtensa/include/uapi/asm/socket.h | 2 ++ include/net/sock.h | 1 + include/uapi/asm-generic/socket.h | 2 ++ net/bluetooth/af_bluetooth.c | 3 ++- net/core/datagram.c | 4 +++- net/core/sock.c | 8 ++++++++ net/iucv/af_iucv.c | 3 ++- net/nfc/llcp/sock.c | 3 ++- net/sctp/socket.c | 3 ++- net/unix/af_unix.c | 4 +++- 23 files changed, 53 insertions(+), 6 deletions(-)
arch/alpha/include/uapi/asm/socket.h +2 -0
@@ -79,4 +79,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _UAPI_ASM_SOCKET_H */
arch/avr32/include/uapi/asm/socket.h +2 -0
@@ -72,4 +72,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* __ASM_AVR32_SOCKET_H */
arch/cris/include/uapi/asm/socket.h +2 -0
@@ -74,6 +74,8 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _ASM_SOCKET_H */
arch/frv/include/uapi/asm/socket.h +2 -0
@@ -72,5 +72,7 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _ASM_SOCKET_H */
arch/h8300/include/uapi/asm/socket.h +2 -0
@@ -72,4 +72,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _ASM_SOCKET_H */
arch/ia64/include/uapi/asm/socket.h +2 -0
@@ -81,4 +81,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _ASM_IA64_SOCKET_H */
arch/m32r/include/uapi/asm/socket.h +2 -0
@@ -72,4 +72,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _ASM_M32R_SOCKET_H */
arch/mips/include/uapi/asm/socket.h +2 -0
@@ -90,4 +90,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _UAPI_ASM_SOCKET_H */
arch/mn10300/include/uapi/asm/socket.h +2 -0
@@ -72,4 +72,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _ASM_SOCKET_H */
arch/parisc/include/uapi/asm/socket.h +2 -0
@@ -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. */
arch/powerpc/include/uapi/asm/socket.h +2 -0
@@ -79,4 +79,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _ASM_POWERPC_SOCKET_H */
arch/s390/include/uapi/asm/socket.h +2 -0
@@ -78,4 +78,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _ASM_SOCKET_H */
arch/sparc/include/uapi/asm/socket.h +2 -0
@@ -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
arch/xtensa/include/uapi/asm/socket.h +2 -0
@@ -83,4 +83,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* _XTENSA_SOCKET_H */
include/net/sock.h +1 -0
@@ -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)
include/uapi/asm-generic/socket.h +2 -0
@@ -74,4 +74,6 @@#define SO_LOCK_FILTER 44 +#define SO_SELECT_ERR_QUEUE 45 +#endif /* __ASM_GENERIC_SOCKET_H */
net/bluetooth/af_bluetooth.c +2 -1
@@ -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 ;
net/core/datagram.c +3 -1
@@ -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 )
net/core/sock.c +8 -0
@@ -907,6 +907,10 @@ set_rcvbuf: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 ;
@@ -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 ; }
net/iucv/af_iucv.c +2 -1
@@ -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 ;
net/nfc/llcp/sock.c +2 -1
@@ -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 ;
net/sctp/socket.c +2 -1
@@ -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 )
net/unix/af_unix.c +3 -1
@@ -2197,7 +2197,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 )
Quoted 8 lines · Jacob Keller
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.
I would fully support having this kind of ability. As it stands now, the SO_TIMESTAMPING interface makes it very inconvenient for the application to obtain transmit time stamps.
As a concrete example, take the ptp4l [1] program. After sending a packet for which a time stamp is expected, we call recvmsg() on the MSG_ERRQUEUE repeatedly, but give up after a certain number of tries. The repetitions are needed because the driver may delay the time stamped packet for quite some time, and the giving up is required because it is possible for time stamps to be lost or dropped.
Having the ability to poll/select the error queue would open more attractive possibilities for applications. Instead of a cheesy retry loop, just poll/select the error queue with a reasonable timeout value.
Thanks,
Richard
1. http://linuxptp.sourceforge.net/
file: sk.c
line: 199
function: sk_receive()
From: Jacob Keller <[email protected]>
Date: Thu, 28 Mar 2013 14:19:25 -0700
Quoted 9 lines
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.
Quoted 5 lines
-v2-
* Added theSO_SELECT_ERR_QUEUEsocket option to every architechture specific file
* Modified every socket poll function that checks error queueSigned-off-by Jacob Keller <[email protected]>
Applied, thanks.