From patchwork Thu Mar 2 19:08:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 658151 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp68481wrb; Thu, 2 Mar 2023 11:18:43 -0800 (PST) X-Google-Smtp-Source: AK7set+AloTVUC7Cu1ezdTxyUPlVOj5CigaiYnHgZmik/qd1JniSb8VOiRI/0/79FKW9zM2GawVQ X-Received: by 2002:ad4:5de4:0:b0:56e:a07b:f4d4 with SMTP id jn4-20020ad45de4000000b0056ea07bf4d4mr19327029qvb.3.1677784722992; Thu, 02 Mar 2023 11:18:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677784722; cv=none; d=google.com; s=arc-20160816; b=kO/FXFOkiLIz4Sjk3ZPZAgcIOB/UNTy1TEGvZbVXK2PqCvdR5EnnAx7bSrXNLmjoYC 8w+nQl/t7JmIVtNXb2rtietSXsO6M/JdqHfZjxpVM4gzPlzKO4kbgp8awQaEt0dduWVI SCuAvZbzW5dte3EPW1Mvcr64BLTv2YVQXePCXXQKk3tVG0w21X8YEWGJAE47icGlBqPy geuzw5iHpfJKi27nFN/UZFOaI+4iUu7rWQxDA7Trv9jGmdOVHy+eVMNVrB3RhATRsdh3 GDAvOhCTZE+TVQo1Pgi54IWPMoZ+agbFMWDoPc/Eie54r67/vtki9lbhSjktcdtg3Txk 9xaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OkchIjEfD+60EpcbCT5XhulXGtH6Nh+X+dtOXOoAXwo=; b=ntJc6Y+EPCqxcBHcAjUp9z3UzudSUbky+4TTQBy4KuUeenVdkRZ9iaCzdMC8Yjpdvb f0RE5/xUCh5DUcblgz3cRXuD1uUvUC8q63hNqUN6ZvafHuLLl7JKUPeztHDNABaYxiuu I7cD6n6cebZleVoOFeHzkSBk4UfnD/ejZSY7+/lvYGywly+3DExDfgQSZVmwfaNQIq18 E2sPpAspvufrPLIQkqz8848jmROxtjHukghTiskxOEP3PLRkaPqd7la9/3i86jluyCNF +NUMBVmCHWxSF50QHSey9KKmyNK9DMkknzoyZ1+6Kqqzlf/HRcrqhTllmAdikBRp6B/R FGqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZA0YRhSK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s3-20020a0cdc03000000b0056e8ecf84d0si13315236qvk.491.2023.03.02.11.18.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Mar 2023 11:18:42 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZA0YRhSK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXoO6-0007VN-Ur; Thu, 02 Mar 2023 14:14:47 -0500 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 1pXoNz-00077J-Jj for qemu-devel@nongnu.org; Thu, 02 Mar 2023 14:14:39 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXoNo-0000mN-NR for qemu-devel@nongnu.org; Thu, 02 Mar 2023 14:14:39 -0500 Received: by mail-wr1-x42d.google.com with SMTP id h11so151275wrm.5 for ; Thu, 02 Mar 2023 11:14:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OkchIjEfD+60EpcbCT5XhulXGtH6Nh+X+dtOXOoAXwo=; b=ZA0YRhSKo0mKNsXz/40NcIJ0lx+r74+ySfJ0wptw+mc/NHg3LXJwLe4oaSogxLLvVT MXaHUbDMuxCP6fJGdN38Fu8rlaUvahqRlx2skoLOTRMdw8X/f/aca7JRT9Rx+4z0nzYS k5WaUGckPkD+ZLTewsmx3JKjlbTiM7+ZII8UCzvNcYO1sKmlss9ilWL424WKSssCIJUB ke35tRnrzFvWs3bfo9a3ubqRZfNorhdc412Rc52usg1Bo8O7YFCj+aDf5elShp6qi6ns Hm+TnfopORY7xXsyOj9rxGCTOGGkWXiZ+4kyNRsOqWktKGBiVyas2NduA6sg9DHdhZQp 3ScA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OkchIjEfD+60EpcbCT5XhulXGtH6Nh+X+dtOXOoAXwo=; b=VTuGAHT37GywzxcFN5j32zPsLTpbqR6sED8d9NUhzKjOqk79/jjHT/HYqJKhwLyURK xXqry1qHcRzJAWAEceZp4rVNdMl6yWyRJeHiDA/n5spRANnaxl2sYERV2AAkCnktpfKk Laj0wl4u+LnpDLrLv5IiqdCJDuPtRXlz5l+XiCE+saaIb3sUmSayJltFwhQjOUYlB81D C1ZZqoRK46xLdTVkx9XcIwPmmTMf8aMmiw2aj6d/eO3QXdMOe2Ha932AQ+BIlb2sM2MF jIGckl03lKWnGwZSgV+YAO5CdLTiXxKPtLkqikXQ03kbcZpnISabH3wdocxN9+6jqSyn xqjw== X-Gm-Message-State: AO0yUKVAO1J4h0ZALh8G8sl+E13KGq6ldIGSXjlGnS9Vg+XydivPNN8Q NeqhpUpVb2W9zgGPDMcDTsIiXA== X-Received: by 2002:a5d:5189:0:b0:2c3:be89:7c2b with SMTP id k9-20020a5d5189000000b002c3be897c2bmr2200483wrv.14.1677784463604; Thu, 02 Mar 2023 11:14:23 -0800 (PST) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id x9-20020a5d60c9000000b002c70d97af78sm141079wrt.85.2023.03.02.11.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 11:14:21 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C5DF41FFC5; Thu, 2 Mar 2023 19:08:48 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Weiwei Li , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Palmer Dabbelt , Laurent Vivier , nicolas.eder@lauterbach.com, Ilya Leoshkevich , kvm@vger.kernel.org, "Edgar E. Iglesias" , David Gibson , Max Filippov , Sunil Muthuswamy , qemu-s390x@nongnu.org, Stafford Horne , Bin Meng , Marek Vasut , Greg Kurz , Song Gao , Aleksandar Rikalo , Liu Zhiwei , Alistair Francis , Chris Wulff , qemu-riscv@nongnu.org, Michael Rolnik , qemu-arm@nongnu.org, Cleber Rosa , Artyom Tarasenko , Marcel Apfelbaum , Eduardo Habkost , Yoshinori Sato , Alexandre Iooss , Daniel Henrique Barboza , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , mads@ynddal.dk, Mark Cave-Ayland , qemu-ppc@nongnu.org, Richard Henderson , John Snow , Xiaojuan Yang , Thomas Huth , Paolo Bonzini , Mahmoud Mandour , Aurelien Jarno , Bastian Koppelmann , Yanan Wang , David Hildenbrand , Taylor Simpson , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v4 16/26] gdbstub: introduce gdb_get_max_cpus Date: Thu, 2 Mar 2023 19:08:36 +0000 Message-Id: <20230302190846.2593720-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302190846.2593720-1-alex.bennee@linaro.org> References: <20230302190846.2593720-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This is needed for handling vcont packets as the way of calculating max cpus vhanges between user and softmmu mode. Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- v3 - rm out of date comment --- gdbstub/internals.h | 1 + gdbstub/gdbstub.c | 11 +---------- gdbstub/softmmu.c | 9 +++++++++ gdbstub/user.c | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index d8c0292d99..26a6468a69 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -129,6 +129,7 @@ bool gdb_got_immediate_ack(void); CPUState *gdb_first_attached_cpu(void); void gdb_append_thread_id(CPUState *cpu, GString *buf); int gdb_get_cpu_index(CPUState *cpu); +unsigned int gdb_get_max_cpus(void); /* both */ void gdb_create_default_process(GDBState *s); diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index ed38ab0aaa..1b783100c2 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -624,16 +624,7 @@ static int gdb_handle_vcont(const char *p) GDBProcess *process; CPUState *cpu; GDBThreadIdKind kind; -#ifdef CONFIG_USER_ONLY - int max_cpus = 1; /* global variable max_cpus exists only in system mode */ - - CPU_FOREACH(cpu) { - max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index + 1 : max_cpus; - } -#else - MachineState *ms = MACHINE(qdev_get_machine()); - unsigned int max_cpus = ms->smp.max_cpus; -#endif + unsigned int max_cpus = gdb_get_max_cpus(); /* uninitialised CPUs stay 0 */ newstates = g_new0(char, max_cpus); diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index ab2d182654..3a5587d387 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -440,6 +440,15 @@ int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr, return cpu_memory_rw_debug(cpu, addr, buf, len, is_write); } +/* + * cpu helpers + */ + +unsigned int gdb_get_max_cpus(void) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + return ms->smp.max_cpus; +} /* * Softmmu specific command helpers diff --git a/gdbstub/user.c b/gdbstub/user.c index 92663d971c..e10988a62b 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -393,6 +393,23 @@ int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr, return cpu_memory_rw_debug(cpu, addr, buf, len, is_write); } +/* + * cpu helpers + */ + +unsigned int gdb_get_max_cpus(void) +{ + CPUState *cpu; + unsigned int max_cpus = 1; + + CPU_FOREACH(cpu) { + max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index + 1 : max_cpus; + } + + return max_cpus; +} + + /* * Break/Watch point helpers */