ANDROID: libtracecmd: Add pthread_set/get_affinity_np() am: 61488b8939 am: 494481b06a
Original change: https://android-review.googlesource.com/c/platform/external/trace-cmd/+/2084180
Change-Id: I07c1e69fce543f74b314753beca6110f596eb411
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index cc44af3..bbefda2 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -41,6 +41,28 @@
unsigned short cpu;
} __packed;
+#ifdef __ANDROID__
+#define __NR_sched_setaffinity 122
+#define __NR_sched_getaffinity 123
+
+static int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset)
+{
+ return -syscall(__NR_sched_setaffinity, thread, cpusetsize, cpuset);
+}
+
+static int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset)
+{
+ long ret = syscall(__NR_sched_getaffinity, thread, cpusetsize, cpuset);
+
+ if (ret < 0)
+ return ret;
+ if (ret < cpusetsize)
+ memset((char *)cpuset+ret, 0, cpusetsize-ret);
+
+ return 0;
+}
+#endif /* __ANDROID__ */
+
static struct tsync_proto *tsync_proto_list;
static struct tsync_proto *tsync_proto_find(const char *proto_name)