tools/tracing/rtla/src/timerlat_u.c
Source file repositories/reference/linux-study-clean/tools/tracing/rtla/src/timerlat_u.c
File Facts
- System
- Linux kernel
- Corpus path
tools/tracing/rtla/src/timerlat_u.c- Extension
.c- Size
- 4640 bytes
- Lines
- 222
- 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.hstdlib.hunistd.hstdio.herrno.hstring.htracefs.hpthread.hsys/wait.hsys/prctl.hcommon.htimerlat_u.h
Detected Declarations
function Copyrightfunction timerlat_u_send_kill
Annotated Snippet
if (retval) {
/* __set_sched_attr prints an error message, so */
exit(0);
}
}
if (params->cgroup_name) {
retval = set_pid_cgroup(gettid(), params->cgroup_name);
if (!retval) {
err_msg("Error setting timerlat u cgroup pid\n");
pthread_exit(&retval);
}
}
/*
* This is the tool's loop. If you want to use as base for your own tool...
* go ahead.
*/
snprintf(buffer, sizeof(buffer), "osnoise/per_cpu/cpu%d/timerlat_fd", cpu);
timerlat_fd = tracefs_instance_file_open(NULL, buffer, O_RDONLY);
if (timerlat_fd < 0)
fatal("Error opening %s:%s", buffer, strerror(errno));
debug_msg("User-space timerlat pid %d on cpu %d\n", gettid(), cpu);
/* add should continue with a signal handler */
while (true) {
retval = read(timerlat_fd, buffer, ARRAY_SIZE(buffer));
if (retval < 0)
break;
}
close(timerlat_fd);
debug_msg("Leaving timerlat pid %d on cpu %d\n", gettid(), cpu);
exit(0);
}
/*
* timerlat_u_send_kill - send a kill signal for all processes
*
* Return the number of processes that received the kill.
*/
static int timerlat_u_send_kill(pid_t *procs)
{
int killed = 0;
int i, retval;
for (i = 0; i < nr_cpus; i++) {
if (!procs[i])
continue;
retval = kill(procs[i], SIGKILL);
if (!retval)
killed++;
else
err_msg("Error killing child process %d\n", procs[i]);
}
return killed;
}
/**
* timerlat_u_dispatcher - dispatch one timerlatu/ process per monitored CPU
*
* This is a thread main that will fork one new process for each monitored
* CPU. It will wait for:
*
* - rtla to tell to kill the child processes
* - some child process to die, and the cleanup all the processes
*
* whichever comes first.
*
*/
void *timerlat_u_dispatcher(void *data)
{
struct timerlat_u_params *params = data;
char proc_name[128];
int procs_count = 0;
int retval = 1;
pid_t *procs;
int wstatus;
pid_t pid;
int i;
debug_msg("Dispatching timerlat u procs\n");
procs = calloc(nr_cpus, sizeof(pid_t));
if (!procs)
pthread_exit(&retval);
Annotation
- Immediate include surface: `sched.h`, `fcntl.h`, `stdlib.h`, `unistd.h`, `stdio.h`, `errno.h`, `string.h`, `tracefs.h`.
- Detected declarations: `function Copyright`, `function timerlat_u_send_kill`.
- 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.