From patchwork Wed May 13 10:48:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenyu Zheng X-Patchwork-Id: 186588 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp343459ilb; Wed, 13 May 2020 03:51:20 -0700 (PDT) X-Google-Smtp-Source: APiQypKcjK+mwZ3IwOohdUGf39Oqg2L6hgPVkcXbiftf3upYicfbuH1B3pxvr6oVPhwEy/uV6sjr X-Received: by 2002:a17:906:31da:: with SMTP id f26mr18437266ejf.308.1589367079956; Wed, 13 May 2020 03:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589367079; cv=none; d=google.com; s=arc-20160816; b=QrQL4nYXDh24hef4Dn8ecKpI9VVQNa4VmkbUxpkZf67PehFo9rOKeLw15jtiVSW48h jP9yyWOFb8WrQfL7GWq8WgamLrBROzgsA+lOAd+ExFyhFTH5+XyBit8WMA8jg+sgOsOT pGwyMVBnfBzekT8A8U6BmX2LEKGQYeQPeT3HjZRtToiwJECqqmnHI16NMpv1JEEWuf2O TxfFWCVEBpeT/okqSevlxUTb/tNF+pp96cbUNMlA8Ylgyu0zt6K/yzIw3EPPeTgQKzWp X/blexVXNHXKlyXaG0aRnQ86LIdZU1S2OVT3jt4LM4zx43ffzXGEZewiG7DPmMnqLgl3 5JkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:errors-to:sender:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:cc :mime-version:references:in-reply-to:message-id:date:subject:to:from :delivered-to:dkim-signature; bh=FIllbGoHvLfePiJ4hEeXgn2dg8GUAUTp5k702bSMnko=; b=ne+BrnybB25+/63AziC96degWU1NuBXUeD0uFJnqdLudzAnhisWYRRUYPiW1QIJ3ma 1dp9tHL/ic+xtTxzT12HUF4HKROBFAykyFfzDFOtKByO/V1x9VcIymKGYQE6NdbjKuQF 39l6QHbbVChhfweEHw5pWb2m21ZxHM8KwKvjJIvlyvSBiWM55GScLXWjaoDtPmLzPlOu 3h7T87r2FwJXe7M+d+xTw/y4Z+47ZMgd++JzXBtgXmT7UCC5wkU7yvDmQXKCAjtMVnJQ FevHrWSWT/g4UAaZxbgU4cwcyiSFDFppQn3cVGIRJnf1WMl+t0pNF2iqkeBXFq5kY6cO h8uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X9AfFVcJ; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com. [207.211.31.120]) by mx.google.com with ESMTPS id l30si6442778edj.293.2020.05.13.03.51.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 May 2020 03:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X9AfFVcJ; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589367078; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FIllbGoHvLfePiJ4hEeXgn2dg8GUAUTp5k702bSMnko=; b=X9AfFVcJWhOzmX9FSWC/1rD0ylKo3cQ3CrmghNey71kU76zXbgPmqKRxPxPaHifh40C6Lj 6+Vih5yGxj2njx5A/9U/jCRyYJ7cyfABb6bl8om+dHu3+7FBvKvBYa4zR+PNvuh/QMzebB EEjaSHzG6ZMPsGBXEI3Uj4O7O933Scg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-391-FWkF4IlPN5WZGSs8kgwY4w-1; Wed, 13 May 2020 06:51:16 -0400 X-MC-Unique: FWkF4IlPN5WZGSs8kgwY4w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D2C90835B92; Wed, 13 May 2020 10:51:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 60A02619A7; Wed, 13 May 2020 10:51:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 096821809543; Wed, 13 May 2020 10:51:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04DAoNe9010283 for ; Wed, 13 May 2020 06:50:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id B204A2156A2D; Wed, 13 May 2020 10:50:23 +0000 (UTC) Delivered-To: libvir-list@redhat.com Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC52B2166BA4 for ; Wed, 13 May 2020 10:50:20 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A9A10916104 for ; Wed, 13 May 2020 10:50:20 +0000 (UTC) Received: from APC01-PU1-obe.outbound.protection.outlook.com (mail-oln040092254053.outbound.protection.outlook.com [40.92.254.53]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-2eXOJsTlNJ-Cs-hdzByoVw-1; Wed, 13 May 2020 06:50:18 -0400 X-MC-Unique: 2eXOJsTlNJ-Cs-hdzByoVw-1 Received: from SG2APC01FT003.eop-APC01.prod.protection.outlook.com (2a01:111:e400:7ebd::42) by SG2APC01HT108.eop-APC01.prod.protection.outlook.com (2a01:111:e400:7ebd::498) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27; Wed, 13 May 2020 10:50:14 +0000 Received: from TY2PR01MB3113.jpnprd01.prod.outlook.com (10.152.250.56) by SG2APC01FT003.mail.protection.outlook.com (10.152.250.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Wed, 13 May 2020 10:50:14 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:CE0CC333F5A9331A8D4A36DBF0BEE3C87202A1870C105CD67C2DA87717B6682F; UpperCasedChecksum:BF85FBF43901180E4109A4318EF5B262FD69E5D06420A19AB3D4AC54BC831937; SizeAsReceived:7597; Count:50 Received: from TY2PR01MB3113.jpnprd01.prod.outlook.com ([fe80::b9e6:3960:1f6:7d81]) by TY2PR01MB3113.jpnprd01.prod.outlook.com ([fe80::b9e6:3960:1f6:7d81%7]) with mapi id 15.20.2979.033; Wed, 13 May 2020 10:50:14 +0000 From: Zhenyu Zheng To: libvir-list@redhat.com Subject: [PATCH V5 2/4] cpu: Add helper functions to parse vendor and model Date: Wed, 13 May 2020 18:48:32 +0800 Message-ID: In-Reply-To: <20200513104832.7390-1-zheng.zhenyu@outlook.com> References: <20200513104832.7390-1-zheng.zhenyu@outlook.com> X-ClientProxiedBy: HK2PR0401CA0023.apcprd04.prod.outlook.com (2603:1096:202:2::33) To TY2PR01MB3113.jpnprd01.prod.outlook.com (2603:1096:404:78::22) X-Microsoft-Original-Message-ID: <20200513104832.7390-3-zheng.zhenyu@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.8.114.27) by HK2PR0401CA0023.apcprd04.prod.outlook.com (2603:1096:202:2::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24 via Frontend Transport; Wed, 13 May 2020 10:50:14 +0000 X-Microsoft-Original-Message-ID: <20200513104832.7390-3-zheng.zhenyu@outlook.com> X-TMN: [8y75GH8dcqBD5Z2yQCjTxY8S3dWHvTOV] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 5747e434-4f7b-4b2a-70bf-08d7f72b6abb X-MS-Exchange-SLBlob-MailProps: mBRmoEB1kyL4voMrsTyEApS0tCh7wjsR7MDEl5fY9uySxqLLueamJ8vS2NKTa84OOljcuUbYyPb24j2jQkBszhSUq4NVjrLOIkh3xaBZ403Ps7gwFxhhepJ1AYdUhUnT8bHhtbpnk5pUuf4D0BRo8Ws9TQb/Lb3C+KAidi2VEPIgwLArBYDYy3XX6jwSlQmlg7FwnnWYEAPQO6EzZAGuVLl9/H12H3o9WlFzyN8EeiJ3qgBMS9Pd2gCUDr1YoEMQbZ6HlOiUUOEz7oh0mg/HsTHm1GsRQtRzSypiAUY4Y+HnpKbAXTN6sFsSh7mxEwQXSKkr5p3BmyQ4upvEwfIQJY+1JzXQifitcKvZLQnM36vBqbSDtfm4Zk289FkX2g9PXk0q2HfkqH/lmMBXC62+x68eCLPtRYo9IUF+TJS+E1Qr7XeqW9WN0U91ZJIBPQjAluXt9DqLfaJcBiAZexKfwW1u4OtAtoGFQcOrFcZQrnJ4lExcisifAjRR9ILd0S7Li1X2KAOg4IQf5gY+PlujBIz2IoH3eO0jguSsxOuW2SQ8IyU0YmNJwfR/JwL78Sd90JjwwF3JmLa4Vg9scI75RP1addgx4FHHnVx5UJ51oNLNagWrO10aD8FCnq1+Uv8MNUKqZBLifvmngnd33jlBa/B+aEzg/FYFIlhKjvmyP13ygkEHWxAArKOzHuzyxAYQn1zYpvsskT+8vzroIU0OAALK9Sfnhlb4MdpbGwAuKMPIqQKUL1HFGhRYh182B0qi57HT/zYiQCo= X-MS-TrafficTypeDiagnostic: SG2APC01HT108: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9yRMFt2bprmzVHT6+pBjNbLS9VKy43jM+8PIRwrUpTKTl+jfNN3oKEbb5CL9zyrTbljJD4lerJT8JbuzfDIvOwa/bdViHTbjQ2rMhRuiPNiQt6f17LDhlWT/9WGd+PzTJXQpuhiY6/DL1uzbn1LMuklVaBbumZR2XrQY/R1xWagcVHf7wvnXzKlaNKpZjrSVPZcSyrqk+5pVLbbT+tqTzg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:0; SRV:; IPV:NLI; SFV:NSPM; H:TY2PR01MB3113.jpnprd01.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:; DIR:OUT; SFP:1901; X-MS-Exchange-AntiSpam-MessageData: j0bVZMb0Acguk5UfmGH7e9k1Dx+oOpQpR5lNnh8vjv/xU9d7MjNW3W/85SO+eqQRzxxRG8PtfCJU0GMeCyKdRryvG6SS09Ojel/kGjAfEWyUp6YZWfl1lADMcIqk+D0l6zAzVBzPkU0UNuo5p5hORw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5747e434-4f7b-4b2a-70bf-08d7f72b6abb X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 May 2020 10:50:14.5416 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2APC01HT108 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 04DAoNe9010283 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Wed, 13 May 2020 06:51:05 -0400 Cc: Zhenyu Zheng X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Add helper functions to parse vendor and model for ARM CPUs, and use them as callbacks when load cpu maps. Signed-off-by: Zhenyu Zheng --- src/cpu/cpu_arm.c | 159 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 1bb0afb762..c7a6abfb22 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -165,6 +165,7 @@ virCPUarmMapFree(virCPUarmMapPtr map) virCPUarmVendorFree(map->vendors[i]); g_free(map->vendors); + g_ptr_array_free(map->features, TRUE); g_free(map); @@ -210,6 +211,160 @@ virCPUarmMapFeatureParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED, return 0; } +static virCPUarmVendorPtr +virCPUarmVendorFindByID(virCPUarmMapPtr map, + unsigned long vendor_id) +{ + size_t i; + + for (i = 0; i < map->nvendors; i++) { + if (map->vendors[i]->value == vendor_id) + return map->vendors[i]; + } + + return NULL; +} + + +static virCPUarmVendorPtr +virCPUarmVendorFindByName(virCPUarmMapPtr map, + const char *name) +{ + size_t i; + + for (i = 0; i < map->nvendors; i++) { + if (STREQ(map->vendors[i]->name, name)) + return map->vendors[i]; + } + + return NULL; +} + + +static int +virCPUarmVendorParse(xmlXPathContextPtr ctxt, + const char *name, + void *data) +{ + virCPUarmMapPtr map = data; + g_autoptr(virCPUarmVendor) vendor = NULL; + + vendor = g_new0(virCPUarmVendor, 1); + vendor->name = g_strdup(name); + + if (virCPUarmVendorFindByName(map, vendor->name)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("CPU vendor %s already defined"), + vendor->name); + return -1; + } + + if (virXPathULongHex("string(@value)", ctxt, &vendor->value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Missing CPU vendor value")); + return -1; + } + + if (virCPUarmVendorFindByID(map, vendor->value)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("CPU vendor value 0x%2lx already defined"), + vendor->value); + return -1; + } + + if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0) + return -1; + + return 0; +} + +static virCPUarmModelPtr +virCPUarmModelFind(virCPUarmMapPtr map, + const char *name) +{ + size_t i; + + for (i = 0; i < map->nmodels; i++) { + if (STREQ(map->models[i]->name, name)) + return map->models[i]; + } + + return NULL; +} + +#if defined(__aarch64__) +static virCPUarmModelPtr +virCPUarmModelFindByPVR(virCPUarmMapPtr map, + unsigned long pvr) +{ + size_t i; + + for (i = 0; i < map->nmodels; i++) { + if (map->models[i]->data.pvr == pvr) + return map->models[i]; + } + + return NULL; +} +#endif + +static int +virCPUarmModelParse(xmlXPathContextPtr ctxt, + const char *name, + void *data) +{ + virCPUarmMapPtr map = data; + virCPUarmModel *model; + g_autofree xmlNodePtr *nodes = NULL; + g_autofree char *vendor = NULL; + + model = g_new0(virCPUarmModel, 1); + model->name = g_strdup(name); + + if (virCPUarmModelFind(map, model->name)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("CPU model %s already defined"), + model->name); + return -1; + } + + if (virXPathBoolean("boolean(./vendor)", ctxt)) { + vendor = virXPathString("string(./vendor/@name)", ctxt); + if (!vendor) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid vendor element in CPU model %s"), + model->name); + return -1; + } + + if (!(model->vendor = virCPUarmVendorFindByName(map, vendor))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown vendor %s referenced by CPU model %s"), + vendor, model->name); + return -1; + } + } + + if (!virXPathBoolean("boolean(./pvr)", ctxt)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing PVR information for CPU model %s"), + model->name); + return -1; + } + + if (virXPathULongHex("string(./pvr/@value)", ctxt, &model->data.pvr) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing or invalid PVR value in CPU model %s"), + model->name); + return -1; + } + + if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0) + return -1; + + return 0; +} + static virCPUarmMapPtr virCPUarmLoadMap(void) { @@ -217,7 +372,8 @@ virCPUarmLoadMap(void) map = virCPUarmMapNew(); - if (cpuMapLoad("arm", NULL, virCPUarmMapFeatureParse, NULL, map) < 0) + if (cpuMapLoad("arm", virCPUarmVendorParse, virCPUarmMapFeatureParse, + virCPUarmModelParse, map) < 0) return NULL; return g_steal_pointer(&map); @@ -279,6 +435,7 @@ virCPUarmUpdate(virCPUDefPtr guest, return ret; } + static virCPUDefPtr virCPUarmBaseline(virCPUDefPtr *cpus, unsigned int ncpus G_GNUC_UNUSED,