2009-12-18 13:44:55 +00:00
|
|
|
/*
|
|
|
|
* cpu_conf.h: CPU XML handling
|
|
|
|
*
|
2014-05-22 07:13:05 +00:00
|
|
|
* Copyright (C) 2009-2011, 2013, 2014 Red Hat, Inc.
|
2009-12-18 13:44:55 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-12-18 13:44:55 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-07 20:20:21 +00:00
|
|
|
#pragma once
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-06-07 20:20:21 +00:00
|
|
|
#include "virbuffer.h"
|
|
|
|
#include "virxml.h"
|
|
|
|
#include "virarch.h"
|
|
|
|
#include "numa_conf.h"
|
|
|
|
#include "virenum.h"
|
|
|
|
#include "virhostcpu.h"
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-06-07 20:20:21 +00:00
|
|
|
#define VIR_CPU_VENDOR_ID_LENGTH 12
|
2012-06-28 10:21:17 +00:00
|
|
|
|
2014-04-28 00:15:21 +00:00
|
|
|
typedef enum {
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_CPU_TYPE_HOST,
|
|
|
|
VIR_CPU_TYPE_GUEST,
|
2011-05-27 09:47:30 +00:00
|
|
|
VIR_CPU_TYPE_AUTO,
|
|
|
|
|
|
|
|
VIR_CPU_TYPE_LAST
|
2014-04-28 00:15:21 +00:00
|
|
|
} virCPUType;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virCPU);
|
2011-05-27 09:47:30 +00:00
|
|
|
|
2014-04-28 00:15:21 +00:00
|
|
|
typedef enum {
|
2011-08-18 10:14:36 +00:00
|
|
|
VIR_CPU_MODE_CUSTOM,
|
|
|
|
VIR_CPU_MODE_HOST_MODEL,
|
|
|
|
VIR_CPU_MODE_HOST_PASSTHROUGH,
|
2021-02-05 15:51:09 +00:00
|
|
|
VIR_CPU_MODE_MAXIMUM,
|
2011-08-18 10:14:36 +00:00
|
|
|
|
|
|
|
VIR_CPU_MODE_LAST
|
2014-04-28 00:15:21 +00:00
|
|
|
} virCPUMode;
|
2011-08-18 10:14:36 +00:00
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virCPUMode);
|
2011-08-18 10:14:36 +00:00
|
|
|
|
2014-04-28 00:15:21 +00:00
|
|
|
typedef enum {
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_CPU_MATCH_EXACT,
|
2019-11-12 14:26:23 +00:00
|
|
|
VIR_CPU_MATCH_MINIMUM,
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_CPU_MATCH_STRICT,
|
|
|
|
|
|
|
|
VIR_CPU_MATCH_LAST
|
2014-04-28 00:15:21 +00:00
|
|
|
} virCPUMatch;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virCPUMatch);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2017-03-01 14:18:22 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_CPU_CHECK_DEFAULT,
|
|
|
|
VIR_CPU_CHECK_NONE,
|
|
|
|
VIR_CPU_CHECK_PARTIAL,
|
|
|
|
VIR_CPU_CHECK_FULL,
|
|
|
|
|
|
|
|
VIR_CPU_CHECK_LAST
|
|
|
|
} virCPUCheck;
|
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virCPUCheck);
|
2017-03-01 14:18:22 +00:00
|
|
|
|
2014-04-28 00:15:21 +00:00
|
|
|
typedef enum {
|
2011-12-21 13:27:16 +00:00
|
|
|
VIR_CPU_FALLBACK_ALLOW,
|
|
|
|
VIR_CPU_FALLBACK_FORBID,
|
|
|
|
|
|
|
|
VIR_CPU_FALLBACK_LAST
|
2014-04-28 00:15:21 +00:00
|
|
|
} virCPUFallback;
|
2011-12-21 13:27:16 +00:00
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virCPUFallback);
|
2011-12-21 13:27:16 +00:00
|
|
|
|
2014-04-28 00:15:21 +00:00
|
|
|
typedef enum {
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_CPU_FEATURE_FORCE,
|
|
|
|
VIR_CPU_FEATURE_REQUIRE,
|
|
|
|
VIR_CPU_FEATURE_OPTIONAL,
|
|
|
|
VIR_CPU_FEATURE_DISABLE,
|
|
|
|
VIR_CPU_FEATURE_FORBID,
|
|
|
|
|
|
|
|
VIR_CPU_FEATURE_LAST
|
2014-04-28 00:15:21 +00:00
|
|
|
} virCPUFeaturePolicy;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virCPUFeaturePolicy);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
typedef struct _virCPUFeatureDef virCPUFeatureDef;
|
|
|
|
struct _virCPUFeatureDef {
|
|
|
|
char *name;
|
|
|
|
int policy; /* enum virCPUFeaturePolicy */
|
|
|
|
};
|
|
|
|
|
2011-11-11 12:51:45 +00:00
|
|
|
|
2017-04-24 13:40:07 +00:00
|
|
|
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;
|
|
|
|
struct _virCPUCacheDef {
|
|
|
|
int level; /* -1 for unspecified */
|
|
|
|
virCPUCacheMode mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-07-29 19:34:33 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_CPU_MAX_PHYS_ADDR_MODE_EMULATE,
|
|
|
|
VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH,
|
|
|
|
|
|
|
|
VIR_CPU_MAX_PHYS_ADDR_MODE_LAST
|
|
|
|
} virCPUMaxPhysAddrMode;
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(virCPUMaxPhysAddrMode);
|
|
|
|
|
|
|
|
typedef struct _virCPUMaxPhysAddrDef virCPUMaxPhysAddrDef;
|
|
|
|
struct _virCPUMaxPhysAddrDef {
|
|
|
|
int bits; /* -1 for unspecified */
|
2023-03-01 10:27:30 +00:00
|
|
|
unsigned int limit; /* 0 for unspecified */
|
2022-07-29 19:34:33 +00:00
|
|
|
virCPUMaxPhysAddrMode mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
typedef struct _virCPUDef virCPUDef;
|
|
|
|
struct _virCPUDef {
|
2019-11-29 11:00:26 +00:00
|
|
|
int refs;
|
2009-12-18 13:44:55 +00:00
|
|
|
int type; /* enum virCPUType */
|
2011-08-18 10:14:36 +00:00
|
|
|
int mode; /* enum virCPUMode */
|
2022-01-20 20:57:35 +00:00
|
|
|
virCPUMatch match;
|
2017-03-01 14:18:22 +00:00
|
|
|
virCPUCheck check;
|
2012-12-11 12:58:54 +00:00
|
|
|
virArch arch;
|
2009-12-18 13:44:55 +00:00
|
|
|
char *model;
|
2012-06-28 10:21:17 +00:00
|
|
|
char *vendor_id; /* vendor id returned by CPUID in the guest */
|
2011-12-21 13:27:16 +00:00
|
|
|
int fallback; /* enum virCPUFallback */
|
2010-07-02 15:51:59 +00:00
|
|
|
char *vendor;
|
2017-12-12 15:23:40 +00:00
|
|
|
unsigned int microcodeVersion;
|
2009-12-18 13:44:55 +00:00
|
|
|
unsigned int sockets;
|
2019-12-16 11:16:51 +00:00
|
|
|
unsigned int dies;
|
2009-12-18 13:44:55 +00:00
|
|
|
unsigned int cores;
|
|
|
|
unsigned int threads;
|
2022-06-11 16:24:37 +00:00
|
|
|
unsigned int sigFamily;
|
|
|
|
unsigned int sigModel;
|
|
|
|
unsigned int sigStepping;
|
2010-08-17 21:41:51 +00:00
|
|
|
size_t nfeatures;
|
|
|
|
size_t nfeatures_max;
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUFeatureDef *features;
|
|
|
|
virCPUCacheDef *cache;
|
2022-07-29 19:34:33 +00:00
|
|
|
virCPUMaxPhysAddrDef *addr;
|
2021-03-11 07:16:13 +00:00
|
|
|
virHostCPUTscInfo *tsc;
|
2020-06-02 10:29:57 +00:00
|
|
|
virTristateSwitch migratable; /* for host-passthrough mode */
|
2009-12-18 13:44:55 +00:00
|
|
|
};
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef *virCPUDefNew(void);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2017-03-16 11:21:58 +00:00
|
|
|
void ATTRIBUTE_NONNULL(1)
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFreeFeatures(virCPUDef *def);
|
2017-03-16 11:21:58 +00:00
|
|
|
|
2011-12-19 14:41:16 +00:00
|
|
|
void ATTRIBUTE_NONNULL(1)
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFreeModel(virCPUDef *def);
|
2011-12-19 14:41:16 +00:00
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefRef(virCPUDef *def);
|
2009-12-18 13:44:55 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFree(virCPUDef *def);
|
2019-09-26 16:41:42 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUDef, virCPUDefFree);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2023-03-03 09:04:47 +00:00
|
|
|
void ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefCopyModel(virCPUDef *dst,
|
maint: avoid 'const fooPtr' in cpu files
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up offenders in src/cpu.
* src/cpu/cpu.h (cpuArchDecode, cpuArchEncode, cpuArchUpdate)
(cpuArchHasFeature, cpuDecode, cpuEncode, cpuUpdate)
(cpuHasFeature): Use intended type.
* src/conf/cpu_conf.h (virCPUDefCopyModel, virCPUDefCopy):
Likewise.
(virCPUDefParseXML): Drop const.
* src/cpu/cpu.c (cpuDecode, cpuEncode, cpuUpdate, cpuHasFeature):
Fix fallout.
* src/cpu/cpu_x86.c (x86ModelFromCPU, x86ModelSubtractCPU)
(x86DecodeCPUData, x86EncodePolicy, x86Encode, x86UpdateCustom)
(x86UpdateHostModel, x86Update, x86HasFeature): Likewise.
* src/cpu/cpu_s390.c (s390Decode): Likewise.
* src/cpu/cpu_arm.c (ArmDecode): Likewise.
* src/cpu/cpu_powerpc.c (ppcModelFromCPU, ppcCompute, ppcDecode)
(ppcUpdate): Likewise.
* src/conf/cpu_conf.c (virCPUDefCopyModel, virCPUDefCopy)
(virCPUDefParseXML): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 20:01:02 +00:00
|
|
|
const virCPUDef *src,
|
2011-12-19 14:41:16 +00:00
|
|
|
bool resetPolicy);
|
|
|
|
|
2016-06-28 08:44:20 +00:00
|
|
|
/*
|
|
|
|
* Returns true if feature @name should copied, false otherwise.
|
|
|
|
*/
|
|
|
|
typedef bool (*virCPUDefFeatureFilter)(const char *name,
|
2019-11-07 15:25:47 +00:00
|
|
|
virCPUFeaturePolicy policy,
|
2016-06-28 08:44:20 +00:00
|
|
|
void *opaque);
|
|
|
|
|
2023-03-03 09:04:47 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefCopyModelFilter(virCPUDef *dst,
|
2016-06-28 08:44:20 +00:00
|
|
|
const virCPUDef *src,
|
|
|
|
bool resetPolicy,
|
|
|
|
virCPUDefFeatureFilter filter,
|
|
|
|
void *opaque)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
2016-06-23 10:54:19 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefStealModel(virCPUDef *dst,
|
|
|
|
virCPUDef *src,
|
2016-11-10 09:26:03 +00:00
|
|
|
bool keepVendor);
|
2016-06-23 10:54:19 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef *
|
2023-03-03 09:33:09 +00:00
|
|
|
virCPUDefCopy(const virCPUDef *cpu)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
2010-03-23 08:34:04 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef *
|
2023-03-03 09:21:44 +00:00
|
|
|
virCPUDefCopyWithoutModel(const virCPUDef *cpu)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
2016-06-17 07:44:43 +00:00
|
|
|
|
2019-09-19 20:25:04 +00:00
|
|
|
int
|
|
|
|
virCPUDefParseXMLString(const char *xml,
|
|
|
|
virCPUType type,
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef **cpu,
|
2020-10-07 08:54:55 +00:00
|
|
|
bool validateXML);
|
2019-09-19 20:25:04 +00:00
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
int
|
|
|
|
virCPUDefParseXML(xmlXPathContextPtr ctxt,
|
|
|
|
const char *xpath,
|
|
|
|
virCPUType mode,
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef **cpu,
|
2020-10-07 08:54:55 +00:00
|
|
|
bool validateXML);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
bool
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefIsEqual(virCPUDef *src,
|
|
|
|
virCPUDef *dst,
|
2017-05-31 14:42:42 +00:00
|
|
|
bool reportError);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
char *
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFormat(virCPUDef *def,
|
|
|
|
virDomainNuma *numa);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFormatBuf(virBuffer *buf,
|
|
|
|
virCPUDef *def);
|
2011-09-21 23:42:07 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFormatBufFull(virBuffer *buf,
|
|
|
|
virCPUDef *def,
|
|
|
|
virDomainNuma *numa);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefAddFeature(virCPUDef *cpu,
|
2009-12-18 13:44:55 +00:00
|
|
|
const char *name,
|
|
|
|
int policy);
|
|
|
|
|
2013-07-15 12:36:09 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefUpdateFeature(virCPUDef *cpu,
|
2013-07-15 12:36:09 +00:00
|
|
|
const char *name,
|
|
|
|
int policy);
|
|
|
|
|
2020-11-19 17:44:48 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefAddFeatureIfMissing(virCPUDef *def,
|
2020-11-19 17:44:48 +00:00
|
|
|
const char *name,
|
|
|
|
int policy);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUFeatureDef *
|
2021-03-23 10:01:53 +00:00
|
|
|
virCPUDefFindFeature(const virCPUDef *def,
|
2017-10-09 14:20:43 +00:00
|
|
|
const char *name);
|
|
|
|
|
2019-06-07 12:07:10 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFilterFeatures(virCPUDef *cpu,
|
2019-06-07 12:07:10 +00:00
|
|
|
virCPUDefFeatureFilter filter,
|
|
|
|
void *opaque);
|
|
|
|
|
2019-06-19 17:01:30 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefCheckFeatures(virCPUDef *cpu,
|
2019-06-19 17:01:30 +00:00
|
|
|
virCPUDefFeatureFilter filter,
|
|
|
|
void *opaque,
|
|
|
|
char ***features);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef **
|
2017-09-13 13:23:43 +00:00
|
|
|
virCPUDefListParse(const char **xmlCPUs,
|
|
|
|
unsigned int ncpus,
|
|
|
|
virCPUType cpuType);
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefListFree(virCPUDef **cpus);
|