@@ -2611,6 +2611,8 @@ int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t policy,
int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t policy,
uint32_t leaf, uint32_t subleaf,
xen_cpuid_leaf_t *out);
+int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t policy,
+ uint32_t msr, xen_msr_entry_t *out);
int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);
int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
@@ -845,3 +845,45 @@ int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t policy,
*out = *tmp;
return 0;
}
+
+static int compare_entries(const void *l, const void *r)
+{
+ const xen_msr_entry_t *lhs = l;
+ const xen_msr_entry_t *rhs = r;
+
+ if ( lhs->idx == rhs->idx )
+ return 0;
+ return lhs->idx < rhs->idx ? -1 : 1;
+}
+
+static xen_msr_entry_t *find_entry(xen_msr_entry_t *entries,
+ unsigned int nr_entries, unsigned int index)
+{
+ const xen_msr_entry_t key = { index };
+
+ return bsearch(&key, entries, nr_entries, sizeof(*entries), compare_entries);
+}
+
+int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t policy,
+ uint32_t msr, xen_msr_entry_t *out)
+{
+ unsigned int nr_entries = ARRAY_SIZE(policy->entries);
+ xen_msr_entry_t *tmp;
+ int rc;
+
+ rc = xc_cpu_policy_serialise(xch, policy, NULL, 0,
+ policy->entries, &nr_entries);
+ if ( rc )
+ return rc;
+
+ tmp = find_entry(policy->entries, nr_entries, msr);
+ if ( !tmp )
+ {
+ /* Unable to find a matching MSR. */
+ errno = ENOENT;
+ return -1;
+ }
+
+ *out = *tmp;
+ return 0;
+}
Introduce an interface that returns a specific MSR entry from a cpu policy in xen_msr_entry_t format. Provide a helper to perform a binary search against an array of MSR entries. This is useful to callers can peek data from the opaque xc_cpu_policy_t type. No caller of the interface introduced on this patch. Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> --- Changes since v1: - Introduce a helper to perform a binary search of the MSR entries array. --- tools/include/xenctrl.h | 2 ++ tools/libs/guest/xg_cpuid_x86.c | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)