From patchwork Wed May 20 08:58:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tankut Baris Aktemur X-Patchwork-Id: 135319 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F9F14BB5902 for ; Wed, 20 May 2026 09:01:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F9F14BB5902 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=HdKYh0sv X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazlp170130001.outbound.protection.outlook.com [IPv6:2a01:111:f403:c10c::1]) by sourceware.org (Postfix) with ESMTPS id 6C7444BB5917 for ; Wed, 20 May 2026 08:59:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C7444BB5917 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6C7444BB5917 Authentication-Results: sourceware.org; arc=fail smtp.remote-ip=2a01:111:f403:c10c::1 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1779267549; cv=fail; b=bIUQm6CIVVpYwPUIYtF5N7gyePEOwWhnu8e83Va8NZ4Rdf+XjCGnOCcmk/H6diwu/ft2Ckzgyxk37qc8IKJDVSdb6r7/yN+kDfSFpdk4gPWR5QWpZVxVJNGR2e352+A4bwa/NNemeNg32H3YwXuORviPVerrtzS7oIBNQEkd0nM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1779267549; c=relaxed/simple; bh=jd2zk/m8ili2BfJvIZqqrSbrqv8VbnckFiwL44gRrHs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nRIQMr/dsgWCg12QvK4ULsvQiNLDub2QoWCMScKfUrrgJjg3j12QL97U019CZ/QjRX3DvWhTmOzxdLhQhQBgyXbQAuwx3m3a49D+pX6jdvSFP9ElzjvRuqEsXX7kByyGGIu2oXjplvGc1Vfyg1bOuCMWZXOaCd6Z3HEv5UM/lIY= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=HdKYh0sv DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C7444BB5917 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KHWgP7E1/4ug/Ol/CThzLVij2Uf0mkN0P0vbaOCWktksDROqev96SOWAA+q32Sz6bjDOxqh1Mg6Zf3FZsKdP1Kgb8VfrMKVUyyeOgYfx0brCCGEkaPfxy6ZpKgQjBmrRP2eh1gUMYg4tMyUlvpqMMjB7hd2CNSkovN968SI1l9CqjjaYraDiAA6jatpOszTvWmcQZkK2ZjfoJ/KtGq9OFfb26IQXqJMa2eZLDCImOEPQ1h9wTnl4IiTWrY2K+hYTEUR+sjq1cg5kEdgCGiZButx72zETqh3whEU967p+MKPZhk74c+WJibZcGsfgaiwWc/HsFRvFIxQCwxSOQ412YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=z7OxHPx8Os/nXp13ldU6IQNWnF0re4AkCs/6WFP2N5E=; b=hSg+1x4/8KBVrMIIH63pIUdcF16G0BWZ6v8KBLqV+D+4BBrmjwudO8zpcPfbEeGwy33+fK4qEEf+t71ER3P5Q7j8bC2nXx8yfZWq3YMYYIJpziOTN02e1TQFbpiMybSwkhfETnpIGDVNJmYjTeemO8XHK8d2HtqaUkwL7D14cwIpH08h/E98eHlhUQ3i+SDZKZBKDtCITMrUtP8S3CVtxri/t14KiV+OdMtSyAoBvMbzvDMgqir0N4lRJFviGT9x0h5x7bQLID/ChVwZVHdHHPwRX7TCQFdNWwFBgoAUU8IVMkNBIqTk+wBjgjrM6bHM7TRWaBQMtHiakm1rpgLgpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z7OxHPx8Os/nXp13ldU6IQNWnF0re4AkCs/6WFP2N5E=; b=HdKYh0svHBxBjEkRVowsDtp2SFSG2fV4aDDJHrT1E7QovvKZBIN0f4AAt+MQq34cQqWfRl5Ad7km/Dfjb9jY1sCV25XjoAvVHqwkl8+v4EwP/l/K4tQFhjdriVfAWHKdvW2qDjdhlxZNMc/kg9dE2tmwHZNfJPCzz/I5Bik9Me0= Received: from CY5PR15CA0221.namprd15.prod.outlook.com (2603:10b6:930:88::14) by LV8PR12MB9272.namprd12.prod.outlook.com (2603:10b6:408:201::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.14; Wed, 20 May 2026 08:58:58 +0000 Received: from CY4PEPF0000E9D0.namprd03.prod.outlook.com (2603:10b6:930:88:cafe::43) by CY5PR15CA0221.outlook.office365.com (2603:10b6:930:88::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.48.16 via Frontend Transport; Wed, 20 May 2026 08:58:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CY4PEPF0000E9D0.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Wed, 20 May 2026 08:58:57 +0000 Received: from ctr-rack32-mi300x-1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Wed, 20 May 2026 03:58:56 -0500 From: Tankut Baris Aktemur To: CC: Subject: [PATCH] gdb/amd-dbgapi-target: suppress a repeated stop request Date: Wed, 20 May 2026 03:58:20 -0500 Message-ID: <20260520085820.1299345-1-tankutbaris.aktemur@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D0:EE_|LV8PR12MB9272:EE_ X-MS-Office365-Filtering-Correlation-Id: 0680f8d4-b668-449b-bf5b-08deb64e0745 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|36860700016|82310400026|56012099003|18002099003|13003099007|3023799007|11063799006|5023799004; X-Microsoft-Antispam-Message-Info: Mkbq2n9J2PGGJcJ5lx9XXn475L65tdnLHzs0B5iBk4+veU/GZqwUcdV+K5ZyQfTLv5vqdd+D/kJLqQqVe4AmLaFcg68oeKYGFJikGWKEtMssPBwPHdv4oUc1NAF8OivTQP2CT+taDjiITn6YGufoh0CM/8qRAlztxMT5VzhwPrxQYyirVS0LNEPnPmze5HZUndVUrSRl82eiH3KH3rZVmijxtM4Y6tPsOZJuNNMnzdAXkF2sn2eXxREaOxxC0ikPV3CrslxgVNWDA1piM0rPhsbLZNeozJMdU8pFt/kTf2RIME0/VaUNhqevHPAQI26zmOtbXndHXQGx/2pXoHDsiVSVVMiMnD2kIWSOawCAKjoaubsGLpyG0ptKkUZXqwyi3sfrQs8naSuI7c4d4UlsPm56liaLkJkOmBRh+qCINyjFSDaqUr7PLZcTuDabQUYKvgtFEdKTUYahn+N4nxei2RpGjvcn1+6Cg3Bx95YRy5tz6dDT+THCQPq4TTmO09TRb+8zq2vwF1xqcKANPuOUUVFdqhNfQf7rhQUDW5tmUVNGAfEjdZduOkAGn8XidHdKs37CteOp9QtipYXRLYsL3sb5SeeZKdHf1sAl/HjACgJXViLnz1fcE3m/6B1M0VUN1xdnf12M0JwVjtV4kB3xCuCrHOIv7wPeh5yThRx7IRIDOaeaNje4LRDnUZWuvwmJH24dXGhCElnd2/NNKqtgxTEApWiltePGgm4RcshfCx0= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(376014)(1800799024)(36860700016)(82310400026)(56012099003)(18002099003)(13003099007)(3023799007)(11063799006)(5023799004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: k18LKimUJ2pdAbz7kpsZ1BaTWXdQdlPNnQK/wRWsVd1cJNQVQgWm9vNbg+H1lEBS34l0d9rWgishHiy8n1uh7xxnnmAQJcI8B20Aa8+jpVnJGQyM4cIwX7BcBg/ZS5e/UKRUmn9hrQzkoEa1vudqmWftoP6JQo22Gus/LJ8Syuy12j5kC+4/QOVESBGO0qzDhBBYMen1m/hjBXUJB68T5uuygrmeSsYu4lqkzAzJ0DeRnfWGZm03DfglvUDIGObWfMaN8UtHTGXnuuH0j+hpXs2OPyfGec1iTyn8EZ6cII/PA6BCtZUHupBQKRslc4Mpv032Cu7AwO3AlQ63tKeovphepz9b79UTBXxOXR89ZOy3J24QW5jAhe7iBiXVvr3P5llDBaYGAAHN6A0mdhIUjfo6jp9dNh9mrk8y/52OuNWR99H0c0uubrNiqExDK19S X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2026 08:58:57.8032 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0680f8d4-b668-449b-bf5b-08deb64e0745 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9D0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9272 X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, KAM_SHORT, LOCAL_AUTHENTICATION_FAIL_ARC, LOCAL_AUTHENTICATION_FAIL_SPF, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org Sending a second stop request to an AMD GPU thread before fetching the event caused by the first request leads to an error: wave_stop for wave_1 failed (The wave has an outstanding stop request) Prevent sending a new stop request if there already is an outstanding one. The fix is in amd_dbgapi_target::stop. A regression test is included. The test uses non-stop mode and executes the "interrupt" command twice, because in non-stop mode this command uses the 'stop' target op, where the fix is applied. To be able to execute two interrupt commands repeatedly, we define a user command. --- gdb/amd-dbgapi-target.c | 8 ++- gdb/testsuite/gdb.rocm/interrupt-twice.cpp | 43 ++++++++++++ gdb/testsuite/gdb.rocm/interrupt-twice.exp | 82 ++++++++++++++++++++++ 3 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.rocm/interrupt-twice.cpp create mode 100644 gdb/testsuite/gdb.rocm/interrupt-twice.exp diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c index 421ec8599ed..d44f03d0b80 100644 --- a/gdb/amd-dbgapi-target.c +++ b/gdb/amd-dbgapi-target.c @@ -1090,14 +1090,16 @@ amd_dbgapi_target::stop (ptid_t ptid) sizeof (state), &state); if (status == AMD_DBGAPI_STATUS_SUCCESS) { - /* If the wave is already known to be stopped then do nothing. */ - if (state == AMD_DBGAPI_WAVE_STATE_STOP) + wave_info &wi = get_thread_wave_info (thread); + + /* If the wave is already known to be stopped or there is an + outstanding stop request, then do nothing. */ + if (state == AMD_DBGAPI_WAVE_STATE_STOP || wi.stopping) return; status = amd_dbgapi_wave_stop (wave_id); if (status == AMD_DBGAPI_STATUS_SUCCESS) { - wave_info &wi = get_thread_wave_info (thread); wi.stopping = true; return; } diff --git a/gdb/testsuite/gdb.rocm/interrupt-twice.cpp b/gdb/testsuite/gdb.rocm/interrupt-twice.cpp new file mode 100644 index 00000000000..fc8d2cca697 --- /dev/null +++ b/gdb/testsuite/gdb.rocm/interrupt-twice.cpp @@ -0,0 +1,43 @@ +/* Copyright 2026 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 . */ + +#include +#include "gdb_watchdog.h" + +__device__ void +loop () +{ + while (true) + __builtin_amdgcn_s_sleep (8); +} + +__global__ void +kern () +{ + loop (); +} + +int +main () +{ + /* Make sure that if anything goes wrong, the program eventually + gets killed. */ + gdb_watchdog (30); + + kern<<<1, 1>>> (); + return hipDeviceSynchronize () != hipSuccess; +} diff --git a/gdb/testsuite/gdb.rocm/interrupt-twice.exp b/gdb/testsuite/gdb.rocm/interrupt-twice.exp new file mode 100644 index 00000000000..681efab0af3 --- /dev/null +++ b/gdb/testsuite/gdb.rocm/interrupt-twice.exp @@ -0,0 +1,82 @@ +# Copyright 2026 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 that sending repeated stop requests to a running GPU thread +# does not cause a failure. This is done in non-stop mode because +# "interrupt" command in this mode uses the 'stop' target op. + +load_lib rocm.exp + +require allow_hipcc_tests + +standard_testfile .cpp + +if {[build_executable "failed to prepare" $testfile $srcfile {debug hip}]} { + return +} + +with_rocm_gpu_lock { + save_vars { ::GDBFLAGS } { + append ::GDBFLAGS " -ex \"set non-stop on\"" + clean_restart $::testfile + } + + gdb_breakpoint "loop" {allow-pending} {temporary} + gdb_run_cmd + + set gpu_thread "undefined" + + gdb_test_multiple "" "hit breakpoint" { + -re -wrap "Thread ($decimal) \[^\r\n\]*hit Temporary breakpoint.*" { + set gpu_thread $expect_out(1,string) + pass $gdb_test_name + } + } + + gdb_test "thread $gpu_thread" "Switching to.*" "switch to gpu thread" + + # Resume the thread in the background. It will loop. Then we + # interrupt twice. To be able to run the "interrupt" command back + # to back, we define a user command. + gdb_test "continue &" "Continuing." "continue async" + + gdb_test_multiple "define inttwice" "" { + -re "End with .*>$" { + pass $gdb_test_name + } + } + + gdb_test [multi_line_input \ + {interrupt} \ + {interrupt} \ + {end}] \ + "" \ + "enter commands" + + # For logging purposes. + gdb_test "show user inttwice" + + gdb_test_multiple "inttwice" "interrupt twice" { + -re "wave_stop \[^\r\n\]+ failed \[^\r\n\]+ outstanding stop request\\)\r\n" { + fail $gdb_test_name + } + -re "Thread $gpu_thread \[^\r\n\]*stopped" { + pass $gdb_test_name + } + -re "$gdb_prompt" { + exp_continue + } + } +}