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 #include "ffrt_inner.h"
17 #include "common.h"
18
19 constexpr uint32_t FORK_JOIN_COUNT = 10000;
20
ForkJoin()21 void ForkJoin()
22 {
23 PreHotFFRT();
24
25 TIME_BEGIN(t);
26 for (uint32_t r = 0; r < REPEAT; r++) {
27 for (uint32_t i = 0; i < FORK_JOIN_COUNT; i++) {
28 ffrt::submit([=]() { simulate_task_compute_time(COMPUTE_TIME_US); }, {}, {});
29 }
30 ffrt::wait();
31 }
32 TIME_END_INFO(t, "fork_join");
33 }
34
ForkJoinWorker()35 void ForkJoinWorker()
36 {
37 PreHotFFRT();
38
39 TIME_BEGIN(t);
40 for (uint32_t r = 0; r < REPEAT; r++) {
41 ffrt::submit(
42 [&]() {
43 for (uint32_t i = 0; i < FORK_JOIN_COUNT; i++) {
44 ffrt::submit([=]() { simulate_task_compute_time(COMPUTE_TIME_US); }, {}, {});
45 }
46 ffrt::wait();
47 },
48 {}, {&r});
49 ffrt::wait({&r});
50 }
51 TIME_END_INFO(t, "fork_join_worker_submit");
52 }
53
main()54 int main()
55 {
56 GetEnvs();
57 ForkJoin();
58 ForkJoinWorker();
59 }