1 /******************************************************************************
2  * xenoprof.h
3  *
4  * Xenoprof: Xenoprof enables performance profiling in Xen
5  *
6  * Copyright (C) 2005 Hewlett-Packard Co.
7  * written by Aravind Menon & Jose Renato Santos
8  */
9 
10 #ifndef __XEN_XENOPROF_H__
11 #define __XEN_XENOPROF_H__
12 
13 #include <xen/inttypes.h>
14 #include <public/xenoprof.h>
15 #include <asm/xenoprof.h>
16 
17 #define PMU_OWNER_NONE          0
18 #define PMU_OWNER_XENOPROF      1
19 #define PMU_OWNER_HVM           2
20 
21 #ifdef CONFIG_XENOPROF
22 
23 #define XENOPROF_DOMAIN_IGNORED    0
24 #define XENOPROF_DOMAIN_ACTIVE     1
25 #define XENOPROF_DOMAIN_PASSIVE    2
26 
27 #define XENOPROF_IDLE              0
28 #define XENOPROF_INITIALIZED       1
29 #define XENOPROF_COUNTERS_RESERVED 2
30 #define XENOPROF_READY             3
31 #define XENOPROF_PROFILING         4
32 
33 #ifndef CONFIG_COMPAT
34 typedef struct xenoprof_buf xenoprof_buf_t;
35 #else
36 #include <compat/xenoprof.h>
37 typedef union {
38 	struct xenoprof_buf native;
39 	struct compat_oprof_buf compat;
40 } xenoprof_buf_t;
41 #endif
42 
43 struct xenoprof_vcpu {
44     int event_size;
45     xenoprof_buf_t *buffer;
46 };
47 
48 struct xenoprof {
49     char *rawbuf;
50     int npages;
51     int nbuf;
52     int bufsize;
53     int domain_type;
54     int domain_ready;
55     int is_primary;
56 #ifdef CONFIG_COMPAT
57     int is_compat;
58 #endif
59     struct xenoprof_vcpu *vcpu;
60 };
61 
62 #ifndef CONFIG_COMPAT
63 #define XENOPROF_COMPAT(x) 0
64 #define xenoprof_buf(d, b, field) ((b)->field)
65 #else
66 #define XENOPROF_COMPAT(x) ((x)->is_compat)
67 #define xenoprof_buf(d, b, field) (*(!(d)->xenoprof->is_compat ? \
68                                        &(b)->native.field : \
69                                        &(b)->compat.field))
70 #endif
71 
72 struct domain;
73 
74 int acquire_pmu_ownership(int pmu_ownership);
75 void release_pmu_ownership(int pmu_ownership);
76 
77 int is_active(struct domain *d);
78 int is_passive(struct domain *d);
79 void free_xenoprof_pages(struct domain *d);
80 
81 int xenoprof_add_trace(struct vcpu *, uint64_t pc, int mode);
82 
83 void xenoprof_log_event(struct vcpu *, const struct cpu_user_regs *,
84                         uint64_t pc, int mode, int event);
85 
86 #else
acquire_pmu_ownership(int pmu_ownership)87 static inline int acquire_pmu_ownership(int pmu_ownership)
88 {
89     return 1;
90 }
91 
release_pmu_ownership(int pmu_ownership)92 static inline void release_pmu_ownership(int pmu_ownership)
93 {
94 }
95 #endif /* CONFIG_XENOPROF */
96 
97 #endif  /* __XEN__XENOPROF_H__ */
98