Received: by 2002:ac2:51c9:0:0:0:0:0 with SMTP id u9csp347894lfm; Sun, 16 May 2021 03:32:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyURKgTrWePCh+Z7Z3Ghgs2xEPRb42VJfhjRthGTZ0ak/YmgFFJwiXhIs3wysdDgasUVMRy X-Received: by 2002:a25:10d6:: with SMTP id 205mr58681982ybq.83.1621161143902; Sun, 16 May 2021 03:32:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621161143; cv=none; d=google.com; s=arc-20160816; b=Ww2HSzVv2adp0E7xtZwsudlapcEdgFHVqm7wZp1sUGoaPXmezhLh5gyNUumrb5/Cf+ VevBARtqd5lh6DnQrZkq4V85ezZIOLbG3shj0IGXrNnW3mCju+h/aGp7i+P/nw5Bm8lW SA9XqxG2ngd6d31OyVoOh9QN2YAqnONDYYnhwVuLUmqKN6JZ4D5tAatN2tXj2bCtBvfM tfohQ28yjhx6XNnYsytYTNG0rYVWT8ANle1KaDzkeUvbODb4Re4xIBivrPMPQD6k5n4W sV+w4gTj9NFRzsQ8dmUX4ZOH7hyrJbl27HBd9ZoktMe5Ckahrn1x9hvTRkL9AMWSsgCF TpsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:references :in-reply-to:message-id:date:subject:to:from; bh=hyBy29f7ckLWBtyOr9BkT3NIccjy9OqxD85q3kw6Xyk=; b=GU2RMMX8arQskHwIXPP3/+jyA5XbPkhRG/9fKAXjfUJWSMyyUBkOBSdHc/Ol9H5rFe slxC/yGAuvmg/qptCn8asXOkB8W5/JIZHaRBRM2pfOTI0rB96q4iLlUfl+Bw7cSib9w9 yYSgabCtzxw570zeqRXZgtrvkShcU614B5tNFYppG7jrDLjSITTx5iqT68KdNFw/nz+Y 8O34BVaNIeUTndZGqIgwuFsJyl7b0WRnnQ59DrMgqmJq/lFPVSJm2gtSoH+c2+Lpte/o U9djcbLsgLcxYTpNMcZ/4b2IUY0dNh+7z3JWNROBRPh+D9ya1akKXgZRaEt7JJJWsCB1 oyHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v140si815372ybe.270.2021.05.16.03.32.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 May 2021 03:32:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: from localhost ([::1]:57834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1liE4N-0007AY-8M for alex.bennee@linaro.org; Sun, 16 May 2021 06:32:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1liE1X-0001Tr-O9; Sun, 16 May 2021 06:29:27 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1liE1M-0007BT-13; Sun, 16 May 2021 06:29:26 -0400 Received: from dggems703-chm.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Fjdhy1g1GzmVW6; Sun, 16 May 2021 18:26:26 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggems703-chm.china.huawei.com (10.3.19.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sun, 16 May 2021 18:29:09 +0800 Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sun, 16 May 2021 18:29:08 +0800 From: Yanan Wang To: Peter Maydell , Andrew Jones , "Michael S . Tsirkin" , Igor Mammedov , Shannon Zhao , "Alistair Francis" , David Gibson , , Subject: [RFC PATCH v3 3/9] hw/arm/virt: Add cpu-map to device tree Date: Sun, 16 May 2021 18:28:54 +0800 Message-ID: <20210516102900.28036-4-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210516102900.28036-1-wangyanan55@huawei.com> References: <20210516102900.28036-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500023.china.huawei.com (7.185.36.83) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.191; envelope-from=wangyanan55@huawei.com; helo=szxga05-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Barry Song , zhukeqian1@huawei.com, yangyicong@huawei.com, prime.zeng@hisilicon.com, wanghaibin.wang@huawei.com, yuzenghui@huawei.com, Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: rRb5PZCdPs6G From: Andrew Jones Support device tree CPU topology descriptions. In accordance with the Devicetree Specification, the Linux Doc "arm/cpus.yaml" requires that cpus and cpu nodes in the DT are present. And we meet the requirement by creating /cpus/cpu@* nodes for members within ms->smp.cpus. Correspondingly, we should also create subnodes in cpu-map for the present cpus, each of which relates to an unique cpu node. Signed-off-by: Andrew Jones Co-developed-by: Yanan Wang Signed-off-by: Yanan Wang --- hw/arm/virt.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index c07841e3a4..e5dcdebdbc 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -349,10 +349,11 @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms) int cpu; int addr_cells = 1; const MachineState *ms = MACHINE(vms); + const VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms); int smp_cpus = ms->smp.cpus; /* - * From Documentation/devicetree/bindings/arm/cpus.txt + * See Linux Documentation/devicetree/bindings/arm/cpus.yaml * On ARM v8 64-bit systems value should be set to 2, * that corresponds to the MPIDR_EL1 register size. * If MPIDR_EL1[63:32] value is equal to 0 on all CPUs @@ -405,8 +406,46 @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms) ms->possible_cpus->cpus[cs->cpu_index].props.node_id); } + if (!vmc->no_cpu_topology) { + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", + qemu_fdt_alloc_phandle(ms->fdt)); + } + g_free(nodename); } + + if (!vmc->no_cpu_topology) { + /* + * See Linux Documentation/devicetree/bindings/cpu/cpu-topology.txt + * In a SMP system, the hierarchy of CPUs is defined through four + * entities that are used to describe the layout of physical CPUs + * in the system: socket/cluster/core/thread. + */ + qemu_fdt_add_subnode(ms->fdt, "/cpus/cpu-map"); + + for (cpu = smp_cpus - 1; cpu >= 0; cpu--) { + char *cpu_path = g_strdup_printf("/cpus/cpu@%d", cpu); + char *map_path; + + if (ms->smp.threads > 1) { + map_path = g_strdup_printf( + "/cpus/cpu-map/%s%d/%s%d/%s%d", + "socket", cpu / (ms->smp.cores * ms->smp.threads), + "core", (cpu / ms->smp.threads) % ms->smp.cores, + "thread", cpu % ms->smp.threads); + } else { + map_path = g_strdup_printf( + "/cpus/cpu-map/%s%d/%s%d", + "socket", cpu / ms->smp.cores, + "core", cpu % ms->smp.cores); + } + qemu_fdt_add_path(ms->fdt, map_path); + qemu_fdt_setprop_phandle(ms->fdt, map_path, "cpu", cpu_path); + + g_free(map_path); + g_free(cpu_path); + } + } } static void fdt_add_its_gic_node(VirtMachineState *vms) -- 2.19.1