From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75852 invoked by alias); 19 May 2016 14:48:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 75754 invoked by uid 89); 19 May 2016 14:48:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=paused, Hx-languages-length:2471, thousands X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 19 May 2016 14:48:18 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE2CE64473 for ; Thu, 19 May 2016 14:48:14 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4JEmBLq009731 for ; Thu, 19 May 2016 10:48:14 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 3/6] [Linux] Avoid refetching core-of-thread if thread hasn't run Date: Thu, 19 May 2016 14:48:00 -0000 Message-Id: <1463669290-30415-4-git-send-email-palves@redhat.com> In-Reply-To: <1463669290-30415-1-git-send-email-palves@redhat.com> References: <1463669290-30415-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-05/txt/msg00330.txt.bz2 Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, I saw GDB having trouble keeping up with threads being spawned too fast, when it tried to stop them all. This was because while gdb is doing that, it updates the thread list to make sure no new thread has sneaked in that might need to be paused. It does this a few times until it sees no-new-threads twice in a row. The thread listing update itself is not that expensive, however, in the Linux backend, updating the threads list calls linux_common_core_of_thread for each LWP to record on which core each LWP was last seen running, which opens/reads/closes a /proc file for each LWP which becomes expensive when you need to do it for thousands of LWPs. perf shows gdb in linux_common_core_of_thread 44% of the time, in the stop_all_threads -> update_thread_list path in this use case. This patch simply makes linux_common_core_of_thread avoid updating the core the thread is bound to if the thread hasn't run since the last time we updated that info. This makes linux_common_core_of_thread disappear into the noise in the perf report. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * linux-nat.c (linux_resume_one_lwp_throw): Clear the LWP's core field. (linux_nat_update_thread_list): Don't fetch the core if already known. --- gdb/linux-nat.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 5ec56c1..509212e 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1432,6 +1432,7 @@ linux_resume_one_lwp_throw (struct lwp_info *lp, int step, status. Note that we must not throw after this is cleared, otherwise handle_zombie_lwp_error would get confused. */ lp->stopped = 0; + lp->core = -1; lp->stop_reason = TARGET_STOPPED_BY_NO_REASON; registers_changed_ptid (lp->ptid); } @@ -3791,7 +3792,13 @@ linux_nat_update_thread_list (struct target_ops *ops) /* Update the processor core that each lwp/thread was last seen running on. */ ALL_LWPS (lwp) - lwp->core = linux_common_core_of_thread (lwp->ptid); + { + /* Avoid accessing /proc if the thread hasn't run since we last + time we fetched the thread's core. Accessing /proc becomes + noticeably expensive when we have thousands of LWPs. */ + if (lwp->core == -1) + lwp->core = linux_common_core_of_thread (lwp->ptid); + } } static char * -- 2.5.5