18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __TRACE_AGENT_H__ 38c2ecf20Sopenharmony_ci#define __TRACE_AGENT_H__ 48c2ecf20Sopenharmony_ci#include <pthread.h> 58c2ecf20Sopenharmony_ci#include <stdbool.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define MAX_CPUS 256 88c2ecf20Sopenharmony_ci#define PIPE_INIT (1024*1024) 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/* 118c2ecf20Sopenharmony_ci * agent_info - structure managing total information of guest agent 128c2ecf20Sopenharmony_ci * @pipe_size: size of pipe (default 1MB) 138c2ecf20Sopenharmony_ci * @use_stdout: set to true when o option is added (default false) 148c2ecf20Sopenharmony_ci * @cpus: total number of CPUs 158c2ecf20Sopenharmony_ci * @ctl_fd: fd of control path, /dev/virtio-ports/agent-ctl-path 168c2ecf20Sopenharmony_ci * @rw_ti: structure managing information of read/write threads 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_cistruct agent_info { 198c2ecf20Sopenharmony_ci unsigned long pipe_size; 208c2ecf20Sopenharmony_ci bool use_stdout; 218c2ecf20Sopenharmony_ci int cpus; 228c2ecf20Sopenharmony_ci int ctl_fd; 238c2ecf20Sopenharmony_ci struct rw_thread_info *rw_ti[MAX_CPUS]; 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* 278c2ecf20Sopenharmony_ci * rw_thread_info - structure managing a read/write thread a cpu 288c2ecf20Sopenharmony_ci * @cpu_num: cpu number operating this read/write thread 298c2ecf20Sopenharmony_ci * @in_fd: fd of reading trace data path in cpu_num 308c2ecf20Sopenharmony_ci * @out_fd: fd of writing trace data path in cpu_num 318c2ecf20Sopenharmony_ci * @read_pipe: fd of read pipe 328c2ecf20Sopenharmony_ci * @write_pipe: fd of write pipe 338c2ecf20Sopenharmony_ci * @pipe_size: size of pipe (default 1MB) 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_cistruct rw_thread_info { 368c2ecf20Sopenharmony_ci int cpu_num; 378c2ecf20Sopenharmony_ci int in_fd; 388c2ecf20Sopenharmony_ci int out_fd; 398c2ecf20Sopenharmony_ci int read_pipe; 408c2ecf20Sopenharmony_ci int write_pipe; 418c2ecf20Sopenharmony_ci unsigned long pipe_size; 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* use for stopping rw threads */ 458c2ecf20Sopenharmony_ciextern bool global_sig_receive; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* use for notification */ 488c2ecf20Sopenharmony_ciextern bool global_run_operation; 498c2ecf20Sopenharmony_ciextern pthread_mutex_t mutex_notify; 508c2ecf20Sopenharmony_ciextern pthread_cond_t cond_wakeup; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* for controller of read/write threads */ 538c2ecf20Sopenharmony_ciextern int rw_ctl_init(const char *ctl_path); 548c2ecf20Sopenharmony_ciextern void *rw_ctl_loop(int ctl_fd); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* for trace read/write thread */ 578c2ecf20Sopenharmony_ciextern void *rw_thread_info_new(void); 588c2ecf20Sopenharmony_ciextern void *rw_thread_init(int cpu, const char *in_path, const char *out_path, 598c2ecf20Sopenharmony_ci bool stdout_flag, unsigned long pipe_size, 608c2ecf20Sopenharmony_ci struct rw_thread_info *rw_ti); 618c2ecf20Sopenharmony_ciextern pthread_t rw_thread_run(struct rw_thread_info *rw_ti); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic inline void *zalloc(size_t size) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci return calloc(1, size); 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#define pr_err(format, ...) fprintf(stderr, format, ## __VA_ARGS__) 698c2ecf20Sopenharmony_ci#define pr_info(format, ...) fprintf(stdout, format, ## __VA_ARGS__) 708c2ecf20Sopenharmony_ci#ifdef DEBUG 718c2ecf20Sopenharmony_ci#define pr_debug(format, ...) fprintf(stderr, format, ## __VA_ARGS__) 728c2ecf20Sopenharmony_ci#else 738c2ecf20Sopenharmony_ci#define pr_debug(format, ...) do {} while (0) 748c2ecf20Sopenharmony_ci#endif 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#endif /*__TRACE_AGENT_H__*/ 77