From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AAFOLtsq42BLYwAAWB0awg (envelope-from ) for ; Mon, 05 Jul 2021 11:52:59 -0400 Received: by simark.ca (Postfix, from userid 112) id BA3201F1F2; Mon, 5 Jul 2021 11:52:59 -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.6 required=5.0 tests=MAILING_LIST_MULTI, RDNS_DYNAMIC 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 12DB31E940 for ; Mon, 5 Jul 2021 11:52:59 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D03253843893 for ; Mon, 5 Jul 2021 15:52:58 +0000 (GMT) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by sourceware.org (Postfix) with ESMTPS id B7A77385700B for ; Mon, 5 Jul 2021 15:52:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B7A77385700B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f52.google.com with SMTP id o22so11734987wms.0 for ; Mon, 05 Jul 2021 08:52:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UU2he5mnYMkWXSl6JSWxaSGfOalsVDajtOREGbw+yMw=; b=CptYPlufP6rSi3bCw7mt7WX+L/DNrpKbTGrys0kbaxlCJ/QErd2lJFA1lTkkIwB6Y+ 0pgQFykcD5HPVU18Kmi5zNPEo9b7W/IxfziNMZuKCv/34kPcOlLe0wvHp7dLmLRqjU+R De/06NI3/52Ua77UumIvdQJb7sghy9HRFLxl/OK+XkCi0m0mh1qF8wChkQlPhvMQVcIR OyA4dAYAAB9CCmpOEAt+4CldY+oq0xAU8/G7hErTTIhbtqFfRS8Vo6VtqAQoRzZQO1gC 3x+AWPoGuIzGtdrBWTmzJMcK305cmGpBoEbpTm3RnFnRV2aX7YR+n++TCF0gScRLyQxJ weIA== X-Gm-Message-State: AOAM531Mue+8vurYpmC4BytGqZuzZW095pBmhyR8cGQLZ6p/yHjCHQjh tE280IUWWoOUVomLgP1JkloTsa4aeJyQCA== X-Google-Smtp-Source: ABdhPJxTQsZl9iyndut6wmsZLoDrzThfaAWsgZVO4QV5fRzoDeKZ8MF83dg6vrtxWWC5QbLvNFdRJw== X-Received: by 2002:a1c:f314:: with SMTP id q20mr15892142wmq.154.1625500366265; Mon, 05 Jul 2021 08:52:46 -0700 (PDT) Received: from ?IPv6:2001:8a0:f932:6a00:46bc:d03b:7b3a:2227? ([2001:8a0:f932:6a00:46bc:d03b:7b3a:2227]) by smtp.gmail.com with ESMTPSA id z4sm12355000wrp.46.2021.07.05.08.52.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Jul 2021 08:52:45 -0700 (PDT) Subject: Re: [PATCH 11/11] gdb: optimize all_matching_threads_iterator From: Pedro Alves To: Simon Marchi , gdb-patches@sourceware.org References: <20210622165704.2404007-1-simon.marchi@polymtl.ca> <20210622165704.2404007-12-simon.marchi@polymtl.ca> Message-ID: Date: Mon, 5 Jul 2021 16:52:44 +0100 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-12-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2021-06-22 5:57 p.m., Simon Marchi via Gdb-patches wrote: > all_matching_threads_iterator is used extensively in some pretty fast > paths, often under the all_non_exited_threads function. > > If a filter target and thread-specific ptid are given, it iterates on > all threads of all inferiors of that target, to ultimately yield exactly > on thread. And this happens quite often, which means we unnecessarily > spend time iterating on threads to find the one we are looking for. The > same thing happens if an inferior-specific ptid is given, although there > the iterator yields all the threads of that inferior. > > In those cases, the callers of all_non_exited_threads could have > different behaviors depending on the kind of ptid, to avoid this > inefficiency, but that would be very tedious. Using > all_non_exited_threads has the advantage that one simple implementation > can work seamlessly on multiple threads or on one specific thread, just > by playing with the ptid. > > Instead, optimize all_matching_threads_iterator directly to detect these > different cases and limiting what we iterate on to just what we need. > > - if filter_ptid is minus_one_ptid, do as we do now: filter inferiors > based on filter_target, iterate on all of the matching inferiors' > threads > - if filter_ptid is a pid-only ptid (then a filter_target must > necessarily be given), look up that inferior and iterate on all its > threads > - otherwise, filter_ptid is a thread-specific ptid, so look up that > specific thread and "iterate" only on it > > For the last case, what was an iteration on all threads of the filter > target now becomes a call to find_thread_ptid, which is quite efficient > now thanks to inferior::ptid_thread_map. > > gdb/ChangeLog: > > * thread-iter.h (class all_matching_threads_iterator) > : Use default. > : New. > : Initialize. > : Remove. > * thread-iter.c (all_matching_threads_iterator::m_inf_matches): > Don't filter on m_filter_ptid. > (all_matching_threads_iterator::all_matching_threads_iterator): > Choose path based on filter_ptid (all threads, all threads of > inferior, single thread). > (all_matching_threads_iterator::advance): Likewise. OK.