void SingleEvent () { real vvSum; int n; NextEvent (); if (evIdB < MOL_LIMIT) { ProcessCollision (); ++ collCount; } else if (evIdB >= MOL_LIMIT + 100) { ProcessCellCrossing (); ++ crossCount; } else if (evIdB == MOL_LIMIT + 7) { UpdateSystem (); EvalRdf (); nextRdfTime += intervalRdf; ScheduleEvent (0, MOL_LIMIT + 7, nextRdfTime); } else if (evIdB == MOL_LIMIT + 6) { UpdateSystem (); nextSumTime += intervalSum; ScheduleEvent (0, MOL_LIMIT + 6, nextSumTime); VZero (vSum); vvSum = 0.; DO_MOL { VVAdd (vSum, mol[n].rv); vvSum += VLenSq (mol[n].rv); } kinEnVal = vvSum * 0.5 / nMol; PrintSummary (stdout); }
void SetupJob () { AllocArrays (); InitCoords (); InitVels (); timeNow = nextSumTime = 0.; collCount = crossCount = 0.; StartRun (); ScheduleEvent (0, MOL_LIMIT + 6, nextSumTime); nextRdfTime = 0.; ScheduleEvent (0, MOL_LIMIT + 7, nextRdfTime); countRdf = 0; }
void SetupJob () { SetupFiles (); AllocArrays (); InitCoords (); InitVels (); timeNow = nextSumTime = 0.; collCount = crossCount = 0.; countGrid = 0; nextSnapTime = intervalGrid; StartRun (); GridAverage (0); ScheduleEvent (0, MOL_LIMIT + 6, nextSumTime); ScheduleEvent (0, MOL_LIMIT + 7, nextSnapTime); }
void SingleEvent () { real vvSum; real sp; int n; NextEvent (); if (evIdB < MOL_LIMIT) { ProcessCollision (); ++ collCount; } else if (evIdB < MOL_LIMIT + NDIM * 2 || evIdB >= MOL_LIMIT + 100) { ProcessCellCrossing (); ++ crossCount; } else if (evIdB == MOL_LIMIT + 6) { UpdateSystem (); nextSumTime += intervalSum; ScheduleEvent (0, MOL_LIMIT + 6, nextSumTime); VZero (vSum); vvSum = 0.; sp = 0.; DO_MOL { VVAdd (vSum, mol[n].rv); vvSum += VLenSq (mol[n].rv); sp += VDot (mol[n].r, gravField); } kinEnVal = vvSum * 0.5 / nMol; totEnVal = kinEnVal - sp / nMol; PrintSummary (stdout); } else if (evIdB == MOL_LIMIT + 7) {
void GPUCommon::ReapplyGfxState() { if (IsOnSeparateCPUThread()) { ScheduleEvent(GPU_EVENT_REAPPLY_GFX_STATE); } else { ReapplyGfxStateInternal(); } }
// To be used from any thread, including the CPU thread void ScheduleEvent_AnyThread(s64 cyclesIntoFuture, int event_type, u64 userdata) { if (Core::IsCPUThread()) ScheduleEvent(cyclesIntoFuture, event_type, userdata); else ScheduleEvent_Threadsafe(cyclesIntoFuture, event_type, userdata); }
void AsyncIOManager::ScheduleOperation(AsyncIOEvent ev) { { lock_guard guard(resultsLock_); if (!resultsPending_.insert(ev.handle).second) { ERROR_LOG_REPORT(SCEIO, "Scheduling operation for file %d while one is pending (type %d)", ev.handle, ev.type); } } ScheduleEvent(ev); }
bool AsyncIOManager::WaitResult(u32 handle, AsyncIOResult &result) { std::unique_lock<std::mutex> guard(resultsLock_); ScheduleEvent(IO_EVENT_SYNC); while (HasEvents() && ThreadEnabled() && resultsPending_.find(handle) != resultsPending_.end()) { if (PopResult(handle, result)) { return true; } resultsWait_.wait_for(guard, std::chrono::milliseconds(16)); } return PopResult(handle, result); }
int GPUCommon::ListSync(int listid, int mode) { if (g_Config.bSeparateCPUThread) { // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. ScheduleEvent(GPU_EVENT_PROCESS_QUEUE); // Sync first, because the CPU is usually faster than the emulated GPU. SyncThread(); } easy_guard guard(listLock); if (listid < 0 || listid >= DisplayListMaxCount) return SCE_KERNEL_ERROR_INVALID_ID; if (mode < 0 || mode > 1) return SCE_KERNEL_ERROR_INVALID_MODE; DisplayList& dl = dls[listid]; if (mode == 1) { switch (dl.state) { case PSP_GE_DL_STATE_QUEUED: if (dl.interrupted) return PSP_GE_LIST_PAUSED; return PSP_GE_LIST_QUEUED; case PSP_GE_DL_STATE_RUNNING: if (dl.pc == dl.stall) return PSP_GE_LIST_STALLING; return PSP_GE_LIST_DRAWING; case PSP_GE_DL_STATE_COMPLETED: return PSP_GE_LIST_COMPLETED; case PSP_GE_DL_STATE_PAUSED: return PSP_GE_LIST_PAUSED; default: return SCE_KERNEL_ERROR_INVALID_ID; } } if (!__KernelIsDispatchEnabled()) { return SCE_KERNEL_ERROR_CAN_NOT_WAIT; } if (__IsInInterrupt()) { return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT; } if (dl.waitTicks > CoreTiming::GetTicks()) { __GeWaitCurrentThread(WAITTYPE_GELISTSYNC, listid, "GeListSync"); } return PSP_GE_LIST_COMPLETED; }
u32 GPUCommon::DrawSync(int mode) { // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. if (g_Config.bSeparateCPUThread) { // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. ScheduleEvent(GPU_EVENT_PROCESS_QUEUE); // Sync first, because the CPU is usually faster than the emulated GPU. SyncThread(); } easy_guard guard(listLock); if (mode < 0 || mode > 1) return SCE_KERNEL_ERROR_INVALID_MODE; if (mode == 0) { if (!__KernelIsDispatchEnabled()) { return SCE_KERNEL_ERROR_CAN_NOT_WAIT; } if (__IsInInterrupt()) { return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT; } if (drawCompleteTicks > CoreTiming::GetTicks()) { __GeWaitCurrentThread(WAITTYPE_GEDRAWSYNC, 1, "GeDrawSync"); } else { for (int i = 0; i < DisplayListMaxCount; ++i) { if (dls[i].state == PSP_GE_DL_STATE_COMPLETED) { dls[i].state = PSP_GE_DL_STATE_NONE; } } } return 0; } // If there's no current list, it must be complete. DisplayList *top = NULL; for (auto it = dlQueue.begin(), end = dlQueue.end(); it != end; ++it) { if (dls[*it].state != PSP_GE_DL_STATE_COMPLETED) { top = &dls[*it]; break; } } if (!top || top->state == PSP_GE_DL_STATE_COMPLETED) return PSP_GE_LIST_COMPLETED; if (currentList->pc == currentList->stall) return PSP_GE_LIST_STALLING; return PSP_GE_LIST_DRAWING; }
bool AsyncIOManager::WaitResult(u32 handle, AsyncIOResult &result) { lock_guard guard(resultsLock_); ScheduleEvent(IO_EVENT_SYNC); while (HasEvents() && ThreadEnabled() && resultsPending_.find(handle) != resultsPending_.end()) { if (PopResult(handle, result)) { return true; } resultsWait_.wait_for(resultsLock_, 16); } if (PopResult(handle, result)) { return true; } return false; }
bool DIRECTX9_GPU::FramebufferDirty() { // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. if (g_Config.bSeparateCPUThread) { // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. ScheduleEvent(GPU_EVENT_PROCESS_QUEUE); // Allow it to process fully before deciding if it's dirty. SyncThread(); } VirtualFramebufferDX9 *vfb = framebufferManager_.GetDisplayFBO(); if (vfb) { bool dirty = vfb->dirtyAfterDisplay; vfb->dirtyAfterDisplay = false; return dirty; } return true; }
u64 AsyncIOManager::ResultFinishTicks(u32 handle) { AsyncIOResult result; lock_guard guard(resultsLock_); ScheduleEvent(IO_EVENT_SYNC); while (HasEvents() && ThreadEnabled() && resultsPending_.find(handle) != resultsPending_.end()) { if (ReadResult(handle, result)) { return result.finishTicks; } resultsWait_.wait_for(resultsLock_, 16); } if (ReadResult(handle, result)) { return result.finishTicks; } return 0; }
u64 AsyncIOManager::ResultFinishTicks(u32 handle) { AsyncIOResult result; std::unique_lock<std::mutex> guard(resultsLock_); ScheduleEvent(IO_EVENT_SYNC); while (HasEvents() && ThreadEnabled() && resultsPending_.find(handle) != resultsPending_.end()) { if (ReadResult(handle, result)) { return result.finishTicks; } resultsWait_.wait_for(guard, std::chrono::milliseconds(16)); } if (ReadResult(handle, result)) { return result.finishTicks; } return 0; }
void SoftGPU::CopyDisplayToOutput() { ScheduleEvent(GPU_EVENT_COPY_DISPLAY_TO_OUTPUT); }
void DIRECTX9_GPU::BeginFrame() { ScheduleEvent(GPU_EVENT_BEGIN_FRAME); }
void DIRECTX9_GPU::InitClear() { ScheduleEvent(GPU_EVENT_INIT_CLEAR); }
void GLES_GPU::BeginFrame() { ScheduleEvent(GPU_EVENT_BEGIN_FRAME); }
void GLES_GPU::InitClear() { ScheduleEvent(GPU_EVENT_INIT_CLEAR); }
void AsyncIOManager::ScheduleOperation(AsyncIOEvent ev) { lock_guard guard(resultsLock_); resultsPending_.insert(ev.handle); ScheduleEvent(ev); }
bool GPUCommon::ProcessDLQueue() { ScheduleEvent(GPU_EVENT_PROCESS_QUEUE); return true; }
void GPU_Vulkan::BeginFrame() { ScheduleEvent(GPU_EVENT_BEGIN_FRAME); }