tools/testing/selftests/net/tcp_ao/lib/ftrace.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/tcp_ao/lib/ftrace.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/tcp_ao/lib/ftrace.c- Extension
.c- Size
- 11911 bytes
- Lines
- 544
- 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.
- 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
inttypes.hpthread.hstdbool.hstdio.hstdlib.hsys/mount.hsys/time.hunistd.h../../../../../include/linux/kernel.haolib.h
Detected Declarations
struct test_ftracerstruct opts_list_tfunction mount_ftracefunction unmount_ftracefunction disable_trace_optionsfunction setup_buffer_sizefunction setup_ftrace_instancefunction remove_ftrace_instancefunction tracer_cleanupfunction tracer_set_errorfunction tracer_get_savedlines_nrfunction setup_trace_threadfunction stop_trace_threadfunction final_wait_for_eventsfunction setup_trace_eventfunction ftracer_opfunction __destroy_ftracerfunction destroy_ftracerfunction destroy_all_ftracersfunction test_unset_tracingfunction test_setup_tracingfunction get_ns_cookiefunction test_init_ftrace
Annotated Snippet
struct test_ftracer {
pthread_t tracer_thread;
int error;
char *instance_path;
FILE *trace_pipe;
enum ftracer_op (*process_line)(const char *line);
void (*destructor)(struct test_ftracer *tracer);
bool (*expecting_more)(void);
char **saved_lines;
size_t saved_lines_size;
size_t next_line_ind;
pthread_cond_t met_all_expected;
pthread_mutex_t met_all_expected_lock;
struct test_ftracer *next;
};
static struct test_ftracer *ftracers;
static pthread_mutex_t ftracers_lock = PTHREAD_MUTEX_INITIALIZER;
static int mount_ftrace(void)
{
if (!mkdtemp(ftrace_path))
test_error("Can't create temp dir");
if (mount("tracefs", ftrace_path, "tracefs", 0, "rw"))
return -errno;
ftrace_mounted = true;
return 0;
}
static void unmount_ftrace(void)
{
if (ftrace_mounted && umount(ftrace_path))
test_print("Failed on cleanup: can't unmount tracefs: %m");
if (rmdir(ftrace_path))
test_error("Failed on cleanup: can't remove ftrace dir %s",
ftrace_path);
}
struct opts_list_t {
char *opt_name;
struct opts_list_t *next;
};
static int disable_trace_options(const char *ftrace_path)
{
struct opts_list_t *opts_list = NULL;
char *fopts, *line = NULL;
size_t buf_len = 0;
ssize_t line_len;
int ret = 0;
FILE *opts;
fopts = test_sprintf("%s/%s", ftrace_path, "trace_options");
if (!fopts)
return -ENOMEM;
opts = fopen(fopts, "r+");
if (!opts) {
ret = -errno;
goto out_free;
}
while ((line_len = getline(&line, &buf_len, opts)) != -1) {
struct opts_list_t *tmp;
if (!strncmp(line, "no", 2))
continue;
tmp = malloc(sizeof(*tmp));
if (!tmp) {
ret = -ENOMEM;
goto out_free_opts_list;
}
tmp->next = opts_list;
tmp->opt_name = test_sprintf("no%s", line);
if (!tmp->opt_name) {
ret = -ENOMEM;
free(tmp);
goto out_free_opts_list;
}
opts_list = tmp;
}
Annotation
- Immediate include surface: `inttypes.h`, `pthread.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `sys/mount.h`, `sys/time.h`, `unistd.h`.
- Detected declarations: `struct test_ftracer`, `struct opts_list_t`, `function mount_ftrace`, `function unmount_ftrace`, `function disable_trace_options`, `function setup_buffer_size`, `function setup_ftrace_instance`, `function remove_ftrace_instance`, `function tracer_cleanup`, `function tracer_set_error`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.