From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id geuqDFyCqmrnOBIAWB0awg (envelope-from ) for ; Wed, 16 Sep 2026 07:49:48 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=sOmVD6OR; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2F9751E06B; Wed, 16 Sep 2026 07:49:48 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 37B431E01F for ; Wed, 16 Sep 2026 07:49:46 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 968774BA23FF for ; Wed, 16 Sep 2026 11:49:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 968774BA23FF Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=sOmVD6OR Received: from mail-pz2-x0d.google.com (mail-pz2-x0d.google.com [IPv6:2607:f8b0:4864:3b::d]) by sourceware.org (Postfix) with ESMTPS id A865E4BA2E30 for ; Wed, 16 Sep 2026 11:49:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A865E4BA2E30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A865E4BA2E30 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:3b::d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789559358; cv=none; b=Brd5b2ZVvQZdl4EADUNiefCzW0hGRnGG5ncl8+P3MgvkW7RRzWeJ45jOG9E6hJmuzwvzGGQoIibhAY2bRO4D1LfAe3EZimi3C86nsanQHX6RzfWTd1UqpS8W53OgMlITWa768e9l1RwnmC4dr9WbGn3NqvmlwS+uuEZnn0lmnKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789559358; c=relaxed/simple; bh=ewRXPLXyQO9KMCKnMOsG1rELoFGUMvcslnjjG6J6y2M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kEV50tFBrk/02Rxb34SAJPEKjpZaGFX4mDI3gEknCMQAsdVsl+2DKVITplDq/E/OOdM0cyXXuwojCzNqycAAUX14Nq8ruROOPwHqSKV3cRKTVDE3RA2Am33iCa7p+vqW+x1hS+UzQRWNwJyl3R9i3SyDsGTGxHwkHdSN46wLT9k= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=sOmVD6OR DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A865E4BA2E30 Received: by mail-pz2-x0d.google.com with SMTP id d2e1a72fcca58-85469e25187so528279b3a.2 for ; Wed, 16 Sep 2026 04:49:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789559358; x=1790164158; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=5MkhQn8BeXJjg8cfsXOK6R00v6utpJACWF7Ll316514=; b=sOmVD6ORQafomayTDTchSHx7Yo202+GFkKxz8uPUjj74wAHmBVU8yqo0lKqkw9it8M KV7zSWcp/RAxb9/G1ZyDQ+CM2ttlugv7Q19OmCEBAthZD83s2fwWyRNl1RnF/xGehAuG aZU09XWHe1hKi1nxGooDlNOoAMWX1d4wC28ifMkZ1sJi/GQRyIx68N2/4ETljtiDqsgg eFViF0DICxqmAe8tAKcsWsXDX9SplBl8KQehOI3OGk38AawHUEb+efIsnyqZXyZakJgN ssaAHNLwGX+PxImuW005lQ5CLcWQUNo2iOak/mlg66I+//oBoG3UAWlQrxWOZclHVdvc lzNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789559358; x=1790164158; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5MkhQn8BeXJjg8cfsXOK6R00v6utpJACWF7Ll316514=; b=aH+NmiXjH0chwNiIqLPmY2eLMvkePpbfoM7/VrSD9RVwZqt80E7L/eKwDl8xluN9lx 3dRQfWCNeLmzPyEhsxzq84P+a5shiFOX2FQGkj6/xHwKRcHPAVGpAcEK/jOH5IFGEHzM ngi0Q/NXdATOPSvA7b2lfmlbsXnvti0bP9298Cq/1nbHuqEVgNqbzv2NTFceKL2jyjVo 8u0l1xBPgZP+ZQ8SzcGAJWY+Ct5vrSaKuC3BVh0dMcilU7gzzSIwICt+S78YEbfwo1g6 txkSMfNxKgeD/T725tisxAgzM2r9J0BYHABV+OeLMS4OchucOfzpqXbdH3/3BRvOYwEX vWdQ== X-Gm-Message-State: AFuF++meJm01iM6cThfMLLA6anQuWxkgG+BNr8Oe67N4SQMF34nPkq4v n+f/QlN9cfY1hDq1XarMh21Ox7iOVgRHb0UEQI+1yXD68uGsHn2oy7Dh X-Gm-Gg: AYBFou3bLrpCzhKJRSZa2f1wgGrvL6s6P+nud1cHzlHCWk7Wb6edvnvSUxU5taNSCmC gqxMLhSL13dzKgW8dwABXwy6x4vx6e7SlzfqlfGg2ObQBwKKQ/sdhjTwyYn1/L2U5BOpIiOLEcM o4KAQraKgXiiI2bFZgxYIeo36DeKheMR+cDLqKTYpOod5v8wYo2afPbzPj6+gsSbEGnwB505sqc rD723AS8FEHXCSxZBKZndbNp/Q0DJJxWiUBzmBWtN7cu0Srcnu3AE1UuKrxZWUt9kFZEnZBQ0x4 nwbiDX+p+Xo/w1EtkkH4nmnwSlX0BzG+hyYpJ8nI5AXy+AKusY/HrKHwuZcX4k1o9UNxonGKQVh cSHDBG2bWOh3h0SIoRtavUA1KwG2JfWQU8W11AUWc3r28sdhi5cplKgEyrYvh5aYCX/8DBjJ2vE icAOYPziR2QLJpIuAhSCsZK7GbmOMGMehspTu4EgKqc7zz4JhhtsomN1Q/sHYI7oLlFC4zR1jfN DaOL+s1rO/gipPbc2NqAVmzYBw5 X-Received: by 2002:a05:6a21:3949:b0:3cc:3d08:da2b with SMTP id adf61e73a8af0-3dd5f5d6749mr6315897637.15.1789559357353; Wed, 16 Sep 2026 04:49:17 -0700 (PDT) Received: from localhost.localdomain ([122.171.19.232]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-33c011378f1sm5195168eec.29.2026.09.16.04.49.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 16 Sep 2026 04:49:17 -0700 (PDT) From: Aditya Vidyadhar Kamath To: ulrich.weigand@de.ibm.com, simon.marchi@polymtl.ca, tom@tromey.com Cc: gdb-patches@sourceware.org, Aditya.Kamath1@ibm.com, sangamesh.swamy@in.ibm.com, Aditya Vidyadhar Kamath Subject: [PATCH 2/3][RFC] Batch getthrds() calls in get_signaled_thread Date: Wed, 16 Sep 2026 17:16:06 +0530 Message-ID: <20260916114603.17488-4-akamath996@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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~public-inbox=simark.ca@sourceware.org From: Aditya Vidyadhar Kamath The original code called getthrds() with a count of 1, fetching one kernel thread descriptor per syscall. With N threads in the process that costs N syscalls per stop just to find the signaled thread. Change to fetch GETTHRDS_BATCH (64) descriptors per call and scan the batch in a loop. This reduces the syscall count from O(N) to O(N/64). Also done the benchmark here who results are pasted below. To analyse where time is being spent. For now, this patch request for comment/draft and will remove the same and this paragraph from the commit message after feedback. ========== Benchmark C code // cat ../bench_next.c /* Spawns NUM_THREADS worker threads that spin, then steps through 10 assignments in do_steps() so GDB can time each next. Also tests two scenarios from the bug report: 1. "next" over a call that spawns a thread (spawn_thread_here()). 2. A background thread exits while "next" is in progress (exit_thread_here()). */ #include #include #include #include #ifndef NUM_THREADS #define NUM_THREADS 3 #endif static volatile int keep_running = 1; static volatile int extra_thread_started = 0; static void * worker (void *arg) { while (keep_running) sched_yield (); return NULL; } /* Thread that exits on its own after signalling it has started. */ static void * short_lived (void *arg) { extra_thread_started = 1; return NULL; } /* GDB will "next" over this call -- a new thread is spawned inside. */ static void spawn_thread_here (void) { pthread_t t; pthread_create (&t, NULL, short_lived, NULL); pthread_join (t, NULL); } /* GDB will "next" over this call -- the short-lived background thread is in the process of exiting while we step. */ static void exit_thread_here (void) { /* Just a visible marker so GDB can stop here. */ volatile int x = 42; (void)x; } void do_steps (void) { volatile int a = 1; volatile int b = 2; volatile int c = a + b; volatile int d = c * 2; volatile int e = d - a; volatile int f = e + c; volatile int g = f / 2; volatile int h = g + 1; volatile int i2 = h * h; volatile int j = i2 - b; (void)j; } int main (void) { pthread_t threads[NUM_THREADS]; pthread_t bg; int i; /* Start background spinning threads. */ for (i = 0; i < NUM_THREADS; i++) pthread_create (&threads[i], NULL, worker, NULL); /* Next over a call that spawns a thread */ spawn_thread_here (); /* Next while a background thread is exiting Launch a thread that exits quickly; "next" through exit_thread_here() while that exit is in flight. */ pthread_create (&bg, NULL, short_lived, NULL); exit_thread_here (); pthread_join (bg, NULL); do_steps (); keep_running = 0; for (i = 0; i < NUM_THREADS; i++) pthread_join (threads[i], NULL); return 0; } ============ Benchmark GDB code: // cat ../bench_next.gdb set pagination off set confirm off maintenance set per-command time on # Scenario 1: next over a call that spawns a thread break spawn_thread_here run next # Scenario 2: next while a background thread is exiting break exit_thread_here continue next break do_steps continue next next next next next next next next next next quit =============== # cd /current_gdb && time /current_gdb/binutils-gdb/gdb/gdb -batch -x bench_next.gdb ./bench_next_bin 2>&1 | grep -E "^(real|user|sys)|volatile int |pd_update total|sync_thread|pthdb_session" Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "pd_update total": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "pd_update total": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.146, user 0.081, sys 0.085, user+sys 0.166, 14.5 % CPU Time for "pd_update total": wall 1.146, user 0.081, sys 0.085, user+sys 0.166, 14.5 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.025, user 0.092, sys 0.092, user+sys 0.184, 18.0 % CPU Time for "pd_update total": wall 1.025, user 0.092, sys 0.092, user+sys 0.184, 18.0 % CPU 25 volatile int a = 1; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.962, user 0.098, sys 0.095, user+sys 0.193, 20.1 % CPU Time for "pd_update total": wall 0.962, user 0.098, sys 0.095, user+sys 0.193, 20.1 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.965, user 0.098, sys 0.094, user+sys 0.192, 19.9 % CPU Time for "pd_update total": wall 0.965, user 0.098, sys 0.094, user+sys 0.192, 19.9 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.954, user 0.098, sys 0.094, user+sys 0.192, 20.1 % CPU Time for "pd_update total": wall 0.954, user 0.098, sys 0.094, user+sys 0.192, 20.1 % CPU 26 volatile int b = 2; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.949, user 0.098, sys 0.094, user+sys 0.192, 20.2 % CPU Time for "pd_update total": wall 0.949, user 0.098, sys 0.094, user+sys 0.192, 20.2 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.957, user 0.098, sys 0.094, user+sys 0.192, 20.1 % CPU Time for "pd_update total": wall 0.957, user 0.098, sys 0.094, user+sys 0.192, 20.1 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.033, user 0.101, sys 0.098, user+sys 0.199, 19.3 % CPU Time for "pd_update total": wall 1.033, user 0.101, sys 0.098, user+sys 0.199, 19.3 % CPU 27 volatile int c = a + b; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.031, user 0.101, sys 0.098, user+sys 0.199, 19.3 % CPU Time for "pd_update total": wall 1.031, user 0.101, sys 0.098, user+sys 0.199, 19.3 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.028, user 0.100, sys 0.098, user+sys 0.198, 19.3 % CPU Time for "pd_update total": wall 1.028, user 0.100, sys 0.098, user+sys 0.198, 19.3 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.996, user 0.100, sys 0.098, user+sys 0.198, 19.9 % CPU Time for "pd_update total": wall 0.996, user 0.100, sys 0.098, user+sys 0.198, 19.9 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.000, user 0.098, sys 0.098, user+sys 0.196, 19.6 % CPU Time for "pd_update total": wall 1.001, user 0.098, sys 0.098, user+sys 0.196, 19.6 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.998, user 0.098, sys 0.098, user+sys 0.196, 19.6 % CPU Time for "pd_update total": wall 0.998, user 0.098, sys 0.098, user+sys 0.196, 19.6 % CPU 28 volatile int d = c * 2; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.999, user 0.098, sys 0.098, user+sys 0.196, 19.6 % CPU Time for "pd_update total": wall 0.999, user 0.098, sys 0.098, user+sys 0.196, 19.6 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.001, user 0.099, sys 0.098, user+sys 0.197, 19.7 % CPU Time for "pd_update total": wall 1.001, user 0.099, sys 0.098, user+sys 0.197, 19.7 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.969, user 0.100, sys 0.095, user+sys 0.195, 20.1 % CPU Time for "pd_update total": wall 0.969, user 0.100, sys 0.095, user+sys 0.195, 20.1 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.980, user 0.099, sys 0.096, user+sys 0.195, 19.9 % CPU Time for "pd_update total": wall 0.980, user 0.099, sys 0.096, user+sys 0.195, 19.9 % CPU 29 volatile int e = d - a; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.984, user 0.100, sys 0.096, user+sys 0.196, 19.9 % CPU Time for "pd_update total": wall 0.984, user 0.100, sys 0.096, user+sys 0.196, 19.9 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.094, user 0.098, sys 0.094, user+sys 0.192, 17.6 % CPU Time for "pd_update total": wall 1.094, user 0.099, sys 0.094, user+sys 0.193, 17.6 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.019, user 0.106, sys 0.097, user+sys 0.203, 19.9 % CPU Time for "pd_update total": wall 1.019, user 0.106, sys 0.097, user+sys 0.203, 19.9 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.002, user 0.106, sys 0.096, user+sys 0.202, 20.2 % CPU Time for "pd_update total": wall 1.002, user 0.106, sys 0.096, user+sys 0.202, 20.2 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.003, user 0.105, sys 0.096, user+sys 0.201, 20.0 % CPU Time for "pd_update total": wall 1.003, user 0.105, sys 0.096, user+sys 0.201, 20.0 % CPU 30 volatile int f = e + c; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.011, user 0.106, sys 0.097, user+sys 0.203, 20.1 % CPU Time for "pd_update total": wall 1.011, user 0.106, sys 0.097, user+sys 0.203, 20.1 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.010, user 0.107, sys 0.096, user+sys 0.203, 20.1 % CPU Time for "pd_update total": wall 1.010, user 0.107, sys 0.096, user+sys 0.203, 20.1 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.026, user 0.110, sys 0.096, user+sys 0.206, 20.1 % CPU Time for "pd_update total": wall 1.026, user 0.110, sys 0.096, user+sys 0.206, 20.1 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.200, user 0.090, sys 0.085, user+sys 0.175, 14.6 % CPU Time for "pd_update total": wall 1.201, user 0.090, sys 0.085, user+sys 0.175, 14.6 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.212, user 0.090, sys 0.091, user+sys 0.181, 14.9 % CPU Time for "pd_update total": wall 1.212, user 0.090, sys 0.091, user+sys 0.181, 14.9 % CPU 31 volatile int g = f / 2; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 0.993, user 0.103, sys 0.096, user+sys 0.199, 20.0 % CPU Time for "pd_update total": wall 0.993, user 0.103, sys 0.096, user+sys 0.199, 20.0 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.258, user 0.079, sys 0.082, user+sys 0.161, 12.8 % CPU Time for "pd_update total": wall 1.258, user 0.079, sys 0.082, user+sys 0.161, 12.8 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.255, user 0.080, sys 0.081, user+sys 0.161, 12.8 % CPU Time for "pd_update total": wall 1.255, user 0.080, sys 0.081, user+sys 0.161, 12.8 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.259, user 0.080, sys 0.081, user+sys 0.161, 12.8 % CPU Time for "pd_update total": wall 1.259, user 0.080, sys 0.081, user+sys 0.161, 12.8 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.264, user 0.080, sys 0.082, user+sys 0.162, 12.8 % CPU Time for "pd_update total": wall 1.265, user 0.080, sys 0.082, user+sys 0.162, 12.8 % CPU 32 volatile int h = g + 1; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.261, user 0.079, sys 0.083, user+sys 0.162, 12.8 % CPU Time for "pd_update total": wall 1.261, user 0.079, sys 0.083, user+sys 0.162, 12.8 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.232, user 0.076, sys 0.081, user+sys 0.157, 12.7 % CPU Time for "pd_update total": wall 1.232, user 0.076, sys 0.081, user+sys 0.157, 12.7 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.250, user 0.078, sys 0.083, user+sys 0.161, 12.9 % CPU Time for "pd_update total": wall 1.250, user 0.078, sys 0.083, user+sys 0.161, 12.9 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.258, user 0.080, sys 0.084, user+sys 0.164, 13.0 % CPU Time for "pd_update total": wall 1.258, user 0.080, sys 0.084, user+sys 0.164, 13.0 % CPU 33 volatile int i2 = h * h; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.276, user 0.082, sys 0.082, user+sys 0.164, 12.9 % CPU Time for "pd_update total": wall 1.276, user 0.082, sys 0.082, user+sys 0.164, 12.9 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.271, user 0.083, sys 0.081, user+sys 0.164, 12.9 % CPU Time for "pd_update total": wall 1.271, user 0.083, sys 0.081, user+sys 0.164, 12.9 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.280, user 0.079, sys 0.086, user+sys 0.165, 12.9 % CPU Time for "pd_update total": wall 1.280, user 0.079, sys 0.086, user+sys 0.165, 12.9 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.211, user 0.075, sys 0.081, user+sys 0.156, 12.9 % CPU Time for "pd_update total": wall 1.211, user 0.075, sys 0.081, user+sys 0.156, 12.9 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.264, user 0.077, sys 0.086, user+sys 0.163, 12.9 % CPU Time for "pd_update total": wall 1.264, user 0.077, sys 0.086, user+sys 0.163, 12.9 % CPU 34 volatile int j = i2 - b; Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.240, user 0.078, sys 0.081, user+sys 0.159, 12.8 % CPU Time for "pd_update total": wall 1.240, user 0.078, sys 0.081, user+sys 0.159, 12.8 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.256, user 0.078, sys 0.082, user+sys 0.160, 12.7 % CPU Time for "pd_update total": wall 1.257, user 0.078, sys 0.082, user+sys 0.160, 12.7 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.267, user 0.078, sys 0.082, user+sys 0.160, 12.6 % CPU Time for "pd_update total": wall 1.267, user 0.078, sys 0.082, user+sys 0.160, 12.6 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.254, user 0.079, sys 0.081, user+sys 0.160, 12.8 % CPU Time for "pd_update total": wall 1.255, user 0.079, sys 0.081, user+sys 0.160, 12.7 % CPU Time for "pthdb_session_update": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, NaNQ % CPU Time for "sync_threadlists": wall 1.257, user 0.078, sys 0.082, user+sys 0.160, 12.7 % CPU Time for "pd_update total": wall 1.257, user 0.078, sys 0.082, user+sys 0.160, 12.7 % CPU real 0m52.611s user 0m5.930s sys 0m8.012s --- gdb/aix-thread.c | 60 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index aa14f8ff045..2355f87db54 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -44,6 +44,7 @@ #include "inferior.h" #include "regcache.h" #include "cli/cli-cmds.h" +#include "maint.h" #include "ppc-tdep.h" #include "observable.h" #include "objfiles.h" @@ -706,30 +707,35 @@ state2str (pthdb_state_t state) } } +/* Number of thread descriptors to fetch per getthrds() call. + Fetching in batches reduces syscall overhead to one call per + GETTHRDS_BATCH threads. */ +constexpr int GETTHRDS_BATCH = 64; + /* Search through the list of all kernel threads for the thread - that has stopped on a SIGTRAP signal, and return its TID. + that has stopped on a signal, and return its TID. Return 0 if none found. */ static pthdb_tid_t get_signaled_thread (int pid) { - struct thrdsinfo64 thrinf; + struct thrdsinfo64 thrinf[GETTHRDS_BATCH]; tid_t ktid = 0; - while (1) - { - if (getthrds (pid, &thrinf, - sizeof (thrinf), &ktid, 1) != 1) - break; + scoped_time_it time_it ("get_signaled_thread"); + for (int count; + (count = getthrds (pid, thrinf, sizeof (thrinf[0]), &ktid, + GETTHRDS_BATCH)) > 0;) + { /* We also need to keep in mind Trap and interrupt or any signal that needs to be handled in pd_update (). */ - - if (thrinf.ti_cursig) - return thrinf.ti_tid; + for (int i = 0; i < count; i++) + if (thrinf[i].ti_cursig) + return thrinf[i].ti_tid; } - /* Didn't find any thread stopped on a SIGTRAP signal. */ + /* Didn't find any thread stopped on a signal. */ return 0; } @@ -763,18 +769,30 @@ sync_threadlists (pid_t pid) for (cmd = PTHDB_LIST_FIRST;; cmd = PTHDB_LIST_NEXT) { - status = pthdb_pthread (data->pd_session, &pdtid, cmd); + { + scoped_time_it time_it ("pthdb_pthread"); + status = pthdb_pthread (data->pd_session, &pdtid, cmd); + } if (status != PTHDB_SUCCESS || pdtid == PTHDB_INVALID_PTHREAD) break; - status = pthdb_pthread_ptid (data->pd_session, pdtid, &pthid); + { + scoped_time_it time_it ("pthdb_pthread_ptid"); + status = pthdb_pthread_ptid (data->pd_session, pdtid, &pthid); + } if (status != PTHDB_SUCCESS || pthid == PTHDB_INVALID_PTID) continue; - status = pthdb_pthread_tid (data->pd_session, pdtid, &tid); + { + scoped_time_it time_it ("pthdb_pthread_tid"); + status = pthdb_pthread_tid (data->pd_session, pdtid, &tid); + } ptid_t ptid (pid, tid, pthid); - status = pthdb_pthread_state (data->pd_session, pdtid, &state); + { + scoped_time_it time_it ("pthdb_pthread_state"); + status = pthdb_pthread_state (data->pd_session, pdtid, &state); + } in_queue_threads.insert (pdtid); /* If this thread has reported and exited, do not add it again. */ @@ -853,7 +871,12 @@ pd_update (pid_t pid) if (!data->pd_active) return ptid_t (pid); - status = pthdb_session_update (data->pd_session); + scoped_time_it total_time_it ("pd_update total"); + + { + scoped_time_it time_it ("pthdb_session_update"); + status = pthdb_session_update (data->pd_session); + } if (status != PTHDB_SUCCESS) return ptid_t (pid); @@ -861,7 +884,10 @@ pd_update (pid_t pid) and not core files since list of threads never change for core files. */ if (target_has_execution ()) - sync_threadlists (pid); + { + scoped_time_it time_it ("sync_threadlists"); + sync_threadlists (pid); + } /* Define "current thread" as one that just received a trap signal. */ -- 2.51.2