2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* @file sched.c
|
|
|
|
*
|
|
|
|
* This file implements a cooperative scheduler for managing tasks that run on the RSP and RDP
|
|
|
|
* asynchronously such as graphics and audio processing. Tasks are prepared and sent to it from
|
|
|
|
* other threads, where it is placed in a queue until the necessary resources are available. Tasks
|
|
|
|
* are usually ran in the order they are received, with one exception described below. Tasks can
|
|
|
|
* also request, through flags, whether the scheduler should swap the active framebuffer once the
|
|
|
|
* task completes.
|
|
|
|
* Together with irqmgr.c, these systems implement the libultra video and task scheduling model from
|
|
|
|
* the libultra "sched" module. Notably, the original sched module supports a wider range of ways to
|
|
|
|
* communicate with the RDP, while the Zelda 64 implementation only allows the RSP microcode to send
|
|
|
|
* commands to the RDP. The Zelda 64 implementation also has more complex behavior involving the
|
|
|
|
* framebuffers.
|
|
|
|
*
|
|
|
|
* There are four task types supported:
|
|
|
|
*
|
|
|
|
* M_NULTASK
|
|
|
|
* "NULL" tasks.
|
|
|
|
* Tasks of this type don't perform any operations, it can be used to "flush" the task queue. Threads
|
|
|
|
* can wait for this task to complete to ensure there are no more tasks queued in the scheduler.
|
|
|
|
*
|
|
|
|
* M_GFXTASK
|
|
|
|
* Graphics Processing tasks.
|
|
|
|
* Only these tasks can make use of the RDP.
|
|
|
|
*
|
|
|
|
* M_AUDTASK
|
|
|
|
* Audio Processing tasks.
|
|
|
|
* These tasks have a higher "priority" than other tasks. If an audio task is enqueued and another
|
|
|
|
* task is currently running, the scheduler will signal to the running task that it should "yield"
|
|
|
|
* the RSP to the audio task. The running task will save its current state and stop running, allowing
|
|
|
|
* the scheduler to send the audio task. This ensures that audio data is always available to be consumed
|
|
|
|
* by the audio DAC even if another task such as graphics is running slow, avoiding undesirable sound
|
|
|
|
* artifacts. This is the meaning of "cooperative" scheduler, the current task must acknowledge the
|
|
|
|
* yield request rather than be immediately interrupted as it would be in a preemptive scheduler.
|
|
|
|
*
|
|
|
|
* M_NJPEGTASK
|
|
|
|
* JPEG to RGBA16 decoding tasks.
|
|
|
|
*
|
|
|
|
* @see irqmgr.c
|
|
|
|
*/
|
2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
#define RSP_DONE_MSG 667
|
|
|
|
#define RDP_DONE_MSG 668
|
2022-06-03 19:43:30 +00:00
|
|
|
#define NOTIFY_MSG 670 // original name: ENTRY_MSG
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-10-03 15:22:44 +00:00
|
|
|
vs32 sLogScheduler = false;
|
2020-05-26 15:39:27 +00:00
|
|
|
|
2022-10-29 20:44:27 +00:00
|
|
|
OSTime sRSPGfxTimeStart;
|
|
|
|
OSTime sRSPAudioTimeStart;
|
|
|
|
OSTime sRSPOtherTimeStart;
|
|
|
|
OSTime sRDPTimeStart;
|
2020-05-26 15:39:27 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Set the current framebuffer to the swapbuffer pointed to by the provided cfb
|
|
|
|
*/
|
|
|
|
void Sched_SwapFrameBufferImpl(CfbInfo* cfbInfo) {
|
2020-05-26 15:39:27 +00:00
|
|
|
u16 width;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
LogUtils_CheckValidPointer("cfbinfo->swapbuffer", cfbInfo->swapBuffer, "../sched.c", 340);
|
2022-06-03 19:43:30 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (cfbInfo->swapBuffer != NULL) {
|
2022-06-03 19:43:30 +00:00
|
|
|
// Register the swapbuffer to display on next VI
|
2020-05-26 15:39:27 +00:00
|
|
|
osViSwapBuffer(cfbInfo->swapBuffer);
|
2022-06-03 19:43:30 +00:00
|
|
|
cfbInfo->updateTimer = cfbInfo->updateRate;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("osViSwapBuffer %08x %08x %08x\n", osViGetCurrentFramebuffer(), osViGetNextFramebuffer(),
|
2022-06-03 19:43:30 +00:00
|
|
|
(cfbInfo != NULL) ? cfbInfo->swapBuffer : NULL);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
|
|
|
|
width = (cfbInfo->viMode != NULL) ? cfbInfo->viMode->comRegs.width : (u32)gScreenWidth;
|
|
|
|
Fault_SetFrameBuffer(cfbInfo->swapBuffer, width, 16);
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_HREG_MODE == HREG_MODE_SCHED && R_SCHED_INIT != HREG_MODE_SCHED) {
|
|
|
|
R_SCHED_TOGGLE_SPECIAL_FEATURES = 0;
|
|
|
|
R_SCHED_GAMMA_ON = 0;
|
|
|
|
R_SCHED_DITHER_FILTER_ON = 1;
|
|
|
|
R_SCHED_GAMMA_DITHER_ON = 0;
|
|
|
|
R_SCHED_DIVOT_ON = 1;
|
|
|
|
|
|
|
|
// these regs are not used in this mode
|
2020-05-26 15:39:27 +00:00
|
|
|
HREG(86) = 0;
|
|
|
|
HREG(87) = 0;
|
|
|
|
HREG(88) = 0;
|
|
|
|
HREG(89) = 0;
|
|
|
|
HREG(90) = 0;
|
|
|
|
HREG(91) = 0;
|
|
|
|
HREG(92) = 0;
|
|
|
|
HREG(93) = 0;
|
|
|
|
HREG(94) = 0;
|
2022-11-26 20:22:01 +00:00
|
|
|
|
|
|
|
R_SCHED_INIT = HREG_MODE_SCHED;
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2022-11-26 20:22:01 +00:00
|
|
|
|
|
|
|
if (R_HREG_MODE == HREG_MODE_SCHED && R_SCHED_TOGGLE_SPECIAL_FEATURES == 2) {
|
|
|
|
osViSetSpecialFeatures(R_SCHED_GAMMA_ON ? OS_VI_GAMMA_ON : OS_VI_GAMMA_OFF);
|
|
|
|
osViSetSpecialFeatures(R_SCHED_DITHER_FILTER_ON ? OS_VI_DITHER_FILTER_ON : OS_VI_DITHER_FILTER_OFF);
|
|
|
|
osViSetSpecialFeatures(R_SCHED_GAMMA_DITHER_ON ? OS_VI_GAMMA_DITHER_ON : OS_VI_GAMMA_DITHER_OFF);
|
|
|
|
osViSetSpecialFeatures(R_SCHED_DIVOT_ON ? OS_VI_DIVOT_ON : OS_VI_DIVOT_OFF);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-26 20:22:01 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
cfbInfo->unk_10 = 0;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
void Sched_SwapFrameBuffer(Scheduler* sc, CfbInfo* cfbInfo) {
|
|
|
|
if (sc->isFirstSwap) {
|
|
|
|
sc->isFirstSwap = false;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-03-13 23:22:14 +00:00
|
|
|
if (gIrqMgrResetStatus == IRQ_RESET_STATUS_IDLE) {
|
2022-06-03 19:43:30 +00:00
|
|
|
ViConfig_UpdateVi(false);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
Sched_SwapFrameBufferImpl(cfbInfo);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
void Sched_HandlePreNMI(Scheduler* sc) {
|
2020-05-26 15:39:27 +00:00
|
|
|
OSTime now;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->curRSPTask != NULL) {
|
|
|
|
now = osGetTime();
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->curRSPTask->framebuffer == NULL) {
|
2022-06-03 19:43:30 +00:00
|
|
|
// audio and jpeg tasks end up in here
|
2020-05-26 15:39:27 +00:00
|
|
|
LOG_TIME("(((u64)(now - audio_rsp_start_time)*(1000000LL/15625LL))/((62500000LL*3/4)/15625LL))",
|
2022-10-29 20:44:27 +00:00
|
|
|
OS_CYCLES_TO_USEC(now - sRSPAudioTimeStart), "../sched.c", 421);
|
|
|
|
} else if (OS_CYCLES_TO_USEC(now - sRSPGfxTimeStart) > 1000000 ||
|
|
|
|
OS_CYCLES_TO_USEC(now - sRDPTimeStart) > 1000000) {
|
2022-06-03 19:43:30 +00:00
|
|
|
// More than 1 second since the RSP or RDP tasks began, halt the RSP and RDP
|
2022-01-23 23:04:50 +00:00
|
|
|
RcpUtils_Reset();
|
2022-06-03 19:43:30 +00:00
|
|
|
// Manually send RSP/RDP done messages to the scheduler interrupt queue if appropriate
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->curRSPTask != NULL) {
|
|
|
|
LOG_TIME("(((u64)(now - graph_rsp_start_time)*(1000000LL/15625LL))/((62500000LL*3/4)/15625LL))",
|
2022-10-29 20:44:27 +00:00
|
|
|
OS_CYCLES_TO_USEC(now - sRSPGfxTimeStart), "../sched.c", 427);
|
2022-04-09 00:20:23 +00:00
|
|
|
osSendMesg(&sc->interruptQueue, (OSMesg)RSP_DONE_MSG, OS_MESG_NOBLOCK);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
if (sc->curRDPTask != NULL) {
|
|
|
|
LOG_TIME("(((u64)(now - rdp_start_time)*(1000000LL/15625LL))/((62500000LL*3/4)/15625LL))",
|
2022-10-29 20:44:27 +00:00
|
|
|
OS_CYCLES_TO_USEC(now - sRDPTimeStart), "../sched.c", 431);
|
2022-04-09 00:20:23 +00:00
|
|
|
osSendMesg(&sc->interruptQueue, (OSMesg)RDP_DONE_MSG, OS_MESG_NOBLOCK);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
void Sched_HandleNMI(Scheduler* sc) {
|
|
|
|
// black the screen and reset the VI y scale just in time for NMI reset
|
|
|
|
ViConfig_UpdateVi(true);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Enqueue a task to either the audio task list or the gfx task list
|
|
|
|
*/
|
|
|
|
void Sched_QueueTask(Scheduler* sc, OSScTask* task) {
|
2020-05-26 15:39:27 +00:00
|
|
|
s32 type = task->list.t.type;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT((type == M_AUDTASK) || (type == M_GFXTASK) || (type == M_NJPEGTASK) || (type == M_NULTASK),
|
|
|
|
"(type == M_AUDTASK) || (type == M_GFXTASK) || (type == M_NJPEGTASK) || (type == M_NULTASK)", "../sched.c",
|
|
|
|
463);
|
2020-05-26 15:39:27 +00:00
|
|
|
|
|
|
|
if (type == M_AUDTASK) {
|
|
|
|
if (sLogScheduler) {
|
2021-09-04 13:33:19 +00:00
|
|
|
// "You have entered an audio task"
|
2020-05-26 15:39:27 +00:00
|
|
|
osSyncPrintf("オーディオタスクをエントリしました\n");
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
// Add to audio queue
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->audioListTail != NULL) {
|
|
|
|
sc->audioListTail->next = task;
|
|
|
|
} else {
|
|
|
|
sc->audioListHead = task;
|
|
|
|
}
|
|
|
|
sc->audioListTail = task;
|
2022-06-03 19:43:30 +00:00
|
|
|
|
|
|
|
// Set audio flag
|
|
|
|
sc->doAudio = true;
|
2020-05-26 15:39:27 +00:00
|
|
|
} else {
|
|
|
|
if (sLogScheduler) {
|
2022-06-03 19:43:30 +00:00
|
|
|
// "Entered graph task"
|
|
|
|
osSyncPrintf("グラフタスクをエントリしました\n");
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
// Add to graphics queue
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->gfxListTail != NULL) {
|
|
|
|
sc->gfxListTail->next = task;
|
|
|
|
} else {
|
|
|
|
sc->gfxListHead = task;
|
|
|
|
}
|
|
|
|
sc->gfxListTail = task;
|
|
|
|
}
|
|
|
|
task->next = NULL;
|
2022-06-03 19:43:30 +00:00
|
|
|
task->state = task->flags & OS_SC_RCP_MASK;
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
void Sched_Yield(Scheduler* sc) {
|
2020-05-26 15:39:27 +00:00
|
|
|
if (!(sc->curRSPTask->state & OS_SC_YIELD)) {
|
2022-06-03 19:43:30 +00:00
|
|
|
// Not already been asked to yield
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(sc->curRSPTask->list.t.type != M_AUDTASK, "sc->curRSPTask->list.t.type != M_AUDTASK", "../sched.c", 496);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
sc->curRSPTask->state |= OS_SC_YIELD;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Send yield request
|
2020-03-17 04:31:30 +00:00
|
|
|
osSpTaskYield();
|
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
2020-04-08 16:36:15 +00:00
|
|
|
osSyncPrintf("%08d:osSpTaskYield\n", (u32)(OS_CYCLES_TO_USEC(osGetTime())));
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Check if the framebuffer the gfx task wants to use is allowed
|
|
|
|
*/
|
|
|
|
OSScTask* Sched_GfxTaskFramebufferValid(Scheduler* sc, OSScTask* task) {
|
2020-05-26 15:39:27 +00:00
|
|
|
if (task == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// If there are pending swaps, wait until there are none (within 2 VI)
|
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->pendingSwapBuf1 != NULL) {
|
|
|
|
if (0) {
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(sc->pendingSwapBuf1 != NULL, "sc->pending_swapbuffer1", "../sched.c", UNK_LINE);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->pendingSwapBuf2 != NULL) {
|
|
|
|
if (0) {
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(sc->pendingSwapBuf2 != NULL, "sc->pending_swapbuffer2", "../sched.c", UNK_LINE);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// If the task's framebuffer is one of the pending swaps or NULL.
|
|
|
|
// In conjunction with the above, these checks are redundant as the pending swap buffers will only be
|
|
|
|
// NULL here, so these could have been simplified to checks for the task's framebuffer being non-NULL.
|
|
|
|
|
|
|
|
if (((sc->pendingSwapBuf2 != NULL) ? sc->pendingSwapBuf2->swapBuffer : NULL) == task->framebuffer->framebuffer) {
|
2020-05-26 15:39:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
if (((sc->pendingSwapBuf1 != NULL) ? sc->pendingSwapBuf1->swapBuffer : NULL) == task->framebuffer->framebuffer) {
|
2020-05-26 15:39:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// If the task's framebuffer is the current framebuffer, abort
|
|
|
|
|
|
|
|
if (osViGetCurrentFramebuffer() == task->framebuffer->framebuffer) {
|
2020-05-26 15:39:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
return task;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Schedules the next tasks to run on the RSP and RDP
|
|
|
|
*
|
|
|
|
* @param sc Scheduler
|
|
|
|
* @param spTaskOut Next task to run on the RSP
|
|
|
|
* @param dpTaskOut Next task to run on the RDP
|
|
|
|
* @param state Bits containing whether the RSP and RDP are currently in use
|
|
|
|
* @return Bits containing whether the RSP and RDP will be in use after starting the next tasks
|
|
|
|
*/
|
|
|
|
s32 Sched_Schedule(Scheduler* sc, OSScTask** spTaskOut, OSScTask** dpTaskOut, s32 state) {
|
|
|
|
s32 nextState = state;
|
2020-05-26 15:39:27 +00:00
|
|
|
OSScTask* gfxTask = sc->gfxListHead;
|
|
|
|
OSScTask* audioTask = sc->audioListHead;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
if (sc->doAudio && (state & OS_SC_SP)) {
|
|
|
|
// Audio Task, RSP is available
|
|
|
|
|
|
|
|
// Return next audio task
|
|
|
|
*spTaskOut = audioTask;
|
|
|
|
// RSP required
|
|
|
|
nextState &= ~OS_SC_SP;
|
|
|
|
//! @bug If there is more than one audio task in the queue at any time, unsetting doAudio here
|
|
|
|
//! will cause only one task to be processed until a new audio task is enqueued. In practice, audio
|
|
|
|
//! tasks are sent infrequently enough that there are never two audio tasks in the queue.
|
|
|
|
sc->doAudio = false;
|
|
|
|
// Advance task queue
|
2020-05-26 15:39:27 +00:00
|
|
|
sc->audioListHead = sc->audioListHead->next;
|
|
|
|
if (sc->audioListHead == NULL) {
|
|
|
|
sc->audioListTail = NULL;
|
|
|
|
}
|
2020-08-15 17:23:29 +00:00
|
|
|
} else if (gfxTask != NULL) {
|
2022-06-03 19:43:30 +00:00
|
|
|
// GFX Task
|
|
|
|
|
|
|
|
if ((gfxTask->state & OS_SC_YIELDED) || !(gfxTask->flags & OS_SC_NEEDS_RDP)) {
|
|
|
|
// If this is a yielded GFX task, or the RDP is not needed for this GFX task
|
|
|
|
|
|
|
|
if (state & OS_SC_SP) {
|
|
|
|
// If the RSP is available, return next graphics task
|
|
|
|
|
|
|
|
*spTaskOut = gfxTask;
|
|
|
|
// RSP required
|
|
|
|
nextState &= ~OS_SC_SP;
|
|
|
|
// Advance task queue
|
2020-08-15 17:23:29 +00:00
|
|
|
sc->gfxListHead = sc->gfxListHead->next;
|
|
|
|
if (sc->gfxListHead == NULL) {
|
|
|
|
sc->gfxListTail = NULL;
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2020-08-15 17:23:29 +00:00
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
} else if (state == (OS_SC_SP | OS_SC_DP)) {
|
|
|
|
// Both the RSP and RDP are available, check requested framebuffer
|
|
|
|
if (gfxTask->framebuffer == NULL || Sched_GfxTaskFramebufferValid(sc, gfxTask) != NULL) {
|
|
|
|
// Return next graphics task
|
|
|
|
*spTaskOut = *dpTaskOut = gfxTask;
|
|
|
|
// RSP and RDP both required
|
|
|
|
nextState &= ~(OS_SC_SP | OS_SC_DP);
|
|
|
|
// Advance task queue
|
2020-08-15 17:23:29 +00:00
|
|
|
sc->gfxListHead = sc->gfxListHead->next;
|
|
|
|
if (sc->gfxListHead == NULL) {
|
|
|
|
sc->gfxListTail = NULL;
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
return nextState;
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Sets the next framebuffer to the framebuffer associated to `task`.
|
|
|
|
* If there is no current buffer or it is time to swap, this buffer will be swapped to
|
|
|
|
* immediately, otherwise it will be swapped to later in Sched_HandleRetrace.
|
|
|
|
*
|
|
|
|
* @see Sched_HandleRetrace
|
|
|
|
*/
|
|
|
|
void Sched_SetNextFramebufferFromTask(Scheduler* sc, OSScTask* task) {
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->pendingSwapBuf1 == NULL) {
|
|
|
|
sc->pendingSwapBuf1 = task->framebuffer;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
LogUtils_CheckValidPointer("sc->pending_swapbuffer1", sc->pendingSwapBuf1, "../sched.c", 618);
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
if (sc->curBuf == NULL || sc->curBuf->updateTimer <= 0) {
|
|
|
|
Sched_SwapFrameBuffer(sc, task->framebuffer);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Checks if the task is done, i.e. it is no longer running on either the RSP or RDP.
|
|
|
|
* If so, send a message to the task's message queue if there is one, and swap the framebuffer
|
|
|
|
* if required.
|
|
|
|
*/
|
|
|
|
u32 Sched_TaskComplete(Scheduler* sc, OSScTask* task) {
|
|
|
|
// Check that the task has released both the RSP and RDP. For graphics tasks that use both,
|
|
|
|
// the RSP will typically finish before the RDP, as the RSP can halt while the RDP is still
|
|
|
|
// working through the command buffer.
|
2020-05-26 15:39:27 +00:00
|
|
|
if (!(task->state & (OS_SC_DP | OS_SC_SP))) {
|
2022-06-03 19:43:30 +00:00
|
|
|
// Send a message to the notify queue if there is one
|
2022-04-09 00:20:23 +00:00
|
|
|
if (task->msgQueue != NULL) {
|
|
|
|
osSendMesg(task->msgQueue, task->msg, OS_MESG_BLOCK);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Swap the framebuffer if needed
|
2020-05-26 15:39:27 +00:00
|
|
|
if (task->flags & OS_SC_SWAPBUFFER) {
|
2022-06-03 19:43:30 +00:00
|
|
|
Sched_SetNextFramebufferFromTask(sc, task);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
return false;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Runs the next tasks. The scheduler doesn't support running RDP tasks without
|
|
|
|
* passthrough via the RSP, if there is no RSP task to run then the RDP task will
|
|
|
|
* also do nothing.
|
|
|
|
*/
|
|
|
|
void Sched_RunTask(Scheduler* sc, OSScTask* spTask, OSScTask* dpTask) {
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(sc->curRSPTask == NULL, "sc->curRSPTask == NULL", "../sched.c", 663);
|
2022-06-03 19:43:30 +00:00
|
|
|
|
|
|
|
// If there is no RSP task there's nothing to do.
|
2020-05-26 15:39:27 +00:00
|
|
|
if (spTask != NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
if (spTask->list.t.type == M_NULTASK) {
|
2022-06-03 19:43:30 +00:00
|
|
|
// NULTASK is a sync/flush operation, clear current RSP and RDP tasks
|
|
|
|
// and unset flags for this task
|
2020-05-26 15:39:27 +00:00
|
|
|
if (spTask->flags & OS_SC_NEEDS_RSP) {
|
|
|
|
spTask->state &= ~OS_SC_SP;
|
|
|
|
sc->curRSPTask = NULL;
|
|
|
|
}
|
|
|
|
if (spTask->flags & OS_SC_NEEDS_RDP) {
|
|
|
|
spTask->state &= ~OS_SC_DP;
|
|
|
|
sc->curRDPTask = NULL;
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
// Finalize
|
|
|
|
Sched_TaskComplete(sc, spTask);
|
2020-05-26 15:39:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
spTask->state &= ~(OS_SC_YIELD | OS_SC_YIELDED);
|
2022-06-03 19:43:30 +00:00
|
|
|
// Write back data cache and load the OSTask into the RSP
|
2020-05-26 15:39:27 +00:00
|
|
|
osWritebackDCacheAll();
|
|
|
|
osSpTaskLoad(&spTask->list);
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Begin profiling timers
|
2020-05-26 15:39:27 +00:00
|
|
|
if (spTask->list.t.type == M_AUDTASK) {
|
2022-10-29 20:44:27 +00:00
|
|
|
sRSPAudioTimeStart = osGetTime();
|
2020-05-26 15:39:27 +00:00
|
|
|
} else if (spTask->list.t.type == M_GFXTASK) {
|
2022-10-29 20:44:27 +00:00
|
|
|
sRSPGfxTimeStart = osGetTime();
|
2020-05-26 15:39:27 +00:00
|
|
|
} else {
|
2022-10-29 20:44:27 +00:00
|
|
|
sRSPOtherTimeStart = osGetTime();
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Run RSP
|
2020-05-26 15:39:27 +00:00
|
|
|
osSpTaskStartGo(&spTask->list);
|
2022-06-03 19:43:30 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf(
|
|
|
|
"%08d:osSpTaskStartGo(%08x) %s\n", (u32)OS_CYCLES_TO_USEC(osGetTime()), &spTask->list,
|
|
|
|
(spTask->list.t.type == M_AUDTASK ? "AUDIO" : (spTask->list.t.type == M_GFXTASK ? "GRAPH" : "OTHER")));
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
|
|
|
|
// Set currently running RSP task
|
2020-05-26 15:39:27 +00:00
|
|
|
sc->curRSPTask = spTask;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// If the task also uses the RDP, set current running RDP task
|
2020-05-26 15:39:27 +00:00
|
|
|
if (spTask == dpTask && sc->curRDPTask == NULL) {
|
|
|
|
sc->curRDPTask = dpTask;
|
2022-10-29 20:44:27 +00:00
|
|
|
sRDPTimeStart = sRSPGfxTimeStart;
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Runs when the scheduler has received a notification, either from another thread or
|
|
|
|
* on VI Retrace. Tasks that have been sent to it will be enqueued onto the audio or
|
|
|
|
* gfx task queue and one may be ran if the RSP is available.
|
|
|
|
*/
|
|
|
|
void Sched_HandleNotification(Scheduler* sc) {
|
2021-02-14 00:49:40 +00:00
|
|
|
OSScTask* nextRSP = NULL;
|
|
|
|
OSScTask* nextRDP = NULL;
|
|
|
|
s32 state;
|
2022-04-09 00:20:23 +00:00
|
|
|
OSScTask* task = NULL;
|
2020-05-26 15:39:27 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Enqueue any tasks sent by other threads
|
2022-04-09 00:20:23 +00:00
|
|
|
while (osRecvMesg(&sc->cmdQueue, (OSMesg*)&task, OS_MESG_NOBLOCK) != -1) {
|
|
|
|
Sched_QueueTask(sc, task);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// If an audio task has been enqueued and there is currently an RSP task running,
|
|
|
|
// signal to the currently running task to yield the RSP so that the audio task may
|
|
|
|
// be ran as soon as possible.
|
|
|
|
if (sc->doAudio && sc->curRSPTask != NULL) {
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("[YIELD B]");
|
|
|
|
}
|
|
|
|
Sched_Yield(sc);
|
|
|
|
return;
|
|
|
|
}
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Run next task in the queue if there is one and the necessary resources are available
|
|
|
|
state = ((sc->curRSPTask == NULL) << 1) | (sc->curRDPTask == NULL);
|
2020-05-26 15:39:27 +00:00
|
|
|
if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) {
|
|
|
|
Sched_RunTask(sc, nextRSP, nextRDP);
|
|
|
|
}
|
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("EN sc:%08x sp:%08x dp:%08x state:%x\n", sc, nextRSP, nextRDP, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
void Sched_HandleRetrace(Scheduler* sc) {
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("%08d:scHandleRetrace %08x\n", (u32)OS_CYCLES_TO_USEC(osGetTime()), osViGetCurrentFramebuffer());
|
|
|
|
}
|
|
|
|
ViConfig_UpdateBlack();
|
2022-06-03 19:43:30 +00:00
|
|
|
sc->retraceCount++;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Retrace handlers run after VI context swap. The last swap buffer may now be the current buffer.
|
|
|
|
if (osViGetCurrentFramebuffer() == ((sc->pendingSwapBuf1 != NULL) ? sc->pendingSwapBuf1->swapBuffer : NULL)) {
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->curBuf != NULL) {
|
|
|
|
sc->curBuf->unk_10 = 0;
|
|
|
|
}
|
|
|
|
if (sc->pendingSwapBuf1 != NULL) {
|
|
|
|
sc->pendingSwapBuf1->unk_10 = 0;
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
// Advance buffers
|
2020-05-26 15:39:27 +00:00
|
|
|
sc->curBuf = sc->pendingSwapBuf1;
|
|
|
|
sc->pendingSwapBuf1 = sc->pendingSwapBuf2;
|
|
|
|
sc->pendingSwapBuf2 = NULL;
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->curBuf != NULL) {
|
2022-06-03 19:43:30 +00:00
|
|
|
// Swap the framebuffer when the update timer runs out
|
|
|
|
if (sc->curBuf->updateTimer > 0) {
|
|
|
|
sc->curBuf->updateTimer--;
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
if (sc->curBuf->updateTimer <= 0 && sc->pendingSwapBuf1 != NULL) {
|
|
|
|
Sched_SwapFrameBuffer(sc, sc->pendingSwapBuf1);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("%08x %08x %08x %d\n", osViGetCurrentFramebuffer(), osViGetNextFramebuffer(),
|
2022-06-03 19:43:30 +00:00
|
|
|
(sc->pendingSwapBuf1 != NULL) ? sc->pendingSwapBuf1->swapBuffer : NULL,
|
|
|
|
(sc->curBuf != NULL) ? sc->curBuf->updateTimer : 0);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
|
|
|
|
// Run the notification handler to enqueue any waiting tasks and possibly run one
|
|
|
|
Sched_HandleNotification(sc);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* RSP has signalled that the task has either completed or yielded.
|
|
|
|
*/
|
|
|
|
void Sched_HandleRSPDone(Scheduler* sc) {
|
2020-05-26 15:39:27 +00:00
|
|
|
OSScTask* curRSPTask;
|
2021-02-14 00:49:40 +00:00
|
|
|
OSScTask* nextRSP = NULL;
|
|
|
|
OSScTask* nextRDP = NULL;
|
2020-05-26 15:39:27 +00:00
|
|
|
s32 state;
|
|
|
|
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(sc->curRSPTask != NULL, "sc->curRSPTask", "../sched.c", 819);
|
2020-05-26 15:39:27 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Task profiling
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sc->curRSPTask->list.t.type == M_AUDTASK) {
|
2022-10-29 20:44:27 +00:00
|
|
|
gRSPAudioTimeAcc += osGetTime() - sRSPAudioTimeStart;
|
2020-05-26 15:39:27 +00:00
|
|
|
} else if (sc->curRSPTask->list.t.type == M_GFXTASK) {
|
2022-10-29 20:44:27 +00:00
|
|
|
gRSPGfxTimeAcc += osGetTime() - sRSPGfxTimeStart;
|
2020-05-26 15:39:27 +00:00
|
|
|
} else {
|
2022-10-29 20:44:27 +00:00
|
|
|
gRSPOtherTimeAcc += osGetTime() - sRSPOtherTimeStart;
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Clear current RSP task
|
2020-05-26 15:39:27 +00:00
|
|
|
curRSPTask = sc->curRSPTask;
|
|
|
|
sc->curRSPTask = NULL;
|
2022-06-03 19:43:30 +00:00
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
2022-06-03 19:43:30 +00:00
|
|
|
osSyncPrintf("RSP DONE %d %d", curRSPTask->state & OS_SC_YIELD, osSpTaskYielded(&curRSPTask->list));
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
|
|
|
|
if ((curRSPTask->state & OS_SC_YIELD) && osSpTaskYielded(&curRSPTask->list)) {
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("[YIELDED]\n");
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
// Task yielded, set yielded state
|
2020-05-26 15:39:27 +00:00
|
|
|
curRSPTask->state |= OS_SC_YIELDED;
|
2022-06-03 19:43:30 +00:00
|
|
|
// Add it to the front of the queue
|
2020-05-26 15:39:27 +00:00
|
|
|
curRSPTask->next = sc->gfxListHead;
|
|
|
|
sc->gfxListHead = curRSPTask;
|
|
|
|
if (sc->gfxListTail == NULL) {
|
|
|
|
sc->gfxListTail = curRSPTask;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("[NOT YIELDED]\n");
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
// Task has completed on the RSP, unset RSP flag and check if the task is fully complete
|
2020-05-26 15:39:27 +00:00
|
|
|
curRSPTask->state &= ~OS_SC_SP;
|
2022-06-03 19:43:30 +00:00
|
|
|
Sched_TaskComplete(sc, curRSPTask);
|
2020-05-26 15:39:27 +00:00
|
|
|
}
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Run next task in the queue if there is one and the necessary resources are available
|
2020-05-26 15:39:27 +00:00
|
|
|
state = ((sc->curRSPTask == NULL) << 1) | (sc->curRDPTask == NULL);
|
|
|
|
if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) {
|
|
|
|
Sched_RunTask(sc, nextRSP, nextRDP);
|
|
|
|
}
|
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("SP sc:%08x sp:%08x dp:%08x state:%x\n", sc, nextRSP, nextRDP, state);
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* RDP has signalled task done upon reaching a DPFullSync command
|
|
|
|
*/
|
|
|
|
void Sched_HandleRDPDone(Scheduler* sc) {
|
2020-05-26 15:39:27 +00:00
|
|
|
OSScTask* curTask;
|
2021-02-14 00:49:40 +00:00
|
|
|
OSScTask* nextRSP = NULL;
|
|
|
|
OSScTask* nextRDP = NULL;
|
2020-05-26 15:39:27 +00:00
|
|
|
s32 state;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Task profiling
|
2022-10-29 20:44:27 +00:00
|
|
|
gRDPTimeAcc = osGetTime() - sRDPTimeStart;
|
2022-06-03 19:43:30 +00:00
|
|
|
|
|
|
|
// Sanity check
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(sc->curRDPTask != NULL, "sc->curRDPTask", "../sched.c", 878);
|
|
|
|
ASSERT(sc->curRDPTask->list.t.type == M_GFXTASK, "sc->curRDPTask->list.t.type == M_GFXTASK", "../sched.c", 879);
|
2022-06-03 19:43:30 +00:00
|
|
|
|
|
|
|
// Clear current RDP task
|
2020-05-26 15:39:27 +00:00
|
|
|
curTask = sc->curRDPTask;
|
|
|
|
sc->curRDPTask = NULL;
|
2022-06-03 19:43:30 +00:00
|
|
|
|
|
|
|
// Task has completed on the RDP, unset RDP flag and check if the task is fully complete
|
2020-05-26 15:39:27 +00:00
|
|
|
curTask->state &= ~OS_SC_DP;
|
2022-06-03 19:43:30 +00:00
|
|
|
Sched_TaskComplete(sc, curTask);
|
|
|
|
|
|
|
|
// Run next task in the queue if there is one and the necessary resources are available
|
2020-05-26 15:39:27 +00:00
|
|
|
state = ((sc->curRSPTask == NULL) << 1) | (sc->curRDPTask == NULL);
|
|
|
|
if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) {
|
|
|
|
Sched_RunTask(sc, nextRSP, nextRDP);
|
|
|
|
}
|
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("DP sc:%08x sp:%08x dp:%08x state:%x\n", sc, nextRSP, nextRDP, state);
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Called by other threads in order to wake the scheduler up immediately to enqueue and
|
|
|
|
* possibly run a task that has been sent to the task queue. Otherwise, any pending tasks
|
|
|
|
* will be enqueued on next vertical retrace.
|
|
|
|
*
|
|
|
|
* Original name: osScKickEntryMsg
|
|
|
|
*/
|
|
|
|
void Sched_Notify(Scheduler* sc) {
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf("osScKickEntryMsg\n");
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
osSendMesg(&sc->interruptQueue, (OSMesg)NOTIFY_MSG, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
void Sched_ThreadEntry(void* arg) {
|
2022-04-09 00:20:23 +00:00
|
|
|
OSMesg msg = NULL;
|
2022-06-03 19:43:30 +00:00
|
|
|
Scheduler* sc = (Scheduler*)arg;
|
2020-05-26 15:39:27 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
while (true) {
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
2021-09-28 23:53:56 +00:00
|
|
|
// "%08d: standby"
|
2020-05-26 15:39:27 +00:00
|
|
|
osSyncPrintf("%08d:待機中\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
// Await interrupt messages, either from the OS, IrqMgr, or another thread
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(&sc->interruptQueue, &msg, OS_MESG_BLOCK);
|
2020-05-26 15:39:27 +00:00
|
|
|
|
|
|
|
switch ((s32)msg) {
|
2022-06-03 19:43:30 +00:00
|
|
|
case NOTIFY_MSG:
|
2020-05-26 15:39:27 +00:00
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("%08d:ENTRY_MSG\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
|
|
|
|
}
|
2022-06-03 19:43:30 +00:00
|
|
|
Sched_HandleNotification(sc);
|
2020-05-26 15:39:27 +00:00
|
|
|
continue;
|
|
|
|
case RSP_DONE_MSG:
|
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("%08d:RSP_DONE_MSG\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
|
|
|
|
}
|
|
|
|
Sched_HandleRSPDone(sc);
|
|
|
|
continue;
|
|
|
|
case RDP_DONE_MSG:
|
|
|
|
if (sLogScheduler) {
|
|
|
|
osSyncPrintf("%08d:RDP_DONE_MSG\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
|
|
|
|
}
|
|
|
|
Sched_HandleRDPDone(sc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (((OSScMsg*)msg)->type) {
|
2022-06-03 19:43:30 +00:00
|
|
|
case OS_SC_RETRACE_MSG:
|
2020-05-26 15:39:27 +00:00
|
|
|
Sched_HandleRetrace(sc);
|
|
|
|
continue;
|
2022-06-03 19:43:30 +00:00
|
|
|
case OS_SC_PRE_NMI_MSG:
|
|
|
|
Sched_HandlePreNMI(sc);
|
2020-05-26 15:39:27 +00:00
|
|
|
continue;
|
2022-06-03 19:43:30 +00:00
|
|
|
case OS_SC_NMI_MSG:
|
|
|
|
Sched_HandleNMI(sc);
|
2020-05-26 15:39:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-11-13 23:07:27 +00:00
|
|
|
void Sched_Init(Scheduler* sc, void* stack, OSPri priority, u8 viModeType, UNK_TYPE arg4, IrqMgr* irqMgr) {
|
2022-06-03 19:43:30 +00:00
|
|
|
bzero(sc, sizeof(Scheduler));
|
|
|
|
sc->isFirstSwap = true;
|
|
|
|
|
|
|
|
// Create message queues for receiving interrupt events and tasks
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateMesgQueue(&sc->interruptQueue, sc->interruptMsgBuf, ARRAY_COUNT(sc->interruptMsgBuf));
|
|
|
|
osCreateMesgQueue(&sc->cmdQueue, sc->cmdMsgBuf, ARRAY_COUNT(sc->cmdMsgBuf));
|
2022-06-16 00:15:44 +00:00
|
|
|
osSetEventMesg(OS_EVENT_SP, &sc->interruptQueue, (OSMesg)RSP_DONE_MSG);
|
|
|
|
osSetEventMesg(OS_EVENT_DP, &sc->interruptQueue, (OSMesg)RDP_DONE_MSG);
|
2022-04-09 00:20:23 +00:00
|
|
|
IrqMgr_AddClient(irqMgr, &sc->irqClient, &sc->interruptQueue);
|
|
|
|
osCreateThread(&sc->thread, THREAD_ID_SCHED, Sched_ThreadEntry, sc, stack, priority);
|
2020-03-17 04:31:30 +00:00
|
|
|
osStartThread(&sc->thread);
|
|
|
|
}
|