From patchwork Wed Jun 22 07:23:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 9192023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D953C601C0 for ; Wed, 22 Jun 2016 07:24:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6DC7283F0 for ; Wed, 22 Jun 2016 07:24:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBB1A283F2; Wed, 22 Jun 2016 07:24:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8DA3E283F0 for ; Wed, 22 Jun 2016 07:24:52 +0000 (UTC) Received: from localhost ([::1]:56228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFcWp-0005gl-OF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 22 Jun 2016 03:24:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFcWN-0005dY-KP for qemu-devel@nongnu.org; Wed, 22 Jun 2016 03:24:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFcWI-0005fd-IY for qemu-devel@nongnu.org; Wed, 22 Jun 2016 03:24:22 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:1137 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFcWI-0005fY-DR for qemu-devel@nongnu.org; Wed, 22 Jun 2016 03:24:18 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5M7OFUw039684 for ; Wed, 22 Jun 2016 03:24:17 -0400 Received: from e28smtp05.in.ibm.com (e28smtp05.in.ibm.com [125.16.236.5]) by mx0b-001b2d01.pphosted.com with ESMTP id 23n0eukhxq-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Jun 2016 03:24:17 -0400 Received: from localhost by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Jun 2016 12:54:11 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Jun 2016 12:53:59 +0530 X-IBM-Helo: d28dlp01.in.ibm.com X-IBM-MailFrom: bharata@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 0AA8CE0045; Wed, 22 Jun 2016 12:57:42 +0530 (IST) Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay02.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5M7Nq6Y20906312; Wed, 22 Jun 2016 12:53:52 +0530 Received: from d28av05.in.ibm.com (localhost [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u5M7NuP9006582; Wed, 22 Jun 2016 12:53:57 +0530 Received: from bharata.in.ibm.com ([9.84.230.142]) by d28av05.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u5M7NsiL006498; Wed, 22 Jun 2016 12:53:55 +0530 From: Bharata B Rao To: qemu-devel@nongnu.org Date: Wed, 22 Jun 2016 12:53:49 +0530 X-Mailer: git-send-email 2.1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062207-0016-0000-0000-000002AE4614 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062207-0017-0000-0000-00002472EBBA Message-Id: <1466580229-4600-1-git-send-email-bharata@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-22_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606220080 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [RFC PATCH v1 1/1] spapr: Support setting of compat CPU type for CPU cores X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, thuth@redhat.com, Bharata B Rao , qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Compat CPU type is typically specified on -cpu cmdline option like: -cpu host,compat=power7 or -cpu POWER8E,compat=power7 etc. With the introduction of sPAPR CPU core devices, we need to support the same for core devices too. Support the specification of CPU compat type on device_add command for sPAPRCPUCore devices like: (qemu) device_add POWER8E-spapr-cpu-core,id=core3,compat=power7,core-id=24 Signed-off-by: Bharata B Rao --- Changes in v1: - In the routine that extracts "compat=" from -cpu cmdline, made the parsing generic as suggested by Thomas Huth so that it works in the presence of any other additional features. - Addressed review comments by David with major one being setting of compat property directly instead of going via ->parse_features(). TODO: - Reconcile with Igor's work that make cpu features as global properties. - Find a way to export the compat infomation via query-hotpluggable-cpus. v0: https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg05279.html hw/ppc/spapr.c | 8 +++++ hw/ppc/spapr_cpu_core.c | 78 +++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 2 ++ 3 files changed, 88 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 778fa25..2049d7d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1807,6 +1807,7 @@ static void ppc_spapr_init(MachineState *machine) if (i < spapr_cores) { char *type = spapr_get_cpu_core_type(machine->cpu_model); Object *core; + char *compat; if (!object_class_by_name(type)) { error_report("Unable to find sPAPR CPU Core definition"); @@ -1818,6 +1819,13 @@ static void ppc_spapr_init(MachineState *machine) &error_fatal); object_property_set_int(core, core_dt_id, CPU_CORE_PROP_CORE_ID, &error_fatal); + compat = spapr_get_cpu_compat_type(machine->cpu_model); + if (compat) { + object_property_set_str(core, compat, "compat", + &error_fatal); + g_free(compat); + } + object_property_set_bool(core, true, "realized", &error_fatal); } } diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 3a5da09..d500cd6 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -96,6 +96,31 @@ char *spapr_get_cpu_core_type(const char *model) return core_type; } +/* + * Returns the CPU compat type specified in -cpu @model. + */ +char *spapr_get_cpu_compat_type(const char *model) +{ + char *model_str = g_strdup(model); + char *featurestr, *compat = NULL; + + featurestr = model_str ? strtok(model_str, ",") : NULL; + while (featurestr) { + char *val; + if (!strncmp(featurestr, "compat=", 7)) { + val = strchr(featurestr, '='); + val++; + compat = g_strdup(val); + goto out; + } + featurestr = strtok(NULL, ","); + } + +out: + g_free(model_str); + return compat; +} + static void spapr_core_release(DeviceState *dev, void *opaque) { sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); @@ -223,12 +248,31 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, CPUCore *cc = CPU_CORE(dev); char *base_core_type = spapr_get_cpu_core_type(machine->cpu_model); const char *type = object_get_typename(OBJECT(dev)); + char *base_compat_type = NULL; + char *compat = NULL; + bool compat_set; if (strcmp(base_core_type, type)) { error_setg(&local_err, "CPU core type should be %s", base_core_type); goto out; } + base_compat_type = spapr_get_cpu_compat_type(machine->cpu_model); + compat = object_property_get_str(OBJECT(dev), "compat", NULL); + compat_set = compat && *compat; + + if (base_compat_type) { + if ((compat_set && strcmp(base_compat_type, compat)) || + !compat_set) { + error_setg(&local_err, "CPU compat type should be %s", + base_compat_type); + goto out; + } + } else if (compat_set) { + error_setg(&local_err, "CPU compat type shouldn't be set"); + goto out; + } + if (!smc->dr_cpu_enabled && dev->hotplugged) { error_setg(&local_err, "CPU hotplug not supported for this machine"); goto out; @@ -256,6 +300,8 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, } out: + g_free(compat); + g_free(base_compat_type); g_free(base_core_type); error_propagate(errp, local_err); } @@ -288,6 +334,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp) Error *local_err = NULL; Object *obj; int i; + char *compat = object_property_get_str(OBJECT(sc), "compat", NULL); + bool compat_set = compat && *compat; sc->threads = g_malloc0(size * cc->nr_threads); for (i = 0; i < cc->nr_threads; i++) { @@ -300,11 +348,18 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp) if (local_err) { goto err; } + if (compat_set) { + object_property_set_str(obj, compat, "compat", &local_err); + if (local_err) { + goto err; + } + } } object_child_foreach(OBJECT(dev), spapr_cpu_core_realize_child, &local_err); if (local_err) { goto err; } else { + g_free(compat); return; } @@ -315,9 +370,31 @@ err: i--; } g_free(sc->threads); + g_free(compat); error_propagate(errp, local_err); } +static char *spapr_cpu_core_prop_get_compat(Object *obj, Error **errp) +{ + sPAPRCPUCore *core = SPAPR_CPU_CORE(obj); + + return g_strdup(core->cpu_compat); +} + +static void spapr_cpu_core_prop_set_compat(Object *obj, const char *val, + Error **errp) +{ + sPAPRCPUCore *core = SPAPR_CPU_CORE(obj); + + core->cpu_compat = g_strdup(val); +} + +static void spapr_cpu_core_instance_init(Object *obj) +{ + object_property_add_str(obj, "compat", spapr_cpu_core_prop_get_compat, + spapr_cpu_core_prop_set_compat, NULL); +} + static void spapr_cpu_core_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); @@ -388,6 +465,7 @@ static const TypeInfo spapr_cpu_core_type_info = { .parent = TYPE_CPU_CORE, .abstract = true, .instance_size = sizeof(sPAPRCPUCore), + .instance_init = spapr_cpu_core_instance_init, .class_init = spapr_cpu_core_class_init, }; diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h index 1c9b319..e697dab 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -24,11 +24,13 @@ typedef struct sPAPRCPUCore { /*< public >*/ void *threads; ObjectClass *cpu_class; + char *cpu_compat; } sPAPRCPUCore; void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); char *spapr_get_cpu_core_type(const char *model); +char *spapr_get_cpu_compat_type(const char *model); void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,