linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: David Ahern <dsahern@gmail.com>
Cc: Yunlong Song <yunlong.song@huawei.com>,
	a.p.zijlstra@chello.nl, paulus@samba.org, mingo@redhat.com,
	linux-kernel@vger.kernel.org, wangnan0@huawei.com
Subject: Re: [PATCH 3/9] perf sched replay: Alloc the memory of pid_to_task dynamically to adapt to the unexpected change of pid_max
Date: Tue, 31 Mar 2015 12:56:55 -0300	[thread overview]
Message-ID: <20150331155655.GL9438@kernel.org> (raw)
In-Reply-To: <551AB005.8080102@gmail.com>

Em Tue, Mar 31, 2015 at 08:32:37AM -0600, David Ahern escreveu:
> On 3/31/15 7:46 AM, Yunlong Song wrote:
> >-	BUG_ON(pid >= MAX_PID);
> >+	if (sched->pid_to_task == NULL) {
> >+		if (sysctl__read_int("kernel/pid_max", &pid_max) < 0)
> >+			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);
 
> so why the previous patch bumping the MAX_PID count if you move to dynamic
> here? And shouldn't MAX_PID get dropped here as well?
 
> So attached is what i put together last week; just have not had time to send
> it out.

Yunlong, can you please check/Ack this?

- Arnaldo

> >From 159dc732e0ad66d9151e93761bc9c685872e9fa4 Mon Sep 17 00:00:00 2001
> From: David Ahern <david.ahern@oracle.com>
> Date: Tue, 24 Mar 2015 16:57:10 -0400
> Subject: [PATCH 3/5] perf sched: Remove max pid assumption from perf-sched
> 
> 'perf sched replay' currently fails on sparc64:
>     $ perf sched replay
>     run measurement overhead: 2475 nsecs
>     sleep measurement overhead: 56165 nsecs
>     the run test took 999705 nsecs
>     the sleep test took 1059270 nsecs
>     perf: builtin-sched.c:384: register_pid: Assertion `!(pid >= 65536)' failed.
>     Aborted
> 
> The max pid limitation is removed by converting pid_to_task from a
> pid based array to an intlist (rblist) with the pid as the index
> and task_desc stored in the priv element.
> 
> In the process pid is converted from a long int to int.
> 
> Signed-off-by: David Ahern <david.ahern@oracle.com>
> ---
>  tools/perf/builtin-sched.c | 30 ++++++++++++++++++++----------
>  1 file changed, 20 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index cc52c993a1fa..858d85396d81 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -33,13 +33,12 @@
>  #define MAX_CPUS		4096
>  #define COMM_LEN		20
>  #define SYM_LEN			129
> -#define MAX_PID			65536
>  
>  struct sched_atom;
>  
>  struct task_desc {
>  	unsigned long		nr;
> -	unsigned long		pid;
> +	int			pid;
>  	char			comm[COMM_LEN];
>  
>  	unsigned long		nr_events;
> @@ -129,7 +128,7 @@ struct perf_sched {
>  	struct perf_tool tool;
>  	const char	 *sort_order;
>  	unsigned long	 nr_tasks;
> -	struct task_desc *pid_to_task[MAX_PID];
> +	struct intlist	 *pid_to_task;
>  	struct task_desc **tasks;
>  	const struct trace_sched_handler *tp_handler;
>  	pthread_mutex_t	 start_work_mutex;
> @@ -377,14 +376,18 @@ static void add_sched_event_sleep(struct perf_sched *sched, struct task_desc *ta
>  }
>  
>  static struct task_desc *register_pid(struct perf_sched *sched,
> -				      unsigned long pid, const char *comm)
> +				      int pid, const char *comm)
>  {
> -	struct task_desc *task;
>  
> -	BUG_ON(pid >= MAX_PID);
> +	struct int_node *node = intlist__findnew(sched->pid_to_task, pid);
> +	struct task_desc *task;
>  
> -	task = sched->pid_to_task[pid];
> +	if (node == NULL) {
> +		pr_err("Failed to allocate entry for task\n");
> +		return NULL;
> +	}
>  
> +	task = (struct task_desc *) node->priv;
>  	if (task)
>  		return task;
>  
> @@ -392,20 +395,21 @@ static struct task_desc *register_pid(struct perf_sched *sched,
>  	task->pid = pid;
>  	task->nr = sched->nr_tasks;
>  	strcpy(task->comm, comm);
> +
>  	/*
>  	 * every task starts in sleeping state - this gets ignored
>  	 * if there's no wakeup pointing to this sleep state:
>  	 */
>  	add_sched_event_sleep(sched, task, 0, 0);
>  
> -	sched->pid_to_task[pid] = task;
> +	node->priv = task;
>  	sched->nr_tasks++;
>  	sched->tasks = realloc(sched->tasks, sched->nr_tasks * sizeof(struct task_task *));
>  	BUG_ON(!sched->tasks);
>  	sched->tasks[task->nr] = task;
>  
>  	if (verbose)
> -		printf("registered task #%ld, PID %ld (%s)\n", sched->nr_tasks, pid, comm);
> +		printf("registered task #%ld, PID %d (%s)\n", sched->nr_tasks, pid, comm);
>  
>  	return task;
>  }
> @@ -418,7 +422,7 @@ static void print_task_traces(struct perf_sched *sched)
>  
>  	for (i = 0; i < sched->nr_tasks; i++) {
>  		task = sched->tasks[i];
> -		printf("task %6ld (%20s:%10ld), nr_events: %ld\n",
> +		printf("task %6ld (%20s:%10d), nr_events: %ld\n",
>  			task->nr, task->comm, task->pid, task->nr_events);
>  	}
>  }
> @@ -2981,6 +2985,12 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
>  	};
>  	unsigned int i;
>  
> +	sched.pid_to_task = intlist__new(NULL);
> +	if (sched.pid_to_task == NULL) {
> +		pr_err("Failed to allocate intlist for tracking tasks\n");
> +		return -ENOMEM;
> +	}
> +
>  	for (i = 0; i < ARRAY_SIZE(sched.curr_pid); i++)
>  		sched.curr_pid[i] = -1;
>  
> -- 
> 2.3.0
> 


  reply	other threads:[~2015-03-31 15:56 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-31 13:46 [PATCH 0/9] perf sched replay: Make some improvements and fixes Yunlong Song
2015-03-31 13:46 ` [PATCH 1/9] perf sched replay: Use struct task_desc instead of struct task_task for correct meaning Yunlong Song
2015-04-08 15:11   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-31 13:46 ` [PATCH 2/9] perf sched replay: Increase the MAX_PID value to fix assertion failure problem Yunlong Song
2015-03-31 14:25   ` David Ahern
2015-04-01  7:10     ` Yunlong Song
2015-04-08 15:11   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-31 13:46 ` [PATCH 3/9] perf sched replay: Alloc the memory of pid_to_task dynamically to adapt to the unexpected change of pid_max Yunlong Song
2015-03-31 14:32   ` David Ahern
2015-03-31 15:56     ` Arnaldo Carvalho de Melo [this message]
2015-04-01  7:06       ` Yunlong Song
2015-04-07 13:23         ` Yunlong Song
2015-04-07 15:02           ` Arnaldo Carvalho de Melo
2015-03-31 20:25     ` Arnaldo Carvalho de Melo
2015-03-31 22:26       ` David Ahern
2015-03-31 22:35         ` Arnaldo Carvalho de Melo
2015-04-01  7:23     ` Yunlong Song
2015-04-08 15:12   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-31 13:46 ` [PATCH 4/9] perf sched replay: Realloc the memory of pid_to_task stepwise to adapt to the different pid_max configurations Yunlong Song
2015-04-08 15:12   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-31 13:46 ` [PATCH 5/9] perf sched replay: Fix the segmentation fault problem caused by pr_err in threads Yunlong Song
2015-04-08 15:12   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-31 13:46 ` [PATCH 6/9] perf sched replay: Handle the dead halt of sem_wait when create_tasks() fails for any task Yunlong Song
2015-04-08 15:13   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-31 13:46 ` [PATCH 7/9] perf sched replay: Fix the EMFILE error caused by the limitation of the maximum open files Yunlong Song
2015-04-07 16:49   ` David Ahern
2015-04-08 15:13   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-31 13:46 ` [PATCH 8/9] perf sched replay: Support using -f to override perf.data file ownership Yunlong Song
2015-04-08 15:13   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-09-21 13:54   ` [RFC] Perf: Trigger and dump sample info to perf.data from user space ring buffer Yunlong Song
2015-09-21 15:12     ` Borislav Petkov
2015-03-31 13:46 ` [PATCH 9/9] perf sched replay: Use replay_repeat to calculate the runavg of cpu usage instead of the default value 10 Yunlong Song
2015-04-08 15:13   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-04-07  3:20 ` [PATCH 0/9] perf sched replay: Make some improvements and fixes Yunlong Song
2015-04-07 13:53   ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150331155655.GL9438@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=dsahern@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --cc=wangnan0@huawei.com \
    --cc=yunlong.song@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).