1 #ifndef ANDROID_DVR_PERFORMANCED_PERFORMANCE_SERVICE_H_
2 #define ANDROID_DVR_PERFORMANCED_PERFORMANCE_SERVICE_H_
3 
4 #include <string>
5 #include <unordered_map>
6 
7 #include <pdx/service.h>
8 
9 #include "cpu_set.h"
10 
11 namespace android {
12 namespace dvr {
13 
14 // PerformanceService manages compute partitions usings cpusets. Different
15 // cpusets are assigned specific purposes and performance characteristics;
16 // clients may request for threads to be moved into these cpusets to help
17 // achieve system performance goals.
18 class PerformanceService : public pdx::ServiceBase<PerformanceService> {
19  public:
20   pdx::Status<void> HandleMessage(pdx::Message& message) override;
21   bool IsInitialized() const override;
22 
23   std::string DumpState(size_t max_length) override;
24 
25  private:
26   friend BASE;
27 
28   PerformanceService();
29 
30   int OnSetCpuPartition(pdx::Message& message, pid_t task_id,
31                         const std::string& partition);
32   int OnSetSchedulerClass(pdx::Message& message, pid_t task_id,
33                           const std::string& scheduler_class);
34   std::string OnGetCpuPartition(pdx::Message& message, pid_t task_id);
35 
36   CpuSetManager cpuset_;
37 
38   int sched_fifo_min_priority_;
39   int sched_fifo_max_priority_;
40 
41   // Scheduler class config type.
42   struct SchedulerClassConfig {
43     unsigned long timer_slack;
44     int scheduler_policy;
45     int priority;
46   };
47 
48   std::unordered_map<std::string, SchedulerClassConfig> scheduler_classes_;
49 
50   PerformanceService(const PerformanceService&) = delete;
51   void operator=(const PerformanceService&) = delete;
52 };
53 
54 }  // namespace dvr
55 }  // namespace android
56 
57 #endif  // ANDROID_DVR_PERFORMANCED_PERFORMANCE_SERVICE_H_
58