tools/testing/selftests/net/so_incoming_cpu.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/so_incoming_cpu.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/so_incoming_cpu.c- Extension
.c- Size
- 6055 bytes
- Lines
- 275
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sched.hfcntl.hnetinet/in.hsys/socket.hsys/sysinfo.hkselftest_harness.h
Detected Declarations
enum when_to_setfunction write_sysctlfunction setup_netnsfunction set_so_incoming_cpufunction create_serverfunction create_serversfunction create_clientsfunction verify_incoming_cpu
Annotated Snippet
if (i == 0) {
ret = getsockname(self->servers[i], &self->addr, &self->addrlen);
ASSERT_EQ(ret, 0);
}
}
if (variant->when_to_set == AFTER_ALL_LISTEN) {
for (i = 0; i < nr_server; i++)
set_so_incoming_cpu(_metadata, self->servers[i], i);
}
}
void create_clients(struct __test_metadata *_metadata,
FIXTURE_DATA(so_incoming_cpu) *self)
{
cpu_set_t cpu_set;
int i, j, fd, ret;
for (i = 0; i < nr_server; i++) {
CPU_ZERO(&cpu_set);
CPU_SET(i, &cpu_set);
ASSERT_EQ(CPU_COUNT(&cpu_set), 1);
ASSERT_NE(CPU_ISSET(i, &cpu_set), 0);
/* Make sure SYN will be processed on the i-th CPU
* and finally distributed to the i-th listener.
*/
ret = sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
ASSERT_EQ(ret, 0);
for (j = 0; j < nr_client_per_server; j++) {
fd = socket(AF_INET, SOCK_STREAM, 0);
ASSERT_NE(fd, -1);
ret = connect(fd, &self->addr, self->addrlen);
ASSERT_EQ(ret, 0);
close(fd);
}
}
}
void verify_incoming_cpu(struct __test_metadata *_metadata,
FIXTURE_DATA(so_incoming_cpu) *self)
{
int i, j, fd, cpu, ret, total = 0;
socklen_t len = sizeof(int);
for (i = 0; i < nr_server; i++) {
for (j = 0; j < nr_client_per_server; j++) {
/* If we see -EAGAIN here, SO_INCOMING_CPU is broken */
fd = accept(self->servers[i], &self->addr, &self->addrlen);
ASSERT_NE(fd, -1);
ret = getsockopt(fd, SOL_SOCKET, SO_INCOMING_CPU, &cpu, &len);
ASSERT_EQ(ret, 0);
ASSERT_EQ(cpu, i);
close(fd);
total++;
}
}
ASSERT_EQ(total, nr_client);
TH_LOG("SO_INCOMING_CPU is very likely to be "
"working correctly with %d sockets.", total);
}
TEST_F(so_incoming_cpu, test1)
{
create_servers(_metadata, self, variant);
create_clients(_metadata, self);
verify_incoming_cpu(_metadata, self);
}
TEST_F(so_incoming_cpu, test2)
{
int server;
create_servers(_metadata, self, variant);
/* No CPU specified */
server = create_server(_metadata, self, variant, -1);
close(server);
create_clients(_metadata, self);
verify_incoming_cpu(_metadata, self);
}
Annotation
- Immediate include surface: `sched.h`, `fcntl.h`, `netinet/in.h`, `sys/socket.h`, `sys/sysinfo.h`, `kselftest_harness.h`.
- Detected declarations: `enum when_to_set`, `function write_sysctl`, `function setup_netns`, `function set_so_incoming_cpu`, `function create_server`, `function create_servers`, `function create_clients`, `function verify_incoming_cpu`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.