root/tools/virtio/virtio-trace/trace-agent.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. zalloc

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

/* [<][>][^][v][top][bottom][index][help] */