Skip to content

Commit 3cafb37

Browse files
author
Christoph Hellwig
committed
net: refactor socket_poll
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 <[email protected]>
1 parent 1962da0 commit 3cafb37

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

include/net/busy_poll.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock)
121121
#endif
122122
}
123123

124+
static inline void sock_poll_busy_loop(struct socket *sock, __poll_t events)
125+
{
126+
if (sk_can_busy_loop(sock->sk) &&
127+
events && (events & POLL_BUSY_LOOP)) {
128+
/* once, only if requested by syscall */
129+
sk_busy_loop(sock->sk, 1);
130+
}
131+
}
132+
133+
/* if this socket can poll_ll, tell the system call */
134+
static inline __poll_t sock_poll_busy_flag(struct socket *sock)
135+
{
136+
return sk_can_busy_loop(sock->sk) ? POLL_BUSY_LOOP : 0;
137+
}
138+
124139
/* used in the NIC receive handler to mark the skb */
125140
static inline void skb_mark_napi_id(struct sk_buff *skb,
126141
struct napi_struct *napi)

net/socket.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,24 +1117,11 @@ EXPORT_SYMBOL(sock_create_lite);
11171117
/* No kernel lock held - perfect */
11181118
static __poll_t sock_poll(struct file *file, poll_table *wait)
11191119
{
1120-
__poll_t busy_flag = 0;
1121-
struct socket *sock;
1122-
1123-
/*
1124-
* We can't return errors to poll, so it's either yes or no.
1125-
*/
1126-
sock = file->private_data;
1127-
1128-
if (sk_can_busy_loop(sock->sk)) {
1129-
/* this socket can poll_ll so tell the system call */
1130-
busy_flag = POLL_BUSY_LOOP;
1131-
1132-
/* once, only if requested by syscall */
1133-
if (wait && (wait->_key & POLL_BUSY_LOOP))
1134-
sk_busy_loop(sock->sk, 1);
1135-
}
1120+
struct socket *sock = file->private_data;
1121+
__poll_t events = poll_requested_events(wait);
11361122

1137-
return busy_flag | sock->ops->poll(file, sock, wait);
1123+
sock_poll_busy_loop(sock, events);
1124+
return sock->ops->poll(file, sock, wait) | sock_poll_busy_flag(sock);
11381125
}
11391126

11401127
static int sock_mmap(struct file *file, struct vm_area_struct *vma)

0 commit comments

Comments
 (0)