trace-agent.h 2.1 KB

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