Howard Chen | 35ae446 | 2017-04-07 20:15:28 +0800 | [diff] [blame^] | 1 | #include "ScheduleTest.h" |
| 2 | #include <pthread.h> |
| 3 | #include <iomanip> |
| 4 | #include <iostream> |
| 5 | |
| 6 | using namespace std; |
| 7 | |
| 8 | #define ASSERT(cond) \ |
| 9 | do { \ |
| 10 | if (!(cond)) { \ |
| 11 | cerr << __func__ << ":" << __LINE__ << " condition:" << #cond << " failed\n" << endl; \ |
| 12 | exit(EXIT_FAILURE); \ |
| 13 | } \ |
| 14 | } while (0) |
| 15 | |
| 16 | static int threadPri() { |
| 17 | struct sched_param param; |
| 18 | int policy; |
| 19 | ASSERT(!pthread_getschedparam(pthread_self(), &policy, ¶m)); |
| 20 | return param.sched_priority; |
| 21 | } |
| 22 | |
| 23 | static void threadDump(const char* prefix, int verbose) { |
| 24 | struct sched_param param; |
| 25 | int policy; |
| 26 | if (!verbose) return; |
| 27 | cout << "--------------------------------------------------" << endl; |
| 28 | cout << setw(12) << left << prefix << " pid: " << getpid() << " tid: " << gettid() |
| 29 | << " cpu: " << sched_getcpu() << endl; |
| 30 | ASSERT(!pthread_getschedparam(pthread_self(), &policy, ¶m)); |
| 31 | string s = |
| 32 | (policy == SCHED_OTHER) |
| 33 | ? "SCHED_OTHER" |
| 34 | : (policy == SCHED_FIFO) ? "SCHED_FIFO" : (policy == SCHED_RR) ? "SCHED_RR" : "???"; |
| 35 | cout << setw(12) << left << s << param.sched_priority << endl; |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | namespace android { |
| 40 | namespace hardware { |
| 41 | namespace tests { |
| 42 | namespace libhwbinder { |
| 43 | namespace V1_0 { |
| 44 | namespace implementation { |
| 45 | |
| 46 | // Methods from ::android::hardware::tests::libhwbinder::V1_0::IScheduleTest |
| 47 | // follow. |
| 48 | Return<uint32_t> ScheduleTest::send(uint32_t cfg, uint32_t callerSta) { |
| 49 | // TODO implement |
| 50 | int priority = threadPri(); |
| 51 | int priority_caller = (callerSta >> 16) & 0xffff; |
| 52 | int verbose = cfg & 1; |
| 53 | threadDump("hwbinder", verbose); |
| 54 | uint32_t h = 0, s = 0; |
| 55 | if (priority_caller != priority) { |
| 56 | h++; |
| 57 | if (verbose) { |
| 58 | cout << "err priority_caller:" << priority_caller << ", priority:" << priority << endl; |
| 59 | } |
| 60 | } |
| 61 | int cpu = sched_getcpu(); |
| 62 | int cpu_caller = (callerSta)&0xffff; |
| 63 | if (cpu != cpu_caller) { |
| 64 | s++; |
| 65 | } |
| 66 | return (h << 16) | (s & 0xffff); |
| 67 | } |
| 68 | |
| 69 | // Methods from ::android::hidl::base::V1_0::IBase follow. |
| 70 | |
| 71 | IScheduleTest* HIDL_FETCH_IScheduleTest(const char* /* name */) { |
| 72 | return new ScheduleTest(); |
| 73 | } |
| 74 | |
| 75 | } // namespace implementation |
| 76 | } // namespace V1_0 |
| 77 | } // namespace libhwbinder |
| 78 | } // namespace tests |
| 79 | } // namespace hardware |
| 80 | } // namespace android |