From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754809AbaGNKOM (ORCPT ); Mon, 14 Jul 2014 06:14:12 -0400 Received: from mga11.intel.com ([192.55.52.93]:41894 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754508AbaGNKFg (ORCPT ); Mon, 14 Jul 2014 06:05:36 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,657,1400050800"; d="scan'208";a="561434554" From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, David Ahern , Frederic Weisbecker , Jiri Olsa , Namhyung Kim , Paul Mackerras , Stephane Eranian Subject: [PATCH 25/41] perf tools: Add ability to record the current tid for each cpu Date: Mon, 14 Jul 2014 13:02:49 +0300 Message-Id: <1405332185-4050-26-git-send-email-adrian.hunter@intel.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1405332185-4050-1-git-send-email-adrian.hunter@intel.com> References: <1405332185-4050-1-git-send-email-adrian.hunter@intel.com> Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add an array to struct machine to store the current tid running on each cpu. Add machine functions to get / set the tid for a cpu. This will be used to determine the tid when decoding a per-cpu Instruction Trace. Signed-off-by: Adrian Hunter --- tools/perf/util/machine.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/machine.h | 5 +++++ 2 files changed, 51 insertions(+) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 347ac65..8d9e4a7 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -47,6 +47,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) thread__set_comm(thread, comm, 0); } + machine->current_tid = NULL; + return 0; } @@ -106,6 +108,7 @@ void machine__exit(struct machine *machine) dsos__delete(&machine->user_dsos); dsos__delete(&machine->kernel_dsos); zfree(&machine->root_dir); + zfree(&machine->current_tid); } void machine__delete(struct machine *machine) @@ -1497,3 +1500,46 @@ int machine__get_kernel_start(struct machine *machine) } return err; } + +pid_t machine__get_current_tid(struct machine *machine, int cpu) +{ + if (cpu < 0 || cpu >= MAX_NR_CPUS || !machine->current_tid) + return -1; + + return machine->current_tid[cpu]; +} + +int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, + pid_t tid) +{ + struct thread *thread; + + if (cpu < 0) + return -EINVAL; + + if (!machine->current_tid) { + int i; + + machine->current_tid = calloc(MAX_NR_CPUS, sizeof(pid_t)); + if (!machine->current_tid) + return -ENOMEM; + for (i = 0; i < MAX_NR_CPUS; i++) + machine->current_tid[i] = -1; + } + + if (cpu >= MAX_NR_CPUS) { + pr_err("Requested CPU %d too large. ", cpu); + pr_err("Consider raising MAX_NR_CPUS\n"); + return -EINVAL; + } + + machine->current_tid[cpu] = tid; + + thread = machine__findnew_thread(machine, pid, tid); + if (!thread) + return -ENOMEM; + + thread->cpu = cpu; + + return 0; +} diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index be97021..6442d65 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -35,6 +35,7 @@ struct machine { struct map *vmlinux_maps[MAP__NR_TYPES]; u64 kernel_start; symbol_filter_t symbol_filter; + pid_t *current_tid; }; static inline @@ -212,4 +213,8 @@ int machine__synthesize_threads(struct machine *machine, struct target *target, perf_event__process, data_mmap); } +pid_t machine__get_current_tid(struct machine *machine, int cpu); +int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, + pid_t tid); + #endif /* __PERF_MACHINE_H */ -- 1.8.3.2