pmu.h revision 302408
1/*
2 * Permission is hereby granted, free of charge, to any person obtaining a copy
3 * of this software and associated documentation files (the "Software"), to
4 * deal in the Software without restriction, including without limitation the
5 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6 * sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 * DEALINGS IN THE SOFTWARE.
19 *
20 * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
21 */
22
23#ifndef __XEN_PUBLIC_PMU_H__
24#define __XEN_PUBLIC_PMU_H__
25
26#include "xen.h"
27#if defined(__i386__) || defined(__x86_64__)
28#include "arch-x86/pmu.h"
29#elif defined (__arm__) || defined (__aarch64__)
30#include "arch-arm.h"
31#else
32#error "Unsupported architecture"
33#endif
34
35#define XENPMU_VER_MAJ    0
36#define XENPMU_VER_MIN    1
37
38/*
39 * ` enum neg_errnoval
40 * ` HYPERVISOR_xenpmu_op(enum xenpmu_op cmd, struct xenpmu_params *args);
41 *
42 * @cmd  == XENPMU_* (PMU operation)
43 * @args == struct xenpmu_params
44 */
45/* ` enum xenpmu_op { */
46#define XENPMU_mode_get        0 /* Also used for getting PMU version */
47#define XENPMU_mode_set        1
48#define XENPMU_feature_get     2
49#define XENPMU_feature_set     3
50#define XENPMU_init            4
51#define XENPMU_finish          5
52#define XENPMU_lvtpc_set       6
53#define XENPMU_flush           7 /* Write cached MSR values to HW     */
54/* ` } */
55
56/* Parameters structure for HYPERVISOR_xenpmu_op call */
57struct xen_pmu_params {
58    /* IN/OUT parameters */
59    struct {
60        uint32_t maj;
61        uint32_t min;
62    } version;
63    uint64_t val;
64
65    /* IN parameters */
66    uint32_t vcpu;
67    uint32_t pad;
68};
69typedef struct xen_pmu_params xen_pmu_params_t;
70DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);
71
72/* PMU modes:
73 * - XENPMU_MODE_OFF:   No PMU virtualization
74 * - XENPMU_MODE_SELF:  Guests can profile themselves
75 * - XENPMU_MODE_HV:    Guests can profile themselves, dom0 profiles
76 *                      itself and Xen
77 * - XENPMU_MODE_ALL:   Only dom0 has access to VPMU and it profiles
78 *                      everyone: itself, the hypervisor and the guests.
79 */
80#define XENPMU_MODE_OFF           0
81#define XENPMU_MODE_SELF          (1<<0)
82#define XENPMU_MODE_HV            (1<<1)
83#define XENPMU_MODE_ALL           (1<<2)
84
85/*
86 * PMU features:
87 * - XENPMU_FEATURE_INTEL_BTS: Intel BTS support (ignored on AMD)
88 */
89#define XENPMU_FEATURE_INTEL_BTS  1
90
91/*
92 * Shared PMU data between hypervisor and PV(H) domains.
93 *
94 * The hypervisor fills out this structure during PMU interrupt and sends an
95 * interrupt to appropriate VCPU.
96 * Architecture-independent fields of xen_pmu_data are WO for the hypervisor
97 * and RO for the guest but some fields in xen_pmu_arch can be writable
98 * by both the hypervisor and the guest (see arch-$arch/pmu.h).
99 */
100struct xen_pmu_data {
101    /* Interrupted VCPU */
102    uint32_t vcpu_id;
103
104    /*
105     * Physical processor on which the interrupt occurred. On non-privileged
106     * guests set to vcpu_id;
107     */
108    uint32_t pcpu_id;
109
110    /*
111     * Domain that was interrupted. On non-privileged guests set to DOMID_SELF.
112     * On privileged guests can be DOMID_SELF, DOMID_XEN, or, when in
113     * XENPMU_MODE_ALL mode, domain ID of another domain.
114     */
115    domid_t  domain_id;
116
117    uint8_t pad[6];
118
119    /* Architecture-specific information */
120    struct xen_pmu_arch pmu;
121};
122
123#endif /* __XEN_PUBLIC_PMU_H__ */
124
125/*
126 * Local variables:
127 * mode: C
128 * c-file-style: "BSD"
129 * c-basic-offset: 4
130 * tab-width: 4
131 * indent-tabs-mode: nil
132 * End:
133 */
134