tools/xen-cpuid: Rework the handling of dynamic featuresets

struct fsinfo is the vestigial remnant of an older internal design which
didn't survive very long.

Simplify things by inlining get_featureset() and having a single memory
allocation that gets reused.  This in turn changes featuresets[] to be a
simple list of names, so rename it to fs_names[].

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
(cherry picked from commit ec3474e1dd)
This commit is contained in:
Andrew Cooper committed 2023-08-08 16:02:53 +01:00
1 parent 08e5cf49d9
commit 95535c4209
1 file changed
+22 -31
+22 -31
View File
@@ -238,16 +238,11 @@ static const struct {
#define COL_ALIGN "18"
static struct fsinfo {
const char *name;
uint32_t len;
uint32_t *fs;
} featuresets[] =
{
[XEN_SYSCTL_cpu_featureset_host] = { "Host", 0, NULL },
[XEN_SYSCTL_cpu_featureset_raw] = { "Raw", 0, NULL },
[XEN_SYSCTL_cpu_featureset_pv] = { "PV", 0, NULL },
[XEN_SYSCTL_cpu_featureset_hvm] = { "HVM", 0, NULL },
static const char *const fs_names[] = {
[XEN_SYSCTL_cpu_featureset_host] = "Host",
[XEN_SYSCTL_cpu_featureset_raw] = "Raw",
[XEN_SYSCTL_cpu_featureset_pv] = "PV",
[XEN_SYSCTL_cpu_featureset_hvm] = "HVM",
};
static void dump_leaf(uint32_t leaf, const char *const *strs)
@@ -294,22 +289,10 @@ static void decode_featureset(const uint32_t *features,
}
}
static int get_featureset(xc_interface *xch, unsigned int idx)
{
struct fsinfo *f = &featuresets[idx];
f->len = nr_features;
f->fs = calloc(nr_features, sizeof(*f->fs));
if ( !f->fs )
err(1, "calloc(, featureset)");
return xc_get_cpu_featureset(xch, idx, &f->len, f->fs);
}
static void dump_info(xc_interface *xch, bool detail)
{
unsigned int i;
uint32_t *fs;
printf("nr_features: %u\n", nr_features);
@@ -340,26 +323,34 @@ static void dump_info(xc_interface *xch, bool detail)
nr_features, "HVM Hap Default", detail);
printf("\nDynamic sets:\n");
for ( i = 0; i < ARRAY_SIZE(featuresets); ++i )
fs = malloc(sizeof(*fs) * nr_features);
if ( !fs )
err(1, "malloc(featureset)");
for ( i = 0; i < ARRAY_SIZE(fs_names); ++i )
{
if ( get_featureset(xch, i) )
uint32_t len = nr_features;
int ret;
memset(fs, 0, sizeof(*fs) * nr_features);
ret = xc_get_cpu_featureset(xch, i, &len, fs);
if ( ret )
{
if ( errno == EOPNOTSUPP )
{
printf("%s featureset not supported by Xen\n",
featuresets[i].name);
printf("%s featureset not supported by Xen\n", fs_names[i]);
continue;
}
err(1, "xc_get_featureset()");
}
decode_featureset(featuresets[i].fs, featuresets[i].len,
featuresets[i].name, detail);
decode_featureset(fs, len, fs_names[i], detail);
}
for ( i = 0; i < ARRAY_SIZE(featuresets); ++i )
free(featuresets[i].fs);
free(fs);
}
static void print_policy(const char *name,
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.