Lines Matching +full:cpu +full:- +full:read
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Read/write thread of a guest agent for virtio-trace
16 #include "trace-agent.h"
30 rw_ti->cpu_num = -1; in rw_thread_info_new()
31 rw_ti->in_fd = -1; in rw_thread_info_new()
32 rw_ti->out_fd = -1; in rw_thread_info_new()
33 rw_ti->read_pipe = -1; in rw_thread_info_new()
34 rw_ti->write_pipe = -1; in rw_thread_info_new()
35 rw_ti->pipe_size = PIPE_INIT; in rw_thread_info_new()
40 void *rw_thread_init(int cpu, const char *in_path, const char *out_path, in rw_thread_init() argument
46 rw_ti->cpu_num = cpu; in rw_thread_init()
48 /* set read(input) fd */ in rw_thread_init()
49 rw_ti->in_fd = open(in_path, O_RDONLY); in rw_thread_init()
50 if (rw_ti->in_fd == -1) { in rw_thread_init()
51 pr_err("Could not open in_fd (CPU:%d)\n", cpu); in rw_thread_init()
57 /* virtio-serial output mode */ in rw_thread_init()
58 rw_ti->out_fd = open(out_path, O_WRONLY); in rw_thread_init()
59 if (rw_ti->out_fd == -1) { in rw_thread_init()
60 pr_err("Could not open out_fd (CPU:%d)\n", cpu); in rw_thread_init()
65 rw_ti->out_fd = STDOUT_FILENO; in rw_thread_init()
68 pr_err("Could not create pipe in rw-thread(%d)\n", cpu); in rw_thread_init()
74 * To read/write trace data speedy, pipe size is changed. in rw_thread_init()
77 pr_err("Could not change pipe size in rw-thread(%d)\n", cpu); in rw_thread_init()
81 rw_ti->read_pipe = data_pipe[1]; in rw_thread_init()
82 rw_ti->write_pipe = data_pipe[0]; in rw_thread_init()
83 rw_ti->pipe_size = pipe_size; in rw_thread_init()
91 /* Bind a thread to a cpu */
100 if (sched_setaffinity(0, sizeof(mask), &mask) == -1) in bind_cpu()
101 pr_err("Could not set CPU#%d affinity\n", (int)cpu_num); in bind_cpu()
110 bind_cpu(ts->cpu_num); in rw_thread_main()
113 /* Wait for a read order of trace data by Host OS */ in rw_thread_main()
124 * Each thread read trace_pipe_raw of each cpu bounding the in rw_thread_main()
125 * thread, so contention of multi-threads does not occur. in rw_thread_main()
127 rlen = splice(ts->in_fd, NULL, ts->read_pipe, NULL, in rw_thread_main()
128 ts->pipe_size, SPLICE_F_MOVE | SPLICE_F_MORE); in rw_thread_main()
131 pr_err("Splice_read in rw-thread(%d)\n", ts->cpu_num); in rw_thread_main()
138 * ring-buffer. in rw_thread_main()
141 pr_debug("Read retry(cpu:%d)\n", ts->cpu_num); in rw_thread_main()
148 ret = splice(ts->write_pipe, NULL, ts->out_fd, NULL, in rw_thread_main()
149 rlen - wlen, in rw_thread_main()
153 pr_err("Splice_write in rw-thread(%d)\n", in rw_thread_main()
154 ts->cpu_num); in rw_thread_main()
161 * non-blocking mode. Then, writer might be in rw_thread_main()
164 * non-blocking mode. in rw_thread_main()
185 pr_err("Could not create a rw thread(%d)\n", rw_ti->cpu_num); in rw_thread_run()