cpu_conf.h 4.4 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
typedef enum {
67 68 69 70
    VIR_CPU_FALLBACK_ALLOW,
    VIR_CPU_FALLBACK_FORBID,

    VIR_CPU_FALLBACK_LAST
71
} virCPUFallback;
72 73 74

VIR_ENUM_DECL(virCPUFallback)

75
typedef enum {
76 77 78 79 80 81 82
    VIR_CPU_FEATURE_FORCE,
    VIR_CPU_FEATURE_REQUIRE,
    VIR_CPU_FEATURE_OPTIONAL,
    VIR_CPU_FEATURE_DISABLE,
    VIR_CPU_FEATURE_FORBID,

    VIR_CPU_FEATURE_LAST
83
} virCPUFeaturePolicy;
84 85 86 87 88 89 90 91 92 93

VIR_ENUM_DECL(virCPUFeaturePolicy)

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

94

95 96 97 98
typedef struct _virCPUDef virCPUDef;
typedef virCPUDef *virCPUDefPtr;
struct _virCPUDef {
    int type;           /* enum virCPUType */
99
    int mode;           /* enum virCPUMode */
100
    int match;          /* enum virCPUMatch */
101
    virArch arch;
102
    char *model;
103
    char *vendor_id;    /* vendor id returned by CPUID in the guest */
104
    int fallback;       /* enum virCPUFallback */
J
Jiri Denemark 已提交
105
    char *vendor;
106 107 108
    unsigned int sockets;
    unsigned int cores;
    unsigned int threads;
E
Eric Blake 已提交
109 110
    size_t nfeatures;
    size_t nfeatures_max;
111 112 113 114
    virCPUFeatureDefPtr features;
};


115 116 117
void ATTRIBUTE_NONNULL(1)
virCPUDefFreeModel(virCPUDefPtr def);

118 119 120
void
virCPUDefFree(virCPUDefPtr def);

121 122
int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
virCPUDefCopyModel(virCPUDefPtr dst,
123
                   const virCPUDef *src,
124 125
                   bool resetPolicy);

126 127 128 129 130 131 132 133 134 135 136 137 138 139
/*
 * 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);

140 141
void
virCPUDefStealModel(virCPUDefPtr dst,
142 143
                    virCPUDefPtr src,
                    bool keepVendor);
144

145
virCPUDefPtr
146
virCPUDefCopy(const virCPUDef *cpu);
147

148 149 150
virCPUDefPtr
virCPUDefCopyWithoutModel(const virCPUDef *cpu);

151
virCPUDefPtr
152
virCPUDefParseXML(xmlNodePtr node,
153
                  xmlXPathContextPtr ctxt,
154
                  virCPUType mode);
155

156 157 158
bool
virCPUDefIsEqual(virCPUDefPtr src,
                 virCPUDefPtr dst);
159 160

char *
161
virCPUDefFormat(virCPUDefPtr def,
162
                virDomainNumaPtr numa,
163
                bool updateCPU);
164 165

int
166
virCPUDefFormatBuf(virBufferPtr buf,
167
                   virCPUDefPtr def,
168
                   bool updateCPU);
169 170
int
virCPUDefFormatBufFull(virBufferPtr buf,
171
                       virCPUDefPtr def,
172
                       virDomainNumaPtr numa,
173
                       bool updateCPU);
174 175

int
176
virCPUDefAddFeature(virCPUDefPtr cpu,
177 178 179
                    const char *name,
                    int policy);

P
Peter Krempa 已提交
180 181 182 183 184
int
virCPUDefUpdateFeature(virCPUDefPtr cpu,
                       const char *name,
                       int policy);

185
#endif /* __VIR_CPU_CONF_H__ */