Linux Perf Users
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Emil Berg <emil.berg@ericsson.com>
Cc: "linux-perf-users@vger.kernel.org" <linux-perf-users@vger.kernel.org>
Subject: Re: Possible overwriting of errno
Date: Wed, 29 Jun 2022 11:44:36 +0200	[thread overview]
Message-ID: <YrwfBPMR+2kZFgHH@krava> (raw)
In-Reply-To: <AM8PR07MB7666EEF15D803DAFB5A8284D98BB9@AM8PR07MB7666.eurprd07.prod.outlook.com>

On Wed, Jun 29, 2022 at 05:31:42AM +0000, Emil Berg wrote:
> Hi!
> 
> I'm getting the error "Failed to start threads: File exists" from perf, probably EEXIST.
> 
> I just want to discuss the changes to tools/perf/builtin-record.c made Feb 10 2022 with:
> perf record: Start threads in the beginning of trace streaming
> SHA: 3217e9fecf118d5dcabdd68d91e0c6afcb4c3e1b
> 
> At line 2014 pthread_create() is run and on line 2017 strerror(errno) is printed. Between line 2014 and 2017 record__terminate_thread() is run.
> 
> I just think record__terminate_thread() run in-between looks like it may overwrite errno, thus messing up the error message. To be clear I think the error message should come from failure of thread creation and not from failure of thread termination. Can someone enlighten me here?
> 
> if (pthread_create(&handle, &attrs, record__thread, &thread_data[t])) {
>     for (tt = 1; tt < t; tt++)
>         record__terminate_thread(&thread_data[t]);
>     pr_err("Failed to start threads: %s\n", strerror(errno));
> 
> /Emil Berg

yea, seems wrong.. could you try patch below?

thanks,
jirka


---
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index cf5c5379ceaa..158bb0f293d2 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -2103,11 +2103,11 @@ static int record__start_threads(struct record *rec)
 					    MMAP_CPU_MASK_BYTES(&(thread_data[t].mask->affinity)),
 					    (cpu_set_t *)(thread_data[t].mask->affinity.bits));
 #endif
-		if (pthread_create(&handle, &attrs, record__thread, &thread_data[t])) {
+		ret = pthread_create(&handle, &attrs, record__thread, &thread_data[t]);
+		if (ret) {
 			for (tt = 1; tt < t; tt++)
 				record__terminate_thread(&thread_data[t]);
-			pr_err("Failed to start threads: %s\n", strerror(errno));
-			ret = -1;
+			pr_err("Failed to start threads: %s\n", strerror(ret));
 			goto out_err;
 		}
 

  reply	other threads:[~2022-06-29  9:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-29  5:31 Possible overwriting of errno Emil Berg
2022-06-29  9:44 ` Jiri Olsa [this message]
2022-06-29 12:50   ` Emil Berg
2022-10-11  8:04 ` Emil Berg

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=YrwfBPMR+2kZFgHH@krava \
    --to=olsajiri@gmail.com \
    --cc=emil.berg@ericsson.com \
    --cc=linux-perf-users@vger.kernel.org \
    /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