diff mbox

[RFC,5/8] libxl: introduce smt field

Message ID 1456174934-22973-6-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
By setting it to true, it enables the vcpus set by the guest
to be seen as a SMT-enabled topology. It uses then
libxl__cpuid_set_topology() to change the cpuid accordingly.
This setting is made *before* the cpuid is set so that
any changes could be overwritten. The number of SMT threads
are the ones supported by the host. And for that it adds
another helper routine libxl__count_threads_per_core to fetch
it.

This feature is useful in HT-enabled hosts so that hard
pinned domains can see the right topology (i.e. SMT cores exposed
as SMT cores) which in return would lead guest scheduler making
better decisions.

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_create.c   |  2 ++
 tools/libxl/libxl_dom.c      | 10 ++++++++++
 tools/libxl/libxl_internal.h |  1 +
 tools/libxl/libxl_types.idl  |  1 +
 tools/libxl/libxl_utils.c    | 17 +++++++++++++++++
 5 files changed, 31 insertions(+)

Comments

Wei Liu Feb. 25, 2016, 4:29 p.m. UTC | #1
On Mon, Feb 22, 2016 at 09:02:11PM +0000, Joao Martins wrote:
> By setting it to true, it enables the vcpus set by the guest
> to be seen as a SMT-enabled topology. It uses then
> libxl__cpuid_set_topology() to change the cpuid accordingly.
> This setting is made *before* the cpuid is set so that
> any changes could be overwritten. The number of SMT threads
> are the ones supported by the host. And for that it adds
> another helper routine libxl__count_threads_per_core to fetch
> it.
> 
> This feature is useful in HT-enabled hosts so that hard
> pinned domains can see the right topology (i.e. SMT cores exposed
> as SMT cores) which in return would lead guest scheduler making
> better decisions.
> 

I think we need more sophisticated configuration options then just a
bool. If we're doing this, there is no reason why we shouldn't allow
administrator to set arbitrary topology for the guest.

Wei.
diff mbox

Patch

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index de5d27f..dac15d5 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -195,6 +195,8 @@  int libxl__domain_build_info_setdefault(libxl__gc *gc,
         b_info->num_vcpu_hard_affinity = b_info->max_vcpus;
     }
 
+    libxl_defbool_setdefault(&b_info->smt, false);
+
     libxl_defbool_setdefault(&b_info->numa_placement, true);
 
     if (b_info->max_memkb == LIBXL_MEMKB_DEFAULT)
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 2269998..ff9356d 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -507,6 +507,16 @@  int libxl__build_post(libxl__gc *gc, uint32_t domid,
     }
 
     libxl_cpuid_apply_policy(ctx, domid);
+    if (info->type == LIBXL_DOMAIN_TYPE_HVM
+        && libxl_defbool_val(info->smt)) {
+
+        uint32_t threads = 0;
+
+        if (!libxl__count_threads_per_core(gc, &threads))
+            libxl__cpuid_set_topology(ctx, domid,
+                                      info->max_vcpus / threads, threads);
+    }
+
     if (info->cpuid != NULL)
         libxl_cpuid_set(ctx, domid, info->cpuid);
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 903ad7b..7cc4de7 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -4033,6 +4033,7 @@  void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,
                                     const libxl_bitmap *sptr);
 
 int libxl__count_physical_sockets(libxl__gc *gc, int *sockets);
+int libxl__count_threads_per_core(libxl__gc *gc, uint32_t *threads);
 
 
 #define LIBXL_QEMU_USER_PREFIX "xen-qemuuser"
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index f04279e..fa4725a 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -421,6 +421,7 @@  libxl_domain_build_info = Struct("domain_build_info",[
     ("nodemap",         libxl_bitmap),
     ("vcpu_hard_affinity", Array(libxl_bitmap, "num_vcpu_hard_affinity")),
     ("vcpu_soft_affinity", Array(libxl_bitmap, "num_vcpu_soft_affinity")),
+    ("smt",             libxl_defbool),
     ("numa_placement",  libxl_defbool),
     ("tsc_mode",        libxl_tsc_mode),
     ("max_memkb",       MemKB),
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index e42422a..dd063c8 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -861,6 +861,23 @@  int libxl__count_physical_sockets(libxl__gc *gc, int *sockets)
     return 0;
 }
 
+int libxl__count_threads_per_core(libxl__gc *gc, uint32_t *threads)
+{
+    int rc;
+    libxl_physinfo info;
+
+    libxl_physinfo_init(&info);
+
+    rc = libxl_get_physinfo(CTX, &info);
+    if (rc)
+        return rc;
+
+    *threads = info.threads_per_core;
+
+    libxl_physinfo_dispose(&info);
+    return 0;
+}
+
 int libxl_socket_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *socketmap,
                               int max_sockets)
 {