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 142 143
void
virCPUDefStealModel(virCPUDefPtr dst,
                    virCPUDefPtr src);

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

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

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

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

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

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

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

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

184
#endif /* __VIR_CPU_CONF_H__ */