Introduce vendor and model struct and related
cleanup functions for ARM cpu.
Signed-off-by: Zhenyu Zheng <zhengzhenyulixi@xxxxxxxxx>
---
src/cpu/cpu_arm.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index ee5802198f..d8f571cae3 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -1,6 +1,7 @@
/*
* cpu_arm.c: CPU driver for arm CPUs
*
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd.
* Copyright (C) 2013 Red Hat, Inc.
* Copyright (C) Canonical Ltd. 2012
*
@@ -23,12 +24,16 @@
#include "viralloc.h"
#include "cpu.h"
+#include "cpu_arm.h"
#include "cpu_map.h"
+#include "virlog.h"
#include "virstring.h"
#include "virxml.h"
#define VIR_FROM_THIS VIR_FROM_CPU
+VIR_LOG_INIT("cpu.cpu_arm");
+
static const virArch archs[] = {
VIR_ARCH_ARMV6L,
VIR_ARCH_ARMV7B,
@@ -36,6 +41,21 @@ static const virArch archs[] = {
VIR_ARCH_AARCH64,
};
+typedef struct _virCPUarmVendor virCPUarmVendor;
+typedef virCPUarmVendor *virCPUarmVendorPtr;
+struct _virCPUarmVendor {
+ char *name;
+ unsigned long value;
+};
+
+typedef struct _virCPUarmModel virCPUarmModel;
+typedef virCPUarmModel *virCPUarmModelPtr;
+struct _virCPUarmModel {
+ char *name;
+ virCPUarmVendorPtr vendor;
+ virCPUarmData data;
+};
+
typedef struct _virCPUarmFeature virCPUarmFeature;
typedef virCPUarmFeature *virCPUarmFeaturePtr;
struct _virCPUarmFeature {
@@ -64,6 +84,10 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUarmFeature, virCPUarmFeatureFree);
typedef struct _virCPUarmMap virCPUarmMap;
typedef virCPUarmMap *virCPUarmMapPtr;
struct _virCPUarmMap {
+ size_t nvendors;
+ virCPUarmVendorPtr *vendors;
+ size_t nmodels;
+ virCPUarmModelPtr *models;
GPtrArray *features;
};
@@ -81,12 +105,62 @@ virCPUarmMapNew(void)
return map;
}
+static void
+virCPUarmDataClear(virCPUarmData *data)
+{
+ if (!data)
+ return;
+
+ VIR_FREE(data->features);
+}
+
+static void
+virCPUarmDataFree(virCPUDataPtr cpuData)
+{
+ if (!cpuData)
+ return;
+
+ virCPUarmDataClear(&cpuData->data.arm);
+ VIR_FREE(cpuData);
+}
+
+static void
+virCPUarmModelFree(virCPUarmModelPtr model)
+{
+ if (!model)
+ return;
+
+ virCPUarmDataClear(&model->data);
+ g_free(model->name);
+ g_free(model);
+}
+
+static void
+virCPUarmVendorFree(virCPUarmVendorPtr vendor)
+{
+ if (!vendor)
+ return;
+
+ g_free(vendor->name);
+ g_free(vendor);
+}
+
static void
virCPUarmMapFree(virCPUarmMapPtr map)
{
if (!map)
return;
+ size_t i;
+
+ for (i = 0; i < map->nmodels; i++)
+ virCPUarmModelFree(map->models[i]);
+ g_free(map->models);
+
+ for (i = 0; i < map->nvendors; i++)
+ virCPUarmVendorFree(map->vendors[i]);
+ g_free(map->vendors);
+
g_ptr_array_free(map->features, TRUE);
g_free(map);
@@ -259,6 +333,7 @@ struct cpuArchDriver cpuDriverArm = {
.compare = virCPUarmCompare,
.decode = NULL,
.encode = NULL,
+ .dataFree = virCPUarmDataFree,
.baseline = virCPUarmBaseline,
.update = virCPUarmUpdate,
.validateFeatures = virCPUarmValidateFeatures,
--
2.26.0.windows.1
cleanup functions for ARM cpu.
Signed-off-by: Zhenyu Zheng <zhengzhenyulixi@xxxxxxxxx>
---
src/cpu/cpu_arm.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index ee5802198f..d8f571cae3 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -1,6 +1,7 @@
/*
* cpu_arm.c: CPU driver for arm CPUs
*
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd.
* Copyright (C) 2013 Red Hat, Inc.
* Copyright (C) Canonical Ltd. 2012
*
@@ -23,12 +24,16 @@
#include "viralloc.h"
#include "cpu.h"
+#include "cpu_arm.h"
#include "cpu_map.h"
+#include "virlog.h"
#include "virstring.h"
#include "virxml.h"
#define VIR_FROM_THIS VIR_FROM_CPU
+VIR_LOG_INIT("cpu.cpu_arm");
+
static const virArch archs[] = {
VIR_ARCH_ARMV6L,
VIR_ARCH_ARMV7B,
@@ -36,6 +41,21 @@ static const virArch archs[] = {
VIR_ARCH_AARCH64,
};
+typedef struct _virCPUarmVendor virCPUarmVendor;
+typedef virCPUarmVendor *virCPUarmVendorPtr;
+struct _virCPUarmVendor {
+ char *name;
+ unsigned long value;
+};
+
+typedef struct _virCPUarmModel virCPUarmModel;
+typedef virCPUarmModel *virCPUarmModelPtr;
+struct _virCPUarmModel {
+ char *name;
+ virCPUarmVendorPtr vendor;
+ virCPUarmData data;
+};
+
typedef struct _virCPUarmFeature virCPUarmFeature;
typedef virCPUarmFeature *virCPUarmFeaturePtr;
struct _virCPUarmFeature {
@@ -64,6 +84,10 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUarmFeature, virCPUarmFeatureFree);
typedef struct _virCPUarmMap virCPUarmMap;
typedef virCPUarmMap *virCPUarmMapPtr;
struct _virCPUarmMap {
+ size_t nvendors;
+ virCPUarmVendorPtr *vendors;
+ size_t nmodels;
+ virCPUarmModelPtr *models;
GPtrArray *features;
};
@@ -81,12 +105,62 @@ virCPUarmMapNew(void)
return map;
}
+static void
+virCPUarmDataClear(virCPUarmData *data)
+{
+ if (!data)
+ return;
+
+ VIR_FREE(data->features);
+}
+
+static void
+virCPUarmDataFree(virCPUDataPtr cpuData)
+{
+ if (!cpuData)
+ return;
+
+ virCPUarmDataClear(&cpuData->data.arm);
+ VIR_FREE(cpuData);
+}
+
+static void
+virCPUarmModelFree(virCPUarmModelPtr model)
+{
+ if (!model)
+ return;
+
+ virCPUarmDataClear(&model->data);
+ g_free(model->name);
+ g_free(model);
+}
+
+static void
+virCPUarmVendorFree(virCPUarmVendorPtr vendor)
+{
+ if (!vendor)
+ return;
+
+ g_free(vendor->name);
+ g_free(vendor);
+}
+
static void
virCPUarmMapFree(virCPUarmMapPtr map)
{
if (!map)
return;
+ size_t i;
+
+ for (i = 0; i < map->nmodels; i++)
+ virCPUarmModelFree(map->models[i]);
+ g_free(map->models);
+
+ for (i = 0; i < map->nvendors; i++)
+ virCPUarmVendorFree(map->vendors[i]);
+ g_free(map->vendors);
+
g_ptr_array_free(map->features, TRUE);
g_free(map);
@@ -259,6 +333,7 @@ struct cpuArchDriver cpuDriverArm = {
.compare = virCPUarmCompare,
.decode = NULL,
.encode = NULL,
+ .dataFree = virCPUarmDataFree,
.baseline = virCPUarmBaseline,
.update = virCPUarmUpdate,
.validateFeatures = virCPUarmValidateFeatures,
--
2.26.0.windows.1
On Thu, Apr 9, 2020 at 6:16 PM Daniel P. Berrangé <berrange@xxxxxxxxxx> wrote:
On Thu, Apr 02, 2020 at 05:03:55PM +0800, Zhenyu Zheng wrote:
> Introduce vendor and model struct and related
> cleanup functions for ARM cpu.
>
> Signed-off-by: Zhenyu Zheng <zhengzhenyulixi@xxxxxxxxx>
> ---
> src/cpu/cpu_arm.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 75 insertions(+)
>
> diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
> index ee5802198f..c757c24a37 100644
> --- a/src/cpu/cpu_arm.c
> +++ b/src/cpu/cpu_arm.c
> @@ -1,6 +1,7 @@
> /*
> * cpu_arm.c: CPU driver for arm CPUs
> *
> + * Copyright (C) 2020 Huawei Technologies Co., Ltd.
> * Copyright (C) 2013 Red Hat, Inc.
> * Copyright (C) Canonical Ltd. 2012
> *
> @@ -23,12 +24,16 @@
>
> #include "viralloc.h"
> #include "cpu.h"
> +#include "cpu_arm.h"
> #include "cpu_map.h"
> +#include "virlog.h"
> #include "virstring.h"
> #include "virxml.h"
>
> #define VIR_FROM_THIS VIR_FROM_CPU
>
> +VIR_LOG_INIT("cpu.cpu_arm");
> +
> static const virArch archs[] = {
> VIR_ARCH_ARMV6L,
> VIR_ARCH_ARMV7B,
> @@ -36,6 +41,21 @@ static const virArch archs[] = {
> VIR_ARCH_AARCH64,
> };
>
> +typedef struct _virCPUarmVendor virCPUarmVendor;
> +typedef virCPUarmVendor *virCPUarmVendorPtr;
> +struct _virCPUarmVendor {
> + char *name;
> + unsigned long value;
> +};
> +
> +typedef struct _virCPUarmModel virCPUarmModel;
> +typedef virCPUarmModel *virCPUarmModelPtr;
> +struct _virCPUarmModel {
> + char *name;
> + virCPUarmVendorPtr vendor;
> + virCPUarmData data;
> +};
> +
> typedef struct _virCPUarmFeature virCPUarmFeature;
> typedef virCPUarmFeature *virCPUarmFeaturePtr;
> struct _virCPUarmFeature {
> @@ -64,6 +84,10 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUarmFeature, virCPUarmFeatureFree);
> typedef struct _virCPUarmMap virCPUarmMap;
> typedef virCPUarmMap *virCPUarmMapPtr;
> struct _virCPUarmMap {
> + size_t nvendors;
> + virCPUarmVendorPtr *vendors;
> + size_t nmodels;
> + virCPUarmModelPtr *models;
> GPtrArray *features;
> };
>
> @@ -81,12 +105,62 @@ virCPUarmMapNew(void)
> return map;
> }
>
> +static void
> +virCPUarmDataClear(virCPUarmData *data)
> +{
> + if (!data)
> + return;
> +
> + VIR_FREE(data->features);
> +}
> +
> +static void
> +virCPUarmDataFree(virCPUDataPtr cpuData)
> +{
> + if (!cpuData)
> + return;
> +
> + virCPUarmDataClear(&cpuData->data.arm);
> + VIR_FREE(cpuData);
> +}
> +
> +static void
> +armModelFree(virCPUarmModelPtr model)
Normally we want the method name prefix match the struct name
eg virCPUarmModelFree()
> +{
> + if (!model)
> + return;
> +
> + virCPUarmDataClear(&model->data);
> + g_free(model->name);
> + g_free(model);
> +}
> +
> +static void
> +armVendorFree(virCPUarmVendorPtr vendor)
virCPUarmVendorFree()
> +{
> + if (!vendor)
> + return;
> +
> + g_free(vendor->name);
> + g_free(vendor);
> +}
> +
With those two changes
Reviewed-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|