Skip to contentSkip to conversation

powerpc tools perf: Initialize error code in auxtrace_record_init function

PATCH Superseded Athira Rajeev 3 participants 5 messages May 2 – May 4 perf events

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 powerpc tools perf: Initialize error code in auxtrace_record_init function

perf trace record fails some cases in powerpc

 # ./perf test "perf trace record and replay"
 128: perf trace record and replay                                    : FAILED!
 # ./perf trace record sleep 1
 # echo $?
   32

This is happening because of non-zero err value from auxtrace_record__init() function.

static int record__auxtrace_init(struct record *rec)

 {
        int err;

        if ((rec->opts.auxtrace_snapshot_opts || rec->opts.auxtrace_sample_opts)
            && record__threads_enabled(rec)) {
                pr_err("AUX area tracing options are not available in parallel streaming mode.\n");
                return -EINVAL;
        }

        if (!rec->itr) {
                rec->itr = auxtrace_record__init(rec->evlist, &err);
                if (err)
                        return err;
        }

Here "int err" is not initialised. The code expects "err" to be set from auxtrace_record__init() function.

Update auxtrace_record__init() in arch/powerpc/util/auxtrace.c to clear err value in the beginning.

- Clear err value in beginning of function. Any fail later will set appropriate return code to err.
- Even if we haven't found any event for auxtrace, perf record should continue for other events. NULL return
will indicate that there is no auxtrace record initialized.
- Not having "err" set here will affect monitoring of other events also because perf record will fail seeing random value in err.

Set err to -EINVAL before invoking auxtrace_record__init() in builtin-record.c

With the fix,

 # ./perf trace record sleep 1
 [ perf record: Woken up 2 times to write data ]
 [ perf record: Captured and wrote 0.033 MB perf.data (228 samples) ]
Fixes 1dbfaf94cf66 ("perf powerpc: Add basic CONFIG_AUXTRACE support for VPA pmu on powerpc")

---
Changelog:
v1 -> v2
Addressed review comment from Adrian:
- Set err to -EINVAL before invoking auxtrace_record__init() in builtin-record.c
- Added kernel-doc to auxtrace_record__init() in tools/perf/util/auxtrace.c Addressed review comment from Namhyung:
- Added fixes tag

 tools/perf/arch/powerpc/util/auxtrace.c | 6 ++++++
 tools/perf/builtin-record.c             | 1 +
 2 files changed, 7 insertions(+)
tools/perf/arch/powerpc/util/auxtrace.c +6 -0
index e39deff6c857..4600a1661b4f 100644
@@ -71,6 +71,12 @@ struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
 	struct evsel *pos;
 	int found = 0;
 
+	/*
+	 * Set err value to zero here. Any fail later
+	 * will set appropriate return code to err.
+	 */
+	*err = 0;
+
 	evlist__for_each_entry(evlist, pos) {
 		if (strstarts(pos->name, "vpa_dtl")) {
 			found = 1;
tools/perf/builtin-record.c +1 -0
index 4a5eba498c02..708825747af5 100644
@@ -865,6 +865,7 @@ static int record__auxtrace_init(struct record *rec)
 	}
 
 	if (!rec->itr) {
+		err = -EINVAL;
 		rec->itr = auxtrace_record__init(rec->evlist, &err);
 		if (err)
 			return err;
Signature · 1 line
2.47.3
#1 lore raw

PATCH v4 2/2 tools/perf: Add kernel-doc comment to auxtrace_record__init() function

Add documentation comment describing the parameters and return code for auxtrace_record__init() in util/auxtrace.c

Using "struct evlist *evlist __maybe_unused", gives below warning with "scripts/kernel-doc".

 # ./scripts/kernel-doc -none tools/perf/util/auxtrace.c
 Warning: tools/perf/util/auxtrace.c:912 function parameter '__maybe_unused' not described in 'auxtrace_record__init'
 Warning: tools/perf/util/auxtrace.c:912 function parameter '__maybe_unused' not described in 'auxtrace_record__init'

Updated parameter as "struct evlist __maybe_unused *evlist" With the change, there is no erros/warnings with kernel-doc

---
Changelog:
v3 -> v4:
Addressed review comment from Sashiko:
Update return value expectation for fail as
non zero return err code.

v2 -> v3:
Addressed review comment from Sashiko:
Update return value expectation for success and fail correctly.

 tools/perf/util/auxtrace.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
tools/perf/util/auxtrace.c +16 -1
index a224687ffbc1..9e11cf4299b8 100644
@@ -896,8 +896,23 @@ int auxtrace_parse_aux_action(struct evlist *evlist)
 	return 0;
 }
 
+/**
+ * auxtrace_record__init - Initialize an AUX area tracing record.
+ * @evlist: The list of events to check for AUX area tracing event.
+ * @err: Pointer to an integer to store return code.
+ *
+ * This function looks through the @evlist to determine which AUX area
+ * tracing hardware is being used and initializes the auxtrace_record
+ * structure.
+ *
+ * Return:
+ * a) A pointer to the struct auxtrace_record on success.
+ * b) NULL with @err = 0 if no AUX area tracing event is found/supported
+ *    (not considered an error).
+ * c) NULL with non-zero @err on actual auxtrace_record__init failure.
+ */
 struct auxtrace_record *__weak
-auxtrace_record__init(struct evlist *evlist __maybe_unused, int *err)
+auxtrace_record__init(struct evlist __maybe_unused *evlist, int *err)
 {
 	*err = 0;
 	return NULL;
Signature · 1 line
2.47.3
maintainer
#2 lore raw

Re: [PATCH V4 2/2] tools/perf: Add kernel-doc comment to auxtrace_record__init() function

Hello,

Quoted 6 lines · Athira Rajeev

Add documentation comment describing the parameters and return code for auxtrace_record__init() in util/auxtrace.c

Using "struct evlist *evlist __maybe_unused", gives below warning with "scripts/kernel-doc".

Quoted 6 lines
 # ./scripts/kernel-doc -none tools/perf/util/auxtrace.c
 Warning: tools/perf/util/auxtrace.c:912 function parameter '__maybe_unused' not described in 'auxtrace_record__init'
 Warning: tools/perf/util/auxtrace.c:912 function parameter '__maybe_unused' not described in 'auxtrace_record__init'

Updated parameter as "struct evlist __maybe_unused *evlist" With the change, there is no erros/warnings with kernel-doc

Hmm.. this is not what we used to have. I'm not sure if we want to update them all. Maybe better to leave it for now.

Quoted 26 lines

---
Changelog:
v3 -> v4:
Addressed review comment from Sashiko:
Update return value expectation for fail as
non zero return err code.

v2 -> v3:
Addressed review comment from Sashiko:
Update return value expectation for success and fail correctly.

 tools/perf/util/auxtrace.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
tools/perf/util/auxtrace.c +1 -0
index a224687ffbc1..9e11cf4299b8 100644
@@ -896,8 +896,23 @@ int auxtrace_parse_aux_action(struct evlist *evlist)
 	return 0;
 }
 
+/**

tools/perf/util/auxtrace.c int auxtrace_parse_aux_action(struct evlist *evlist) · line 909

Quoted 10 lines
tools/perf/util/auxtrace.c +10 -0
+ * auxtrace_record__init - Initialize an AUX area tracing record.
+ * @evlist: The list of events to check for AUX area tracing event.
+ * @err: Pointer to an integer to store return code.
+ *
+ * This function looks through the @evlist to determine which AUX area
+ * tracing hardware is being used and initializes the auxtrace_record
+ * structure.
+ *
+ * Return:
+ * a) A pointer to the struct auxtrace_record on success.

I think you should mention that the this function should set *err to zero on success.

Thanks,
Namhyung

Quoted 13 lines
tools/perf/util/auxtrace.c +5 -1
+ * b) NULL with @err = 0 if no AUX area tracing event is found/supported
+ *    (not considered an error).
+ * c) NULL with non-zero @err on actual auxtrace_record__init failure.
+ */
 struct auxtrace_record *__weak
-auxtrace_record__init(struct evlist *evlist __maybe_unused, int *err)
+auxtrace_record__init(struct evlist __maybe_unused *evlist, int *err)
 {
 	*err = 0;
 	return NULL;
Signature · 1 line
2.47.3
#3 lore raw

Re: [PATCH V4 2/2] tools/perf: Add kernel-doc comment to auxtrace_record__init() function

Quoted 17 lines · Namhyung Kim

Hello,

Quoted 10 lines · Athira Rajeev

Add documentation comment describing the parameters and return code for auxtrace_record__init() in util/auxtrace.c

Using "struct evlist *evlist __maybe_unused", gives below warning with "scripts/kernel-doc".

# ./scripts/kernel-doc -none tools/perf/util/auxtrace.c
Warning: tools/perf/util/auxtrace.c:912 function parameter '__maybe_unused' not described in 'auxtrace_record__init'
Warning: tools/perf/util/auxtrace.c:912 function parameter '__maybe_unused' not described in 'auxtrace_record__init'
Quoted 5 lines
Quoted 2 lines

Updated parameter as "struct evlist __maybe_unused *evlist" With the change, there is no erros/warnings with kernel-doc

Hmm.. this is not what we used to have. I'm not sure if we want to update them all. Maybe better to leave it for now.

Sure, I will keep it as original version.

Quoted 26 lines
Quoted 26 lines

---
Changelog:
v3 -> v4:
Addressed review comment from Sashiko:
Update return value expectation for fail as
non zero return err code.

v2 -> v3:
Addressed review comment from Sashiko:
Update return value expectation for success and fail correctly.

tools/perf/util/auxtrace.c | 17 ++++++++++++++++-

1 file changed, 16 insertions(+), 1 deletion(-)
tools/perf/util/auxtrace.c +0 -0
index a224687ffbc1..9e11cf4299b8 100644
@@ -896,8 +896,23 @@ int auxtrace_parse_aux_action(struct evlist *evlist)
 return 0;
 }
 
Quoted 14 lines

tools/perf/util/auxtrace.c int auxtrace_parse_aux_action(struct evlist *evlist) · line 909

Quoted 11 lines
tools/perf/util/auxtrace.c +11 -0
+/**
+ * auxtrace_record__init - Initialize an AUX area tracing record.
+ * @evlist: The list of events to check for AUX area tracing event.
+ * @err: Pointer to an integer to store return code.
+ *
+ * This function looks through the @evlist to determine which AUX area
+ * tracing hardware is being used and initializes the auxtrace_record
+ * structure.
+ *
+ * Return:
+ * a) A pointer to the struct auxtrace_record on success.

I think you should mention that the this function should set *err to zero on success.

Sure, I will update this

Thanks
Athira

Quoted 17 lines

Thanks,
Namhyung

Quoted 12 lines
tools/perf/util/auxtrace.c +4 -0
+ * b) NULL with @err = 0 if no AUX area tracing event is found/supported
+ *    (not considered an error).
+ * c) NULL with non-zero @err on actual auxtrace_record__init failure.
+ */

struct auxtrace_record *__weak

tools/perf/util/auxtrace.c +1 -1
-auxtrace_record__init(struct evlist *evlist __maybe_unused, int *err)
+auxtrace_record__init(struct evlist __maybe_unused *evlist, int *err)

{
*err = 0;
return NULL;

Signature · 1 line
2.47.3
reviewer Reviewed-by on v4 1/2
#4 lore raw
In reply to Athira Rajeev
Quoted 45 lines · Athira Rajeev

perf trace record fails some cases in powerpc

 # ./perf test "perf trace record and replay"
 128: perf trace record and replay                                    : FAILED!
 # ./perf trace record sleep 1
 # echo $?
   32

This is happening because of non-zero err value from auxtrace_record__init() function.

static int record__auxtrace_init(struct record *rec)

 {
        int err;

        if ((rec->opts.auxtrace_snapshot_opts || rec->opts.auxtrace_sample_opts)
            && record__threads_enabled(rec)) {
                pr_err("AUX area tracing options are not available in parallel streaming mode.\n");
                return -EINVAL;
        }

        if (!rec->itr) {
                rec->itr = auxtrace_record__init(rec->evlist, &err);
                if (err)
                        return err;
        }

Here "int err" is not initialised. The code expects "err" to be set from auxtrace_record__init() function.

Update auxtrace_record__init() in arch/powerpc/util/auxtrace.c to clear err value in the beginning.

- Clear err value in beginning of function. Any fail later will set appropriate return code to err.
- Even if we haven't found any event for auxtrace, perf record should continue for other events. NULL return
will indicate that there is no auxtrace record initialized.
- Not having "err" set here will affect monitoring of other events also because perf record will fail seeing random value in err.

Set err to -EINVAL before invoking auxtrace_record__init() in builtin-record.c

Quoted 8 lines

With the fix,

 # ./perf trace record sleep 1
 [ perf record: Woken up 2 times to write data ]
 [ perf record: Captured and wrote 0.033 MB perf.data (228 samples) ]
Fixes 1dbfaf94cf66 ("perf powerpc: Add basic CONFIG_AUXTRACE support for VPA pmu on powerpc")
Quoted 43 lines

---
Changelog:
v1 -> v2
Addressed review comment from Adrian:
- Set err to -EINVAL before invoking auxtrace_record__init() in builtin-record.c
- Added kernel-doc to auxtrace_record__init() in tools/perf/util/auxtrace.c Addressed review comment from Namhyung:
- Added fixes tag

 tools/perf/arch/powerpc/util/auxtrace.c | 6 ++++++
 tools/perf/builtin-record.c             | 1 +
 2 files changed, 7 insertions(+)
tools/perf/arch/powerpc/util/auxtrace.c +6 -0
index e39deff6c857..4600a1661b4f 100644
@@ -71,6 +71,12 @@ struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
 	struct evsel *pos;
 	int found = 0;
 
+	/*
+	 * Set err value to zero here. Any fail later
+	 * will set appropriate return code to err.
+	 */
+	*err = 0;
+
 	evlist__for_each_entry(evlist, pos) {
 		if (strstarts(pos->name, "vpa_dtl")) {
 			found = 1;
tools/perf/builtin-record.c +1 -0
index 4a5eba498c02..708825747af5 100644
@@ -865,6 +865,7 @@ static int record__auxtrace_init(struct record *rec)
 	}
 
 	if (!rec->itr) {
+		err = -EINVAL;
 		rec->itr = auxtrace_record__init(rec->evlist, &err);
 		if (err)
 			return err;