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 \
12 << " failed\n" \
13 << endl; \
14 exit(EXIT_FAILURE); \
15 } \
16 } while (0)
17
threadPri()18 static int threadPri() {
19 struct sched_param param;
20 int policy;
21 ASSERT(!pthread_getschedparam(pthread_self(), &policy, ¶m));
22 return param.sched_priority;
23 }
24
threadDump(const char * prefix,int verbose)25 static void threadDump(const char* prefix, int verbose) {
26 struct sched_param param;
27 int policy;
28 if (!verbose) return;
29 cout << "--------------------------------------------------" << endl;
30 cout << setw(12) << left << prefix << " pid: " << getpid()
31 << " tid: " << gettid() << " cpu: " << sched_getcpu() << endl;
32 ASSERT(!pthread_getschedparam(pthread_self(), &policy, ¶m));
33 string s = (policy == SCHED_OTHER)
34 ? "SCHED_OTHER"
35 : (policy == SCHED_FIFO)
36 ? "SCHED_FIFO"
37 : (policy == SCHED_RR) ? "SCHED_RR" : "???";
38 cout << setw(12) << left << s << param.sched_priority << endl;
39 return;
40 }
41
42 namespace android {
43 namespace hardware {
44 namespace tests {
45 namespace libhwbinder {
46 namespace V1_0 {
47 namespace implementation {
48
49 // Methods from ::android::hardware::tests::libhwbinder::V1_0::IScheduleTest
50 // follow.
send(uint32_t cfg,uint32_t callerSta)51 Return<uint32_t> ScheduleTest::send(uint32_t cfg, uint32_t callerSta) {
52 // TODO implement
53 int priority = threadPri();
54 int priority_caller = (callerSta >> 16) & 0xffff;
55 int verbose = cfg & 1;
56 threadDump("hwbinder", verbose);
57 uint32_t h = 0, s = 0;
58 if (priority_caller != priority) {
59 h++;
60 if (verbose) {
61 cout << "err priority_caller:" << priority_caller
62 << ", priority:" << priority << endl;
63 }
64 }
65 int cpu = sched_getcpu();
66 int cpu_caller = (callerSta)&0xffff;
67 if (cpu != cpu_caller) {
68 s++;
69 }
70 return (h << 16) | (s & 0xffff);
71 }
72
73 // Methods from ::android::hidl::base::V1_0::IBase follow.
74
HIDL_FETCH_IScheduleTest(const char *)75 IScheduleTest* HIDL_FETCH_IScheduleTest(const char* /* name */) {
76 return new ScheduleTest();
77 }
78
79 } // namespace implementation
80 } // namespace V1_0
81 } // namespace libhwbinder
82 } // namespace tests
83 } // namespace hardware
84 } // namespace android
85