Lines Matching +full:cpu +full:- +full:read

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Guest agent for virtio-trace
15 #include "trace-agent.h"
22 "/sys/kernel/debug/tracing/per_cpu/cpu%d/trace_pipe_raw"
23 #define WRITE_PATH_FMT "/dev/virtio-ports/trace-path-cpu%d"
24 #define CTL_PATH "/dev/virtio-ports/agent-ctl-path"
34 pr_err("Could not read cpus\n"); in get_total_cpus()
58 s->pipe_size = PIPE_INIT; in agent_info_new()
59 s->use_stdout = false; in agent_info_new()
60 s->cpus = get_total_cpus(); in agent_info_new()
61 s->ctl_fd = -1; in agent_info_new()
63 /* read/write threads init */ in agent_info_new()
64 for (i = 0; i < s->cpus; i++) in agent_info_new()
65 s->rw_ti[i] = rw_thread_info_new(); in agent_info_new()
96 round = value & (PAGE_SIZE - 1); in parse_size()
97 value = value - round; in parse_size()
106 pr_err("usage: %s [-h] [-o] [-s <size of pipe>]\n", prg); in usage()
124 /* read(input) path */ in make_path()
128 pr_err("Failed to generate %s path(CPU#%d):%d\n", in make_path()
129 this_is_write_path ? "read" : "write", cpu_num, ret); in make_path()
152 int cpu; in agent_info_init() local
156 /* init read/write threads */ in agent_info_init()
157 for (cpu = 0; cpu < s->cpus; cpu++) { in agent_info_init()
158 /* set read(input) path per read/write thread */ in agent_info_init()
159 in_path = make_input_path(cpu); in agent_info_init()
163 /* set write(output) path per read/write thread*/ in agent_info_init()
164 if (!s->use_stdout) { in agent_info_init()
165 out_path = make_output_path(cpu); in agent_info_init()
172 rw_thread_init(cpu, in_path, out_path, s->use_stdout, in agent_info_init()
173 s->pipe_size, s->rw_ti[cpu]); in agent_info_init()
176 /* init controller of read/write threads */ in agent_info_init()
177 s->ctl_fd = rw_ctl_init((const char *)CTL_PATH); in agent_info_init()
190 while ((cmd = getopt(argc, argv, "hos:")) != -1) { in parse_args()
194 s->use_stdout = true; in parse_args()
201 s->pipe_size = size; in parse_args()
220 int cpu; in agent_main_loop() local
223 /* Start all read/write threads */ in agent_main_loop()
224 for (cpu = 0; cpu < s->cpus; cpu++) in agent_main_loop()
225 rw_thread_per_cpu[cpu] = rw_thread_run(s->rw_ti[cpu]); in agent_main_loop()
227 rw_ctl_loop(s->ctl_fd); in agent_main_loop()
229 /* Finish all read/write threads */ in agent_main_loop()
230 for (cpu = 0; cpu < s->cpus; cpu++) { in agent_main_loop()
233 ret = pthread_join(rw_thread_per_cpu[cpu], NULL); in agent_main_loop()
235 pr_err("pthread_join() error:%d (cpu %d)\n", ret, cpu); in agent_main_loop()
245 close(s->ctl_fd); in agent_info_free()
246 for (i = 0; i < s->cpus; i++) { in agent_info_free()
247 close(s->rw_ti[i]->in_fd); in agent_info_free()
248 close(s->rw_ti[i]->out_fd); in agent_info_free()
249 close(s->rw_ti[i]->read_pipe); in agent_info_free()
250 close(s->rw_ti[i]->write_pipe); in agent_info_free()
251 free(s->rw_ti[i]); in agent_info_free()