From patchwork Tue Feb 21 22:52:18 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: 655387 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp370673wrb; Tue, 21 Feb 2023 14:55:06 -0800 (PST) X-Google-Smtp-Source: AK7set8LOplKDZzzRDEe/m+AuTjbdAhsmFSoIAvukLX2G/mlgFZ3fEq7NKtbwHMPVQUWWvrsqBt3 X-Received: by 2002:a05:622a:15cd:b0:3b8:4694:b728 with SMTP id d13-20020a05622a15cd00b003b84694b728mr9983529qty.1.1677020106676; Tue, 21 Feb 2023 14:55:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677020106; cv=none; d=google.com; s=arc-20160816; b=0XAlVfMqBFSw6rYRA8/IaDnj2DWn1bwPhFn2BXL2NQ7WlF9aedK/0qK+LnrxW+tmQl 44qu+41TaJOzB3hPHJcvW8er33dk7wJAzaTWPhrOIX75laJpBsGJTyYgZUGPhcv8jfj0 DN/k2xjq1kCGg4IEwwhQsHxPu9ESlJtIBYGkalQE/67WE4cUl6eaR7aM8lc7y0dTN0nC A1c17ZLb4cWAGUY7Mpq0ZuLGuwAUAuj8pvyBs6YyUfcrjtg1zLKpfKweXUygd+enaVKQ +biQ/qJ9/UP3gtiP2tasm3CiagM0vYcWDG70ArbsrMfoeoYlnYI4tZkGtT9tHXgpb5JX giwQ== 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=yI9cg5uSLm9j6ge6jYumeZR69TGqjGanrthhEwm4YK8=; b=ibKyKoGFqZl3VGe0Hi9JF7IMo2Cr4yPf0KALKgURkctb+cP0GtmvigAGML0C2vUiKN kpPmSGkAW2c0h9t9eX6T1f4RC6w5dqkIFqCxBVUSJHlx2N5sw6T0AESodLZ+TPIfIDQA VbRi4tE3VNRggH/aigKLYSJFH3/70HP9iTZmlw04+YjDViz3uwrqp/mUKYv6Jw4R1tL3 uWBYeKXgTA7dIDAXGtVsrdSa6Gkfc3q56v8rAsEv977nF9HKnbdHtFLPw4ykGJazqzhE A0Rc5nBaCypXfb3Hu7PGm0peaVvVBoj2EKEXbG+RwdQp8mnyGHt4qtuw2dBMT/9KlmLo tMXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="j0hYg/kU"; 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 s22-20020a05622a1a9600b003ba1ccba50fsi13668860qtc.557.2023.02.21.14.55.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Feb 2023 14:55:06 -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="j0hYg/kU"; 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 1pUbVg-00085A-MQ; Tue, 21 Feb 2023 17:53:20 -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 1pUbVJ-0007aj-LV for qemu-devel@nongnu.org; Tue, 21 Feb 2023 17:52:57 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUbV0-00048x-MG for qemu-devel@nongnu.org; Tue, 21 Feb 2023 17:52:57 -0500 Received: by mail-wr1-x431.google.com with SMTP id l25so5625244wrb.3 for ; Tue, 21 Feb 2023 14:52:36 -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=yI9cg5uSLm9j6ge6jYumeZR69TGqjGanrthhEwm4YK8=; b=j0hYg/kU6sMKln7Nhss2ddhhdJRo1ytldg/zuxA/xqUB7CIbQdu4t9eaY5HUCVw4TM Gl0wIr0TlUh7NGukaAgZ9NTUcd6fPo4jqpaCXZJ588Ts3gIyZ5/sYJ4ywqUJ7ock9xRv viRS5X6ox3WV90YQJ5Hl1zr+oJrL2HhXCBmYwpl33KVjVMWjqpRwCY27nsOyNq+4fPTx 9wrg7eHc8Mw9lTzPMSYZb4Nli1IBhSN6XNGqtQaNxi9oBbj/z0d/M8JrDlIgU/42wMRE 2/94QFk84/TcLM9Z0tsDqtXjZa/tpSjsK8SD2jj+CGyWN3OF5s0a6rK1efjBHv6+pCA3 meHQ== 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=yI9cg5uSLm9j6ge6jYumeZR69TGqjGanrthhEwm4YK8=; b=6176w3oF5PH7u8vSOn2gzFdOOw1S0muTiYxhJfX77EOtwlcH28rLHzwOwdfiT8Gpdk iHSEKOpwV7CCLRMKLoSA79do9k/eylG2arwBNLzXoMgfDHauIjvTqV7IUBd0F+uq/zX1 tDkUoMJpv7NzZwqCZz3ubjkJ3I6itwlTwSsFz8TLEzu4nsidgVKKInHWs6RzP1YeQW5j oyKRQ0MJG3bcFWwID3nWG9+kCgjlRwg1ooaw9QLS02MBG5h4exeCwJDYejlo5XaYvAOL hBl0KhLfdlt8WFuwC7DF6TbzSRUd3Twxe3qegdE/uYYYxC9APlT3gYkFa7JitAKhk/ps /jsw== X-Gm-Message-State: AO0yUKVDmFO//pVPI/fdb8252+JLxBwRzVLa3kcgNWrzy34M7AJ6BnEY kxgwRQ2NHlZfoJF1WzZ+tCCJPg== X-Received: by 2002:a5d:4d09:0:b0:2c5:5048:8a6a with SMTP id z9-20020a5d4d09000000b002c550488a6amr6579824wrt.60.1677019955459; Tue, 21 Feb 2023 14:52:35 -0800 (PST) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id d18-20020a5d6452000000b002c54f4d0f71sm7003887wrw.38.2023.02.21.14.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 14:52:34 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 627521FFBA; Tue, 21 Feb 2023 22:52:29 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Yoshinori Sato , nicolas.eder@lauterbach.com, Stafford Horne , Daniel Henrique Barboza , Mahmoud Mandour , Taylor Simpson , mads@ynddal.dk, Marek Vasut , Artyom Tarasenko , Alistair Francis , qemu-ppc@nongnu.org, Yanan Wang , Sunil Muthuswamy , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Eduardo Habkost , Bin Meng , Bastian Koppelmann , Palmer Dabbelt , Marcel Apfelbaum , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Rolnik , Aleksandar Rikalo , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno , Xiaojuan Yang , Richard Henderson , Peter Maydell , Alexandre Iooss , Chris Wulff , Jiaxun Yang , David Gibson , "Edgar E. Iglesias" , Greg Kurz , David Hildenbrand , Song Gao , Ilya Leoshkevich , Max Filippov , Mark Cave-Ayland Subject: [PATCH v3 15/24] gdbstub: introduce gdb_get_max_cpus Date: Tue, 21 Feb 2023 22:52:18 +0000 Message-Id: <20230221225227.3735319-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221225227.3735319-1-alex.bennee@linaro.org> References: <20230221225227.3735319-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.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 9de995ce3a..90069a9415 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -127,6 +127,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 91021859a1..f9950200b8 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 d9b9ba0a32..65aa2018a7 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -433,6 +433,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 b956c0e297..15ff3ab08d 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -388,6 +388,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 */