cpu_conf.h 4.6 KB
Newer Older
1 2 3
/*
 * cpu_conf.h: CPU XML handling
 *
4
 * Copyright (C) 2009-2011, 2013, 2014 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20 21 22 23 24
 *
 * Authors:
 *      Jiri Denemark <jdenemar@redhat.com>
 */

#ifndef __VIR_CPU_CONF_H__
25
# define __VIR_CPU_CONF_H__
26

27
# include "virutil.h"
28
# include "virbuffer.h"
29
# include "virxml.h"
30
# include "virbitmap.h"
31
# include "virarch.h"
32
# include "numa_conf.h"
33

34 35
# define VIR_CPU_VENDOR_ID_LENGTH 12

36
typedef enum {
37 38
    VIR_CPU_TYPE_HOST,
    VIR_CPU_TYPE_GUEST,
39 40 41
    VIR_CPU_TYPE_AUTO,

    VIR_CPU_TYPE_LAST
42
} virCPUType;
43

44 45
VIR_ENUM_DECL(virCPU)

46
typedef enum {
47 48 49 50 51
    VIR_CPU_MODE_CUSTOM,
    VIR_CPU_MODE_HOST_MODEL,
    VIR_CPU_MODE_HOST_PASSTHROUGH,

    VIR_CPU_MODE_LAST
52
} virCPUMode;
53 54 55

VIR_ENUM_DECL(virCPUMode)

56
typedef enum {
57 58 59 60 61
    VIR_CPU_MATCH_MINIMUM,
    VIR_CPU_MATCH_EXACT,
    VIR_CPU_MATCH_STRICT,

    VIR_CPU_MATCH_LAST
62
} virCPUMatch;
63 64 65

VIR_ENUM_DECL(virCPUMatch)

66 67 68 69 70 71 72 73 74 75 76
typedef enum {
    VIR_CPU_CHECK_DEFAULT,
    VIR_CPU_CHECK_NONE,
    VIR_CPU_CHECK_PARTIAL,
    VIR_CPU_CHECK_FULL,

    VIR_CPU_CHECK_LAST
} virCPUCheck;

VIR_ENUM_DECL(virCPUCheck)

77
typedef enum {
78 79 80 81
    VIR_CPU_FALLBACK_ALLOW,
    VIR_CPU_FALLBACK_FORBID,

    VIR_CPU_FALLBACK_LAST
82
} virCPUFallback;
83 84 85

VIR_ENUM_DECL(virCPUFallback)

86
typedef enum {
87 88 89 90 91 92 93
    VIR_CPU_FEATURE_FORCE,
    VIR_CPU_FEATURE_REQUIRE,
    VIR_CPU_FEATURE_OPTIONAL,
    VIR_CPU_FEATURE_DISABLE,
    VIR_CPU_FEATURE_FORBID,

    VIR_CPU_FEATURE_LAST
94
} virCPUFeaturePolicy;
95 96 97 98 99 100 101 102 103 104

VIR_ENUM_DECL(virCPUFeaturePolicy)

typedef struct _virCPUFeatureDef virCPUFeatureDef;
typedef virCPUFeatureDef *virCPUFeatureDefPtr;
struct _virCPUFeatureDef {
    char *name;
    int policy;         /* enum virCPUFeaturePolicy */
};

105

106 107 108 109
typedef struct _virCPUDef virCPUDef;
typedef virCPUDef *virCPUDefPtr;
struct _virCPUDef {
    int type;           /* enum virCPUType */
110
    int mode;           /* enum virCPUMode */
111
    int match;          /* enum virCPUMatch */
112
    virCPUCheck check;
113
    virArch arch;
114
    char *model;
115
    char *vendor_id;    /* vendor id returned by CPUID in the guest */
116
    int fallback;       /* enum virCPUFallback */
J
Jiri Denemark 已提交
117
    char *vendor;
118 119 120
    unsigned int sockets;
    unsigned int cores;
    unsigned int threads;
E
Eric Blake 已提交
121 122
    size_t nfeatures;
    size_t nfeatures_max;
123 124 125 126
    virCPUFeatureDefPtr features;
};


127 128 129
void ATTRIBUTE_NONNULL(1)
virCPUDefFreeModel(virCPUDefPtr def);

130 131 132
void
virCPUDefFree(virCPUDefPtr def);

133 134
int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
virCPUDefCopyModel(virCPUDefPtr dst,
135
                   const virCPUDef *src,
136 137
                   bool resetPolicy);

138 139 140 141 142 143 144 145 146 147 148 149 150 151
/*
 * Returns true if feature @name should copied, false otherwise.
 */
typedef bool (*virCPUDefFeatureFilter)(const char *name,
                                       void *opaque);

int
virCPUDefCopyModelFilter(virCPUDefPtr dst,
                         const virCPUDef *src,
                         bool resetPolicy,
                         virCPUDefFeatureFilter filter,
                         void *opaque)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

152 153
void
virCPUDefStealModel(virCPUDefPtr dst,
154 155
                    virCPUDefPtr src,
                    bool keepVendor);
156

157
virCPUDefPtr
158
virCPUDefCopy(const virCPUDef *cpu);
159

160 161 162
virCPUDefPtr
virCPUDefCopyWithoutModel(const virCPUDef *cpu);

163
virCPUDefPtr
164
virCPUDefParseXML(xmlNodePtr node,
165
                  xmlXPathContextPtr ctxt,
166
                  virCPUType mode);
167

168 169 170
bool
virCPUDefIsEqual(virCPUDefPtr src,
                 virCPUDefPtr dst);
171 172

char *
173
virCPUDefFormat(virCPUDefPtr def,
174
                virDomainNumaPtr numa,
175
                bool updateCPU);
176 177

int
178
virCPUDefFormatBuf(virBufferPtr buf,
179
                   virCPUDefPtr def,
180
                   bool updateCPU);
181 182
int
virCPUDefFormatBufFull(virBufferPtr buf,
183
                       virCPUDefPtr def,
184
                       virDomainNumaPtr numa,
185
                       bool updateCPU);
186 187

int
188
virCPUDefAddFeature(virCPUDefPtr cpu,
189 190 191
                    const char *name,
                    int policy);

P
Peter Krempa 已提交
192 193 194 195 196
int
virCPUDefUpdateFeature(virCPUDefPtr cpu,
                       const char *name,
                       int policy);

197
#endif /* __VIR_CPU_CONF_H__ */