• 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 #include "worker_thread.h"
17 
18 #include <algorithm>
19 #include <unistd.h>
20 
21 #include <sys/syscall.h>
22 #include "dfx/log/ffrt_log_api.h"
23 #include "eu/osattr_manager.h"
24 #include "eu/qos_config.h"
25 #include "internal_inc/config.h"
26 namespace ffrt {
NativeConfig()27 void WorkerThread::NativeConfig()
28 {
29     pid_t pid = syscall(SYS_gettid);
30     this->tid = pid;
31 }
32 
WorkerSetup(WorkerThread * wthread,const QoS & qos)33 void WorkerThread::WorkerSetup(WorkerThread* wthread, const QoS& qos)
34 {
35     static int threadIndex[QoS::Max()] = {0};
36     std::string threadName = "ffrtwk/CPU-" + (std::to_string(qos()))+ "-" + std::to_string(threadIndex[qos()]++);
37     pthread_setname_np(wthread->GetThread().native_handle(), threadName.c_str());
38     if (qos() <= qos_max) {
39         QosApplyForOther(qos(), wthread->Id());
40         FFRT_LOGD("qos apply tid[%d] level[%d]\n", wthread->Id(), qos());
41         if (getFuncAffinity() != nullptr) {
42             getFuncAffinity()(QosConfig::Instance().getPolicySystem().policys[qos()].affinity, wthread->Id());
43         }
44         if (getFuncPriority() != nullptr) {
45             getFuncPriority()(QosConfig::Instance().getPolicySystem().policys[qos()].priority, wthread);
46         }
47     } else {
48         OSAttrManager::Instance()->SetTidToCGroup(wthread->Id());
49     }
50 }
51 }; // namespace ffrt
52