From: Luis Machado <luis.machado@arm.com>
To: Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
gdb-patches@sourceware.org
Subject: Re: [PATCH v3 8/8] gdb/testsuite: Add test to exercise multi-threaded AArch64 SVE inferiors
Date: Wed, 1 Feb 2023 10:10:28 +0000 [thread overview]
Message-ID: <fe700f8e-0012-3373-203b-133bceeb11fe@arm.com> (raw)
In-Reply-To: <20230130044518.3322695-9-thiago.bauermann@linaro.org>
Just a nit.
On 1/30/23 04:45, Thiago Jung Bauermann via Gdb-patches wrote:
> This testcase exercises two scenarios with a multi-threaded inferior, one
> proposed by Luis and another one proposed by Simon.
>
> In the first scenario, one of the inferior threads changes its vector
> length and then hits a breakpoint. In the second one, the main thread hits
> a breakpoint and then GDB switches to another thread.
> ---
> gdb/testsuite/gdb.arch/aarch64-sve-threads.c | 125 ++++++++++++++++++
> .../gdb.arch/aarch64-sve-threads.exp | 70 ++++++++++
> 2 files changed, 195 insertions(+)
> create mode 100644 gdb/testsuite/gdb.arch/aarch64-sve-threads.c
> create mode 100644 gdb/testsuite/gdb.arch/aarch64-sve-threads.exp
>
> diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-threads.c b/gdb/testsuite/gdb.arch/aarch64-sve-threads.c
> new file mode 100644
> index 000000000000..7fad77008da3
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/aarch64-sve-threads.c
> @@ -0,0 +1,125 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> + Copyright 2023 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* Exercise AArch64's Scalable Vector Extension in a multi-threaded program. */
> +
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <pthread.h>
> +#include <semaphore.h>
> +#include <sys/prctl.h>
> +#include <unistd.h>
> +
> +/* For one of the tests, the thread needs to sleep after setting the vector
> + length. This variable is set by GDB. */
> +volatile bool should_sleep = false;
> +
> +/* Used to signal to the main thread that the additional thread's vector length
> + was changed. */
> +sem_t vl_changed;
> +
> +/* Start routine for the additional thread. Sets a new vector length, sleeps if
> + requested then restores the original vector length. */
> +
> +static void *
> +thread_function (void *unused)
> +{
> + unsigned int vl;
> + int rc;
> +
> + rc = prctl (PR_SVE_GET_VL, 0, 0, 0, 0);
> + if (rc < 0)
> + {
> + perror ("FAILED to PR_SVE_GET_VL");
> + sem_post (&vl_changed);
> + return NULL;
> + }
> +
> + vl = rc & PR_SVE_VL_LEN_MASK;
> +
> + /* Decrease vector length by 16 bytes. */
> + vl -= 16;
Is there an initial vector length set before we decrement it by 16? I'm wondering about a case where we already start with 16, and then we'd decrement the vector length to an invalid value.
> +
> + rc = prctl (PR_SVE_SET_VL, vl, 0, 0, 0, 0);
> + if (rc < 0)
> + {
> + perror ("FAILED to PR_SVE_SET_VL");
> + sem_post (&vl_changed);
> + return NULL;
> + }
> +
> + /* Let the main thread continue. */
> + rc = sem_post (&vl_changed);
> + if (rc != 0)
> + {
> + perror ("sem_post");
> + return NULL;
> + }
> +
> + if (should_sleep)
> + sleep (10);
> +
> + /* Restore original vector length. */
> + vl += 16; /* break here 1 */
> +
> + rc = prctl (PR_SVE_SET_VL, vl, 0, 0, 0, 0);
> + if (rc < 0)
> + {
> + perror ("FAILED to PR_SVE_SET_VL");
> + return NULL;
> + }
> +
> + return NULL; /* break here 2 */
> +}
> +
> +int
> +main (int argc, char **argv)
> +{
> + pthread_t thread;
> + int rc;
> +
> + rc = sem_init (&vl_changed, 0, 0);
> + if (rc != 0)
> + {
> + perror ("sem_init");
> + return 1;
> + }
> +
> + rc = pthread_create (&thread, NULL, thread_function, NULL);
> + if (rc != 0)
> + {
> + perror ("pthread_create");
> + return 1;
> + }
> +
> + /* Wait until the additional thread changes it's vector length. */
> + rc = sem_wait (&vl_changed);
> + if (rc != 0)
> + {
> + perror ("sem_wait");
> + return 1;
> + }
> +
> + rc = pthread_join (thread, NULL); /* break here 3 */
> + if (rc != 0)
> + {
> + perror ("pthread_join");
> + return 1;
> + }
> +
> + return 0;
> +}
> diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-threads.exp b/gdb/testsuite/gdb.arch/aarch64-sve-threads.exp
> new file mode 100644
> index 000000000000..48197650e1de
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/aarch64-sve-threads.exp
> @@ -0,0 +1,70 @@
> +# Copyright 2023 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# Test a multi-threaded binary that uses SVE and changes the SVE vector length
> +# in the additional thread.
> +
> +if {[skip_aarch64_sve_tests]} {
> + verbose "Skipping ${gdb_test_file_name}."
> + return
> +}
> +
> +standard_testfile
> +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
> + {debug pthreads}] == -1} {
> + return -1
> +}
> +
> +if ![runto_main] {
> + return -1
> +}
> +
> +# Stop after the additional thread has changed its vector length.
> +gdb_breakpoint [gdb_get_line_number "break here 1"]
> +gdb_continue_to_breakpoint "break here 1"
> +
> +# If GDB and gdbserver don't agree on the thread's vector length, this command
> +# will fail.
> +gdb_test "print \$z0" " = {q = {u = {.*}}}" "print z0 register"
> +
Out of curiosity, what is the failure mode when gdbserver doesn't do the right thing.
> +# Stop after the additional thread has restored its original vector length.
> +gdb_breakpoint [gdb_get_line_number "break here 2"]
> +gdb_continue_to_breakpoint "break here 2"
> +
> +# Test that going back to the original vector length doesn't confuse GDB or
> +# gdbserver.
> +gdb_test "print \$z0" " = {q = {u = {.*}}}" "print z0 register again"
> +
> +# Restart GDB to test a scenario where GDB switches to a thread that changed its
> +# vector length but hasn't hit any breakpoints yet.
> +clean_restart ${binfile}
> +
> +if ![runto_main] {
> + return -1
> +}
> +
> +# Make the thread sleep after changing its vector length.
> +gdb_test_no_output -nopass "set var should_sleep = 1" "make thread sleep"
> +
> +# Stop after the additional thread has been created.
> +gdb_breakpoint [gdb_get_line_number "break here 3"]
> +gdb_continue_to_breakpoint "break here 3"
> +
> +# The regexp accounts for two lines of output after the "Switching to thread" message.
> +gdb_test_lines "thread 2" "switch to another thread" \
> + {\[Switching to thread 2 \(.*\)\]\r\n#0 [[:print:]]+}
> +
> +# Make sure everything is still fine.
> +gdb_test "print \$z0" " = {q = {u = {.*}}}" "print z0 register in thread 2
next prev parent reply other threads:[~2023-02-01 10:10 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-30 4:45 [PATCH v3 0/8] gdbserver improvements for AArch64 SVE support Thiago Jung Bauermann
2023-01-30 4:45 ` [PATCH v3 1/8] gdbserver: Add assert in find_register_by_number Thiago Jung Bauermann
2023-01-31 17:05 ` Simon Marchi
2023-01-31 19:49 ` Thiago Jung Bauermann
2023-02-01 15:43 ` Simon Marchi
2023-01-30 4:45 ` [PATCH v3 2/8] gdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap Thiago Jung Bauermann
2023-02-01 9:07 ` Luis Machado
2023-02-01 10:54 ` Andrew Burgess
2023-02-01 16:01 ` Simon Marchi
2023-02-01 19:33 ` Thiago Jung Bauermann
2023-02-01 19:53 ` Simon Marchi
2023-02-01 21:55 ` Thiago Jung Bauermann
2023-02-06 19:54 ` Pedro Alves
2023-02-06 20:16 ` Simon Marchi
2023-02-07 15:19 ` Pedro Alves
2023-02-07 21:47 ` Thiago Jung Bauermann
2023-02-09 1:31 ` Simon Marchi
2023-02-10 3:54 ` Thiago Jung Bauermann
2023-02-07 22:28 ` Thiago Jung Bauermann
2023-01-30 4:45 ` [PATCH v3 3/8] gdbserver/linux-aarch64: Factor out function to get aarch64_features Thiago Jung Bauermann
2023-02-01 8:59 ` Luis Machado
2023-02-01 16:04 ` Simon Marchi
2023-02-01 22:13 ` Thiago Jung Bauermann
2023-01-30 4:45 ` [PATCH v3 4/8] gdbserver/linux-aarch64: When thread stops, update its target description Thiago Jung Bauermann
2023-02-01 9:05 ` Luis Machado
2023-02-01 11:06 ` Andrew Burgess
2023-02-01 16:21 ` Simon Marchi
2023-02-01 16:32 ` Luis Machado
2023-02-02 2:54 ` Thiago Jung Bauermann
2023-02-02 3:47 ` Simon Marchi
2023-02-03 3:47 ` Thiago Jung Bauermann
2023-02-03 11:13 ` Luis Machado
2023-02-04 15:26 ` Thiago Jung Bauermann
2023-02-03 11:11 ` Luis Machado
2023-02-04 15:21 ` Thiago Jung Bauermann
2023-02-06 9:07 ` Luis Machado
2023-02-06 12:15 ` Thiago Jung Bauermann
2023-02-06 20:29 ` Pedro Alves
2023-02-07 8:11 ` Luis Machado
2023-02-07 14:39 ` Thiago Jung Bauermann
2023-02-03 10:57 ` Luis Machado
2023-02-04 6:18 ` Thiago Jung Bauermann
2023-02-06 20:26 ` Pedro Alves
2023-02-07 21:06 ` Thiago Jung Bauermann
2023-02-09 2:46 ` Simon Marchi
2023-02-10 3:29 ` Thiago Jung Bauermann
2023-02-10 14:56 ` Luis Machado
2023-02-10 15:04 ` Tom Tromey
2023-02-10 15:28 ` Luis Machado
2023-02-10 17:26 ` Thiago Jung Bauermann
2023-02-10 21:01 ` Simon Marchi
2023-01-30 4:45 ` [PATCH v3 5/8] gdbserver: Transmit target description ID in thread list and stop reply Thiago Jung Bauermann
2023-01-30 12:52 ` Eli Zaretskii
2023-01-30 14:05 ` Thiago Jung Bauermann
2023-02-01 9:39 ` Luis Machado
2023-02-01 12:07 ` Andrew Burgess
2023-02-01 13:03 ` Eli Zaretskii
2023-02-01 17:37 ` Simon Marchi
2023-02-02 20:36 ` Thiago Jung Bauermann
2023-02-02 20:56 ` Simon Marchi
2023-02-01 20:46 ` Simon Marchi
2023-02-02 21:43 ` Thiago Jung Bauermann
2023-02-01 14:51 ` Andrew Burgess
2023-02-01 17:03 ` Simon Marchi
2023-02-02 19:52 ` Thiago Jung Bauermann
2023-02-02 20:51 ` Simon Marchi
2023-02-03 2:44 ` Thiago Jung Bauermann
2023-02-03 16:29 ` Andrew Burgess
2023-02-04 6:08 ` Thiago Jung Bauermann
2023-02-03 11:22 ` Luis Machado
2023-02-03 12:50 ` Simon Marchi
2023-01-30 4:45 ` [PATCH v3 6/8] gdb/remote: Parse tdesc field in stop reply and threads list XML Thiago Jung Bauermann
2023-02-01 9:52 ` Luis Machado
2023-02-05 0:06 ` Thiago Jung Bauermann
2023-02-06 9:10 ` Luis Machado
2023-02-01 14:32 ` Andrew Burgess
2023-02-01 19:50 ` Simon Marchi
2023-02-01 20:16 ` Simon Marchi
2023-02-03 11:27 ` Luis Machado
2023-02-03 13:19 ` Simon Marchi
2023-02-03 16:33 ` Andrew Burgess
2023-01-30 4:45 ` [PATCH v3 7/8] gdb/aarch64: Detect vector length changes when debugging remotely Thiago Jung Bauermann
2023-02-01 9:58 ` Luis Machado
2023-02-01 15:26 ` Andrew Burgess
2023-02-01 20:20 ` Simon Marchi
2023-02-03 11:31 ` Luis Machado
2023-02-03 16:38 ` Andrew Burgess
2023-02-03 19:07 ` Simon Marchi
2023-01-30 4:45 ` [PATCH v3 8/8] gdb/testsuite: Add test to exercise multi-threaded AArch64 SVE inferiors Thiago Jung Bauermann
2023-02-01 10:10 ` Luis Machado [this message]
2023-02-06 19:11 ` [PATCH v3 0/8] gdbserver improvements for AArch64 SVE support Pedro Alves
2023-02-06 20:05 ` Simon Marchi
2023-02-06 21:06 ` Pedro Alves
2023-02-07 13:49 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fe700f8e-0012-3373-203b-133bceeb11fe@arm.com \
--to=luis.machado@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=thiago.bauermann@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).