• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 WORKGROUP_INCLUDE
17 #define WORKGROUP_INCLUDE
18 
19 #include <unistd.h>
20 #include <sys/syscall.h>
21 #include <sys/types.h>
22 #include <cstdbool>
23 #include <chrono>
24 #include <fcntl.h>
25 #include <string>
26 
27 #define MAX_WG_THREADS 32
28 #define MAX_FRAME_BUFFER 6
29 #define gettid() syscall(SYS_gettid)
30 namespace ffrt {
31 
32 enum WgType {
33     TYPE_DEFAULT = 0,
34     TYPE_RS = 1,
35     TYPE_MAX
36 };
37 
38 struct Workgroup {
39     bool started;
40     int rtgId;
41     int tids[MAX_WG_THREADS];
42     uint64_t interval;
43     WgType type;
44 };
45 
46 #if defined(QOS_FRAME_RTG)
47 struct Workgroup* WorkgroupCreate(uint64_t interval);
48 void WorkgroupStartInterval(struct Workgroup* wg);
49 void WorkgroupStopInterval(struct Workgroup* wg);
50 void WorkgroupJoin(struct Workgroup* wg, int tid);
51 int WorkgroupClear(struct Workgroup* wg);
52 bool JoinWG(int tid);
53 #else /* !QOS_FRAME_RTG */
54 
WorkgroupStartInterval(struct Workgroup * wg)55 inline void WorkgroupStartInterval(struct Workgroup* wg)
56 {
57     if (wg->started) {
58         return;
59     }
60     wg->started = true;
61 }
62 
WorkgroupStopInterval(struct Workgroup * wg)63 inline void WorkgroupStopInterval(struct Workgroup* wg)
64 {
65     if (!wg->started) {
66         return;
67     }
68     wg->started = false;
69 }
70 
WorkgroupCreate(uint64_t interval)71 inline struct Workgroup* WorkgroupCreate(uint64_t interval __attribute__((unused)))
72 {
73     struct Workgroup* wg = static_cast<struct Workgroup*>(malloc(sizeof(*wg)));
74     if (wg == nullptr) {
75         return nullptr;
76     }
77     return wg;
78 }
79 
WorkgroupJoin(struct Workgroup * wg,int tid)80 inline void WorkgroupJoin(struct Workgroup* wg, int tid)
81 {
82     (void)wg;
83     (void)tid;
84 }
85 
WorkgroupClear(struct Workgroup * wg)86 inline int WorkgroupClear(struct Workgroup* wg)
87 {
88     (void)wg;
89     return 0;
90 }
91 
JoinWG(int tid)92 inline bool JoinWG(int tid)
93 {
94     (void)tid;
95     return true;
96 }
97 
98 #endif /* QOS_FRAME_RTG */
99 }
100 #endif
101