mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 12:09:58 +00:00
62a35aaa31
The previous commit enables conversion of visit_foo(..., &err); if (err) { ... } to if (!visit_foo(..., errp)) { ... } for visitor functions that now return true / false on success / error. Coccinelle script: @@ identifier fun =~ "check_list|input_type_enum|lv_start_struct|lv_type_bool|lv_type_int64|lv_type_str|lv_type_uint64|output_type_enum|parse_type_bool|parse_type_int64|parse_type_null|parse_type_number|parse_type_size|parse_type_str|parse_type_uint64|print_type_bool|print_type_int64|print_type_null|print_type_number|print_type_size|print_type_str|print_type_uint64|qapi_clone_start_alternate|qapi_clone_start_list|qapi_clone_start_struct|qapi_clone_type_bool|qapi_clone_type_int64|qapi_clone_type_null|qapi_clone_type_number|qapi_clone_type_str|qapi_clone_type_uint64|qapi_dealloc_start_list|qapi_dealloc_start_struct|qapi_dealloc_type_anything|qapi_dealloc_type_bool|qapi_dealloc_type_int64|qapi_dealloc_type_null|qapi_dealloc_type_number|qapi_dealloc_type_str|qapi_dealloc_type_uint64|qobject_input_check_list|qobject_input_check_struct|qobject_input_start_alternate|qobject_input_start_list|qobject_input_start_struct|qobject_input_type_any|qobject_input_type_bool|qobject_input_type_bool_keyval|qobject_input_type_int64|qobject_input_type_int64_keyval|qobject_input_type_null|qobject_input_type_number|qobject_input_type_number_keyval|qobject_input_type_size_keyval|qobject_input_type_str|qobject_input_type_str_keyval|qobject_input_type_uint64|qobject_input_type_uint64_keyval|qobject_output_start_list|qobject_output_start_struct|qobject_output_type_any|qobject_output_type_bool|qobject_output_type_int64|qobject_output_type_null|qobject_output_type_number|qobject_output_type_str|qobject_output_type_uint64|start_list|visit_check_list|visit_check_struct|visit_start_alternate|visit_start_list|visit_start_struct|visit_type_.*"; expression list args; typedef Error; Error *err; @@ - fun(args, &err); - if (err) + if (!fun(args, &err)) { ... } A few line breaks tidied up manually. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20200707160613.848843-19-armbru@redhat.com>
105 lines
2.7 KiB
C
105 lines
2.7 KiB
C
/*
|
|
* CPU core abstract device
|
|
*
|
|
* Copyright (C) 2016 Bharata B Rao <bharata@linux.vnet.ibm.com>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "hw/cpu/core.h"
|
|
#include "qapi/visitor.h"
|
|
#include "qemu/module.h"
|
|
#include "qapi/error.h"
|
|
#include "sysemu/cpus.h"
|
|
#include "hw/boards.h"
|
|
|
|
static void core_prop_get_core_id(Object *obj, Visitor *v, const char *name,
|
|
void *opaque, Error **errp)
|
|
{
|
|
CPUCore *core = CPU_CORE(obj);
|
|
int64_t value = core->core_id;
|
|
|
|
visit_type_int(v, name, &value, errp);
|
|
}
|
|
|
|
static void core_prop_set_core_id(Object *obj, Visitor *v, const char *name,
|
|
void *opaque, Error **errp)
|
|
{
|
|
CPUCore *core = CPU_CORE(obj);
|
|
Error *local_err = NULL;
|
|
int64_t value;
|
|
|
|
if (!visit_type_int(v, name, &value, &local_err)) {
|
|
error_propagate(errp, local_err);
|
|
return;
|
|
}
|
|
|
|
if (value < 0) {
|
|
error_setg(errp, "Invalid core id %"PRId64, value);
|
|
return;
|
|
}
|
|
|
|
core->core_id = value;
|
|
}
|
|
|
|
static void core_prop_get_nr_threads(Object *obj, Visitor *v, const char *name,
|
|
void *opaque, Error **errp)
|
|
{
|
|
CPUCore *core = CPU_CORE(obj);
|
|
int64_t value = core->nr_threads;
|
|
|
|
visit_type_int(v, name, &value, errp);
|
|
}
|
|
|
|
static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
|
|
void *opaque, Error **errp)
|
|
{
|
|
CPUCore *core = CPU_CORE(obj);
|
|
Error *local_err = NULL;
|
|
int64_t value;
|
|
|
|
if (!visit_type_int(v, name, &value, &local_err)) {
|
|
error_propagate(errp, local_err);
|
|
return;
|
|
}
|
|
|
|
core->nr_threads = value;
|
|
}
|
|
|
|
static void cpu_core_instance_init(Object *obj)
|
|
{
|
|
MachineState *ms = MACHINE(qdev_get_machine());
|
|
CPUCore *core = CPU_CORE(obj);
|
|
|
|
object_property_add(obj, "core-id", "int", core_prop_get_core_id,
|
|
core_prop_set_core_id, NULL, NULL);
|
|
object_property_add(obj, "nr-threads", "int", core_prop_get_nr_threads,
|
|
core_prop_set_nr_threads, NULL, NULL);
|
|
core->nr_threads = ms->smp.threads;
|
|
}
|
|
|
|
static void cpu_core_class_init(ObjectClass *oc, void *data)
|
|
{
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
set_bit(DEVICE_CATEGORY_CPU, dc->categories);
|
|
}
|
|
|
|
static const TypeInfo cpu_core_type_info = {
|
|
.name = TYPE_CPU_CORE,
|
|
.parent = TYPE_DEVICE,
|
|
.abstract = true,
|
|
.class_init = cpu_core_class_init,
|
|
.instance_size = sizeof(CPUCore),
|
|
.instance_init = cpu_core_instance_init,
|
|
};
|
|
|
|
static void cpu_core_register_types(void)
|
|
{
|
|
type_register_static(&cpu_core_type_info);
|
|
}
|
|
|
|
type_init(cpu_core_register_types)
|