Avoid use of pthread_getschedparam
During Thread::DumpState the pthread may have exited.
We have the tid, use that instead.
Test: m -j50 test-art-host -k
Test: adb shell kill -3 `pid system_server`
Bug: 36445592
Change-Id: Idb28fcb1f9232768d32966973fe9dbeb3fa74b56
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 30a4046..ee77945 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -17,6 +17,7 @@
#include "thread.h"
#include <pthread.h>
+#include <sched.h>
#include <signal.h>
#include <sys/resource.h>
#include <sys/time.h>
@@ -1589,10 +1590,17 @@
<< " nice=" << getpriority(PRIO_PROCESS, tid)
<< " cgrp=" << scheduler_group_name;
if (thread != nullptr) {
- int policy;
+ // b/36445592 Don't use pthread_getschedparam since pthread may have exited.
+ int policy = sched_getscheduler(tid);
+ if (policy == -1) {
+ PLOG(WARNING) << "sched_getscheduler(" << tid << ")";
+ }
sched_param sp;
- CHECK_PTHREAD_CALL(pthread_getschedparam, (thread->tlsPtr_.pthread_self, &policy, &sp),
- __FUNCTION__);
+ int sched_getparam_result = sched_getparam(tid, &sp);
+ if (sched_getparam_result == -1) {
+ PLOG(WARNING) << "sched_getparam(" << tid << ", &sp)";
+ sp.sched_priority = -1;
+ }
os << " sched=" << policy << "/" << sp.sched_priority
<< " handle=" << reinterpret_cast<void*>(thread->tlsPtr_.pthread_self);
}