aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalesh Singh <kaleshsingh@google.com>2022-03-11 17:41:52 -0800
committerKalesh Singh <kaleshsingh@google.com>2022-11-22 15:21:38 +0000
commit61488b893922a3b349d8ea98e7b7f9287a8640f5 (patch)
tree0826fe92a08684f6246d6a7a0986f249d1a43e1a
parent562bd8a1d4c8901044b349c5023193c773926f17 (diff)
downloadtrace-cmd-61488b893922a3b349d8ea98e7b7f9287a8640f5.tar.gz
ANDROID: libtracecmd: Add pthread_set/get_affinity_np()
Implement pthread_setaffinity_np() and pthread_getaffinity_np() in libtracecmd for Android. Bug: 223905587 Change-Id: I8ae788cfb2d799993013c6fbaa9acb3e482977a0 Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
-rw-r--r--lib/trace-cmd/trace-timesync.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index cc44af38..bbefda20 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -41,6 +41,28 @@ struct tsync_probe_request_msg {
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)