diff options
author | Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com> | 2012-08-09 08:31:30 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-09-28 01:35:13 -0400 |
commit | 108fc82596e3b66b819df9d28c1ebbc9ab5de14c (patch) | |
tree | 66c051fac35849764818a47aa278d073af72b182 /tools/virtio/virtio-trace/trace-agent.h | |
parent | 8ca84a50e5b39487ea1de8809d0ee1c8474f6a5c (diff) |
tools: Add guest trace agent as a user tool
This patch adds a user tool, "trace agent" for sending trace data of a guest to
a Host in low overhead. This agent has the following functions:
- splice a page of ring-buffer to read_pipe without memory copying
- splice the page from write_pipe to virtio-console without memory copying
- write trace data to stdout by using -o option
- controlled by start/stop orders from a Host
Changes in v2:
- Cleanup (change fprintf() to pr_err() and an include guard)
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Acked-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'tools/virtio/virtio-trace/trace-agent.h')
-rw-r--r-- | tools/virtio/virtio-trace/trace-agent.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tools/virtio/virtio-trace/trace-agent.h b/tools/virtio/virtio-trace/trace-agent.h new file mode 100644 index 000000000000..8de79bfeaa73 --- /dev/null +++ b/tools/virtio/virtio-trace/trace-agent.h | |||
@@ -0,0 +1,75 @@ | |||
1 | #ifndef __TRACE_AGENT_H__ | ||
2 | #define __TRACE_AGENT_H__ | ||
3 | #include <pthread.h> | ||
4 | #include <stdbool.h> | ||
5 | |||
6 | #define MAX_CPUS 256 | ||
7 | #define PIPE_INIT (1024*1024) | ||
8 | |||
9 | /* | ||
10 | * agent_info - structure managing total information of guest agent | ||
11 | * @pipe_size: size of pipe (default 1MB) | ||
12 | * @use_stdout: set to true when o option is added (default false) | ||
13 | * @cpus: total number of CPUs | ||
14 | * @ctl_fd: fd of control path, /dev/virtio-ports/agent-ctl-path | ||
15 | * @rw_ti: structure managing information of read/write threads | ||
16 | */ | ||
17 | struct agent_info { | ||
18 | unsigned long pipe_size; | ||
19 | bool use_stdout; | ||
20 | int cpus; | ||
21 | int ctl_fd; | ||
22 | struct rw_thread_info *rw_ti[MAX_CPUS]; | ||
23 | }; | ||
24 | |||
25 | /* | ||
26 | * rw_thread_info - structure managing a read/write thread a cpu | ||
27 | * @cpu_num: cpu number operating this read/write thread | ||
28 | * @in_fd: fd of reading trace data path in cpu_num | ||
29 | * @out_fd: fd of writing trace data path in cpu_num | ||
30 | * @read_pipe: fd of read pipe | ||
31 | * @write_pipe: fd of write pipe | ||
32 | * @pipe_size: size of pipe (default 1MB) | ||
33 | */ | ||
34 | struct rw_thread_info { | ||
35 | int cpu_num; | ||
36 | int in_fd; | ||
37 | int out_fd; | ||
38 | int read_pipe; | ||
39 | int write_pipe; | ||
40 | unsigned long pipe_size; | ||
41 | }; | ||
42 | |||
43 | /* use for stopping rw threads */ | ||
44 | extern bool global_sig_receive; | ||
45 | |||
46 | /* use for notification */ | ||
47 | extern bool global_run_operation; | ||
48 | extern pthread_mutex_t mutex_notify; | ||
49 | extern pthread_cond_t cond_wakeup; | ||
50 | |||
51 | /* for controller of read/write threads */ | ||
52 | extern int rw_ctl_init(const char *ctl_path); | ||
53 | extern void *rw_ctl_loop(int ctl_fd); | ||
54 | |||
55 | /* for trace read/write thread */ | ||
56 | extern void *rw_thread_info_new(void); | ||
57 | extern void *rw_thread_init(int cpu, const char *in_path, const char *out_path, | ||
58 | bool stdout_flag, unsigned long pipe_size, | ||
59 | struct rw_thread_info *rw_ti); | ||
60 | extern pthread_t rw_thread_run(struct rw_thread_info *rw_ti); | ||
61 | |||
62 | static inline void *zalloc(size_t size) | ||
63 | { | ||
64 | return calloc(1, size); | ||
65 | } | ||
66 | |||
67 | #define pr_err(format, ...) fprintf(stderr, format, ## __VA_ARGS__) | ||
68 | #define pr_info(format, ...) fprintf(stdout, format, ## __VA_ARGS__) | ||
69 | #ifdef DEBUG | ||
70 | #define pr_debug(format, ...) fprintf(stderr, format, ## __VA_ARGS__) | ||
71 | #else | ||
72 | #define pr_debug(format, ...) do {} while (0) | ||
73 | #endif | ||
74 | |||
75 | #endif /*__TRACE_AGENT_H__*/ | ||