1 // Copyright (C) 2023 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <benchmark.pb.h> 18 19 #include <ditto/logger.h> 20 #include <ditto/syscall.h> 21 22 #include <sys/syscall.h> 23 #include <unistd.h> 24 25 namespace dittosuite { 26 27 enum SchedPolicy { 28 SchedNormal = 0, 29 SchedFifo = 1, 30 SchedRr = 2, 31 SchedBatch = 3, 32 /* SchedIso: reserved but not implemented yet */ 33 SchedIdle = 5, 34 SchedDeadline = 6, 35 }; 36 37 class SchedAttr { 38 SyscallInterface& syscall_; 39 bool initialized_ = false; 40 SchedAttr__ sched_attr_; 41 42 public: SchedAttr(SyscallInterface & syscall)43 SchedAttr(SyscallInterface& syscall) : syscall_(syscall) {} 44 45 void Set() const; 46 bool IsSet() const; 47 48 SchedAttr& operator=(const dittosuiteproto::SchedAttr& pb); 49 }; 50 51 class SchedAffinity { 52 SyscallInterface& syscall_; 53 bool initialized_ = false; 54 uint64_t mask_; 55 56 public: SchedAffinity(SyscallInterface & syscall)57 SchedAffinity(SyscallInterface& syscall) : syscall_(syscall) {} 58 59 void Set() const; 60 bool IsSet() const; 61 62 SchedAffinity& operator=(const uint64_t mask); 63 }; 64 65 66 struct MultithreadingParams { 67 const std::string name_; 68 SchedAttr sched_attr_; 69 SchedAffinity sched_affinity_; 70 MultithreadingParamsMultithreadingParams71 MultithreadingParams(const std::string& name, const SchedAttr& sched_attr, 72 const SchedAffinity &sched_affinity) 73 : name_(name), sched_attr_(sched_attr), sched_affinity_(sched_affinity) {} 74 }; 75 76 void setproctitle(int argc, char** argv, const char* title); 77 78 } // namespace dittosuite 79