<model fallback='allow'>core2duo</model>
<vendor>Intel</vendor>
<topology sockets='1' cores='2' threads='1'/>
+ <cache level='3' mode='emulate'/>
<feature policy='disable' name='lahf_lm'/>
</cpu>
...</pre>
<pre>
<cpu mode='host-passthrough'>
+ <cache mode='passthrough'/>
<feature policy='disable' name='lahf_lm'/>
...</pre>
<span class="since">Since 0.8.5</span> the <code>policy</code>
attribute can be omitted and will default to <code>require</code>.
</dd>
+
+ <dt><code>cache</code></dt>
+ <dd><span class="since">Since 3.3.0</span> the <code>cache</code>
+ element describes the virtual CPU cache. If the element is missing,
+ the hypervisor will use a sensible default.
+
+ <dl>
+ <dt><code>level</code></dt>
+ <dd>This optional attribute specifies which cache level is described
+ by the element. Missing attribute means the element describes all
+ CPU cache levels at once. Mixing <code>cache</code> elements with
+ the <code>level</code> attribute set and those without the
+ attribute is forbidden.</dd>
+
+ <dt><code>mode</code></dt>
+ <dd>
+ The following values are supported:
+ <dl>
+ <dt><code>emulate</code></dt>
+ <dd>The hypervisor will provide a fake CPU cache data.</dd>
+
+ <dt><code>passthrough</code></dt>
+ <dd>The real CPU cache data reported by the host CPU will be
+ passed through to the virtual CPU.</dd>
+
+ <dt><code>disable</code></dt>
+ <dd>The virtual CPU will report no CPU cache of the specified
+ level (or no cache at all if the <code>level</code> attribute
+ is missing).</dd>
+ </dl>
+ </dd>
+ </dl>
+ </dd>
</dl>
<p>
</data>
</define>
+ <define name="cpuCache">
+ <element name="cache">
+ <optional>
+ <attribute name="level">
+ <choice>
+ <value>1</value>
+ <value>2</value>
+ <value>3</value>
+ </choice>
+ </attribute>
+ </optional>
+ <attribute name="mode">
+ <choice>
+ <value>emulate</value>
+ <value>passthrough</value>
+ <value>disable</value>
+ </choice>
+ </attribute>
+ </element>
+ </define>
+
</grammar>
<optional>
<ref name="cpuNuma"/>
</optional>
+ <optional>
+ <ref name="cpuCache"/>
+ </optional>
</interleave>
</element>
</define>
"disable",
"forbid")
+VIR_ENUM_IMPL(virCPUCacheMode, VIR_CPU_CACHE_MODE_LAST,
+ "emulate",
+ "passthrough",
+ "disable")
+
+
void
virCPUDefFreeFeatures(virCPUDefPtr def)
{
return;
virCPUDefFreeModel(def);
+ VIR_FREE(def->cache);
VIR_FREE(def);
}
copy->threads = cpu->threads;
copy->arch = cpu->arch;
+ if (cpu->cache) {
+ if (VIR_ALLOC(copy->cache) < 0)
+ goto error;
+
+ *copy->cache = *cpu->cache;
+ }
+
return copy;
+
+ error:
+ virCPUDefFree(copy);
+ return NULL;
}
def->features[i].policy = policy;
}
+ if (virXPathInt("count(./cache)", ctxt, &n) < 0) {
+ goto cleanup;
+ } else if (n > 1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("at most one CPU cache element may be specified"));
+ goto cleanup;
+ } else if (n == 1) {
+ int level = -1;
+ char *strmode;
+ int mode;
+
+ if (virXPathBoolean("boolean(./cache[1]/@level)", ctxt) == 1 &&
+ (virXPathInt("string(./cache[1]/@level)", ctxt, &level) < 0 ||
+ level < 1 || level > 3)) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("invalid CPU cache level, must be in range [1,3]"));
+ goto cleanup;
+ }
+
+ if (!(strmode = virXPathString("string(./cache[1]/@mode)", ctxt)) ||
+ (mode = virCPUCacheModeTypeFromString(strmode)) < 0) {
+ VIR_FREE(strmode);
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("missing or invalid CPU cache mode"));
+ goto cleanup;
+ }
+ VIR_FREE(strmode);
+
+ if (VIR_ALLOC(def->cache) < 0)
+ goto cleanup;
+
+ def->cache->level = level;
+ def->cache->mode = mode;
+ }
+
cleanup:
ctxt->node = oldnode;
VIR_FREE(fallback);
virBufferAddLit(buf, "/>\n");
}
+ if (def->cache) {
+ virBufferAddLit(buf, "<cache ");
+ if (def->cache->level != -1)
+ virBufferAsprintf(buf, "level='%d' ", def->cache->level);
+ virBufferAsprintf(buf, "mode='%s'",
+ virCPUCacheModeTypeToString(def->cache->mode));
+ virBufferAddLit(buf, "/>\n");
+ }
+
for (i = 0; i < def->nfeatures; i++) {
virCPUFeatureDefPtr feature = def->features + i;
};
+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;
+};
+
+
typedef struct _virCPUDef virCPUDef;
typedef virCPUDef *virCPUDefPtr;
struct _virCPUDef {
size_t nfeatures;
size_t nfeatures_max;
virCPUFeatureDefPtr features;
+ virCPUCacheDefPtr cache;
};
# conf/cpu_conf.h
+virCPUCacheModeTypeFromString;
+virCPUCacheModeTypeToString;
virCPUDefAddFeature;
virCPUDefCopy;
virCPUDefCopyModel;
--- /dev/null
+<domain type='kvm'>
+ <name>foo</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <cpu mode='host-passthrough'>
+ <cache mode='disable'/>
+ </cpu>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ </devices>
+</domain>
--- /dev/null
+<domain type='kvm'>
+ <name>foo</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <cpu mode='host-passthrough'>
+ <cache level='3' mode='emulate'/>
+ </cpu>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ </devices>
+</domain>
--- /dev/null
+<domain type='kvm'>
+ <name>foo</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <cpu mode='host-passthrough'>
+ <cache mode='passthrough'/>
+ </cpu>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ </devices>
+</domain>
DO_TEST("vcpus-individual");
+ DO_TEST("cpu-cache-emulate");
+ DO_TEST("cpu-cache-passthrough");
+ DO_TEST("cpu-cache-disable");
+
virObjectUnref(caps);
virObjectUnref(xmlopt);