[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 04/21] libs/guest: introduce helper to fetch a system cpu policy


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Tue, 13 Apr 2021 16:01:22 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6P/SnasJN8U82dOcBiB6I/f0U0K1k+7/Q7LtDAffDeY=; b=Pj733Uw5RGvl2LpBFwhJaKuG13CVHVXxGAgo1O3ZfG+9TdoRbBVL3xXzXFLnpLNThmk+jlIc4gb/vZBc+nKm8n2xWGMUP6WOGmyr7u0E+wgSDeZ6NB5V1Fl1wUqLu53juWYLTAvM9SYO1HslduTbFCvbFpTmAmcGmyj2U43UFGVsGpNEqOTcofTFQl+3xXDkID+Ja1TrPF1aMJglTOsmbPK2+5VEXKaTFZlSW33gH+TuI2xWznvclexaLII065X9jX8HL371qptqGffOpbu69x2DlqaDXA9BWTu4NY4kvGYXnU+NQiuCWD5g7F1kGhvoAbyfuhmuV2X0sFUZ/AUY9A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nQ4Y8ZA5AMUfBpf6/amurY82kCJ5uJ78eh6wrc8fxBKby1bc3SLKMiAk4a4mctw7yisEKfPoE6Vp7w3wex0cIlhhVIFRZbcuHObaPhEcisaUYgFc1PYleAvnqLNhToP+uSEo/rFWutEPgE5dKvjGIsigVADOgSPtHUkOjXVQWaFK29H87+qW/mEAkzjPxB05M22oAppWAq/vpJtBjBMirIgTuphxMgsaKoTSdNix3wODF0dUyhmVJdKMQI2248MkkEK9kRXxVOxb6EEIBlzmbJroRaBUVTesO6AwudZQQ6K15KeADU52kkYntgSNuQeGp5GLzAWesM/jcNFSKw+zXA==
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 13 Apr 2021 14:02:25 +0000
  • Ironport-hdrordr: A9a23:F72rGaF+VB3OFmT1pLqFMpHXdLJzesId70hD6mlYVQFVfsuEl8 qngfQc0lvOhCwMXWw78OrsBICrR3TA+ZlppbQAJLvKZniChEKEDqFHqbHjzTrpBjHk+odmv5 tIXqBiBLTLYmRSot395GCDfeoI5Pmi3OSWifzFz3FrJDsaCZ1IywtiEA6UHglXaWB9ZaYRL5 aX6spZqzfIQx1+AviTPXUZQ/PF4+TCiZOOW3U7LiQ64wqDhy7A0s+YLzGk2H4lMg9n8PMZ3k Xu1yf44aiitP/T8G6n60bjq654tfGk5t9KBMmngtUYJDP2mm+TFflccozHhh8ZiqWC70srjc ntrn4bTrhOwkKURE6Zi1/M3BTtyzkn4XOK8y7mvVLT5fbXaRh/Lugpv/M8TjLpr3AOkfs57Y dwm0WejJZTBQOoplWE2/H4EytEu2DxnWAvioco/htieLpbUpB9h6oF8nhYFZ8RdRiKk7wPIa 1VAMbQ6O0+SyL9U1np+m1mwNmbVn8uBBuxQk8bpsyP0zRN9UoJtncl+A==
  • Ironport-sdr: Zp14r/kNJzYeinSih6yGez5dnzsPOTnNkIKP5E5mMjTg1o5KeUcGHsguFHr3TUpODXu4VG3zg1 YOkX6ubrhaoW6cOwJIXybBgx34sRXytxxldUhUbrrKzxiIYacJKqgSEUDRyywOWjoe5/yu0mgu HG/+3LThxnEJKcZJHoLyscH55xho23jbw0pKtFplc57NQmBE3NVKYhq24Qan6Eth3RkpIclGhy ugqF9Oxme2JC9eT5TvEcKx/8q0cIbeO9EJEz8Cl08hSF6Zbw46NHg7XzLs+JNSy62UleUNxfxR V+o=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Such helper is based on the existing functions to fetch a CPUID and
MSR policies, but uses the xc_cpu_policy_t type to return the data to
the caller.

Note some helper functions are introduced, those are split from
xc_cpu_policy_get_system because they will be used by other functions
also.

No user of the interface introduced on the patch.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Changes since v1:
 - Always return -1 on error from xc_cpu_policy_get_system.
 - Only print detailed error messages if err_leaf or err_msr is != -1.
 - Rename idx function parameter to policy_idx.
---
 tools/include/xenctrl.h         |  4 +++
 tools/libs/guest/xg_cpuid_x86.c | 54 +++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index 1aba814f01c..187df5c5d2d 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2596,6 +2596,10 @@ typedef struct xc_cpu_policy *xc_cpu_policy_t;
 xc_cpu_policy_t xc_cpu_policy_init(void);
 void xc_cpu_policy_destroy(xc_cpu_policy_t policy);
 
+/* Retrieve a system policy, or get/set a domains policy. */
+int xc_cpu_policy_get_system(xc_interface *xch, unsigned int policy_idx,
+                             xc_cpu_policy_t policy);
+
 int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);
 int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
                           uint32_t *nr_features, uint32_t *featureset);
diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index 8e3a1a8cbf2..78fbc7db9d3 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -678,3 +678,57 @@ void xc_cpu_policy_destroy(xc_cpu_policy_t policy)
     if ( policy )
         free(policy);
 }
+
+static int deserialize_policy(xc_interface *xch, xc_cpu_policy_t policy,
+                              unsigned int nr_leaves, unsigned int nr_entries)
+{
+    uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
+    int rc;
+
+    rc = x86_cpuid_copy_from_buffer(&policy->cpuid, policy->leaves,
+                                    nr_leaves, &err_leaf, &err_subleaf);
+    if ( rc )
+    {
+        if ( err_leaf != -1 )
+            ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d 
= %s)",
+                  err_leaf, err_subleaf, -rc, strerror(-rc));
+        return rc;
+    }
+
+    rc = x86_msr_copy_from_buffer(&policy->msr, policy->entries,
+                                  nr_entries, &err_msr);
+    if ( rc )
+    {
+        if ( err_msr != -1 )
+            ERROR("Failed to deserialise MSR (err MSR %#x) (%d = %s)",
+                  err_msr, -rc, strerror(-rc));
+        return rc;
+    }
+
+    return 0;
+}
+
+int xc_cpu_policy_get_system(xc_interface *xch, unsigned int policy_idx,
+                             xc_cpu_policy_t policy)
+{
+    unsigned int nr_leaves = ARRAY_SIZE(policy->leaves);
+    unsigned int nr_entries = ARRAY_SIZE(policy->entries);
+    int rc;
+
+    rc = xc_get_system_cpu_policy(xch, policy_idx, &nr_leaves, policy->leaves,
+                                  &nr_entries, policy->entries);
+    if ( rc )
+    {
+        PERROR("Failed to obtain %u policy", policy_idx);
+        return rc;
+    }
+
+    rc = deserialize_policy(xch, policy, nr_leaves, nr_entries);
+    if ( rc )
+    {
+        errno = -rc;
+        rc = -1;
+    }
+
+    return rc;
+}
-- 
2.30.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.