Skip to content

Commit

Permalink
net: refactor socket_poll
Browse files Browse the repository at this point in the history
Factor out two busy poll related helpers for late reuse, and remove
a command that isn't very helpful, especially with the __poll_t
annotations in place.

Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Christoph Hellwig committed May 26, 2018
1 parent 1962da0 commit 3cafb37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
15 changes: 15 additions & 0 deletions include/net/busy_poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock)
#endif
}

static inline void sock_poll_busy_loop(struct socket *sock, __poll_t events)
{
if (sk_can_busy_loop(sock->sk) &&
events && (events & POLL_BUSY_LOOP)) {
/* once, only if requested by syscall */
sk_busy_loop(sock->sk, 1);
}
}

/* if this socket can poll_ll, tell the system call */
static inline __poll_t sock_poll_busy_flag(struct socket *sock)
{
return sk_can_busy_loop(sock->sk) ? POLL_BUSY_LOOP : 0;
}

/* used in the NIC receive handler to mark the skb */
static inline void skb_mark_napi_id(struct sk_buff *skb,
struct napi_struct *napi)
Expand Down
21 changes: 4 additions & 17 deletions net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,24 +1117,11 @@ EXPORT_SYMBOL(sock_create_lite);
/* No kernel lock held - perfect */
static __poll_t sock_poll(struct file *file, poll_table *wait)
{
__poll_t busy_flag = 0;
struct socket *sock;

/*
* We can't return errors to poll, so it's either yes or no.
*/
sock = file->private_data;

if (sk_can_busy_loop(sock->sk)) {
/* this socket can poll_ll so tell the system call */
busy_flag = POLL_BUSY_LOOP;

/* once, only if requested by syscall */
if (wait && (wait->_key & POLL_BUSY_LOOP))
sk_busy_loop(sock->sk, 1);
}
struct socket *sock = file->private_data;
__poll_t events = poll_requested_events(wait);

return busy_flag | sock->ops->poll(file, sock, wait);
sock_poll_busy_loop(sock, events);
return sock->ops->poll(file, sock, wait) | sock_poll_busy_flag(sock);
}

static int sock_mmap(struct file *file, struct vm_area_struct *vma)
Expand Down

0 comments on commit 3cafb37

Please sign in to comment.