From patchwork Sat Nov 2 02:56:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 840286 Delivered-To: patch@linaro.org Received: by 2002:adf:a38c:0:b0:37d:45d0:187 with SMTP id l12csp1159703wrb; Fri, 1 Nov 2024 20:02:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzs7/TWiRhefXkhPayJk2ZIqW8mURQHTCsFjGiqz/jQAXgT5tGbwFBDzQ+zi0Oz9uJjWQA8A==@linaro.org X-Google-Smtp-Source: AGHT+IFJ+SfzVtW1/wcuQ8CcA7A6CumT+IcCwHYcg/+0cN3cik50pbI1kZR1HQrqUqfhs0d8Up0v X-Received: by 2002:a05:6214:458f:b0:6cd:f90a:bb1b with SMTP id 6a1803df08f44-6d35c09e107mr79525636d6.4.1730516566562; Fri, 01 Nov 2024 20:02:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1730516566; cv=pass; d=google.com; s=arc-20240605; b=DzM39c1Z4mfMxtaSkDydaIMJ12avP/XX6K+rGNCc/67UHRERUzZfGWcYse10bXGR8N H0n8IxqXQp8as54vt3wgFZb8xXV/DkPCLfETnllb+hvCRpwaFaHkACyRdGxJ13n4KcQD 9jOO57xj2vqlwnlGp/oXovxoXP68a/ALYgQnhtx/VHkOOeG3ANokV76Nv2LmwmB5tHn3 LOaqExBFNajIugVRTwiYO4AQv65E5w+ln8WWX+JvSugmNQZNQNHrZAAiTT9/Y6zVkJAW CGFkFM2si8Q8QKqKSUITWPP7RPXHAJw25b6yndRPceArPbqe9VdgVcX/TRmA8AW5xgrz YQWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=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:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=AvISyIfzlO8hVcDd+oajWMf6POF5iHimONQMZ5hyios=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=LsHuuw08Df2ntd1pvzcoupNorvByK4uX5Kew3ElDX+t5HyvXjglLIYBUXj+GdSFkn+ ad/I9hCNxeTVL4RVC31x078m+fEpAWcnpTGAdMj0Oj/NoDqE9CVgq9T6M/E4If8Uqo0q I0qJylCoePkucSNwPM22t7kPd0vl7mfJiV0eFFR4BL21IPhjbqLKsm2v+b8ken/DzHo4 O0cIvMATkEqnkeBgE8wq0+7e0G4BLeWnh75pMx5OmyKusavN/L7cSQoVN0G7HAu6TEgr ocbwv74/AypwLJ+5CbiPkNLqtikXi4lhor0NwrzGstrFIK9uC103P3OfEEYvMzV3PfEr wHRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xbysBmHu; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 6a1803df08f44-6d3541a7036si56370386d6.498.2024.11.01.20.02.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 20:02:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xbysBmHu; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 21D1F3858432 for ; Sat, 2 Nov 2024 03:02:46 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 528F43858D37 for ; Sat, 2 Nov 2024 02:57:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 528F43858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 528F43858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516250; cv=none; b=hNkrz5CSj1FkLqRaAM2mcB+yyt8+reGlMMS4/l9ooGtQjJkLNv8/QXXzGKxCXGUDY2rGlWXO3m8FTVi8jfvs49BU1YSL/Mr5vGjJDG5MwruaWDqailThDUJljSL8KBByErOFRvtY9WQkSJyYoGdL8/Dnns7jWKfdPjhvO5NHRxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516250; c=relaxed/simple; bh=DILrWNhQY29yOuNAnI3MSUrtDs7/CxmCVYgfKnF04RQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=S61/DsREalOBEQt2itMnb6LM8k9Gcs+EuMAv9QvDoJgwfOQ0ezmH2ukJZjWaqYoxPXd7sBw5+J3i0gOtszsMjuujRgjcRuBVMZb0xaBHR5buTQx2GPF5CMjv+hV0ItG+S+Uy2HE8Cq+JaoajoTisyhlYvhaesqO2oCi9xGEby1Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-20ca1b6a80aso26945805ad.2 for ; Fri, 01 Nov 2024 19:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730516246; x=1731121046; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=AvISyIfzlO8hVcDd+oajWMf6POF5iHimONQMZ5hyios=; b=xbysBmHuoRuWTXTQr6C/Vs1v9//tLOxk1Lp7KatyqgQ5VonnC9AFpaYCZlAjoaXjZt /JgrwSBzIs+u+XhJGl4iSewcZynBy0ChIvmFHTrp3sZV9zSMikAmU1o+ABHdrGkCfTcB QZTeGtLGbucNzWKe1x7+Zdo3ef3vHoBHSq1DkxC2qaWU/oH//Ui2vsp1TiifXQnX8ZDf /E1Q5WB3bSE+bW6kTNCsxKxHwDYchSLRKOAHeL33tHI/OpnQo+mJYBhFHUqjDqKqycDE BVcyGWRfx8jY7ueKl+IK/XDw8ieAlKfntJuHTH+DXwnGU46oFKtsHVmCZohIHvzKqgMr Oafg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730516246; x=1731121046; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AvISyIfzlO8hVcDd+oajWMf6POF5iHimONQMZ5hyios=; b=gGsAiIEMo2aQ1ZVd8gE/laJShJM3XmHHFXtQeCTDn8TmWA6EKWdd0SIYiofluM94pa LWv4vGGA+q4ZxMlODU0sbvmQ3p1vTzJtsiaNydHwgDw8YPQ2Qzy1P3g20XJKkfx/xtW5 OeVC3hfcQeMEWKyLVDlKvEmrQCoirOW47aKzZ9CLlPZXpH0hBXECehyxp/qokQIxG/Vt V9obucmsmEx7ecrieB+F21Gqlue4G/YxCWSAqkjoqai6SpMmkNd9autp7+pZ3TJGNCKA eNH7Gqy85jZqB1vCCorTJz/QfQFfGuDTc8iI3NxI7pdF3vcjny0w+vf3OwfNQGvqVMo/ W8FA== X-Gm-Message-State: AOJu0Yy8cNsQ+jrkl7i/1Zr+je3x/FbWzLl4EZTJ/uYMPEFCR0d8sb8d nC0Sq0Nxq+m3AWc5Nim6PsDwsS8EKrTA5/valRuTsBexF0d4sXr0vcAnV0tfL9MVtT1VOh/9Rwz 8 X-Received: by 2002:a17:902:d2d0:b0:20c:e2ff:4a2e with SMTP id d9443c01a7336-2111b00690bmr87030075ad.53.1730516246224; Fri, 01 Nov 2024 19:57:26 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:f214:b4dc:314a:c1ee]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21105709bdesm27767865ad.94.2024.11.01.19.57.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:57:25 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [RFC PATCH v4 15/15] gdb/testsuite: Add test to exercise multi-threaded AArch64 SVE inferiors Date: Fri, 1 Nov 2024 23:56:35 -0300 Message-ID: <20241102025635.586759-16-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241102025635.586759-1-thiago.bauermann@linaro.org> References: <20241102025635.586759-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patch=linaro.org@sourceware.org This testcase exercises two scenarios involving a multi-threaded inferior. In the first scenario, the secondary inferior thread changes its vector length and then hits a breakpoint. GDB then examines the SVE state. In the second one, the secondary inferior thread changes its vector length and then the main thread hits a breakpoint. GDB then switches to the secondary thread and examines the SVE state. --- gdb/testsuite/gdb.arch/aarch64-sve-threads.c | 125 ++++++++++++++++++ .../gdb.arch/aarch64-sve-threads.exp | 80 +++++++++++ 2 files changed, 205 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..6640bd01a282 --- /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 2024 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 . */ + +/* Exercise AArch64's Scalable Vector Extension in a multi-threaded program. */ + +#include +#include +#include +#include +#include +#include + +/* 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; + + 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..049eb24b1e6d --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sve-threads.exp @@ -0,0 +1,80 @@ +# Copyright 2024 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 . + +# Test a multi-threaded binary that uses SVE and changes the SVE vector +# length in the additional thread. + +require allow_aarch64_sve_tests + +standard_testfile +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + {debug pthreads}] == -1} { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Get the original VG value. +set orig_vg [get_valueof "" {$vg} "0" "get value of VG register"] +set expected_vg [expr {$orig_vg - 2}] + +# 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" + +gdb_test "print \$vg" ". = ${expected_vg}" "vg was changed to ${expected_vg}" + +# 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" + +gdb_test "print \$vg" ". = ${orig_vg}" "vg was changed back to ${orig_vg}" + +# 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 in the main thread after the additional thread has changed its +# vector length. +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" + +gdb_test "print \$vg" ". = ${expected_vg}" \ + "vg was changed to ${expected_vg} in thread 2"