From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 22DC4397EC36 for ; Wed, 14 Jul 2021 09:40:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 22DC4397EC36 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 47D47229FC; Wed, 14 Jul 2021 09:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626255639; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H0qkbd9TID1MG7SDUNqjlMdkvk7bGUxywgzAxhrvpuU=; b=VI6AP+dlpVcOgqQZhqziW4oOGOUBIrHM2vJyPG49uYef7bNhoAvQ9TZacS2yZlzcbg/SQg cjHBGOUW6lXoR0S5YxDsUIhk3JffAHc65qedFZ9bSGcOMR1mpKIWhFJLhYuiIfeSVYVLNo J7SXzxXAh2cbZ8vMLsWKIpV5kWs2/6w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626255639; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H0qkbd9TID1MG7SDUNqjlMdkvk7bGUxywgzAxhrvpuU=; b=kO5hBYaq23q8WoZkeW/LhQgKe6JcPFyzVnI7Z+8mAddNEUS+mim8ZaoNNSGeanVNXx/SO5 r9FPdc5ZO9vyvIDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2E3EA13BFB; Wed, 14 Jul 2021 09:40:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kBU9Chex7mDBIwAAMHmgww (envelope-from ); Wed, 14 Jul 2021 09:40:39 +0000 Subject: Re: [PATCH 11/11] gdb: optimize all_matching_threads_iterator To: Pedro Alves , Simon Marchi , gdb-patches@sourceware.org References: <20210622165704.2404007-1-simon.marchi@polymtl.ca> <20210622165704.2404007-12-simon.marchi@polymtl.ca> From: Tom de Vries Message-ID: <7a178941-a14c-27a5-4d39-4246a5d786f9@suse.de> Date: Wed, 14 Jul 2021 11:40:38 +0200 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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Wed, 14 Jul 2021 09:40:41 -0000 On 7/5/21 5:52 PM, Pedro Alves wrote: > 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. > FTR, this caused an internal-error, filed at https://sourceware.org/bugzilla/show_bug.cgi?id=28086 . Thanks, - Tom