tools/testing/selftests/sched/cs_prctl_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/sched/cs_prctl_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/sched/cs_prctl_test.c- Extension
.c- Size
- 9507 bytes
- Lines
- 360
- 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
sys/eventfd.hsys/wait.hsys/types.hsched.hsys/prctl.hunistd.htime.herrno.hstdio.hstdlib.hstring.hsys/syscall.h
Detected Declarations
struct child_argsenum pid_typefunction gettidfunction _prctlfunction __handle_errorfunction handle_usagefunction get_cs_cookiefunction child_func_threadfunction create_threadsfunction child_func_processfunction create_processesfunction disp_processesfunction _validatefunction main
Annotated Snippet
struct child_args {
int num_threads;
int pfd[2];
int cpid;
int thr_tids[MAX_THREADS];
};
static struct child_args procs[MAX_PROCESSES];
static int num_processes = 2;
static int need_cleanup;
static int _prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4,
unsigned long arg5)
{
int res;
res = prctl(option, arg2, arg3, arg4, arg5);
printf("%d = prctl(%d, %ld, %ld, %ld, %lx)\n", res, option, (long)arg2, (long)arg3,
(long)arg4, arg5);
return res;
}
#define STACK_SIZE (1024 * 1024)
#define handle_error(msg) __handle_error(__FILE__, __LINE__, msg)
static void __handle_error(char *fn, int ln, char *msg)
{
int pidx;
printf("(%s:%d) - ", fn, ln);
perror(msg);
if (need_cleanup) {
for (pidx = 0; pidx < num_processes; ++pidx)
kill(procs[pidx].cpid, 15);
need_cleanup = 0;
}
exit(EXIT_FAILURE);
}
static void handle_usage(int rc, char *msg)
{
puts(USAGE);
puts(msg);
putchar('\n');
exit(rc);
}
static unsigned long get_cs_cookie(int pid)
{
unsigned long long cookie;
int ret;
ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID,
(unsigned long)&cookie);
if (ret) {
printf("Not a core sched system\n");
return -1UL;
}
return cookie;
}
static int child_func_thread(void __attribute__((unused))*arg)
{
while (1)
usleep(20000);
return 0;
}
static void create_threads(int num_threads, int thr_tids[])
{
void *child_stack;
pid_t tid;
int i;
for (i = 0; i < num_threads; ++i) {
child_stack = malloc(STACK_SIZE);
if (!child_stack)
handle_error("child stack allocate");
tid = clone(child_func_thread, child_stack + STACK_SIZE, THREAD_CLONE_FLAGS, NULL);
if (tid == -1)
handle_error("clone thread");
thr_tids[i] = tid;
}
}
static int child_func_process(void *arg)
{
struct child_args *ca = (struct child_args *)arg;
int ret;
Annotation
- Immediate include surface: `sys/eventfd.h`, `sys/wait.h`, `sys/types.h`, `sched.h`, `sys/prctl.h`, `unistd.h`, `time.h`, `errno.h`.
- Detected declarations: `struct child_args`, `enum pid_type`, `function gettid`, `function _prctl`, `function __handle_error`, `function handle_usage`, `function get_cs_cookie`, `function child_func_thread`, `function create_threads`, `function child_func_process`.
- 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.