All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Yunlong Song <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: yunlong.song@huawei.com, mingo@kernel.org, acme@redhat.com,
	tglx@linutronix.de, linux-kernel@vger.kernel.org,
	a.p.zijlstra@chello.nl, paulus@samba.org, wangnan0@huawei.com,
	hpa@zytor.com
Subject: [tip:perf/core] perf sched replay: Fix the segmentation fault problem caused by pr_err in threads
Date: Wed, 8 Apr 2015 08:12:45 -0700	[thread overview]
Message-ID: <tip-08097abc11bcee21355dd857852a807b2a30b79f@git.kernel.org> (raw)
In-Reply-To: <1427809596-29559-6-git-send-email-yunlong.song@huawei.com>

Commit-ID:  08097abc11bcee21355dd857852a807b2a30b79f
Gitweb:     http://git.kernel.org/tip/08097abc11bcee21355dd857852a807b2a30b79f
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Tue, 31 Mar 2015 21:46:32 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Apr 2015 09:07:24 -0300

perf sched replay: Fix the segmentation fault problem caused by pr_err in threads

The pr_err in self_open_counters() prints error message to stderr.
Unlike stdout, stderr uses memory buffer on the stack of each calling
process.

The pr_err in self_open_counters() works in a thread called thread_func
created in function create_tasks, which concurrently creates
sched->nr_tasks threads.

If the error happens and pr_err prints the error message in each of
these threads, the stack size of the perf process (default is 8192
kbytes) will quickly run out and the segmentation fault will happen
then.

To solve this problem, pr_err with self_open_counters() should be moved
from newly created threads to the old main thread of the perf process.
Then the pr_err can work in a stable situation without the strange
segmentation fault problem.

Example:

Test environment: x86_64 with 160 cores

Before this patch:

 $ perf sched replay
 ...
 task   1549 (             :163132:    163132), nr_events: 1
 task   1550 (             :163540:    163540), nr_events: 1
 task   1551 (           <unknown>:         0), nr_events: 10
 Segmentation fault

After this patch:

 $ perf sched replay
 ...
 task   1549 (             :163132:    163132), nr_events: 1
 task   1550 (             :163540:    163540), nr_events: 1
 task   1551 (           <unknown>:         0), nr_events: 10
 ...

As shown above, the result continues without any segmentation fault.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1427809596-29559-6-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-sched.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index dd71481..7fe3b3c 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -472,6 +472,7 @@ static u64 get_cpu_usage_nsec_self(int fd)
 struct sched_thread_parms {
 	struct task_desc  *task;
 	struct perf_sched *sched;
+	int fd;
 };
 
 static void *thread_func(void *ctx)
@@ -482,13 +483,12 @@ static void *thread_func(void *ctx)
 	u64 cpu_usage_0, cpu_usage_1;
 	unsigned long i, ret;
 	char comm2[22];
-	int fd;
+	int fd = parms->fd;
 
 	zfree(&parms);
 
 	sprintf(comm2, ":%s", this_task->comm);
 	prctl(PR_SET_NAME, comm2);
-	fd = self_open_counters();
 	if (fd < 0)
 		return NULL;
 again:
@@ -540,6 +540,7 @@ static void create_tasks(struct perf_sched *sched)
 		BUG_ON(parms == NULL);
 		parms->task = task = sched->tasks[i];
 		parms->sched = sched;
+		parms->fd = self_open_counters();
 		sem_init(&task->sleep_sem, 0, 0);
 		sem_init(&task->ready_for_work, 0, 0);
 		sem_init(&task->work_done_sem, 0, 0);

  reply	other threads:[~2015-04-08 15:13 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
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-bot for Yunlong Song [this message]
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=tip-08097abc11bcee21355dd857852a807b2a30b79f@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulus@samba.org \
    --cc=tglx@linutronix.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.