include/net/rps.h
Source file repositories/reference/linux-study-clean/include/net/rps.h
File Facts
- System
- Linux kernel
- Corpus path
include/net/rps.h- Extension
.h- Size
- 4661 bytes
- Lines
- 198
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/static_key.hnet/sock.hnet/hotdata.hnet/rps-types.h
Detected Declarations
struct rps_mapstruct rps_dev_flowstruct rps_sock_flow_tablefunction rps_record_sock_flowfunction _sock_rps_record_flow_hashfunction _sock_rps_record_flowfunction _sock_rps_delete_flowfunction rfs_is_neededfunction sock_rps_record_flow_hashfunction sock_rps_record_flowfunction sock_rps_delete_flowfunction rps_input_queue_tail_incrfunction rps_input_queue_tail_savefunction rps_input_queue_head_addfunction rps_input_queue_head_incr
Annotated Snippet
struct rps_map {
unsigned int len;
struct rcu_head rcu;
u16 cpus[];
};
#define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + ((_num) * sizeof(u16)))
/*
* The rps_dev_flow structure contains the mapping of a flow to a CPU, the
* tail pointer for that CPU's input queue at the time of last enqueue, a
* hardware filter index, and the hash of the flow if aRFS is enabled.
*/
struct rps_dev_flow {
u16 cpu;
u16 filter;
unsigned int last_qtail;
#ifdef CONFIG_RFS_ACCEL
u32 hash;
#endif
};
#define RPS_NO_FILTER 0xffff
/*
* The rps_sock_flow_table contains mappings of flows to the last CPU
* on which they were processed by the application (set in recvmsg).
* Each entry is a 32bit value. Upper part is the high-order bits
* of flow hash, lower part is CPU number.
* rps_cpu_mask is used to partition the space, depending on number of
* possible CPUs : rps_cpu_mask = roundup_pow_of_two(nr_cpu_ids) - 1
* For example, if 64 CPUs are possible, rps_cpu_mask = 0x3f,
* meaning we use 32-6=26 bits for the hash.
*/
struct rps_sock_flow_table {
u32 ent;
};
#define RPS_NO_CPU 0xffff
static inline void rps_record_sock_flow(rps_tag_ptr tag_ptr, u32 hash)
{
unsigned int index = hash & rps_tag_to_mask(tag_ptr);
u32 val = hash & ~net_hotdata.rps_cpu_mask;
struct rps_sock_flow_table *table;
/* We only give a hint, preemption can change CPU under us */
val |= raw_smp_processor_id();
table = rps_tag_to_table(tag_ptr);
/* The following WRITE_ONCE() is paired with the READ_ONCE()
* here, and another one in get_rps_cpu().
*/
if (READ_ONCE(table[index].ent) != val)
WRITE_ONCE(table[index].ent, val);
}
static inline void _sock_rps_record_flow_hash(__u32 hash)
{
rps_tag_ptr tag_ptr;
if (!hash)
return;
rcu_read_lock();
tag_ptr = READ_ONCE(net_hotdata.rps_sock_flow_table);
if (tag_ptr)
rps_record_sock_flow(tag_ptr, hash);
rcu_read_unlock();
}
static inline void _sock_rps_record_flow(const struct sock *sk)
{
/* Reading sk->sk_rxhash might incur an expensive cache line
* miss.
*
* TCP_ESTABLISHED does cover almost all states where RFS
* might be useful, and is cheaper [1] than testing :
* IPv4: inet_sk(sk)->inet_daddr
* IPv6: ipv6_addr_any(&sk->sk_v6_daddr)
* OR an additional socket flag
* [1] : sk_state and sk_prot are in the same cache line.
*/
if (sk->sk_state == TCP_ESTABLISHED) {
/* This READ_ONCE() is paired with the WRITE_ONCE()
* from sock_rps_save_rxhash() and sock_rps_reset_rxhash().
*/
_sock_rps_record_flow_hash(READ_ONCE(sk->sk_rxhash));
}
}
static inline void _sock_rps_delete_flow(const struct sock *sk)
{
Annotation
- Immediate include surface: `linux/types.h`, `linux/static_key.h`, `net/sock.h`, `net/hotdata.h`, `net/rps-types.h`.
- Detected declarations: `struct rps_map`, `struct rps_dev_flow`, `struct rps_sock_flow_table`, `function rps_record_sock_flow`, `function _sock_rps_record_flow_hash`, `function _sock_rps_record_flow`, `function _sock_rps_delete_flow`, `function rfs_is_needed`, `function sock_rps_record_flow_hash`, `function sock_rps_record_flow`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.