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"
23 #define READ_PATH_FMT "%s/per_cpu/cpu%d/trace_pipe_raw"
24 #define WRITE_PATH_FMT "/dev/virtio-ports/trace-path-cpu%d"
25 #define CTL_PATH "/dev/virtio-ports/agent-ctl-path"
35 pr_err("Could not read cpus\n"); in get_total_cpus()
59 s->pipe_size = PIPE_INIT; in agent_info_new()
60 s->use_stdout = false; in agent_info_new()
61 s->cpus = get_total_cpus(); in agent_info_new()
62 s->ctl_fd = -1; in agent_info_new()
64 /* read/write threads init */ in agent_info_new()
65 for (i = 0; i < s->cpus; i++) in agent_info_new()
66 s->rw_ti[i] = rw_thread_info_new(); in agent_info_new()
97 round = value & (PAGE_SIZE - 1); in parse_size()
98 value = value - round; in parse_size()
107 pr_err("usage: %s [-h] [-o] [-s <size of pipe>]\n", prg); in usage()
125 /* read(input) path */ in make_path()
132 pr_err("Failed to generate %s path(CPU#%d):%d\n", in make_path()
133 this_is_write_path ? "read" : "write", cpu_num, ret); in make_path()
156 int cpu; in agent_info_init() local
160 /* init read/write threads */ in agent_info_init()
161 for (cpu = 0; cpu < s->cpus; cpu++) { in agent_info_init()
162 /* set read(input) path per read/write thread */ in agent_info_init()
163 in_path = make_input_path(cpu); in agent_info_init()
167 /* set write(output) path per read/write thread*/ in agent_info_init()
168 if (!s->use_stdout) { in agent_info_init()
169 out_path = make_output_path(cpu); in agent_info_init()
176 rw_thread_init(cpu, in_path, out_path, s->use_stdout, in agent_info_init()
177 s->pipe_size, s->rw_ti[cpu]); in agent_info_init()
180 /* init controller of read/write threads */ in agent_info_init()
181 s->ctl_fd = rw_ctl_init((const char *)CTL_PATH); in agent_info_init()
194 while ((cmd = getopt(argc, argv, "hos:")) != -1) { in parse_args()
198 s->use_stdout = true; in parse_args()
205 s->pipe_size = size; in parse_args()
224 int cpu; in agent_main_loop() local
227 /* Start all read/write threads */ in agent_main_loop()
228 for (cpu = 0; cpu < s->cpus; cpu++) in agent_main_loop()
229 rw_thread_per_cpu[cpu] = rw_thread_run(s->rw_ti[cpu]); in agent_main_loop()
231 rw_ctl_loop(s->ctl_fd); in agent_main_loop()
233 /* Finish all read/write threads */ in agent_main_loop()
234 for (cpu = 0; cpu < s->cpus; cpu++) { in agent_main_loop()
237 ret = pthread_join(rw_thread_per_cpu[cpu], NULL); in agent_main_loop()
239 pr_err("pthread_join() error:%d (cpu %d)\n", ret, cpu); in agent_main_loop()
249 close(s->ctl_fd); in agent_info_free()
250 for (i = 0; i < s->cpus; i++) { in agent_info_free()
251 close(s->rw_ti[i]->in_fd); in agent_info_free()
252 close(s->rw_ti[i]->out_fd); in agent_info_free()
253 close(s->rw_ti[i]->read_pipe); in agent_info_free()
254 close(s->rw_ti[i]->write_pipe); in agent_info_free()
255 free(s->rw_ti[i]); in agent_info_free()