Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754458AbbLJHy1 (ORCPT ); Thu, 10 Dec 2015 02:54:27 -0500 Received: from LGEAMRELO12.lge.com ([156.147.23.52]:33607 "EHLO lgeamrelo12.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753765AbbLJHxo (ORCPT ); Thu, 10 Dec 2015 02:53:44 -0500 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: namhyung@kernel.org X-Original-SENDERIP: 10.177.227.17 X-Original-MAILFROM: namhyung@kernel.org From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Ingo Molnar , Peter Zijlstra , Jiri Olsa , LKML , David Ahern , Frederic Weisbecker , Andi Kleen , Stephane Eranian , Adrian Hunter Subject: [PATCH/RFC 12/16] perf tools: Reduce lock contention when processing events Date: Thu, 10 Dec 2015 16:53:31 +0900 Message-Id: <1449734015-9148-13-git-send-email-namhyung@kernel.org> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1449734015-9148-1-git-send-email-namhyung@kernel.org> References: <1449734015-9148-1-git-send-email-namhyung@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3491 Lines: 95 When multi-thread is enabled, the machine->threads_lock is contented as all worker threads try to grab the writer lock using the machine__findnew_thread(). Usually, the thread they're looking for is in the tree so they only need the reader lock though. Thus try machine__find_thread() first, and then fallback to the 'findnew' API. This will improve the performance. Signed-off-by: Namhyung Kim --- tools/perf/util/event.c | 7 +++++-- tools/perf/util/machine.c | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 8b10621b415c..cefd43f8ec66 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -993,10 +993,13 @@ int perf_event__preprocess_sample(const union perf_event *event, struct perf_sample *sample) { u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; - struct thread *thread = machine__findnew_thread(machine, sample->pid, - sample->tid); + struct thread *thread = machine__find_thread(machine, sample->pid, + sample->tid); if (thread == NULL) + thread = machine__findnew_thread(machine, sample->pid, + sample->tid); + if (thread == NULL) return -1; dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index f5882b8c8db9..6d7349501f26 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -467,7 +467,7 @@ struct comm *machine__thread_exec_comm(struct machine *machine, int machine__process_comm_event(struct machine *machine, union perf_event *event, struct perf_sample *sample) { - struct thread *thread = machine__findnew_thread(machine, + struct thread *thread = machine__find_thread(machine, event->comm.pid, event->comm.tid); bool exec = event->header.misc & PERF_RECORD_MISC_COMM_EXEC; @@ -479,6 +479,10 @@ int machine__process_comm_event(struct machine *machine, union perf_event *event if (dump_trace) perf_event__fprintf_comm(event, stdout); + if (thread == NULL) { + thread = machine__findnew_thread(machine, event->comm.pid, + event->comm.tid); + } if (thread == NULL || __thread__set_comm(thread, event->comm.comm, sample->time, exec)) { dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n"); @@ -1314,8 +1318,13 @@ int machine__process_mmap2_event(struct machine *machine, return 0; } - thread = machine__findnew_thread(machine, event->mmap2.pid, + thread = machine__find_thread(machine, event->mmap2.pid, event->mmap2.tid); + if (thread == NULL) { + thread = machine__findnew_thread(machine, + event->mmap2.pid, + event->mmap2.tid); + } if (thread == NULL) goto out_problem; @@ -1368,8 +1377,12 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event return 0; } - thread = machine__findnew_thread(machine, event->mmap.pid, + thread = machine__find_thread(machine, event->mmap.pid, event->mmap.tid); + if (thread == NULL) { + thread = machine__findnew_thread(machine, event->mmap.pid, + event->mmap.tid); + } if (thread == NULL) goto out_problem; -- 2.6.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/