diff mbox

[RFC,4/8] libxl: cpuid: add guest topology support

Message ID 1456174934-22973-5-git-send-email-joao.m.martins@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Joao Martins Feb. 22, 2016, 9:02 p.m. UTC
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@oracle.com>
---
CC: Ian Jackson <ian.jackson@eu.citrix.com>
CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
CC: Ian Campbell <ian.campbell@citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
 tools/libxl/libxl_cpuid.c    | 38 ++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |  2 ++
 2 files changed, 40 insertions(+)

Comments

Wei Liu Feb. 25, 2016, 4:29 p.m. UTC | #1
On Mon, Feb 22, 2016 at 09:02:10PM +0000, Joao Martins wrote:
> 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@oracle.com>
> ---
> CC: Ian Jackson <ian.jackson@eu.citrix.com>
> CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> CC: Ian Campbell <ian.campbell@citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> ---
>  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)

Just call it cpuid_parse_list is fine.

Wei.
Joao Martins March 2, 2016, 7:14 p.m. UTC | #2
On 02/25/2016 04:29 PM, Wei Liu wrote:
> On Mon, Feb 22, 2016 at 09:02:10PM +0000, Joao Martins wrote:
>> 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@oracle.com>
>> ---
>> CC: Ian Jackson <ian.jackson@eu.citrix.com>
>> CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
>> CC: Ian Campbell <ian.campbell@citrix.com>
>> CC: Wei Liu <wei.liu2@citrix.com>
>> ---
>>  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)
> 
> Just call it cpuid_parse_list is fine.
> 
OK.

> Wei.
>
diff mbox

Patch

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 {