Lines Matching refs:task

98 bool IsTaskLocalEnable(ffrt::CPUEUTask* task)
100 if ((task->type != ffrt_normal_task) || (!task->taskLocal)) {
104 if (task->tsd == nullptr) {
105 FFRT_LOGE("taskLocal enabled but task tsd invalid");
125 void SwitchTsdAddrToTask(ffrt::CPUEUTask* task)
128 task->threadTsd = threadTsd;
129 pthread_settsd(task->tsd);
132 void SwitchTsdToTask(ffrt::CPUEUTask* task)
134 if (!IsTaskLocalEnable(task)) {
138 InitWorkerTsdValueToTask(task->tsd);
140 SwitchTsdAddrToTask(task);
142 task->runningTid.store(pthread_self());
143 FFRT_LOGD("switch tsd to task Success");
146 bool SwitchTsdAddrToThread(ffrt::CPUEUTask* task)
148 if (!task->threadTsd) {
151 pthread_settsd(task->threadTsd);
152 task->threadTsd = nullptr;
170 "FFRT abort: unexpected: thread exist but task not exist, key = [%u]", key);
176 void SwitchTsdToThread(ffrt::CPUEUTask* task)
178 if (!IsTaskLocalEnable(task)) {
182 if (!SwitchTsdAddrToThread(task)) {
186 UpdateWorkerTsdValueToThread(task->tsd);
188 task->runningTid.store(0);
192 void TaskTsdRunDtors(ffrt::CPUEUTask* task)
194 SwitchTsdAddrToTask(task);
196 SwitchTsdAddrToThread(task);
200 void TaskTsdDeconstruct(ffrt::CPUEUTask* task)
202 if (!IsTaskLocalEnable(task)) {
206 TaskTsdRunDtors(task);
207 if (task->tsd != nullptr) {
208 free(task->tsd);
209 task->tsd = nullptr;
210 task->taskLocal = false;
212 FFRT_LOGD("tsd deconstruct done, task[%lu], name[%s]", task->gid, task->label.c_str());
225 SwitchTsdToThread(co->task);
235 ffrt::CPUEUTask* task = co->task;
237 switch (task->type) {
240 task->Execute();
244 QueueTask* sTask = reinterpret_cast<QueueTask*>(task);
252 FFRT_LOGE("CoStart unsupport task[%lu], type=%d, name[%s]", task->gid, task->type, task->label.c_str());
335 static inline void BindNewCoRoutione(ffrt::CPUEUTask* task)
337 task->coRoutine = GetCoEnv()->runningCo;
338 task->coRoutine->task = task;
339 task->coRoutine->thEnv = GetCoEnv();
342 static inline void UnbindCoRoutione(ffrt::CPUEUTask* task)
344 task->coRoutine->task = nullptr;
345 task->coRoutine = nullptr;
348 static inline int CoAlloc(ffrt::CPUEUTask* task)
350 if (task->coRoutine) { // use allocated coroutine stack
354 GetCoEnv()->runningCo = task->coRoutine;
357 GetCoEnv()->runningCo = AllocNewCoRoutine(task->stack_size);
359 if (GetCoEnv()->runningCo->allocatedSize != task->stack_size) { // stack size not match, alloc one
361 GetCoEnv()->runningCo = AllocNewCoRoutine(task->stack_size);
368 // call CoCreat when task creat
369 static inline int CoCreat(ffrt::CPUEUTask* task)
371 CoAlloc(task);
373 CoAlloc(task);
379 BindNewCoRoutione(task);
380 auto co = task->coRoutine;
387 static inline void CoSwitchInTransaction(ffrt::CPUEUTask* task)
389 if (task->coRoutine->status == static_cast<int>(CoStatus::CO_NOT_FINISH)) {
390 for (auto name : task->traceTag) {
394 FFRT_FAKE_TRACE_MARKER(task->gid);
396 if (task->cpuBoostCtxId >= 0) {
397 CpuBoostRestore(task->cpuBoostCtxId);
401 static inline void CoSwitchOutTransaction(ffrt::CPUEUTask* task)
403 FFRT_FAKE_TRACE_MARKER(task->gid);
404 int traceTagNum = static_cast<int>(task->traceTag.size());
408 if (task->cpuBoostCtxId >= 0) {
409 CpuBoostSave(task->cpuBoostCtxId);
414 int CoStart(ffrt::CPUEUTask* task)
416 if (task->coRoutine) {
417 int ret = task->coRoutine->status.exchange(static_cast<int>(CoStatus::CO_RUNNING));
423 if (CoCreat(task) != 0) {
426 auto co = task->coRoutine;
428 FFRTTraceRecord::TaskRun(task->GetQos(), task);
431 ffrt::TaskLoadTracking::Begin(task);
433 FFRTSetStackId(task->stackId);
435 FFRT_TASK_BEGIN(task->label, task->gid);
436 if (task->type == ffrt_normal_task) {
437 task->UpdateState(ffrt::TaskState::RUNNING);
439 CoSwitchInTransaction(task);
441 SwitchTsdToTask(co->task);
445 ffrt::TaskLoadTracking::End(task); // Todo: deal with CoWait()
448 // 1. coroutine task done, exit normally, need to exec next coroutine task
450 task->UpdateState(ffrt::TaskState::EXITED);
455 // 2. couroutine task block, switch to thread
456 // need suspend the coroutine task or continue to execute the coroutine task.
462 FFRTTraceRecord::TaskCoSwitchOut(task);
464 if ((*pending)(task)) {
465 // The ownership of the task belongs to other host(cv/mutex/epoll etc)
466 // And the task cannot be accessed any more.
469 FFRT_WAKE_TRACER(task->gid); // fast path wk
481 CoSwitchOutTransaction(co->task);
482 if (co->task->type == ffrt_normal_task) {
483 co->task->UpdateState(ffrt::TaskState::BLOCKED);
485 FFRT_BLOCK_MARKER(co->task->gid);
487 SwitchTsdToThread(co->task);
499 CoExit(co, co->task->type == ffrt_normal_task);
509 void CoWake(ffrt::CPUEUTask* task, bool timeOut)
511 if (task == nullptr) {
512 FFRT_LOGE("task is nullptr");
516 FFRT_LOGD("Cowake task[%lu], name[%s], timeOut[%d]", task->gid, task->label.c_str(), timeOut);
517 task->wakeupTimeOut = timeOut;
518 FFRT_WAKE_TRACER(task->gid);
519 switch (task->type) {
521 task->UpdateState(ffrt::TaskState::READY);
525 QueueTask* sTask = reinterpret_cast<QueueTask*>(task);
531 FFRT_LOGE("CoWake unsupport task[%lu], type=%d, name[%s]", task->gid, task->type, task->label.c_str());