Skip to content

Commit c6345ce

Browse files
anambiarindavem330
authored andcommitted
net: Record receive queue number for a connection
This patch adds a new field to sock_common 'skc_rx_queue_mapping' which holds the receive queue number for the connection. The Rx queue is marked in tcp_finish_connect() to allow a client app to do SO_INCOMING_NAPI_ID after a connect() call to get the right queue association for a socket. Rx queue is also marked in tcp_conn_request() to allow syn-ack to go on the right tx-queue associated with the queue on which syn is received. Signed-off-by: Amritha Nambiar <amritha.nambiar@intel.com> Signed-off-by: Sridhar Samudrala <sridhar.samudrala@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 755c31c commit c6345ce

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎include/net/busy_poll.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static inline void sk_mark_napi_id(struct sock *sk, const struct sk_buff *skb)
151151
#ifdef CONFIG_NET_RX_BUSY_POLL
152152
sk->sk_napi_id = skb->napi_id;
153153
#endif
154+
sk_rx_queue_set(sk, skb);
154155
}
155156

156157
/* variant used for unconnected sockets */

‎include/net/sock.h‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ typedef __u64 __bitwise __addrpair;
139139
* @skc_node: main hash linkage for various protocol lookup tables
140140
* @skc_nulls_node: main hash linkage for TCP/UDP/UDP-Lite protocol
141141
* @skc_tx_queue_mapping: tx queue number for this connection
142+
* @skc_rx_queue_mapping: rx queue number for this connection
142143
* @skc_flags: place holder for sk_flags
143144
* %SO_LINGER (l_onoff), %SO_BROADCAST, %SO_KEEPALIVE,
144145
* %SO_OOBINLINE settings, %SO_TIMESTAMPING settings
@@ -215,6 +216,9 @@ struct sock_common {
215216
struct hlist_nulls_node skc_nulls_node;
216217
};
217218
unsigned short skc_tx_queue_mapping;
219+
#ifdef CONFIG_XPS
220+
unsigned short skc_rx_queue_mapping;
221+
#endif
218222
union {
219223
int skc_incoming_cpu;
220224
u32 skc_rcv_wnd;
@@ -326,6 +330,9 @@ struct sock {
326330
#define sk_nulls_node __sk_common.skc_nulls_node
327331
#define sk_refcnt __sk_common.skc_refcnt
328332
#define sk_tx_queue_mapping __sk_common.skc_tx_queue_mapping
333+
#ifdef CONFIG_XPS
334+
#define sk_rx_queue_mapping __sk_common.skc_rx_queue_mapping
335+
#endif
329336

330337
#define sk_dontcopy_begin __sk_common.skc_dontcopy_begin
331338
#define sk_dontcopy_end __sk_common.skc_dontcopy_end
@@ -1702,6 +1709,27 @@ static inline int sk_tx_queue_get(const struct sock *sk)
17021709
return -1;
17031710
}
17041711

1712+
static inline void sk_rx_queue_set(struct sock *sk, const struct sk_buff *skb)
1713+
{
1714+
#ifdef CONFIG_XPS
1715+
if (skb_rx_queue_recorded(skb)) {
1716+
u16 rx_queue = skb_get_rx_queue(skb);
1717+
1718+
if (WARN_ON_ONCE(rx_queue == NO_QUEUE_MAPPING))
1719+
return;
1720+
1721+
sk->sk_rx_queue_mapping = rx_queue;
1722+
}
1723+
#endif
1724+
}
1725+
1726+
static inline void sk_rx_queue_clear(struct sock *sk)
1727+
{
1728+
#ifdef CONFIG_XPS
1729+
sk->sk_rx_queue_mapping = NO_QUEUE_MAPPING;
1730+
#endif
1731+
}
1732+
17051733
static inline void sk_set_socket(struct sock *sk, struct socket *sock)
17061734
{
17071735
sk_tx_queue_clear(sk);

‎net/core/sock.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,8 @@ void sock_init_data(struct socket *sock, struct sock *sk)
28182818
sk->sk_pacing_rate = ~0U;
28192819
sk->sk_pacing_shift = 10;
28202820
sk->sk_incoming_cpu = -1;
2821+
2822+
sk_rx_queue_clear(sk);
28212823
/*
28222824
* Before updating sk_refcnt, we must commit prior changes to memory
28232825
* (Documentation/RCU/rculist_nulls.txt for details)

‎net/ipv4/tcp_input.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include <linux/errqueue.h>
7979
#include <trace/events/tcp.h>
8080
#include <linux/static_key.h>
81+
#include <net/busy_poll.h>
8182

8283
int sysctl_tcp_max_orphans __read_mostly = NR_FILE;
8384

@@ -5592,6 +5593,7 @@ void tcp_finish_connect(struct sock *sk, struct sk_buff *skb)
55925593
if (skb) {
55935594
icsk->icsk_af_ops->sk_rx_dst_set(sk, skb);
55945595
security_inet_conn_established(sk, skb);
5596+
sk_mark_napi_id(sk, skb);
55955597
}
55965598

55975599
tcp_init_transfer(sk, BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB);
@@ -6420,6 +6422,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
64206422
tcp_rsk(req)->snt_isn = isn;
64216423
tcp_rsk(req)->txhash = net_tx_rndhash();
64226424
tcp_openreq_init_rwin(req, sk, dst);
6425+
sk_rx_queue_set(req_to_sk(req), skb);
64236426
if (!want_cookie) {
64246427
tcp_reqsk_record_syn(sk, req, skb);
64256428
fastopen_sk = tcp_try_fastopen(sk, skb, req, &foc, dst);

0 commit comments

Comments
 (0)