aos: Make SetCurrentThreadAffinity errors a bit nicer
When the SetCurrentThreadAffinity call fails, it prints this error
message:
Check failed: sched_setaffinity(0, sizeof(cpuset), &cpuset) == 0: Invalid argument [22]
It doesn't actually tell you what CPUs you tried to set. That can make
debugging harder. This patch fixes that by enhancing the error message
to print the set of CPUs that were pass in.
Change-Id: I3ae58f8a6c38b564b3706517a73e9ad43d85ef53
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/realtime.cc b/aos/realtime.cc
index 72daa6b..1e10457 100644
--- a/aos/realtime.cc
+++ b/aos/realtime.cc
@@ -161,8 +161,24 @@
MarkRealtime(false);
}
+std::ostream &operator<<(std::ostream &stream, const cpu_set_t &cpuset) {
+ stream << "{CPUs ";
+ bool first_found = false;
+ for (int i = 0; i < CPU_SETSIZE; ++i) {
+ if (CPU_ISSET(i, &cpuset)) {
+ if (first_found) {
+ stream << ", ";
+ }
+ stream << i;
+ first_found = true;
+ }
+ }
+ stream << "}";
+ return stream;
+}
+
void SetCurrentThreadAffinity(const cpu_set_t &cpuset) {
- PCHECK(sched_setaffinity(0, sizeof(cpuset), &cpuset) == 0);
+ PCHECK(sched_setaffinity(0, sizeof(cpuset), &cpuset) == 0) << cpuset;
}
void SetCurrentThreadName(const std::string_view name) {