From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8NixDHsW0mAtYAAAWB0awg (envelope-from ) for ; Tue, 22 Jun 2021 12:57:31 -0400 Received: by simark.ca (Postfix, from userid 112) id 31C2C1F1F2; Tue, 22 Jun 2021 12:57:31 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E13201E54D for ; Tue, 22 Jun 2021 12:57:29 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3685383583F for ; Tue, 22 Jun 2021 16:57:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3685383583F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624381049; bh=ptctwqv8+Y6My+4AaVt5kIektpW7zUAgmgQUZIbuOMs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=esAXrcu2y6jj1NhHCTk3FZyUKm7Ub50MhFEXxRV/FKxn9+lcWe88j41VlxcFz6Y4y pW/jsm/QhVJr9peoRt93TEcNaY7fjTRY7GLXmPepcNHO75MjOmCIgSHknpO2Fu3FI+ bZXRQb0nREiGwyZrvITwFGoIdJqUU84vy0EPm6PE= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id AA85B3857C40 for ; Tue, 22 Jun 2021 16:57:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AA85B3857C40 X-ASG-Debug-ID: 1624381026-0c856e6cd5194fab0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id B8qUhXC0zx7e2ngQ (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 22 Jun 2021 12:57:06 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 13DA1441B21; Tue, 22 Jun 2021 12:57:06 -0400 (EDT) X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH 00/11] Various thread lists optimizations Date: Tue, 22 Jun 2021 12:56:53 -0400 X-ASG-Orig-Subj: [PATCH 00/11] Various thread lists optimizations Message-Id: <20210622165704.2404007-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1624381026 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 5534 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.90826 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" This series contains various optimizations written after profiling ROCm-GDB [1]. A typical ROCm program may have thousands of threads (waves), so everything that iterates often on the whole thread list pops up on the profile report. Conceptually, the optimizations are: - maintain a ptid -> thread map in each inferior, to speed up the thread lookups per ptid with find_thread_ptid - make all_matching_threads_iterator a bit smarter, depending on the filter_ptid passed, it can avoid iterating on all threads. When the filter_ptid points to a specific thread, it can use find_thread_ptid to directly find the thread of interest, which is fast thanks to the previous point - maintain a per-process-target list of threads that are resumed and have a pending event. This helps speed up two hot path cases: when we check if we want to re-enable commit-resumed, and when we want to fetch a pending event. Patches up to and including patch 6 are groundwork. Notably, patch 2 (thanks to Pedro) adds an intrusive_list type, which allows using intrusive linked lists in a very C++-y way without writing a ton of boilerplate. This list type is useful for the patch that maintains a list of resumed threads with pending events, but we also converted the per-inferior thread list, the inferior list and the thread step-over-list to use it. It helped iron out a few bugs and ensure the list works well for our purposes. When debugging a ROCm test program whose threads continuously hit a condition breakpoint evaluation to false, the speedup observed with ROCm-GDB is around 5x (a run takes about 30 seconds before and 6 seconds after). With x86-64 / Linux, it's less noticeable, because the time we spend in syscalls to fetch events and resume threads still dominates. Still, when trying a program with 1000 threads hitting 100 times each a false conditional breakpoint, it goes from ~20 seconds to ~16 seconds. But I don't really expect anything that noticeable in everyday use cases though. [1] https://github.com/ROCm-Developer-Tools/ROCgdb Pedro Alves (2): gdb: introduce intrusive_list, make thread_info use it gdb: make inferior_list use intrusive_list Simon Marchi (9): gdb: introduce iterator_range, remove next_adapter gdb: use intrusive list for step-over chain gdb: add setter / getter for thread_info resumed state gdb: make thread_info::suspend private, add getters / setters gdb: maintain per-process-target list of resumed threads with pending wait status gdb: optimize check for resumed threads with pending wait status in maybe_set_commit_resumed_all_targets gdb: optimize selection of resumed thread with pending event gdb: maintain ptid -> thread map, optimize find_thread_ptid gdb: optimize all_matching_threads_iterator gdb/Makefile.in | 1 + gdb/ada-tasks.c | 4 +- gdb/breakpoint.c | 7 +- gdb/breakpoint.h | 10 +- gdb/elf-none-tdep.c | 2 +- gdb/fbsd-tdep.c | 6 +- gdb/gcore.c | 4 +- gdb/gdb-gdb.py.in | 91 ++- gdb/gdb_bfd.h | 4 +- gdb/gdbthread.h | 192 ++++- gdb/infcmd.c | 33 +- gdb/inferior-iter.h | 94 +-- gdb/inferior.c | 105 ++- gdb/inferior.h | 34 +- gdb/inflow.c | 2 +- gdb/infrun.c | 476 ++++++------ gdb/infrun.h | 4 +- gdb/linux-fork.c | 3 +- gdb/linux-nat.c | 12 +- gdb/linux-tdep.c | 2 +- gdb/objfiles.h | 6 +- gdb/process-stratum-target.c | 77 ++ gdb/process-stratum-target.h | 26 + gdb/progspace.c | 11 +- gdb/progspace.h | 45 +- gdb/psymtab.h | 2 +- gdb/python/py-inferior.c | 2 +- gdb/record-btrace.c | 3 +- gdb/record-full.c | 3 +- gdb/regcache.c | 6 +- gdb/remote.c | 68 +- gdb/scoped-mock-context.h | 15 +- gdb/solist.h | 2 + gdb/symtab.h | 15 +- gdb/thread-iter.c | 147 +++- gdb/thread-iter.h | 61 +- gdb/thread.c | 216 +++--- gdb/top.h | 6 +- gdb/unittests/intrusive_list-selftests.c | 818 +++++++++++++++++++++ gdbsupport/intrusive_list.h | 586 +++++++++++++++ gdbsupport/iterator-range.h | 60 ++ gdbsupport/next-iterator.h | 32 +- gdbsupport/reference-to-pointer-iterator.h | 82 +++ 43 files changed, 2574 insertions(+), 801 deletions(-) create mode 100644 gdb/unittests/intrusive_list-selftests.c create mode 100644 gdbsupport/intrusive_list.h create mode 100644 gdbsupport/iterator-range.h create mode 100644 gdbsupport/reference-to-pointer-iterator.h -- 2.32.0