From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932338AbbDHPMt (ORCPT ); Wed, 8 Apr 2015 11:12:49 -0400 Received: from terminus.zytor.com ([198.137.202.10]:40280 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932305AbbDHPMq (ORCPT ); Wed, 8 Apr 2015 11:12:46 -0400 Date: Wed, 8 Apr 2015 08:12:27 -0700 From: tip-bot for Yunlong Song Message-ID: Cc: tglx@linutronix.de, a.p.zijlstra@chello.nl, hpa@zytor.com, acme@redhat.com, yunlong.song@huawei.com, wangnan0@huawei.com, mingo@kernel.org, paulus@samba.org, linux-kernel@vger.kernel.org Reply-To: paulus@samba.org, mingo@kernel.org, linux-kernel@vger.kernel.org, a.p.zijlstra@chello.nl, tglx@linutronix.de, wangnan0@huawei.com, acme@redhat.com, hpa@zytor.com, yunlong.song@huawei.com In-Reply-To: <1427809596-29559-5-git-send-email-yunlong.song@huawei.com> References: <1427809596-29559-5-git-send-email-yunlong.song@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf sched replay: Realloc the memory of pid_to_task stepwise to adapt to the different pid_max configurations Git-Commit-ID: 3a423a5c36d1a28a258beaa7db855568b82d07ab X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 3a423a5c36d1a28a258beaa7db855568b82d07ab Gitweb: http://git.kernel.org/tip/3a423a5c36d1a28a258beaa7db855568b82d07ab Author: Yunlong Song AuthorDate: Tue, 31 Mar 2015 21:46:31 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 8 Apr 2015 09:07:23 -0300 perf sched replay: Realloc the memory of pid_to_task stepwise to adapt to the different pid_max configurations Although the memory of pid_to_task can be allocated via calloc according to the value of /proc/sys/kernel/pid_max, it cannot handle the case when pid_max is changed after 'perf sched record' has created its perf.data. If the new pid_max configured in 'perf sched replay' is smaller than the old pid_max configured in 'perf sched record', then it will cause the assertion failure problem. To solve this problem, we realloc the memory of pid_to_task stepwise once the passed-in pid parameter in register_pid is larger than the current pid_max. Example: Test environment: x86_64 with 160 cores $ cat /proc/sys/kernel/pid_max 163840 $ perf sched record ls $ echo 5000 > /proc/sys/kernel/pid_max $ cat /proc/sys/kernel/pid_max 5000 Before this patch: $ perf sched replay run measurement overhead: 221 nsecs sleep measurement overhead: 55356 nsecs the run test took 1000011 nsecs the sleep test took 1060940 nsecs perf: builtin-sched.c:337: register_pid: Assertion `!(pid >= (unsigned long)pid_max)' failed. Aborted After this patch: $ perf sched replay run measurement overhead: 221 nsecs sleep measurement overhead: 55611 nsecs the run test took 1000026 nsecs the sleep test took 1060486 nsecs nr_run_events: 10 nr_sleep_events: 1562 nr_wakeup_events: 5 task 0 ( :1: 1), nr_events: 1 task 1 ( :2: 2), nr_events: 1 task 2 ( :3: 3), nr_events: 1 task 3 ( :5: 5), nr_events: 1 ... Signed-off-by: Yunlong Song Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/r/1427809596-29559-5-git-send-email-yunlong.song@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-sched.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 20d887b..dd71481 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -334,7 +334,12 @@ static struct task_desc *register_pid(struct perf_sched *sched, pid_max = MAX_PID; BUG_ON((sched->pid_to_task = calloc(pid_max, sizeof(struct task_desc *))) == NULL); } - BUG_ON(pid >= (unsigned long)pid_max); + if (pid >= (unsigned long)pid_max) { + BUG_ON((sched->pid_to_task = realloc(sched->pid_to_task, (pid + 1) * + sizeof(struct task_desc *))) == NULL); + while (pid >= (unsigned long)pid_max) + sched->pid_to_task[pid_max++] = NULL; + } task = sched->pid_to_task[pid];