From patchwork Mon Jul 1 06:19:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 11024969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 48A3614F6 for ; Mon, 1 Jul 2019 06:20:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4980628113 for ; Mon, 1 Jul 2019 06:20:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D4E5284DA; Mon, 1 Jul 2019 06:20:54 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CAA64284B3 for ; Mon, 1 Jul 2019 06:20:53 +0000 (UTC) Received: from localhost ([::1]:48090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhpgK-000660-QY for patchwork-qemu-devel@patchwork.kernel.org; Mon, 01 Jul 2019 02:20:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42175) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhpfU-0005Pf-1v for qemu-devel@nongnu.org; Mon, 01 Jul 2019 02:20:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhpfT-0000ac-03 for qemu-devel@nongnu.org; Mon, 01 Jul 2019 02:19:59 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:33204) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hhpfQ-0000YO-FK; Mon, 01 Jul 2019 02:19:56 -0400 Received: by mail-pl1-x641.google.com with SMTP id c14so6779063plo.0; Sun, 30 Jun 2019 23:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=CPCt4ap55kJWMYFEEuGUSXfENIIqmZAQJDkEOlJni18=; b=MmKUUcnpBuehyYP8twWZ2PbA+dyejxTsjcE13WBC1DTcYQCUq3G5bP1X4WjNVY+S8Z rUx3h+ysJrqF9T2gTf4nWRFhP8vvnQMFUHncEouDkY0xfBkX9CipNN0htLWhg2dF65qn sAfvlOFJUuLbKnKIBLG1tUUrtN8TCteR/HFSVSXKgo5rTs21d/oUyXqGOX8pLLxGduIl SysDfu2ps0LBNQE3xNjpox4z8y5B4LDIf5FW/ldtyh1hSCeuUSNTF2xxK5AQ6tBbaLBl ZL5lsIBh039jRw/FnJQQfJGWnq/XpCbrdnOmNwemzOp5leEsRNRgJc6jZHe/h9ebS1kP WZ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=CPCt4ap55kJWMYFEEuGUSXfENIIqmZAQJDkEOlJni18=; b=GtipC2MJvzz671TlhCEV4e8XUbFGvkWN7lgFJahd3moKDWWhgqRyFu6D6acTt+iYTd ywgNPuXERhBtIUvZIc1CqCVxFWZ8uQs/v3YLv57RoQBHJH+rFOrT6qodpnhMUn2frhq+ M93Cbs2DsZ1jXQ8DDyKSkR+mVd7PBfYfpXOjFe1N26ejB27Ct4eTYBsuGyjENuqpKmWP n+QtIsnsWaUzH6aivtdC3KUO1wOdSKnV7HkHg6akHxq9AzW6PhuW/K7ATc2i6yDcZZd8 R84VUHhH3Q/NkOEDG1WdiParmdDfs8l5XSxwKx/Bfdj8Qwb+YQne9VkfeRp29COfHNWU 1Y4w== X-Gm-Message-State: APjAAAXNu8g/vZTNFEIiWGSCAhHta8sOxiYZBZ6mhkyHPZRyw9or6Gjs SW5zSmYGqwdUezX0OVGtsPI64jC5 X-Google-Smtp-Source: APXvYqwL73Rp2IdWgLy2lxX1X08QdlEa+ZdinrVS4TWY3OpEsmMaidOGhW2XdpPbLfFlKIBlvyszUw== X-Received: by 2002:a17:902:e2:: with SMTP id a89mr27271273pla.210.1561961995165; Sun, 30 Jun 2019 23:19:55 -0700 (PDT) Received: from surajjs2.ozlabs.ibm.com.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id v22sm4981227pgk.69.2019.06.30.23.19.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 30 Jun 2019 23:19:54 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Mon, 1 Jul 2019 16:19:46 +1000 Message-Id: <20190701061946.32636-1-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [QEMU-PPC] [PATCH v3] powerpc/spapr: Add host threads parameter to ibm, get_system_parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-devel@nongnu.org, sjitindarsingh@gmail.com, 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 The ibm,get_system_parameter rtas call is used by the guest to retrieve data relating to certain parameters of the system. The SPLPAR characteristics option (token 20) is used to determin characteristics of the environment in which the lpar will run. It may be useful for a guest to know the number of physical host threads present on the underlying system where it is being run. Add the characteristic "HostThrs" to the SPLPAR Characteristics ibm,get_system_parameter rtas call to expose this information to a guest and provide an implementation which determines this information based on the number of interrupt servers present in the device tree. Signed-off-by: Suraj Jitindar Singh Reviewed-by: Greg Kurz --- V1 -> V2: - Take into account that the core may be operating in split core mode meaning a single core may be split into multiple subcores. V2 -> V3: - Add curly braces for single line if statements --- hw/ppc/spapr_rtas.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 5bc1a93271..1bab71c90c 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -229,6 +229,58 @@ static inline int sysparm_st(target_ulong addr, target_ulong len, return RTAS_OUT_SUCCESS; } +#define CPUS_PATH "/proc/device-tree/cpus/" +#define SUBCORE_PATH "/sys/devices/system/cpu/subcores_per_core" + +static int rtas_get_num_host_threads(void) +{ + int num_threads = -1; + unsigned long len; + const char *entry; + char *buf; + GDir *dir; + + if (!kvm_enabled()) { + return 1; + } + + /* Read interrupt servers to determine number of threads per core */ + dir = g_dir_open(CPUS_PATH, 0, NULL); + if (!dir) { + return -1; + } + + while ((entry = g_dir_read_name(dir))) { + if (!strncmp(entry, "PowerPC,POWER", strlen("PowerPC,POWER"))) { + char *path; + + path = g_strconcat(CPUS_PATH, entry, "/ibm,ppc-interrupt-server#s", + NULL); + if (g_file_get_contents(path, &buf, &len, NULL)) { + num_threads = len / sizeof(int); + g_free(buf); + } + + g_free(path); + break; + } + } + + g_dir_close(dir); + + /* Check if split core mode in use */ + if (g_file_get_contents(SUBCORE_PATH, &buf, &len, NULL)) { + int subcores = g_ascii_strtoll(buf, NULL, 10); + + if (subcores) { + num_threads /= subcores; + } + g_free(buf); + } + + return num_threads; +} + static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, @@ -250,6 +302,16 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, current_machine->ram_size / MiB, smp_cpus, max_cpus); + int num_host_threads = rtas_get_num_host_threads(); + + if (num_host_threads > 0) { + char *hostthr_val, *old = param_val; + + hostthr_val = g_strdup_printf(",HostThrs=%d", num_host_threads); + param_val = g_strconcat(param_val, hostthr_val, NULL); + g_free(hostthr_val); + g_free(old); + } ret = sysparm_st(buffer, length, param_val, strlen(param_val) + 1); g_free(param_val); break;