Re: [PATCH] perf, record: Add clockid parameter

From: David Ahern
Date: Mon Mar 30 2015 - 13:24:22 EST


On 3/28/15 1:55 AM, Peter Zijlstra wrote:
@@ -1085,6 +1093,8 @@ static int __perf_evsel__open(struct per
}

fallback_missing_features:
+ if (perf_missing_features.clockid)
+ evsel->attr.use_clockid = 0;
if (perf_missing_features.cloexec)
flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC;
if (perf_missing_features.mmap2)
@@ -1122,6 +1132,16 @@ static int __perf_evsel__open(struct per
goto try_fallback;
}
set_rlimit = NO_CHANGE;
+
+ /*
+ * If we succeeded but had to kill clockid, fail and
+ * have perf_evsel__open_strerror() print us a nice
+ * error.
+ */
+ if (perf_missing_features.clockid) {
+ err = -EINVAL;
+ goto out_close;
+ }
}
}

@@ -1155,7 +1175,10 @@ static int __perf_evsel__open(struct per
if (err != -EINVAL || cpu > 0 || thread > 0)
goto out_close;

- if (!perf_missing_features.cloexec && (flags & PERF_FLAG_FD_CLOEXEC)) {
+ if (!perf_missing_features.clockid && evsel->attr.use_clockid) {
+ perf_missing_features.clockid = true;
+ goto fallback_missing_features;
+ } else if (!perf_missing_features.cloexec && (flags & PERF_FLAG_FD_CLOEXEC)) {
perf_missing_features.cloexec = true;
goto fallback_missing_features;
} else if (!perf_missing_features.mmap2 && evsel->attr.mmap2) {

...

@@ -2158,6 +2188,12 @@ int perf_evsel__open_strerror(struct per
"The PMU counters are busy/taken by another profiler.\n"
"We found oprofile daemon running, please stop it and try again.");
break;
+
+ case EINVAL:
+ if (perf_missing_features.clockid)
+ return scnprintf(msg, size, "%s", "clockid not supported.");
+ break;
+
default:
break;
}


This works but the result is not always intuitive as to why it failed.

On a kernel that does not support the clock id you get:
$ perf sched record -k mono -- sleep 1
Error:
clockid not supported.

And on a kernel that supports clockid but not for NMI:

$ perf record -k realtime -a -- sleep 1
Error:
clockid not supported.

--> H/W counters so realtime is not allowed

Same message though different root causes.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/