xref: /OK3568_Linux_fs/kernel/tools/virtio/virtio-trace/trace-agent.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef __TRACE_AGENT_H__
3*4882a593Smuzhiyun #define __TRACE_AGENT_H__
4*4882a593Smuzhiyun #include <pthread.h>
5*4882a593Smuzhiyun #include <stdbool.h>
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #define MAX_CPUS	256
8*4882a593Smuzhiyun #define PIPE_INIT       (1024*1024)
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /*
11*4882a593Smuzhiyun  * agent_info - structure managing total information of guest agent
12*4882a593Smuzhiyun  * @pipe_size:	size of pipe (default 1MB)
13*4882a593Smuzhiyun  * @use_stdout:	set to true when o option is added (default false)
14*4882a593Smuzhiyun  * @cpus:	total number of CPUs
15*4882a593Smuzhiyun  * @ctl_fd:	fd of control path, /dev/virtio-ports/agent-ctl-path
16*4882a593Smuzhiyun  * @rw_ti:	structure managing information of read/write threads
17*4882a593Smuzhiyun  */
18*4882a593Smuzhiyun struct agent_info {
19*4882a593Smuzhiyun 	unsigned long pipe_size;
20*4882a593Smuzhiyun 	bool use_stdout;
21*4882a593Smuzhiyun 	int cpus;
22*4882a593Smuzhiyun 	int ctl_fd;
23*4882a593Smuzhiyun 	struct rw_thread_info *rw_ti[MAX_CPUS];
24*4882a593Smuzhiyun };
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun  * rw_thread_info - structure managing a read/write thread a cpu
28*4882a593Smuzhiyun  * @cpu_num:	cpu number operating this read/write thread
29*4882a593Smuzhiyun  * @in_fd:	fd of reading trace data path in cpu_num
30*4882a593Smuzhiyun  * @out_fd:	fd of writing trace data path in cpu_num
31*4882a593Smuzhiyun  * @read_pipe:	fd of read pipe
32*4882a593Smuzhiyun  * @write_pipe:	fd of write pipe
33*4882a593Smuzhiyun  * @pipe_size:	size of pipe (default 1MB)
34*4882a593Smuzhiyun  */
35*4882a593Smuzhiyun struct rw_thread_info {
36*4882a593Smuzhiyun 	int cpu_num;
37*4882a593Smuzhiyun 	int in_fd;
38*4882a593Smuzhiyun 	int out_fd;
39*4882a593Smuzhiyun 	int read_pipe;
40*4882a593Smuzhiyun 	int write_pipe;
41*4882a593Smuzhiyun 	unsigned long pipe_size;
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /* use for stopping rw threads */
45*4882a593Smuzhiyun extern bool global_sig_receive;
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /* use for notification */
48*4882a593Smuzhiyun extern bool global_run_operation;
49*4882a593Smuzhiyun extern pthread_mutex_t mutex_notify;
50*4882a593Smuzhiyun extern pthread_cond_t cond_wakeup;
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /* for controller of read/write threads */
53*4882a593Smuzhiyun extern int rw_ctl_init(const char *ctl_path);
54*4882a593Smuzhiyun extern void *rw_ctl_loop(int ctl_fd);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /* for trace read/write thread */
57*4882a593Smuzhiyun extern void *rw_thread_info_new(void);
58*4882a593Smuzhiyun extern void *rw_thread_init(int cpu, const char *in_path, const char *out_path,
59*4882a593Smuzhiyun 			bool stdout_flag, unsigned long pipe_size,
60*4882a593Smuzhiyun 			struct rw_thread_info *rw_ti);
61*4882a593Smuzhiyun extern pthread_t rw_thread_run(struct rw_thread_info *rw_ti);
62*4882a593Smuzhiyun 
zalloc(size_t size)63*4882a593Smuzhiyun static inline void *zalloc(size_t size)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun 	return calloc(1, size);
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun #define pr_err(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
69*4882a593Smuzhiyun #define pr_info(format, ...) fprintf(stdout, format, ## __VA_ARGS__)
70*4882a593Smuzhiyun #ifdef DEBUG
71*4882a593Smuzhiyun #define pr_debug(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
72*4882a593Smuzhiyun #else
73*4882a593Smuzhiyun #define pr_debug(format, ...) do {} while (0)
74*4882a593Smuzhiyun #endif
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun #endif /*__TRACE_AGENT_H__*/
77