From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oTicOsni7GClfQAAWB0awg (envelope-from ) for ; Mon, 12 Jul 2021 20:48:09 -0400 Received: by simark.ca (Postfix, from userid 112) id BE8831EDEC; Mon, 12 Jul 2021 20:48:09 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.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 A878A1EDDB for ; Mon, 12 Jul 2021 20:48:08 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F5C53898039 for ; Tue, 13 Jul 2021 00:48:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F5C53898039 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1626137287; bh=BO3BvzLeO44HPue6f4/r0urDmWPJb/EHuru2oGVx0oU=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=BDcpWKame7jfpUecwgNwJI1k6X9SFFYSITgm4YtZ6ISUPWvtmI++5TUmcp/Jfwe6n Ck9LbZe/GPFNcBxRHNacpGWvgyZLYECa6yv3gukSlfv5Z2jBKV8grP47CUpYVJM5xV nE0CFyOG6JjB44XscSnhs0uKyDAs+dgniSCz0Hug= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 9459A3896C14 for ; Tue, 13 Jul 2021 00:47:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9459A3896C14 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 16D0ld7T026001 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 12 Jul 2021 20:47:43 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 16D0ld7T026001 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 283AE1EDDB for ; Mon, 12 Jul 2021 20:47:39 -0400 (EDT) Subject: Re: [PATCH 00/11] Various thread lists optimizations To: gdb-patches@sourceware.org References: <20210622165704.2404007-1-simon.marchi@polymtl.ca> Message-ID: <4027da72-9122-0c31-3673-fa359147f074@polymtl.ca> Date: Mon, 12 Jul 2021 20:47:38 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210622165704.2404007-1-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 13 Jul 2021 00:47:39 +0000 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" On 2021-06-22 12:56 p.m., Simon Marchi wrote: > 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 > I pushed this series after addressing Pedro's comments. Simon