1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 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 16#ifndef FFRT_RTG_IOCTL_H 17#define FFRT_RTG_IOCTL_H 18 19#include <cstdint> 20 21#include <sched.h> 22 23namespace ffrt { 24struct RTGLoadInfo { 25 uint64_t load = 0; 26 uint64_t runtime = 0; 27}; 28 29class RTGCtrl { 30 class RTGMsg; 31 32public: 33 static RTGCtrl& Instance() 34 { 35 static RTGCtrl ctrl; 36 return ctrl; 37 } 38 39 bool Enabled() const 40 { 41 return fd >= 0; 42 } 43 44 int GetThreadGroup(); 45 bool PutThreadGroup(int tgid); 46 bool JoinThread(int tgid, pid_t tid); 47 bool RemoveThread(int tgid, pid_t tid); 48 bool UpdatePerfUtil(int tgid, int util); 49 bool UpdatePerfFreq(int tgid, int64_t freq); 50 RTGLoadInfo UpdateAndGetLoad(int tgid, pid_t tid); 51 RTGLoadInfo UpdateAndGetLoad(int tgid); 52 bool SetGroupWindowSize(int tgid, uint64_t size); 53 bool SetInvalidInterval(int tgid, uint64_t interval); 54 55 bool Begin(int tgid); 56 bool End(int tgid); 57 58 bool SetPreferredCluster(int tgid, int clusterId); 59 60 static pid_t GetTID(); 61 62private: 63 RTGCtrl(); 64 ~RTGCtrl(); 65 66 bool RTGIOCtrl(RTGMsg& msg); 67 68 int fd = -1; 69}; 70}; // namespace ffrt 71 72#endif