1 /* SPDX-License-Identifier: MIT */
2 /******************************************************************************
3  * xenoprof.h
4  *
5  * Interface for enabling system wide profiling based on hardware performance
6  * counters
7  *
8  * Copyright (C) 2005 Hewlett-Packard Co.
9  * Written by Aravind Menon & Jose Renato Santos
10  */
11 
12 #ifndef __XEN_PUBLIC_XENOPROF_H__
13 #define __XEN_PUBLIC_XENOPROF_H__
14 
15 #include "xen.h"
16 
17 /*
18  * Commands to HYPERVISOR_xenoprof_op().
19  */
20 #define XENOPROF_init                0
21 #define XENOPROF_reset_active_list   1
22 #define XENOPROF_reset_passive_list  2
23 #define XENOPROF_set_active          3
24 #define XENOPROF_set_passive         4
25 #define XENOPROF_reserve_counters    5
26 #define XENOPROF_counter             6
27 #define XENOPROF_setup_events        7
28 #define XENOPROF_enable_virq         8
29 #define XENOPROF_start               9
30 #define XENOPROF_stop               10
31 #define XENOPROF_disable_virq       11
32 #define XENOPROF_release_counters   12
33 #define XENOPROF_shutdown           13
34 #define XENOPROF_get_buffer         14
35 #define XENOPROF_set_backtrace      15
36 
37 /* AMD IBS support */
38 #define XENOPROF_get_ibs_caps       16
39 #define XENOPROF_ibs_counter        17
40 #define XENOPROF_last_op            17
41 
42 #define MAX_OPROF_EVENTS    32
43 #define MAX_OPROF_DOMAINS   25
44 #define XENOPROF_CPU_TYPE_SIZE 64
45 
46 /* Xenoprof performance events (not Xen events) */
47 struct event_log {
48     uint64_t eip;
49     uint8_t mode;
50     uint8_t event;
51 };
52 
53 /* PC value that indicates a special code */
54 #define XENOPROF_ESCAPE_CODE (~xen_mk_ullong(0))
55 /* Transient events for the xenoprof->oprofile cpu buf */
56 #define XENOPROF_TRACE_BEGIN 1
57 
58 /* Xenoprof buffer shared between Xen and domain - 1 per VCPU */
59 struct xenoprof_buf {
60     uint32_t event_head;
61     uint32_t event_tail;
62     uint32_t event_size;
63     uint32_t vcpu_id;
64     uint64_t xen_samples;
65     uint64_t kernel_samples;
66     uint64_t user_samples;
67     uint64_t lost_samples;
68     struct event_log event_log[1];
69 };
70 #ifndef __XEN__
71 typedef struct xenoprof_buf xenoprof_buf_t;
72 DEFINE_XEN_GUEST_HANDLE(xenoprof_buf_t);
73 #endif
74 
75 struct xenoprof_init {
76     int32_t  num_events;
77     int32_t  is_primary;
78     char cpu_type[XENOPROF_CPU_TYPE_SIZE];
79 };
80 typedef struct xenoprof_init xenoprof_init_t;
81 DEFINE_XEN_GUEST_HANDLE(xenoprof_init_t);
82 
83 struct xenoprof_get_buffer {
84     int32_t  max_samples;
85     int32_t  nbuf;
86     int32_t  bufsize;
87     uint64_t buf_gmaddr;
88 };
89 typedef struct xenoprof_get_buffer xenoprof_get_buffer_t;
90 DEFINE_XEN_GUEST_HANDLE(xenoprof_get_buffer_t);
91 
92 struct xenoprof_counter {
93     uint32_t ind;
94     uint64_t count;
95     uint32_t enabled;
96     uint32_t event;
97     uint32_t hypervisor;
98     uint32_t kernel;
99     uint32_t user;
100     uint64_t unit_mask;
101 };
102 typedef struct xenoprof_counter xenoprof_counter_t;
103 DEFINE_XEN_GUEST_HANDLE(xenoprof_counter_t);
104 
105 typedef struct xenoprof_passive {
106     uint16_t domain_id;
107     int32_t  max_samples;
108     int32_t  nbuf;
109     int32_t  bufsize;
110     uint64_t buf_gmaddr;
111 } xenoprof_passive_t;
112 DEFINE_XEN_GUEST_HANDLE(xenoprof_passive_t);
113 
114 struct xenoprof_ibs_counter {
115     uint64_t op_enabled;
116     uint64_t fetch_enabled;
117     uint64_t max_cnt_fetch;
118     uint64_t max_cnt_op;
119     uint64_t rand_en;
120     uint64_t dispatched_ops;
121 };
122 typedef struct xenoprof_ibs_counter xenoprof_ibs_counter_t;
123 DEFINE_XEN_GUEST_HANDLE(xenoprof_ibs_counter_t);
124 
125 #endif /* __XEN_PUBLIC_XENOPROF_H__ */
126 
127 /*
128  * Local variables:
129  * mode: C
130  * c-file-style: "BSD"
131  * c-basic-offset: 4
132  * tab-width: 4
133  * indent-tabs-mode: nil
134  * End:
135  */
136