trace-agent.h 2.1 KB

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