已合并
【PR】: 简要描述 sync modify #4525
王璐瑶创建于 10 天前
【PR】: 简要描述 sync modify #4525
已合并
共 3 个文件变更+30-7
| @@ -1536,9 +1536,10 @@ rtError_t Stream::GetFinishedTaskIdBySqHead(uint16_t &sqHead, uint32_t &finished | |||
| 1536 | // sqHead indicates the current position of execution; it has not yet been completed. | 1536 | // sqHead indicates the current position of execution; it has not yet been completed. |
| 1537 | const uint32_t rtsqDepth = (((flags_ & RT_STREAM_HUGE) != 0U) && (Runtime::macroValue_.maxTaskNumPerHugeStream != 0)) ? | 1537 | const uint32_t rtsqDepth = (((flags_ & RT_STREAM_HUGE) != 0U) && (Runtime::macroValue_.maxTaskNumPerHugeStream != 0)) ? |
| 1538 | Runtime::macroValue_.maxTaskNumPerHugeStream : Runtime::macroValue_.rtsqDepth; | 1538 | Runtime::macroValue_.maxTaskNumPerHugeStream : Runtime::macroValue_.rtsqDepth; |
| 1539 | + const uint16_t lastId = lastTaskId_; | ||
| 1539 | const uint32_t posTail = GetTaskPosTail(); | 1540 | const uint32_t posTail = GetTaskPosTail(); |
| 1540 | const uint32_t posHead = GetTaskPosHead(); | 1541 | const uint32_t posHead = GetTaskPosHead(); |
| 1541 | - rtError_t error = device_->Driver_()->GetSqHead(Device_()->Id_(), Device_()->DevGetTsId(), sqId_, sqHead); | 1542 | + rtError_t error = device_->Driver_()->GetSqHead(device_->Id_(), device_->DevGetTsId(), sqId_, sqHead); |
| 1542 | COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "Query sq head failed, retCode=%#x.", | 1543 | COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "Query sq head failed, retCode=%#x.", |
| 1543 | static_cast<uint32_t>(error)); | 1544 | static_cast<uint32_t>(error)); |
| 1544 | if (((posTail + rtsqDepth - sqHead) % rtsqDepth) >= (posTail + rtsqDepth - posHead) % rtsqDepth) { | 1545 | if (((posTail + rtsqDepth - sqHead) % rtsqDepth) >= (posTail + rtsqDepth - posHead) % rtsqDepth) { |
| @@ -1550,11 +1551,27 @@ rtError_t Stream::GetFinishedTaskIdBySqHead(uint16_t &sqHead, uint32_t &finished | |||
| 1550 | 1551 | ||
| 1551 | const uint16_t finishedPos = static_cast<uint16_t>((sqHead + rtsqDepth - 1) % rtsqDepth); | 1552 | const uint16_t finishedPos = static_cast<uint16_t>((sqHead + rtsqDepth - 1) % rtsqDepth); |
| 1552 | (void)GetTaskIdByPos(finishedPos, endTaskId); // sqhead-1 is finished pos. | 1553 | (void)GetTaskIdByPos(finishedPos, endTaskId); // sqhead-1 is finished pos. |
| 1553 | - RT_LOG(RT_LOG_INFO, "sqHead=%u, nextTaskId=%u, finishedPos=%u, endTaskId=%u", sqHead, nextTaskId, finishedPos, endTaskId); | 1554 | + const uint32_t reReadPosTail = GetTaskPosTail(); |
| 1555 | + // tail未变化但最新任务已变化,说明本次读取的taskId可能属于新下发任务。 | ||
| 1556 | + if (reReadPosTail == posTail && lastTaskId_ != lastId) { | ||
| 1557 | + return RT_ERROR_NONE; | ||
| 1558 | + } | ||
| 1559 | + // tail已发生变化且新tail到达sqHead,sqHead - 1位置可能读到新下发任务。 | ||
| 1560 | + if ((reReadPosTail + rtsqDepth - sqHead) % rtsqDepth < ((reReadPosTail + rtsqDepth - posTail) % rtsqDepth)) { | ||
| 1561 | + return RT_ERROR_NONE; | ||
| 1562 | + } | ||
| 1563 | + // sqHead - 1位置读到的任务不能比入口时的最新任务更新。 | ||
| 1564 | + if ((endTaskId != MAX_UINT16_NUM) && TASK_ID_GT(endTaskId, lastId)) { | ||
| 1565 | + return RT_ERROR_NONE; | ||
| 1566 | + } | ||
| 1567 | + RT_LOG( | ||
| 1568 | + RT_LOG_INFO, "stream_id=%d, sq_id=%u, sqHead=%u, nextTaskId=%u, finishedPos=%u, endTaskId=%u", streamId_, sqId_, | ||
| 1569 | + sqHead, nextTaskId, finishedPos, endTaskId); | ||
| 1554 | 1570 | ||
| 1555 | // In scenarios with multiple SQEs, ffts+, mem wait, determine whether a task has been completed. | 1571 | // In scenarios with multiple SQEs, ffts+, mem wait, determine whether a task has been completed. |
| 1556 | // If the task IDs before and after are the same, it is considered that the task has not been completed. | 1572 | // If the task IDs before and after are the same, it is considered that the task has not been completed. |
| 1557 | - if (sqHead == posTail || nextTaskId != endTaskId) { // In the multi-task scenario, the task is reclaimed after all the tasks are executed. | 1573 | + // In the multi-task scenario, the task is reclaimed after all the tasks are executed. |
| 1574 | + if ((sqHead == posTail) || (nextTaskId != endTaskId)) { | ||
| 1558 | finishedId = endTaskId; | 1575 | finishedId = endTaskId; |
| 1559 | } | 1576 | } |
| 1560 | 1577 | ||
| @@ -1578,7 +1595,7 @@ bool Stream::SynchronizeDelayTime(const uint16_t finishedId, const uint16_t task | |||
| 1578 | uint32_t tryCount = 0U; | 1595 | uint32_t tryCount = 0U; |
| 1579 | const uint64_t beginTime = GetWallUs(); | 1596 | const uint64_t beginTime = GetWallUs(); |
| 1580 | while (GetWallUs() - beginTime < SLEEP_UNIT) { | 1597 | while (GetWallUs() - beginTime < SLEEP_UNIT) { |
| 1581 | - if (TASK_ID_GEQ(executeEndTaskid_.Value(), taskId)) { | 1598 | + if ((executeEndTaskid_.Value() != MAX_UINT16_NUM) && (TASK_ID_GEQ(executeEndTaskid_.Value(), taskId))) { |
| 1582 | return true; | 1599 | return true; |
| 1583 | } | 1600 | } |
| 1584 | tryCount++; | 1601 | tryCount++; |
| @@ -1614,8 +1631,9 @@ rtError_t Stream::SynchronizeExecutedTask(const uint32_t taskId, const mmTimespe | |||
| 1614 | COND_RETURN_ERROR((GetStreamStatus() != StreamStatus::NORMAL), RT_ERROR_STREAM_SYNC, | 1631 | COND_RETURN_ERROR((GetStreamStatus() != StreamStatus::NORMAL), RT_ERROR_STREAM_SYNC, |
| 1615 | "stream status is %u, device_id=%u, stream_id=%d.", GetStreamStatus(), device_->Id_(), Id_()); | 1632 | "stream status is %u, device_id=%u, stream_id=%d.", GetStreamStatus(), device_->Id_(), Id_()); |
| 1616 | error = CheckContextStatus(false); | 1633 | error = CheckContextStatus(false); |
| 1617 | - COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "context is abort, status=%#x.", static_cast<uint32_t>(error)); | 1634 | + COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "Context is abort, status=%#x.", static_cast<uint32_t>(error)); |
| 1618 | - if ((IsTaskExcuted(GetExecuteEndTaskId(), taskId)) || (sqHead == posTail)) { | 1635 | + const uint16_t exeEndTaskId = GetExecuteEndTaskId(); |
| 1636 | + if (((exeEndTaskId != MAX_UINT16_NUM) && IsTaskExcuted(exeEndTaskId, taskId)) || (sqHead == posTail)) { | ||
| 1619 | return RT_ERROR_NONE; | 1637 | return RT_ERROR_NONE; |
| 1620 | } | 1638 | } |
| 1621 | if (!device_->GetIsDoingRecycling()) { | 1639 | if (!device_->GetIsDoingRecycling()) { |
| @@ -1646,7 +1664,8 @@ rtError_t Stream::WaitConcernedTaskRecycled(const uint16_t taskId, const mmTimes | |||
| 1646 | COND_RETURN_ERROR((IsProcessTimeout(beginTime, timeout)), RT_ERROR_STREAM_SYNC_TIMEOUT, | 1664 | COND_RETURN_ERROR((IsProcessTimeout(beginTime, timeout)), RT_ERROR_STREAM_SYNC_TIMEOUT, |
| 1647 | "Stream recycle timeout, device_id=%u, stream_id=%d, timeout=%dms, tryCount=%u", | 1665 | "Stream recycle timeout, device_id=%u, stream_id=%d, timeout=%dms, tryCount=%u", |
| 1648 | device_->Id_(), streamId_, timeout, tryCount); | 1666 | device_->Id_(), streamId_, timeout, tryCount); |
| 1649 | - COND_RETURN_ERROR((abortStatus_ == RT_ERROR_STREAM_ABORT), RT_ERROR_STREAM_ABORT, "stream_id=%d is abort.", streamId_); | 1667 | + COND_RETURN_ERROR((abortStatus_ == RT_ERROR_STREAM_ABORT), RT_ERROR_STREAM_ABORT, |
| 1668 | + "The stream is in abort state, stream_id=%d.", streamId_); | ||
| 1650 | error = CheckContextStatus(false); | 1669 | error = CheckContextStatus(false); |
| 1651 | COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "context is abort, status=%#x.", static_cast<uint32_t>(error)); | 1670 | COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "context is abort, status=%#x.", static_cast<uint32_t>(error)); |
| 1652 | if (IsTaskExcuted(recycleEndTaskId_.Value(), taskId)) { | 1671 | if (IsTaskExcuted(recycleEndTaskId_.Value(), taskId)) { |
| @@ -752,6 +752,7 @@ TEST_F(DavidStreamTest, TestSeparateSendAndRecycle3) { | |||
| 752 | rtError_t ret; | 752 | rtError_t ret; |
| 753 | MOCKER_CPP(&Stream::IsSeparateSendAndRecycle).stubs().will(returnValue(true)); | 753 | MOCKER_CPP(&Stream::IsSeparateSendAndRecycle).stubs().will(returnValue(true)); |
| 754 | stream->SetBindFlag(false); | 754 | stream->SetBindFlag(false); |
| 755 | + stream->SetExecuteEndTaskId(0); | ||
| 755 | ret = SubmitTaskPostProc(stream, 0, true, 100); | 756 | ret = SubmitTaskPostProc(stream, 0, true, 100); |
| 756 | 757 | ||
| 757 | EXPECT_EQ(ret, RT_ERROR_NONE); | 758 | EXPECT_EQ(ret, RT_ERROR_NONE); |
| @@ -788,6 +789,7 @@ TEST_F(DavidStreamTest, TestSeparateSendAndRecycle4) | |||
| 788 | rtError_t ret; | 789 | rtError_t ret; |
| 789 | MOCKER_CPP(&Stream::IsSeparateSendAndRecycle).stubs().will(returnValue(true)); | 790 | MOCKER_CPP(&Stream::IsSeparateSendAndRecycle).stubs().will(returnValue(true)); |
| 790 | stream->SetBindFlag(false); | 791 | stream->SetBindFlag(false); |
| 792 | + stream->SetExecuteEndTaskId(0); | ||
| 791 | ret = SubmitTaskPostProc(stream, 0, true, 100); | 793 | ret = SubmitTaskPostProc(stream, 0, true, 100); |
| 792 | EXPECT_EQ(ret, RT_ERROR_NONE); | 794 | EXPECT_EQ(ret, RT_ERROR_NONE); |
| 793 | } | 795 | } |
| @@ -291,6 +291,7 @@ TEST_F(DavidTaskRecycleTest, SyncTaskRecycleBySqHead) | |||
| 291 | task->stream = static_cast<Stream *>(stream); | 291 | task->stream = static_cast<Stream *>(stream); |
| 292 | task->sqeNum = 1U; | 292 | task->sqeNum = 1U; |
| 293 | task->type = TS_TASK_TYPE_KERNEL_AICORE; | 293 | task->type = TS_TASK_TYPE_KERNEL_AICORE; |
| 294 | + rt_ut::UnwrapOrNull<Stream>(stream)->SetLastTaskId(task->id); | ||
| 294 | EXPECT_EQ(error, RT_ERROR_NONE); | 295 | EXPECT_EQ(error, RT_ERROR_NONE); |
| 295 | EXPECT_EQ(pos, i); | 296 | EXPECT_EQ(pos, i); |
| 296 | } | 297 | } |
| @@ -342,6 +343,7 @@ TEST_F(DavidTaskRecycleTest, SyncTaskRecycleBySqHeadV2) | |||
| 342 | task->stream = static_cast<Stream *>(stream); | 343 | task->stream = static_cast<Stream *>(stream); |
| 343 | task->sqeNum = 1U; | 344 | task->sqeNum = 1U; |
| 344 | task->type = TS_TASK_TYPE_KERNEL_AICORE; | 345 | task->type = TS_TASK_TYPE_KERNEL_AICORE; |
| 346 | + rt_ut::UnwrapOrNull<Stream>(stream)->SetLastTaskId(task->id); | ||
| 345 | EXPECT_EQ(error, RT_ERROR_NONE); | 347 | EXPECT_EQ(error, RT_ERROR_NONE); |
| 346 | EXPECT_EQ(pos, i); | 348 | EXPECT_EQ(pos, i); |
| 347 | } | 349 | } |