From nobody Wed Nov 27 19:48:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1697644515; cv=none; d=zohomail.com; s=zohoarc; b=FcAjsve91tapGRWaV9xmow+wMG1besCYHYAXpUWNrYzjIzKGUIXynNFZztUaADoGR5aFfAClgwgTrTThEnBgOVFW2RHE40zJvkOSXXXRkyg3mvCgmuKXPCANYnIfBjGTc7Z4z3lluLY6W1Mdd6KomcsuhfkgYkOtdr4IYWFlOB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697644515; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HGbWylb8H+QpIrFYsSYMoQCOLgbUc7uDdWXTJl1zQX0=; b=WI+v0VepRbuMOv7KLwPbDEwfAL3/oEhlfPUfyt+4lpWEQO2CQiTcWMeioP2AwEd68QCRmeV4AGYmxoEKqgjdZ91bzxLEuKNiwaSe1NUeEjykV00zp2ZuAP4WniAxlUns3RRHDD7n4Rc6Cgrr8nqSQzh1A+v2FcmpRckkjNX2CRc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697644515389828.6433189005954; Wed, 18 Oct 2023 08:55:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qt8sF-0007rx-MZ; Wed, 18 Oct 2023 11:54:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qt8sD-0007oQ-D2 for qemu-devel@nongnu.org; Wed, 18 Oct 2023 11:54:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qt8sB-0006PW-J3 for qemu-devel@nongnu.org; Wed, 18 Oct 2023 11:54:17 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-15-Z1m2ZjZOOS2WqcjT2IR45A-1; Wed, 18 Oct 2023 11:54:13 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-402cd372b8bso54051965e9.2 for ; Wed, 18 Oct 2023 08:54:13 -0700 (PDT) Received: from redhat.com ([2a02:14f:1f2:2037:f34:d61b:7da0:a7be]) by smtp.gmail.com with ESMTPSA id z6-20020a05600c220600b00405c33a9a12sm1251228wml.0.2023.10.18.08.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 08:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697644454; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HGbWylb8H+QpIrFYsSYMoQCOLgbUc7uDdWXTJl1zQX0=; b=ZeMljxQUsQQ9R1wCvlAzI7SSJL+lY0cewM4+qwjn9i/feT4OoSFQ2oAzb8yN1WfgpTPF/s fvI23KNIcI9ADUy3sRXcmlds1ijkC7L7nry5yPJ78tDSaZLhq4uMxBki/DI1RalgIQJW2l LnYmu+fzmTgX0tlZzR5PqN21+AF10BQ= X-MC-Unique: Z1m2ZjZOOS2WqcjT2IR45A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697644451; x=1698249251; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HGbWylb8H+QpIrFYsSYMoQCOLgbUc7uDdWXTJl1zQX0=; b=S1p7uxNu8rhVwgvf7NUowJPCdEmuehbDhXGdCoUA8UpeDtVKghtLOg3pxoFeVKA56h tXrZla6Y0Kf/lGIBhpjUp3IAs4zY13EEgMU5LI6EZVHfmSBvWWyEwMXqBDWiERzjIerh oAglAcUH0xZ0LBwQuVJvqkV+CAIQ+eQ100wfSNT8MNh4teC9XDhgFqSRppMk5WU/lB3Q QI9KdFvhGmJXJPoPrxwGLzFGJe6ysIWCTtggv470CuKcOXZTwDn6BcgrZKR6Sk/TKyDv aDEkyk5MeWvfvyyWsKuHy+DBQAwFmV9e0wobtSmIZ1LcD2fy2mrWyLPC6Dg3WtrQi3VN gOCw== X-Gm-Message-State: AOJu0YxZtQNzJ+jHNNetchp3JxiZpG5XTs1T3zCgrneDnc0u1Bq5VRBD 9dvrZmPII7wI57UfU5TLsMUN6/rsRhStPj8fmvcp1N+iaNQEFzq4flw/UWOg3QChpvhqiT1ZIoa iVSY/1k1Cx3CRUGu/OHLyjJ0RbaVrtiVeTG/jaGQZ8RWJLs0Ci3n3e3AkEhdAgE+m/Gy8BPs= X-Received: by 2002:a05:600c:524d:b0:405:1bbd:aa9c with SMTP id fc13-20020a05600c524d00b004051bbdaa9cmr4335881wmb.34.1697644451740; Wed, 18 Oct 2023 08:54:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+Zg7TCOKY3RgV7a4OWMuk0PtF+D6hpxX4UgTpTnGgQTTATsQoRNFk3hE10vu3H4jrX5p9ZA== X-Received: by 2002:a05:600c:524d:b0:405:1bbd:aa9c with SMTP id fc13-20020a05600c524d00b004051bbdaa9cmr4335862wmb.34.1697644451453; Wed, 18 Oct 2023 08:54:11 -0700 (PDT) Date: Wed, 18 Oct 2023 11:54:06 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zhao Liu , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Yanan Wang Subject: [PULL 13/83] tests: test-smp-parse: Add the test for cores/threads per socket helpers Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697644517196100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zhao Liu Use the different ways to calculate cores/threads per socket, so that the new CPU topology levels won't be missed in these 2 helpes: * machine_topo_get_cores_per_socket() * machine_topo_get_threads_per_socket() Test the commit a1d027be95bc3 ("machine: Add helpers to get cores/ threads per socket"). Suggested-by: Igor Mammedov Signed-off-by: Zhao Liu Acked-by: Igor Mammedov Message-Id: <20230928125943.1816922-2-zhao1.liu@linux.intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/unit/test-smp-parse.c | 67 ++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c index fdc39a846c..24972666a7 100644 --- a/tests/unit/test-smp-parse.c +++ b/tests/unit/test-smp-parse.c @@ -394,20 +394,47 @@ static char *smp_config_to_string(const SMPConfigurat= ion *config) config->has_maxcpus ? "true" : "false", config->maxcpus); } =20 -static char *cpu_topology_to_string(const CpuTopology *topo) +/* Use the different calculation than machine_topo_get_threads_per_socket(= ). */ +static unsigned int cpu_topology_get_threads_per_socket(const CpuTopology = *topo) +{ + /* Check the divisor to avoid invalid topology examples causing SIGFPE= . */ + if (!topo->sockets) { + return 0; + } else { + return topo->max_cpus / topo->sockets; + } +} + +/* Use the different calculation than machine_topo_get_cores_per_socket().= */ +static unsigned int cpu_topology_get_cores_per_socket(const CpuTopology *t= opo) +{ + /* Check the divisor to avoid invalid topology examples causing SIGFPE= . */ + if (!topo->threads) { + return 0; + } else { + return cpu_topology_get_threads_per_socket(topo) / topo->threads; + } +} + +static char *cpu_topology_to_string(const CpuTopology *topo, + unsigned int threads_per_socket, + unsigned int cores_per_socket) { return g_strdup_printf( "(CpuTopology) {\n" - " .cpus =3D %u,\n" - " .sockets =3D %u,\n" - " .dies =3D %u,\n" - " .clusters =3D %u,\n" - " .cores =3D %u,\n" - " .threads =3D %u,\n" - " .max_cpus =3D %u,\n" + " .cpus =3D %u,\n" + " .sockets =3D %u,\n" + " .dies =3D %u,\n" + " .clusters =3D %u,\n" + " .cores =3D %u,\n" + " .threads =3D %u,\n" + " .max_cpus =3D %u,\n" + " .threads_per_socket =3D %u,\n" + " .cores_per_socket =3D %u,\n" "}", topo->cpus, topo->sockets, topo->dies, topo->clusters, - topo->cores, topo->threads, topo->max_cpus); + topo->cores, topo->threads, topo->max_cpus, + threads_per_socket, cores_per_socket); } =20 static void check_parse(MachineState *ms, const SMPConfiguration *config, @@ -415,14 +442,26 @@ static void check_parse(MachineState *ms, const SMPCo= nfiguration *config, bool is_valid) { g_autofree char *config_str =3D smp_config_to_string(config); - g_autofree char *expect_topo_str =3D cpu_topology_to_string(expect_top= o); - g_autofree char *output_topo_str =3D NULL; + g_autofree char *expect_topo_str =3D NULL, *output_topo_str =3D NULL; + unsigned int expect_threads_per_socket, expect_cores_per_socket; + unsigned int ms_threads_per_socket, ms_cores_per_socket; Error *err =3D NULL; =20 + expect_threads_per_socket =3D + cpu_topology_get_threads_per_socket(expect_topo); + expect_cores_per_socket =3D + cpu_topology_get_cores_per_socket(expect_topo); + expect_topo_str =3D cpu_topology_to_string(expect_topo, + expect_threads_per_socket, + expect_cores_per_socket); + /* call the generic parser */ machine_parse_smp_config(ms, config, &err); =20 - output_topo_str =3D cpu_topology_to_string(&ms->smp); + ms_threads_per_socket =3D machine_topo_get_threads_per_socket(ms); + ms_cores_per_socket =3D machine_topo_get_cores_per_socket(ms); + output_topo_str =3D cpu_topology_to_string(&ms->smp, ms_threads_per_so= cket, + ms_cores_per_socket); =20 /* when the configuration is supposed to be valid */ if (is_valid) { @@ -433,7 +472,9 @@ static void check_parse(MachineState *ms, const SMPConf= iguration *config, (ms->smp.clusters =3D=3D expect_topo->clusters) && (ms->smp.cores =3D=3D expect_topo->cores) && (ms->smp.threads =3D=3D expect_topo->threads) && - (ms->smp.max_cpus =3D=3D expect_topo->max_cpus)) { + (ms->smp.max_cpus =3D=3D expect_topo->max_cpus) && + (ms_threads_per_socket =3D=3D expect_threads_per_socket) && + (ms_cores_per_socket =3D=3D expect_cores_per_socket)) { return; } =20 --=20 MST