[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 4/8] libxl: cpuid: add guest topology support
Introduce internal cpuid routine for setting the topology as seen by the guest. The topology is made based on leaf 1 and leaf 4 for Intel, more specifically setting: Number of logical processors: proccount (CPUID.1:EBX[16:24]) Number of physical cores - 1: procpkg (CPUID.(4,0):EBX[26:32]) cache core count - 1: proccountX (CPUID.(4,Y):EBX[14:26]) given that X is l1d, l1i, l2 or l3 and Y the correspondent subleave [0-3] Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx> --- CC: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> CC: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> CC: Ian Campbell <ian.campbell@xxxxxxxxxx> CC: Wei Liu <wei.liu2@xxxxxxxxxx> --- tools/libxl/libxl_cpuid.c | 38 ++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/tools/libxl/libxl_cpuid.c b/tools/libxl/libxl_cpuid.c index deb81d2..e220566 100644 --- a/tools/libxl/libxl_cpuid.c +++ b/tools/libxl/libxl_cpuid.c @@ -352,6 +352,44 @@ void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid, (const char**)(cpuid[i].policy), cpuid_res); } +static int libxl_cpuid_parse_list(libxl_cpuid_policy_list *topo, + char **keys, int *vals, size_t sz) +{ + int i, ret = -1; + + for (i = 0; i < sz; i++) { + char *str = NULL; + + asprintf(&str, "%s=%d", keys[i], vals[i]); + + ret = libxl_cpuid_parse_config(topo, str); + free(str); + + if (ret) + break; + } + + return ret; +} + +void libxl__cpuid_set_topology(libxl_ctx *ctx, uint32_t domid, + uint32_t cores, uint32_t threads) +{ + libxl_cpuid_policy_list topo; + char *keys[] = { + "htt", "proccount", "procpkg", + "proccountl1d", "proccountl1i", "proccountl2", "proccountl3" + }; + int vals[] = { + 1, cores * threads, --cores, + --threads, threads, threads, cores + }; + + memset(&topo, 0, sizeof(topo)); + if (!libxl_cpuid_parse_list(&topo, keys, vals, ARRAY_SIZE(keys))) + libxl_cpuid_set(ctx, domid, topo); +} + static const char *input_names[2] = { "leaf", "subleaf" }; static const char *policy_names[4] = { "eax", "ebx", "ecx", "edx" }; /* diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 650a958..903ad7b 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3919,6 +3919,8 @@ static inline int libxl__key_value_list_is_empty(libxl_key_value_list *pkvl) } int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl); +void libxl__cpuid_set_topology(libxl_ctx *ctx, uint32_t domid, + uint32_t max_vcpus, uint32_t threads); /* Portability note: a proper flock(2) implementation is required */ typedef struct { -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |