From nobody Tue May 7 12:16:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1561526422; cv=none; d=zoho.com; s=zohoarc; b=mXphNnrzNCmJYFKjyiwdVVuuCUtkxaSru89C+b0vpKmw7rkrcrb0A7Z1PI0EhbQQv6jDDGXrBnhsYEXuwRsDlZ3zjXWh1HKa9rJRPSgratYEFTK84ANOMSupfiRLw/Wn+PrXm7mG3txjTk66KWHqcNV6Ghktv3Yd8tWjCnbhqPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561526422; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=XwpxBVl70guybapI8XVHMxeo9/0ZLkhofCzAVm65pUM=; b=PVwP9TkI1KMkQ/RvgklHHhTWyli/gPADrWTfRmbdP2jri8y6ncmgSVN4W+AzuTKhkL2/NEPGaP9CK0BoGnzYdl3nP8dXEwxETF2naW5gk+lYKsPpER8sPIkMRQNAbI+fE+CVlwt+0YSsgYas00FXVBlzr4OsmHsVFTrNjq4/pvQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561526422319858.1050516090185; Tue, 25 Jun 2019 22:20:22 -0700 (PDT) Received: from localhost ([::1]:36770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hg0Ly-00086e-AK for importer@patchew.org; Wed, 26 Jun 2019 01:20:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32883) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hg0LC-0007Zs-3R for qemu-devel@nongnu.org; Wed, 26 Jun 2019 01:19:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hg0LB-0007dS-3T for qemu-devel@nongnu.org; Wed, 26 Jun 2019 01:19:30 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:33748) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hg0L8-0007ad-6k; Wed, 26 Jun 2019 01:19:26 -0400 Received: by mail-pg1-x541.google.com with SMTP id m4so624323pgk.0; Tue, 25 Jun 2019 22:19:26 -0700 (PDT) Received: from surajjs2.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id e188sm10037746pfh.99.2019.06.25.22.19.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jun 2019 22:19:23 -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=XwpxBVl70guybapI8XVHMxeo9/0ZLkhofCzAVm65pUM=; b=TlgQeGvMtBE8Dexm1PbxuU0DaYM1WO3KFf+g5Cq73NkA9xGgE6aW24yAFREUe2aSwe U2iNg46XOs1Dian79E0xrdnVizNgUksKsxnURBbdMpyC5i0raBAS+c7Q4tFWDBxrnQRu tWf7qfWXlBhqQ1lXWT6NtGOrchVV+tUfnyYb0JAxc0zIEbRyqbmsXoZQ6ajd3aDwosEt UYkCJQra741yf89NZ7ntOv3eWzDkrRNeZNe2Kmn65kRzDmAh+VWROT3XBfhvi/NqUd4W pt7SFH7K6ad2ZGlXQXsxVHSbhA9NuK5OKheqc86T7CnD3iQp/pyAh+FJTxSJmY/Zk2PO b/bw== 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=XwpxBVl70guybapI8XVHMxeo9/0ZLkhofCzAVm65pUM=; b=g+RMtz67bq0+i3p5kF5JDKsZYapRVFTc7dFwaKalli10/uI250fUoK4zdBwaCfOuEd Z8PkRXc9qDlbR6aNUtPx5SVMK7DIJVOcaLQYyfZZ0e5QDOuDqGdIVzdwtnPUpKp3ELHE KLfAyLKwkqYnN2T1UhbhGR/Rj68PmV+2Faqehv00vdJV67Js90QJqzJ/A5SduxJzseV4 ai89ewKKQaXqHrMXLjoryFp3MXYN/Sf28O9MWVFWWWSDkP056uddGlxA8xwZCG+RafMw SGvwh6D8CfP51beVghoh3+RyYJgSqaiqsXqiXR9MuAxtpUr2CnfjdQdy5pytUfF68/bB iAmQ== X-Gm-Message-State: APjAAAVlxUy2r8gw8ffVauhJh4FHcXum/p6dM7Ef+KNyP7VMRglqySi3 TdtoPV928qxnkhyYAA3f11nEs4EM X-Google-Smtp-Source: APXvYqygcWm8qmZ1LPbbUqfSXcCQfIcPsju6+f1eoMB+zXm/kSwMfIJVN1S2Zszr2Y5OqqVBjIDHNQ== X-Received: by 2002:a63:6011:: with SMTP id u17mr975907pgb.117.1561526364671; Tue, 25 Jun 2019 22:19:24 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Wed, 26 Jun 2019 15:19:03 +1000 Message-Id: <20190626051903.26829-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::541 Subject: [Qemu-devel] [QEMU-PPC] [PATCH v2] 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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. --- hw/ppc/spapr_rtas.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 59 insertions(+) diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 5bc1a93271..9b15e7606b 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -229,6 +229,55 @@ static inline int sysparm_st(target_ulong addr, target= _ulong len, return RTAS_OUT_SUCCESS; } =20 +#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 =3D -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 =3D g_dir_open(CPUS_PATH, 0, NULL); + if (!dir) + return -1; + + while ((entry =3D g_dir_read_name(dir))) { + if (!strncmp(entry, "PowerPC,POWER", strlen("PowerPC,POWER"))) { + char *path; + + path =3D g_strconcat(CPUS_PATH, entry, "/ibm,ppc-interrupt-ser= ver#s", + NULL); + if (g_file_get_contents(path, &buf, &len, NULL)) { + num_threads =3D 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 =3D g_ascii_strtoll(buf, NULL, 10); + + if (subcores) + num_threads /=3D 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 +299,16 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *= cpu, current_machine->ram_size / MiB, smp_cpus, max_cpus); + int num_host_threads =3D rtas_get_num_host_threads(); + + if (num_host_threads > 0) { + char *hostthr_val, *old =3D param_val; + + hostthr_val =3D g_strdup_printf(",HostThrs=3D%d", num_host_thr= eads); + param_val =3D g_strconcat(param_val, hostthr_val, NULL); + g_free(hostthr_val); + g_free(old); + } ret =3D sysparm_st(buffer, length, param_val, strlen(param_val) + = 1); g_free(param_val); break; --=20 2.13.6