cpu_conf.h 5.2 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123
typedef enum {
    VIR_CPU_CACHE_MODE_EMULATE,
    VIR_CPU_CACHE_MODE_PASSTHROUGH,
    VIR_CPU_CACHE_MODE_DISABLE,

    VIR_CPU_CACHE_MODE_LAST
} virCPUCacheMode;

VIR_ENUM_DECL(virCPUCacheMode);

typedef struct _virCPUCacheDef virCPUCacheDef;
typedef virCPUCacheDef *virCPUCacheDefPtr;
struct _virCPUCacheDef {
    int level;          /* -1 for unspecified */
    virCPUCacheMode mode;
};


124 125 126 127
typedef struct _virCPUDef virCPUDef;
typedef virCPUDef *virCPUDefPtr;
struct _virCPUDef {
    int type;           /* enum virCPUType */
128
    int mode;           /* enum virCPUMode */
129
    int match;          /* enum virCPUMatch */
130
    virCPUCheck check;
131
    virArch arch;
132
    char *model;
133
    char *vendor_id;    /* vendor id returned by CPUID in the guest */
134
    int fallback;       /* enum virCPUFallback */
J
Jiri Denemark 已提交
135
    char *vendor;
136 137 138
    unsigned int sockets;
    unsigned int cores;
    unsigned int threads;
E
Eric Blake 已提交
139 140
    size_t nfeatures;
    size_t nfeatures_max;
141
    virCPUFeatureDefPtr features;
142
    virCPUCacheDefPtr cache;
143 144 145
};


146 147 148
void ATTRIBUTE_NONNULL(1)
virCPUDefFreeFeatures(virCPUDefPtr def);

149 150 151
void ATTRIBUTE_NONNULL(1)
virCPUDefFreeModel(virCPUDefPtr def);

152 153 154
void
virCPUDefFree(virCPUDefPtr def);

155 156
int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
virCPUDefCopyModel(virCPUDefPtr dst,
157
                   const virCPUDef *src,
158 159
                   bool resetPolicy);

160 161 162 163 164 165 166 167 168 169 170 171 172 173
/*
 * 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);

174 175
void
virCPUDefStealModel(virCPUDefPtr dst,
176 177
                    virCPUDefPtr src,
                    bool keepVendor);
178

179
virCPUDefPtr
180
virCPUDefCopy(const virCPUDef *cpu);
181

182 183 184
virCPUDefPtr
virCPUDefCopyWithoutModel(const virCPUDef *cpu);

J
Jiri Denemark 已提交
185 186 187 188 189
int
virCPUDefParseXML(xmlXPathContextPtr ctxt,
                  const char *xpath,
                  virCPUType mode,
                  virCPUDefPtr *cpu);
190

191 192
bool
virCPUDefIsEqual(virCPUDefPtr src,
193 194
                 virCPUDefPtr dst,
                 bool reportError);
195 196

char *
197
virCPUDefFormat(virCPUDefPtr def,
198
                virDomainNumaPtr numa);
199 200

int
201
virCPUDefFormatBuf(virBufferPtr buf,
202
                   virCPUDefPtr def);
203 204
int
virCPUDefFormatBufFull(virBufferPtr buf,
205
                       virCPUDefPtr def,
206
                       virDomainNumaPtr numa);
207 208

int
209
virCPUDefAddFeature(virCPUDefPtr cpu,
210 211 212
                    const char *name,
                    int policy);

P
Peter Krempa 已提交
213 214 215 216 217
int
virCPUDefUpdateFeature(virCPUDefPtr cpu,
                       const char *name,
                       int policy);

218 219 220 221 222 223 224
virCPUDefPtr *
virCPUDefListParse(const char **xmlCPUs,
                   unsigned int ncpus,
                   virCPUType cpuType);
void
virCPUDefListFree(virCPUDefPtr *cpus);

225
#endif /* __VIR_CPU_CONF_H__ */