Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __TRACE_AGENT_H__
0003 #define __TRACE_AGENT_H__
0004 #include <pthread.h>
0005 #include <stdbool.h>
0006 
0007 #define MAX_CPUS    256
0008 #define PIPE_INIT       (1024*1024)
0009 
0010 /*
0011  * agent_info - structure managing total information of guest agent
0012  * @pipe_size:  size of pipe (default 1MB)
0013  * @use_stdout: set to true when o option is added (default false)
0014  * @cpus:   total number of CPUs
0015  * @ctl_fd: fd of control path, /dev/virtio-ports/agent-ctl-path
0016  * @rw_ti:  structure managing information of read/write threads
0017  */
0018 struct agent_info {
0019     unsigned long pipe_size;
0020     bool use_stdout;
0021     int cpus;
0022     int ctl_fd;
0023     struct rw_thread_info *rw_ti[MAX_CPUS];
0024 };
0025 
0026 /*
0027  * rw_thread_info - structure managing a read/write thread a cpu
0028  * @cpu_num:    cpu number operating this read/write thread
0029  * @in_fd:  fd of reading trace data path in cpu_num
0030  * @out_fd: fd of writing trace data path in cpu_num
0031  * @read_pipe:  fd of read pipe
0032  * @write_pipe: fd of write pipe
0033  * @pipe_size:  size of pipe (default 1MB)
0034  */
0035 struct rw_thread_info {
0036     int cpu_num;
0037     int in_fd;
0038     int out_fd;
0039     int read_pipe;
0040     int write_pipe;
0041     unsigned long pipe_size;
0042 };
0043 
0044 /* use for stopping rw threads */
0045 extern bool global_sig_receive;
0046 
0047 /* use for notification */
0048 extern bool global_run_operation;
0049 extern pthread_mutex_t mutex_notify;
0050 extern pthread_cond_t cond_wakeup;
0051 
0052 /* for controller of read/write threads */
0053 extern int rw_ctl_init(const char *ctl_path);
0054 extern void *rw_ctl_loop(int ctl_fd);
0055 
0056 /* for trace read/write thread */
0057 extern void *rw_thread_info_new(void);
0058 extern void *rw_thread_init(int cpu, const char *in_path, const char *out_path,
0059             bool stdout_flag, unsigned long pipe_size,
0060             struct rw_thread_info *rw_ti);
0061 extern pthread_t rw_thread_run(struct rw_thread_info *rw_ti);
0062 
0063 static inline void *zalloc(size_t size)
0064 {
0065     return calloc(1, size);
0066 }
0067 
0068 #define pr_err(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
0069 #define pr_info(format, ...) fprintf(stdout, format, ## __VA_ARGS__)
0070 #ifdef DEBUG
0071 #define pr_debug(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
0072 #else
0073 #define pr_debug(format, ...) do {} while (0)
0074 #endif
0075 
0076 #endif /*__TRACE_AGENT_H__*/