Skip to content

Commit

Permalink
net: add socket option for low latency polling
Browse files Browse the repository at this point in the history
adds a socket option for low latency polling.
This allows overriding the global sysctl value with a per-socket one.
Unexport sysctl_net_ll_poll since for now it's not needed in modules.

Signed-off-by: Eliezer Tamir <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eliezer Tamir authored and davem330 committed Jun 17, 2013
1 parent 89bf1b5 commit dafcc43
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 7 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 @@ -81,4 +81,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -74,4 +74,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -76,6 +76,8 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -74,5 +74,7 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -74,4 +74,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -83,4 +83,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -74,4 +74,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -92,4 +92,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -74,4 +74,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -73,6 +73,8 @@

#define SO_SELECT_ERR_QUEUE 0x4026

#define SO_LL 0x4027

/* 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 @@ -81,4 +81,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -80,4 +80,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#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 @@ -70,6 +70,8 @@

#define SO_SELECT_ERR_QUEUE 0x0029

#define SO_LL 0x0030

/* 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 @@ -85,4 +85,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#endif /* _XTENSA_SOCKET_H */
12 changes: 6 additions & 6 deletions include/net/ll_poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ extern unsigned int sysctl_net_ll_poll __read_mostly;
/* we can use sched_clock() because we don't care much about precision
* we only care that the average is bounded
*/
static inline u64 ll_end_time(void)
static inline u64 ll_end_time(struct sock *sk)
{
u64 end_time = ACCESS_ONCE(sysctl_net_ll_poll);
u64 end_time = ACCESS_ONCE(sk->sk_ll_usec);

/* we don't mind a ~2.5% imprecision
* sysctl_net_ll_poll is a u_int so this can't overflow
* sk->sk_ll_usec is a u_int so this can't overflow
*/
end_time = (end_time << 10) + sched_clock();

Expand All @@ -53,7 +53,7 @@ static inline u64 ll_end_time(void)

static inline bool sk_valid_ll(struct sock *sk)
{
return sysctl_net_ll_poll && sk->sk_napi_id &&
return sk->sk_ll_usec && sk->sk_napi_id &&
!need_resched() && !signal_pending(current);
}

Expand All @@ -65,7 +65,7 @@ static inline bool can_poll_ll(u64 end_time)
static inline bool sk_poll_ll(struct sock *sk, int nonblock)
{
const struct net_device_ops *ops;
u64 end_time = ll_end_time();
u64 end_time = ll_end_time(sk);
struct napi_struct *napi;
int rc = false;

Expand Down Expand Up @@ -118,7 +118,7 @@ static inline void sk_mark_ll(struct sock *sk, struct sk_buff *skb)

#else /* CONFIG_NET_LL_RX_POLL */

static inline u64 ll_end_time(void)
static inline u64 ll_end_time(struct sock *sk)
{
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ struct cg_proto;
* @sk_wmem_queued: persistent queue size
* @sk_forward_alloc: space allocated forward
* @sk_napi_id: id of the last napi context to receive data for sk
* @sk_ll_usec: usecs to busypoll when there is no data
* @sk_allocation: allocation mode
* @sk_sndbuf: size of send buffer in bytes
* @sk_flags: %SO_LINGER (l_onoff), %SO_BROADCAST, %SO_KEEPALIVE,
Expand Down Expand Up @@ -328,6 +329,7 @@ struct sock {
#endif
#ifdef CONFIG_NET_LL_RX_POLL
unsigned int sk_napi_id;
unsigned int sk_ll_usec;
#endif
atomic_t sk_drops;
int sk_rcvbuf;
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 @@ -76,4 +76,6 @@

#define SO_SELECT_ERR_QUEUE 45

#define SO_LL 46

#endif /* __ASM_GENERIC_SOCKET_H */
20 changes: 20 additions & 0 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,19 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
sock_valbool_flag(sk, SOCK_SELECT_ERR_QUEUE, valbool);
break;

#ifdef CONFIG_NET_LL_RX_POLL
case SO_LL:
/* allow unprivileged users to decrease the value */
if ((val > sk->sk_ll_usec) && !capable(CAP_NET_ADMIN))
ret = -EPERM;
else {
if (val < 0)
ret = -EINVAL;
else
sk->sk_ll_usec = val;
}
break;
#endif
default:
ret = -ENOPROTOOPT;
break;
Expand Down Expand Up @@ -1170,6 +1183,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
v.val = sock_flag(sk, SOCK_SELECT_ERR_QUEUE);
break;

#ifdef CONFIG_NET_LL_RX_POLL
case SO_LL:
v.val = sk->sk_ll_usec;
break;
#endif

default:
return -ENOPROTOOPT;
}
Expand Down Expand Up @@ -2288,6 +2307,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)

#ifdef CONFIG_NET_LL_RX_POLL
sk->sk_napi_id = 0;
sk->sk_ll_usec = sysctl_net_ll_poll;
#endif

/*
Expand Down
1 change: 0 additions & 1 deletion net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@

#ifdef CONFIG_NET_LL_RX_POLL
unsigned int sysctl_net_ll_poll __read_mostly;
EXPORT_SYMBOL_GPL(sysctl_net_ll_poll);
#endif

static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
Expand Down

0 comments on commit dafcc43

Please sign in to comment.