• 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 enum WgType {
32     TYPE_DEFAULT = 0,
33     TYPE_RS = 1,
34     TYPE_MAX
35 };
36 
37 struct Workgroup {
38     bool started;
39     int rtgId;
40     int tids[MAX_WG_THREADS];
41     uint64_t interval;
42     WgType type;
43 };
44 
45 #if defined(QOS_FRAME_RTG)
46 struct Workgroup* WorkgroupCreate(uint64_t interval);
47 void WorkgroupStartInterval(struct Workgroup* wg);
48 void WorkgroupStopInterval(struct Workgroup* wg);
49 void WorkgroupJoin(struct Workgroup* wg, int tid);
50 int WorkgroupClear(struct Workgroup* wg);
51 bool JoinWG(int tid);
52 #else /* !QOS_FRAME_RTG */
53 
WorkgroupStartInterval(struct Workgroup * wg)54 inline void WorkgroupStartInterval(struct Workgroup* wg)
55 {
56     if (wg->started) {
57         return;
58     }
59     wg->started = true;
60 }
61 
WorkgroupStopInterval(struct Workgroup * wg)62 inline void WorkgroupStopInterval(struct Workgroup* wg)
63 {
64     if (!wg->started) {
65         return;
66     }
67     wg->started = false;
68 }
69 
WorkgroupCreate(uint64_t interval)70 inline struct Workgroup* WorkgroupCreate(uint64_t interval __attribute__((unused)))
71 {
72     struct Workgroup* wg = new (std::nothrow) struct Workgroup();
73     if (wg == nullptr) {
74         return nullptr;
75     }
76     return wg;
77 }
78 
WorkgroupJoin(struct Workgroup * wg,int tid)79 inline void WorkgroupJoin(struct Workgroup* wg, int tid)
80 {
81     (void)wg;
82     (void)tid;
83 }
84 
WorkgroupClear(struct Workgroup * wg)85 inline int WorkgroupClear(struct Workgroup* wg)
86 {
87     delete wg;
88     wg = nullptr;
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