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