#include "common.h"
static const MIL_INT BUTTON_SIZE_X = 125;
static const MIL_INT BUTTON_SIZE_Y = 25;
static const MIL_INT SMALL_BUTTON_SIZE_X = 60;
static const MIL_INT LARGE_BUTTON_SIZE_X = 180;
static const MIL_INT LINKED_BUTTON_GAP = 20;
static const MIL_INT BUTTON_GAP = 6;
static const MIL_INT BUTTON_START_X_POS = 240;
static const MIL_INT BUTTON_START_Y_POS = BUTTON_GAP;
static const MIL_INT SECTION_GAP = 16;
static const MIL_INT TEXT_START_X = 15;
static const MIL_INT TEXT_OFFSET_Y = 8;
static const MIL_INT UPDATE_INFO_TIME_DELAY = 1000;
static const MIL_INT MENU_SIZE_X = 650;
static const MIL_INT INITIAL_MENU_SIZE_Y = 520;
static const MIL_INT CORE_ROW_SIZE = BUTTON_SIZE_Y + BUTTON_GAP;
static const MIL_INT MAX_CORES_PER_ROW = 8;
static const MIL_DOUBLE BACKGROUND_COLOR = M_RGB888(255, 255, 255);
static const MIL_DOUBLE INFO_COLOR = M_COLOR_DARK_BLUE;
static const MIL_INT INFO_TEXT_SIZE = 350;
static const MIL_INT TOTAL_FPS_GAP = 5;
static const MIL_INT PROC_FPS_SIZE = BUTTON_GAP*3;
static const MIL_INT APPLY_TO_ALL_THREADS_ADJUSTMENT = -2;
static const MIL_INT CORE_AFFINITY_GAP = BUTTON_GAP*5;
CMPMenu::CMPMenu(MIL_INT ProcessingArraySize, CMPProcessing** Processing)
: m_ProcessingArraySize(ProcessingArraySize)
{
m_Processing = new CMPProcessing*[m_ProcessingArraySize];
MappInquireMp(M_DEFAULT, M_CORE_NUM_PROCESS, M_DEFAULT, M_DEFAULT, &m_NumberOfProcessorCores);
m_NumberOfProcessorCores = (m_NumberOfProcessorCores<=MAX_CORES)?m_NumberOfProcessorCores:MAX_CORES;
MIL_INT CoreAffinityMaskArraySize;
MappInquireMp(M_DEFAULT, M_CORE_AFFINITY_MASK_ARRAY_SIZE, M_DEFAULT, M_DEFAULT, &CoreAffinityMaskArraySize);
m_CoreAffinityMaskProcess = new MIL_UINT64[CoreAffinityMaskArraySize];
MappInquireMp(M_DEFAULT, M_CORE_AFFINITY_MASK_PROCESS, M_DEFAULT, M_DEFAULT, m_CoreAffinityMaskProcess);
if (MappInquireMp(M_DEFAULT, M_MP_FORCED_DISABLE, M_DEFAULT, M_DEFAULT, M_NULL)==M_YES)
m_NumberOfProcessorCores = 1;
m_MPIsOff = (m_NumberOfProcessorCores<MIN_MP_CORES);
MIL_INT NumCoreRows = (MIL_INT)ceil((MIL_DOUBLE)m_NumberOfProcessorCores/MAX_CORES_PER_ROW);
m_MenuSizeY = INITIAL_MENU_SIZE_Y + ((NumCoreRows)*CORE_ROW_SIZE);
m_NumMemoryBank = MappInquireMp(M_DEFAULT, M_MEMORY_BANK_NUM, M_DEFAULT, M_DEFAULT, M_NULL);
for (MIL_INT i=0; i<m_ProcessingArraySize; i++)
{
m_Processing[i] = Processing[i];
}
m_CurrentProcessing = 0;
m_CurrentProcessingNum = 0;
m_UpdateInfoStarted = false;
if (m_MPIsOff)
{
m_Processing[m_CurrentProcessingNum]->StartThread();
m_Processing[m_CurrentProcessingNum]->SetMP(false);
m_Processing[m_CurrentProcessingNum]->DisplaySelect();
m_Processing[m_CurrentProcessingNum]->RunDisplay(true);
m_Processing[m_CurrentProcessingNum]->Run();
m_CurrentProcessingNum = 1;
}
else
{
MIL_INT RunningThreadsNum = 0;
MIL_INT NumCoresAssigned = 0;
if (m_NumberOfProcessorCores < 4)
{
RunningThreadsNum = 1;
NumCoresAssigned = m_NumberOfProcessorCores;
}
else
{
RunningThreadsNum = 2;
NumCoresAssigned = m_NumberOfProcessorCores>>1;
}
for (m_CurrentProcessingNum=0; m_CurrentProcessingNum<RunningThreadsNum; m_CurrentProcessingNum++)
{
m_Processing[m_CurrentProcessingNum]->StartThread();
InitProcessingMP(NumCoresAssigned, m_Processing[m_CurrentProcessingNum]);
m_Processing[m_CurrentProcessingNum]->DisplaySelect();
m_Processing[m_CurrentProcessingNum]->RunDisplay(true);
m_Processing[m_CurrentProcessingNum]->Run();
}
}
Create();
UpdateTotalFPS();
UpdateCurProcFPS();
for (MIL_INT i=0; i<m_ProcessingArraySize; i++)
{
if (m_Processing[i]->IsRunning() && !m_UpdateInfoStarted)
{
StartUpdateInfo();
}
}
UpdateMenu();
}
CMPMenu::~CMPMenu()
{
Destroy();
delete [] m_Processing;
delete [] m_CoreAffinityMaskProcess;
}
void CMPMenu::Create()
{
MsysAlloc(M_DEFAULT, M_SYSTEM_HOST, M_DEFAULT, M_DEFAULT, &m_MilMenuSystem);
MdispAlloc(m_MilMenuSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_WINDOWED, &m_MilMenuDisplay);
MbufAllocColor(m_MilMenuSystem, 3, MENU_SIZE_X, m_MenuSizeY, 8+M_UNSIGNED, M_IMAGE+M_PROC+M_DISP, &m_MilMenuBuffer);
MbufClear(m_MilMenuBuffer, BACKGROUND_COLOR);
MgraAlloc(m_MilMenuSystem, &m_MilMenuGraphicsContext);
MgraControl(m_MilMenuGraphicsContext, M_BACKGROUND_MODE, M_TRANSPARENT);
MgraColor(m_MilMenuGraphicsContext, INFO_COLOR);
MgraAlloc(m_MilMenuSystem, &m_MilInfoGraphicsContext);
MgraControl(m_MilInfoGraphicsContext, M_BACKGROUND_MODE, M_TRANSPARENT);
MgraControl(m_MilInfoGraphicsContext, M_FONT_SIZE, SMALL_FONT);
MgraFont(m_MilInfoGraphicsContext, NORMAL_FONT_TYPE);
MgraColor(m_MilInfoGraphicsContext, INFO_COLOR);
CreateMenu();
MdispControl(m_MilMenuDisplay, M_KEYBOARD_USE, M_DISABLE);
MdispControl(m_MilMenuDisplay, M_MOUSE_USE, M_DISABLE);
MdispControl(m_MilMenuDisplay, M_WINDOW_RESIZE, M_DISABLE);
#if M_MIL_USE_WINDOWS
MdispControl(m_MilMenuDisplay, M_WINDOW_SYSBUTTON, M_DISABLE);
#endif
MdispControl(m_MilMenuDisplay, M_TITLE, M_PTR_TO_DOUBLE(MIL_TEXT("Multiprocessing")));
MdispControl(m_MilMenuDisplay, M_WINDOW_TITLE_BAR_CHANGE, M_DISABLE);
MdispControl(m_MilMenuDisplay, M_WINDOW_OVERLAP, M_DISABLE);
MthrAlloc (m_MilMenuSystem, M_EVENT, M_NOT_SIGNALED+M_AUTO_RESET, M_NULL, M_NULL, &m_MilInfoEvents[enRun]);
MthrAlloc (m_MilMenuSystem, M_EVENT, M_NOT_SIGNALED+M_AUTO_RESET, M_NULL, M_NULL, &m_MilInfoEvents[enKill]);
MthrAlloc (m_MilMenuSystem, M_THREAD, M_DEFAULT, &UpdateInfoFunction, (void*)this, &m_MilInfoThread);
MthrAlloc (m_MilMenuSystem, M_EVENT, M_NOT_SIGNALED+M_AUTO_RESET, M_NULL, M_NULL, &m_MilUpdateInfoStoppedEvent);
}
void CMPMenu::Destroy()
{
for (MIL_INT i=0; i<m_ProcessingArraySize; i++)
m_Processing[i]->Pause();
StopUpdateInfo();
MthrControl(m_MilInfoEvents[enKill], M_EVENT_SET, M_SIGNALED);
MthrWait(m_MilInfoThread, M_THREAD_END_WAIT, M_NULL);
MthrFree(m_MilInfoEvents[enRun]);
MthrFree(m_MilInfoEvents[enKill]);
MthrFree(m_MilInfoThread);
MthrFree(m_MilUpdateInfoStoppedEvent);
MdispHookFunction(m_MilMenuDisplay, M_MOUSE_LEFT_BUTTON_UP+M_UNHOOK, MenuHookFct, (void*)this);
MdispSelect(m_MilMenuDisplay, M_NULL);
for (MIL_INT i=FIRST_INFO; i<=LAST_INFO; i++)
{
MbufFree(m_InfoRegions[i].MilRectBuffer);
}
for (MIL_INT i=FIRST_BUTTON; i<=LAST_BUTTON; i++)
{
m_Buttons[i].Destroy();
}
MbufFree(m_MilMenuBuffer);
MdispFree(m_MilMenuDisplay);
MgraFree(m_MilInfoGraphicsContext);
MgraFree(m_MilMenuGraphicsContext);
MsysFree(m_MilMenuSystem);
}
void CMPMenu::CreateMenu()
{
MIL_INT ButtonStartX = BUTTON_START_X_POS;
MIL_INT ButtonStartY = BUTTON_START_Y_POS;
CreateApplicationControlSection(ButtonStartX, ButtonStartY);
CreateUserThreadsSection(ButtonStartX, ButtonStartY);
CreateMPSection(ButtonStartX, ButtonStartY);
MdispHookFunction(m_MilMenuDisplay, M_MOUSE_LEFT_BUTTON_UP, MenuHookFct, (void*)this);
}
void CMPMenu::CreateApplicationControlSection(MIL_INT& ButtonStartX, MIL_INT& ButtonStartY)
{
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, LARGE_FONT);
MgraFont(m_MilMenuGraphicsContext, M_FONT_DEFAULT);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
MgraFont(m_MilMenuGraphicsContext, BOLD_FONT_TYPE);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY, MIL_TEXT("Application Control"));
MoveXY(ButtonStartX, ButtonStartY, 0, SECTION_GAP);
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, SMALL_FONT);
MgraFont(m_MilMenuGraphicsContext, M_FONT_DEFAULT);
MgraFont(m_MilMenuGraphicsContext, NORMAL_FONT_TYPE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y,
MIL_TEXT("Number of User Threads"));
MIL_INT LinkedStartX = ButtonStartX;
MIL_INT LinkedStartY = ButtonStartY;
CreateButton(enTotalThreadsLeft, LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(" <<"), false);
MoveXY(LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X+LINKED_BUTTON_GAP, 0);
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
CreateButton(enTotalThreads, LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enTotalThreads, ButtonText), false);
MoveXY(LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X+LINKED_BUTTON_GAP, 0);
CreateButton(enTotalThreadsRight, LinkedStartX, ButtonStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(" >>"), false);
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y, MIL_TEXT("Show Displays"));
CreateButton(enShowDisplay, ButtonStartX, ButtonStartY, BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enShowDisplay, ButtonText), true);
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
m_InfoRegions[enTotalFPS].StartX = TEXT_START_X;
m_InfoRegions[enTotalFPS].StartY = ButtonStartY + TOTAL_FPS_GAP-1;
m_InfoRegions[enTotalFPS].EndX = m_InfoRegions[enTotalFPS].StartX + INFO_TEXT_SIZE-1;
m_InfoRegions[enTotalFPS].EndY = m_InfoRegions[enTotalFPS].StartY + PROC_FPS_SIZE-1;
MbufChild2d(m_MilMenuBuffer,
m_InfoRegions[enTotalFPS].StartX, m_InfoRegions[enTotalFPS].StartY,
m_InfoRegions[enTotalFPS].EndX-m_InfoRegions[enTotalFPS].StartX+1,
m_InfoRegions[enTotalFPS].EndY-m_InfoRegions[enTotalFPS].StartY+1,
&m_InfoRegions[enTotalFPS].MilRectBuffer);
ButtonStartY = m_InfoRegions[enTotalFPS].EndY + TOTAL_FPS_GAP-1;
MgraRectFill(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY, MENU_SIZE_X-TEXT_START_X, ButtonStartY+2);
MoveXY(ButtonStartX, ButtonStartY, 0, SECTION_GAP);
}
void CMPMenu::CreateUserThreadsSection(MIL_INT& ButtonStartX, MIL_INT& ButtonStartY)
{
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, LARGE_FONT);
MgraFont(m_MilMenuGraphicsContext, M_FONT_DEFAULT);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
MgraFont(m_MilMenuGraphicsContext, BOLD_FONT_TYPE);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY, MIL_TEXT("User Thread Selection"));
MoveXY(ButtonStartX, ButtonStartY, 0, SECTION_GAP);
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, SMALL_FONT);
MgraFont(m_MilMenuGraphicsContext, M_FONT_DEFAULT);
MgraFont(m_MilMenuGraphicsContext, NORMAL_FONT_TYPE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y, MIL_TEXT("Thread Index"));
MIL_INT LinkedStartX = ButtonStartX;
MIL_INT LinkedStartY = ButtonStartY;
CreateButton(enProcThreadLeft, LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(" <<"), false);
MoveXY(LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X+LINKED_BUTTON_GAP, 0);
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
CreateButton(enProcThread, LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enProcThread, ButtonText), false);
MoveXY(LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X+LINKED_BUTTON_GAP, 0);
CreateButton(enProcThreadRight, LinkedStartX, ButtonStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(" >>"), false);
MoveXY(LinkedStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
MgraRectFill(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY, MENU_SIZE_X-TEXT_START_X, ButtonStartY+1);
MoveXY(LinkedStartX, ButtonStartY, 0, BUTTON_GAP);
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, LARGE_FONT);
MgraFont(m_MilMenuGraphicsContext, M_FONT_DEFAULT);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
MgraFont(m_MilMenuGraphicsContext, BOLD_FONT_TYPE);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY, MIL_TEXT("Selected Thread Control"));
MoveXY(ButtonStartX, ButtonStartY, 0, APPLY_TO_ALL_THREADS_ADJUSTMENT);
CreateButton(enApplyToAllThreads, LinkedStartX, ButtonStartY, LARGE_BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enApplyToAllThreads, ButtonText), true);
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, SMALL_FONT);
MgraFont(m_MilMenuGraphicsContext, NORMAL_FONT_TYPE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y, MIL_TEXT("Run Processing"));
CreateButton(enRunProcessing, ButtonStartX, ButtonStartY, BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enRunProcessing, ButtonText), true);
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y, MIL_TEXT("Refresh Display"));
CreateButton(enRunDisplay, ButtonStartX, ButtonStartY, BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enRunDisplay, ButtonText), true);
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
}
void CMPMenu::CreateBufferSection(MIL_INT& ButtonStartX, MIL_INT& ButtonStartY)
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, SMALL_FONT);
MgraFont(m_MilMenuGraphicsContext, NORMAL_FONT_TYPE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y,
MIL_TEXT("Memory Bank Affinity"));
MIL_INT LinkedStartX = ButtonStartX;
MIL_INT LinkedStartY = ButtonStartY;
CreateButton(enMemoryBankLeft, LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(" <<"), false);
MoveXY(LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X+LINKED_BUTTON_GAP, 0);
CreateButton(enMemoryBank, LinkedStartX, LinkedStartY, BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enMemoryBank, ButtonText), false);
if (m_MPIsOff)
m_Buttons[enMemoryBank].Disable(MIL_TEXT("n/a"));
MoveXY(LinkedStartX, LinkedStartY, BUTTON_SIZE_X + LINKED_BUTTON_GAP, 0);
CreateButton(enMemoryBankRight, LinkedStartX, ButtonStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(" >>"), false);
MoveXY(LinkedStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
}
void CMPMenu::CreateMPSection(MIL_INT& ButtonStartX, MIL_INT& ButtonStartY)
{
MIL_INT LinkedStartX = 0;
MIL_INT LinkedStartY = 0;
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, SMALL_FONT);
MgraFont(m_MilMenuGraphicsContext, NORMAL_FONT_TYPE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y,
MIL_TEXT("Use Multiprocessing"));
CreateButton(enMP, ButtonStartX, ButtonStartY, BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enMP, ButtonText), true);
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP+SECTION_GAP);
if (m_MPIsOff)
m_Buttons[enMP].Disable(MIL_TEXT("n/a"));
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, MEDIUM_FONT);
MgraFont(m_MilMenuGraphicsContext, M_FONT_DEFAULT);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
MgraFont(m_MilMenuGraphicsContext, BOLD_FONT_TYPE);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY, MIL_TEXT("Multiprocessing Control"));
MoveXY(ButtonStartX, ButtonStartY, 0, SECTION_GAP);
MgraControl(m_MilMenuGraphicsContext, M_FONT_SIZE, SMALL_FONT);
MgraFont(m_MilMenuGraphicsContext, NORMAL_FONT_TYPE);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y, MIL_TEXT("Maximum Cores"));
LinkedStartX = ButtonStartX;
LinkedStartY = ButtonStartY;
CreateButton(enCoreMaxLeft, LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(" <<"), false);
MoveXY(LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X+LINKED_BUTTON_GAP, 0);
CreateButton(enCoreMax, LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enCoreMax, ButtonText), false);
if (m_MPIsOff)
m_Buttons[enCoreMax].Disable(MIL_TEXT("n/a"));
MoveXY(LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X+LINKED_BUTTON_GAP, 0);
CreateButton(enCoreMaxRight, LinkedStartX, ButtonStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(" >>"), false);
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y, MIL_TEXT("Core Sharing"));
CreateButton(enCoreSharing, ButtonStartX, ButtonStartY, BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enCoreSharing, ButtonText), true);
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
if (m_MPIsOff)
m_Buttons[enCoreSharing].Disable(MIL_TEXT("n/a"));
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y, MIL_TEXT("Priority"));
LinkedStartX = ButtonStartX;
LinkedStartY = ButtonStartY;
CreateButton(enMPPriorityLeft, LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(" <<"), false);
MoveXY(LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X+LINKED_BUTTON_GAP, 0);
CreateButton(enMPPriority, LinkedStartX, LinkedStartY, BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, enMPPriority, ButtonText), false);
if (m_MPIsOff)
m_Buttons[enMPPriority].Disable(MIL_TEXT("n/a"));
MoveXY(LinkedStartX, LinkedStartY, BUTTON_SIZE_X+LINKED_BUTTON_GAP, 0);
CreateButton(enMPPriorityRight, LinkedStartX, ButtonStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y, MIL_TEXT(">>"), false);
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_SIZE_Y+BUTTON_GAP);
CreateBufferSection(ButtonStartX, ButtonStartY);
MgraText(m_MilMenuGraphicsContext, m_MilMenuBuffer, TEXT_START_X, ButtonStartY+TEXT_OFFSET_Y,
MIL_TEXT("Core Affinity: (Core Index, Local Memory Bank Index)"));
MoveXY(ButtonStartX, ButtonStartY, 0, CORE_AFFINITY_GAP);
LinkedStartX = TEXT_START_X;
ButtonStartX = LinkedStartX;
LinkedStartY = ButtonStartY;
for (MIL_INT i=FIRST_CORE, Count=0; (i-FIRST_CORE)<m_NumberOfProcessorCores; i++, Count++)
{
CreateButton((MPButtons)i, LinkedStartX, LinkedStartY, SMALL_BUTTON_SIZE_X, BUTTON_SIZE_Y,
GetButtonText(m_CurrentProcessing, (MPButtons)i, ButtonText), true);
if (m_MPIsOff)
m_Buttons[(MPButtons)i].Disable(MIL_TEXT("n/a"));
LinkedStartX = ButtonStartX + ( ((Count+1)%MAX_CORES_PER_ROW) * (SMALL_BUTTON_SIZE_X + LINKED_BUTTON_GAP) );
LinkedStartY = ButtonStartY + ( ((Count+1)/MAX_CORES_PER_ROW) * (BUTTON_GAP + BUTTON_SIZE_Y));
}
ButtonStartX = BUTTON_START_X_POS;
MoveXY(ButtonStartX, ButtonStartY, 0, BUTTON_GAP + SECTION_GAP);
m_InfoRegions[enCurProcFPS].StartX = TEXT_START_X;
m_InfoRegions[enCurProcFPS].StartY = m_MenuSizeY - PROC_FPS_SIZE;
m_InfoRegions[enCurProcFPS].EndX = m_InfoRegions[enCurProcFPS].StartX + INFO_TEXT_SIZE-1;
m_InfoRegions[enCurProcFPS].EndY = m_InfoRegions[enCurProcFPS].StartY + PROC_FPS_SIZE-1;
MbufChild2d(m_MilMenuBuffer,
m_InfoRegions[enCurProcFPS].StartX, m_InfoRegions[enCurProcFPS].StartY,
m_InfoRegions[enCurProcFPS].EndX-m_InfoRegions[enCurProcFPS].StartX+1,
m_InfoRegions[enCurProcFPS].EndY-m_InfoRegions[enCurProcFPS].StartY+1,
&m_InfoRegions[enCurProcFPS].MilRectBuffer);
}
void CMPMenu::CreateButton(MPButtons ButtonType, MIL_INT StartX, MIL_INT StartY,
MIL_INT ButtonSizeX, MIL_INT ButtonSizeY,
const MIL_TEXT_CHAR* ButtonText, bool IsToggle)
{
RectStruct ButtonRect;
ButtonRect.StartX = StartX;
ButtonRect.EndX = ButtonRect.StartX + ButtonSizeX-1;
ButtonRect.StartY = StartY;
ButtonRect.EndY = ButtonRect.StartY + ButtonSizeY-1;
m_Buttons[ButtonType].Create(ButtonText, m_MilMenuBuffer, ButtonRect, IsToggle);
}
void CMPMenu::MoveXY(MIL_INT& StartX, MIL_INT& StartY, MIL_INT OffsetX, MIL_INT OffsetY)
{
StartX += OffsetX;
StartY += OffsetY;
}
void CMPMenu::Run()
{
MdispSelect(m_MilMenuDisplay, m_MilMenuBuffer);
}
CMPMenu::MPButtons CMPMenu::GetButton(MIL_INT PositionX, MIL_INT PositionY)
{
MPButtons Button= (MPButtons)-1;
for (MIL_INT i=FIRST_BUTTON; i<=LAST_BUTTON; i++)
{
if ( (m_Buttons[i].GetRect().StartX<=PositionX) &&
(m_Buttons[i].GetRect().EndX>=PositionX) &&
(m_Buttons[i].GetRect().StartY<=PositionY) &&
(m_Buttons[i].GetRect().EndY>=PositionY) )
{
Button = (MPButtons)i;
break;
}
}
return Button;
}
void CMPMenu::ProcessingButtonClick()
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
if (m_Processing[m_CurrentProcessing]->IsRunning())
{
m_Processing[m_CurrentProcessing]->Pause();
StopUpdateInfo();
}
else
{
m_Processing[m_CurrentProcessing]->Run();
StartUpdateInfo();
}
m_Buttons[enRunProcessing].Push(GetButtonText(m_CurrentProcessing, enRunProcessing, ButtonText));
UpdateMenu();
}
void CMPMenu::MPButtonClick()
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
if (m_Processing[m_CurrentProcessing]->MPEnabled())
{
m_Processing[m_CurrentProcessing]->SetMP(false);
}
else
{
m_Processing[m_CurrentProcessing]->SetMP(true);
}
m_Buttons[enMP].Push(GetButtonText(m_CurrentProcessing, enMP, ButtonText));
}
void CMPMenu::CoreMaxButtonClick(bool Add)
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
MIL_INT CurrentCoreMax = m_Processing[m_CurrentProcessing]->GetCoreMax();
if (Add && (CurrentCoreMax < m_NumberOfProcessorCores))
{
CurrentCoreMax++;
}
else if (!Add && (CurrentCoreMax>2))
{
CurrentCoreMax--;
}
m_Processing[m_CurrentProcessing]->SetCoreMax(CurrentCoreMax);
m_Buttons[enCoreMax].Push(GetButtonText(m_CurrentProcessing, enCoreMax, ButtonText));
}
void CMPMenu::CoreSharingButtonClick()
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
if (m_Processing[m_CurrentProcessing]->CoreSharingEnabled())
{
m_Processing[m_CurrentProcessing]->SetCoreSharing(false);
}
else
{
m_Processing[m_CurrentProcessing]->SetCoreSharing(true);
}
m_Buttons[enCoreSharing].Push(GetButtonText(m_CurrentProcessing, enCoreSharing, ButtonText));
}
void CMPMenu::MPPriorityButtonClick(bool Next)
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
MIL_INT MPPriority = m_Processing[m_CurrentProcessing]->GetMPPriority();
switch (MPPriority)
{
case M_ABOVE_NORMAL:
if (Next)
MPPriority=M_BELOW_NORMAL;
break;
case M_BELOW_NORMAL:
if (Next)
MPPriority=M_HIGHEST;
else
MPPriority=M_ABOVE_NORMAL;
break;
case M_HIGHEST:
if (Next)
MPPriority=M_IDLE;
else
MPPriority=M_BELOW_NORMAL;
break;
case M_IDLE:
if (Next)
MPPriority=M_LOWEST;
else
MPPriority=M_HIGHEST;
break;
case M_LOWEST:
if (Next)
MPPriority=M_NORMAL;
else
MPPriority=M_IDLE;
break;
case M_NORMAL:
if (Next)
MPPriority=M_TIME_CRITICAL;
else
MPPriority=M_LOWEST;
break;
case M_TIME_CRITICAL:
if (!Next)
MPPriority=M_NORMAL;
break;
default:
break;
}
m_Processing[m_CurrentProcessing]->SetMPPriority(MPPriority);
m_Buttons[enMPPriority].Push(GetButtonText(m_CurrentProcessing, enMPPriority, ButtonText));
}
void CMPMenu::ProcessingThreadButtonClick(bool Next)
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
if (Next && (m_CurrentProcessing < m_CurrentProcessingNum-1))
{
m_CurrentProcessing++;
}
else if (!Next && (m_CurrentProcessing > 0))
{
m_CurrentProcessing--;
}
m_Buttons[enProcThread].Push(GetButtonText(m_CurrentProcessing, enProcThread, ButtonText));
UpdateMenu();
}
void CMPMenu::ApplyToAllThreadsButtonClick()
{
MIL_INT ThreadIndex;
bool UseMemoryBank = m_Processing[m_CurrentProcessing]->UseMemoryBank();
MIL_INT64 MemoryBank = m_Processing[m_CurrentProcessing]->GetCurrentMemoryBank();
for (MIL_INT i=1; i<m_CurrentProcessingNum; i++)
{
ThreadIndex = (m_CurrentProcessing+i)%(m_CurrentProcessingNum);
if (m_Processing[m_CurrentProcessing]->IsRunning())
m_Processing[ThreadIndex]->Run();
else
m_Processing[ThreadIndex]->Pause();
m_Processing[ThreadIndex]->RunDisplay(m_Processing[m_CurrentProcessing]->DisplayRunning());
m_Processing[ThreadIndex]->SetMP(m_Processing[m_CurrentProcessing]->MPEnabled());
m_Processing[ThreadIndex]->SetCoreMax(m_Processing[m_CurrentProcessing]->GetCoreMax());
m_Processing[ThreadIndex]->SetCoreSharing(m_Processing[m_CurrentProcessing]->CoreSharingEnabled());
m_Processing[ThreadIndex]->SetMPPriority(m_Processing[m_CurrentProcessing]->GetMPPriority());
m_Processing[ThreadIndex]->SetCoreAffinity(m_Processing[m_CurrentProcessing]->GetCoreAffinity());
m_Processing[ThreadIndex]->SetCurrentMemoryBank(MemoryBank, UseMemoryBank);
}
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
m_Buttons[enApplyToAllThreads].Push(ButtonText);
MosSleep(50);
GetButtonText(m_CurrentProcessing, enApplyToAllThreads, ButtonText);
m_Buttons[enApplyToAllThreads].Push(GetButtonText(m_CurrentProcessing, enApplyToAllThreads, ButtonText));
}
void CMPMenu::NumberOfThreadsButtonClick(bool Next)
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
if (Next && (m_CurrentProcessingNum < m_ProcessingArraySize))
{
m_CurrentProcessingNum++;
m_Processing[m_CurrentProcessingNum-1]->StartThread();
if (m_Processing[m_CurrentProcessing]->DisplaySelected())
{
m_Processing[m_CurrentProcessingNum-1]->DisplaySelect();
m_Processing[m_CurrentProcessingNum-1]->RunDisplay(true);
}
else
{
m_Processing[m_CurrentProcessingNum-1]->RunDisplay(false);
}
InitProcessingMP(m_NumberOfProcessorCores, m_Processing[m_CurrentProcessingNum-1]);
m_Processing[m_CurrentProcessingNum-1]->Run();
m_CurrentProcessing = m_CurrentProcessingNum-1;
StartUpdateInfo();
}
else if (!Next && (m_CurrentProcessingNum > 1))
{
m_Processing[m_CurrentProcessingNum-1]->DisplayDeselect();
m_Processing[m_CurrentProcessingNum-1]->StopThread();
m_CurrentProcessingNum--;
if (m_CurrentProcessing == m_CurrentProcessingNum)
m_CurrentProcessing = m_CurrentProcessingNum-1;
StopUpdateInfo();
}
m_Buttons[enTotalThreads].Push(GetButtonText(m_CurrentProcessing, enTotalThreads, ButtonText));
UpdateMenu();
}
void CMPMenu::CurrentThreadDisplayButtonClick()
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
if (m_Processing[m_CurrentProcessing]->DisplayRunning())
{
m_Processing[m_CurrentProcessing]->RunDisplay(false);
}
else
{
m_Processing[m_CurrentProcessing]->RunDisplay(true);
}
m_Buttons[enRunDisplay].Push(GetButtonText(m_CurrentProcessing, enRunDisplay, ButtonText));
}
void CMPMenu::AllThreadsDisplayButtonClick()
{
if (m_Processing[m_CurrentProcessing]->DisplaySelected())
{
for (MIL_INT i=0; i<m_CurrentProcessingNum; i++)
{
if (m_Processing[i]->DisplayRunning())
m_Processing[i]->RunDisplay(false);
m_Processing[i]->DisplayDeselect();
}
}
else
{
for (MIL_INT i=0; i<m_CurrentProcessingNum; i++)
{
m_Processing[i]->RunDisplay(true);
m_Processing[i]->DisplaySelect();
}
}
UpdateMenu();
}
void CMPMenu::MemoryBankButtonClick(bool Next)
{
if ( (!m_Processing[m_CurrentProcessing]->UseMemoryBank() && Next) && (m_NumMemoryBank>0) )
{
m_Processing[m_CurrentProcessing]->SetCurrentMemoryBank(M_MEMORY_BANK_0, true);
}
else if (m_Processing[m_CurrentProcessing]->UseMemoryBank())
{
bool ValidBank = false;
MIL_INT64 NewMemoryBank = m_Processing[m_CurrentProcessing]->GetMemoryBank(Next, ValidBank);
if (ValidBank)
{
switch(NewMemoryBank)
{
case M_MEMORY_BANK_0:
if (!Next && (m_Processing[m_CurrentProcessing]->GetCurrentMemoryBank()==M_MEMORY_BANK_0))
{
m_Processing[m_CurrentProcessing]->SetCurrentMemoryBank(0, false);
}
else if (!Next)
{
m_Processing[m_CurrentProcessing]->SetCurrentMemoryBank(M_MEMORY_BANK_0, true);
}
break;
case M_MEMORY_BANK_1:
m_Processing[m_CurrentProcessing]->SetCurrentMemoryBank(M_MEMORY_BANK_1, true);
break;
case M_MEMORY_BANK_2:
m_Processing[m_CurrentProcessing]->SetCurrentMemoryBank(M_MEMORY_BANK_2, true);
break;
case M_MEMORY_BANK_3:
m_Processing[m_CurrentProcessing]->SetCurrentMemoryBank(M_MEMORY_BANK_3, true);
break;
case M_MEMORY_BANK_4:
m_Processing[m_CurrentProcessing]->SetCurrentMemoryBank(M_MEMORY_BANK_4, true);
break;
case M_MEMORY_BANK_5:
m_Processing[m_CurrentProcessing]->SetCurrentMemoryBank(M_MEMORY_BANK_5, true);
break;
case M_MEMORY_BANK_6:
m_Processing[m_CurrentProcessing]->SetCurrentMemoryBank(M_MEMORY_BANK_6, true);
break;
default:
break;
}
}
}
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
m_Buttons[enMemoryBank].Push(GetButtonText(m_CurrentProcessing, enMemoryBank, ButtonText));
}
void CMPMenu::CoreAffinityButtonClick(MIL_INT CoreIndex)
{
MIL_UINT64 CurrentCoreAffinity = m_Processing[m_CurrentProcessing]->GetCoreAffinity();
MIL_UINT64 CoreAffinityMask = 0x00000001;
CoreAffinityMask = CoreAffinityMask << GetRealCoreIndex(CoreIndex);
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
if (m_Buttons[CoreIndex+FIRST_CORE].IsPressed())
{
m_Processing[m_CurrentProcessing]->SetCoreAffinity(CurrentCoreAffinity&~CoreAffinityMask);
}
else
{
m_Processing[m_CurrentProcessing]->SetCoreAffinity(CurrentCoreAffinity|CoreAffinityMask);
}
m_Buttons[CoreIndex+FIRST_CORE].Push(GetButtonText(m_CurrentProcessing, (MPButtons)(CoreIndex+FIRST_CORE),
ButtonText));
}
void CMPMenu::UpdateMenu()
{
MIL_TEXT_CHAR ButtonText[STRING_SIZE]=MIL_TEXT("");
if ( (m_Processing[m_CurrentProcessing]->DisplaySelected() && !m_Buttons[enShowDisplay].IsPressed()) ||
(!m_Processing[m_CurrentProcessing]->DisplaySelected() && m_Buttons[enShowDisplay].IsPressed()) )
{
m_Buttons[enShowDisplay].Push(GetButtonText(m_CurrentProcessing, enShowDisplay, ButtonText));
}
m_Buttons[enProcThread].Push(GetButtonText(m_CurrentProcessing, enProcThread, ButtonText));
if (m_Processing[m_CurrentProcessing]->IsRunning() && !m_Buttons[enRunProcessing].IsPressed())
{
m_Buttons[enRunProcessing].Push(GetButtonText(m_CurrentProcessing, enRunProcessing, ButtonText));
}
else if (!m_Processing[m_CurrentProcessing]->IsRunning())
{
UpdateCurProcFPS();
if (m_Buttons[enRunProcessing].IsPressed())
m_Buttons[enRunProcessing].Push(GetButtonText(m_CurrentProcessing, enRunProcessing, ButtonText));
}
MIL_INT i=0;
for (i=0; i<m_CurrentProcessingNum; i++)
{
if (m_Processing[i]->IsRunning())
break;
}
if (i==m_CurrentProcessingNum)
UpdateTotalFPS();
if ( (m_Processing[m_CurrentProcessing]->DisplayRunning() && !m_Buttons[enRunDisplay].IsPressed()) ||
(!m_Processing[m_CurrentProcessing]->DisplayRunning() && m_Buttons[enRunDisplay].IsPressed()) )
{
m_Buttons[enRunDisplay].Push(GetButtonText(m_CurrentProcessing, enRunDisplay, ButtonText));
}
if (!m_MPIsOff)
{
if ( (!m_Processing[m_CurrentProcessing]->MPEnabled() && m_Buttons[enMP].IsPressed()) ||
(m_Processing[m_CurrentProcessing]->MPEnabled() && !m_Buttons[enMP].IsPressed()) )
{
m_Buttons[enMP].Push(GetButtonText(m_CurrentProcessing, enMP, ButtonText));
}
m_Buttons[enCoreMax].Push(GetButtonText(m_CurrentProcessing, enCoreMax, ButtonText));
m_Buttons[enMPPriority].Push(GetButtonText(m_CurrentProcessing, enMPPriority, ButtonText));
m_Buttons[enMemoryBank].Push(GetButtonText(m_CurrentProcessing, enMemoryBank, ButtonText));
if ( (!m_Processing[m_CurrentProcessing]->CoreSharingEnabled() && m_Buttons[enCoreSharing].IsPressed()) ||
(m_Processing[m_CurrentProcessing]->CoreSharingEnabled() && !m_Buttons[enCoreSharing].IsPressed()) )
{
m_Buttons[enCoreSharing].Push(GetButtonText(m_CurrentProcessing, enCoreSharing, ButtonText));
}
MIL_UINT64 CurrentCoreAffinity = m_Processing[m_CurrentProcessing]->GetCoreAffinity();
for (MIL_INT i=FIRST_CORE; (i-FIRST_CORE)<m_NumberOfProcessorCores; i++)
{
bool AffinityIsSet = (CurrentCoreAffinity&((MIL_UINT64)1<<GetRealCoreIndex(i-FIRST_CORE))) != 0x00000000;
if (AffinityIsSet != m_Buttons[i].IsPressed())
{
m_Buttons[i].Push(GetButtonText(m_CurrentProcessing, (MPButtons)i, ButtonText));
}
}
}
}
void CMPMenu::UpdateInfo()
{
while ( MthrWaitMultiple(m_MilInfoEvents, NUM_EVENTS, M_EVENT_WAIT, M_NULL) != (MIL_INT)enKill )
{
while (m_UpdateInfoStarted)
{
UpdateTotalFPS();
if (m_Processing[m_CurrentProcessing]->GetFrameRate()>0)
UpdateCurProcFPS();
MosSleep(UPDATE_INFO_TIME_DELAY);
}
MthrControl(m_MilUpdateInfoStoppedEvent, M_EVENT_SET, M_SIGNALED);
}
}
void CMPMenu::UpdateTotalFPS()
{
MIL_DOUBLE FrameRate = 0;
for (MIL_INT i=0; i<m_CurrentProcessingNum; i++)
{
if (m_Processing[i]->IsRunning())
FrameRate += m_Processing[i]->GetFrameRate();
}
MosSprintf(m_InfoString, STRING_SIZE, MIL_TEXT("%.1f Total Frames per Second"), FrameRate);
MdispControl(m_MilMenuDisplay, M_UPDATE, M_DISABLE);
MbufClear(m_InfoRegions[enTotalFPS].MilRectBuffer, BACKGROUND_COLOR);
MgraText(m_MilInfoGraphicsContext, m_InfoRegions[enTotalFPS].MilRectBuffer, 0, 0, m_InfoString);
MdispControl(m_MilMenuDisplay, M_UPDATE, M_ENABLE);
}
void CMPMenu::UpdateCurProcFPS()
{
MosSprintf(m_InfoString, STRING_SIZE, MIL_TEXT("%.1f Frames per Second"),
m_Processing[m_CurrentProcessing]->GetFrameRate());
MdispControl(m_MilMenuDisplay, M_UPDATE, M_DISABLE);
MbufClear(m_InfoRegions[enCurProcFPS].MilRectBuffer, BACKGROUND_COLOR);
MgraText(m_MilInfoGraphicsContext, m_InfoRegions[enCurProcFPS].MilRectBuffer, 0, 0, m_InfoString);
MdispControl(m_MilMenuDisplay, M_UPDATE, M_ENABLE);
}
void CMPMenu::StartUpdateInfo()
{
m_UpdateInfoStarted = true;
MthrControl(m_MilInfoEvents[enRun], M_EVENT_SET, M_SIGNALED);
}
void CMPMenu::StopUpdateInfo()
{
MIL_INT i=0;
for (i=0; i<m_ProcessingArraySize; i++)
{
if (m_Processing[i]->IsRunning())
break;
}
if ((i==m_ProcessingArraySize) && m_UpdateInfoStarted)
{
m_UpdateInfoStarted = false;
MthrWait(m_MilUpdateInfoStoppedEvent, M_EVENT_WAIT, M_NULL);
}
}
MIL_TEXT_CHAR* CMPMenu::GetButtonText(MIL_INT ProcessingIndex, MPButtons ButtonType,
MIL_TEXT_CHAR* ButtonText)
{
bool UseMemoryBank = false;
MIL_INT64 CurrentMemoryBank = 0;
MIL_UINT64 CoreMask = 0x00000001;
switch (ButtonType)
{
case enTotalThreads:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%d"), m_CurrentProcessingNum);
break;
case enShowDisplay:
if (m_Processing[m_CurrentProcessing]->DisplaySelected())
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Yes"));
else
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("No"));
break;
case enProcThread:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%d"), m_CurrentProcessing);
break;
case enApplyToAllThreads:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Apply to All Threads"));
break;
case enRunProcessing:
if (m_Processing[ProcessingIndex]->IsRunning())
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Yes"));
else
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("No"));
break;
case enRunDisplay:
if (m_Processing[ProcessingIndex]->DisplayRunning())
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Yes"));
else
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("No"));
break;
case enMemoryBank:
CurrentMemoryBank = m_Processing[m_CurrentProcessing]->GetCurrentMemoryBank();
if (m_Processing[m_CurrentProcessing]->UseMemoryBank())
{
switch(CurrentMemoryBank)
{
case M_MEMORY_BANK_0:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Bank 0"));
break;
case M_MEMORY_BANK_1:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Bank 1"));
break;
case M_MEMORY_BANK_2:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Bank 2"));
break;
case M_MEMORY_BANK_3:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Bank 3"));
break;
case M_MEMORY_BANK_4:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Bank 4"));
break;
case M_MEMORY_BANK_5:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Bank 5"));
break;
case M_MEMORY_BANK_6:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Bank 6"));
break;
default:
break;
}
}
else
{
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("No Affinity"));
}
break;
case enMP:
if (m_Processing[ProcessingIndex]->MPEnabled())
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Yes"));
else
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("No"));
break;
case enCoreMax:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%d"), m_Processing[m_CurrentProcessing]->GetCoreMax());
break;
case enCoreSharing:
if (m_Processing[ProcessingIndex]->CoreSharingEnabled())
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Enabled"));
else
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%s"), MIL_TEXT("Disabled"));
break;
case enMPPriority:
switch (m_Processing[ProcessingIndex]->GetMPPriority())
{
case M_ABOVE_NORMAL:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("Above Normal"));
break;
case M_BELOW_NORMAL:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("Below Normal"));
break;
case M_HIGHEST:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("Highest"));
break;
case M_IDLE:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("Idle"));
break;
case M_LOWEST:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("Lowest"));
break;
case M_NORMAL:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("Normal"));
break;
case M_TIME_CRITICAL:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("Time Critical"));
break;
default:
break;
}
break;
case enCore0:case enCore1:case enCore2:case enCore3:
case enCore4:case enCore5:case enCore6:case enCore7:
case enCore8:case enCore9:case enCore10:case enCore11:
case enCore12:case enCore13:case enCore14:case enCore15:
case enCore16:case enCore17:case enCore18:case enCore19:
case enCore20:case enCore21:case enCore22:case enCore23:
case enCore24:case enCore25:case enCore26:case enCore27:
case enCore28:case enCore29:case enCore30:case enCore31:
MosSprintf(ButtonText, STRING_SIZE, MIL_TEXT("%d, %d"), GetRealCoreIndex(ButtonType-FIRST_CORE),
MappInquireMp(M_DEFAULT, M_CORE_MEMORY_BANK, M_DEFAULT, GetRealCoreIndex(ButtonType-FIRST_CORE), M_NULL));
break;
default:
break;
}
return ButtonText;
}
void CMPMenu::InitProcessingMP(MIL_INT NumCores, CMPProcessing* Processing)
{
Processing->SetMP(true);
Processing->SetCoreMax(NumCores);
Processing->SetCoreSharing(false);
Processing->SetMPPriority(M_NORMAL);
Processing->SetCoreAffinity(0x00000000);
Processing->SetCurrentMemoryBank(0, false);
}
MIL_INT CMPMenu::GetRealCoreIndex(MIL_INT Rank)
{
MIL_INT i=0;
MIL_INT AvailableCoresCount = 0;
for (i=0; i<MAX_MP_CORES; i++)
{
if (m_CoreAffinityMaskProcess[0]&((MIL_UINT64)1<<i))
AvailableCoresCount++;
if (AvailableCoresCount==Rank+1)
break;
}
return i;
}
MIL_INT MFTYPE CMPMenu::MenuHookFct(MIL_INT HookType, MIL_ID MilEvent, void *UserDataPtr)
{
CMPMenu* MenuPtr = (CMPMenu*)UserDataPtr;
MIL_INT PositionX = 0;
MIL_INT PositionY = 0;
MIL_UINT64 CoreMask = 0x00000001;
MdispGetHookInfo(MilEvent, M_MOUSE_POSITION_X, &PositionX);
MdispGetHookInfo(MilEvent, M_MOUSE_POSITION_Y, &PositionY);
MPButtons ButtonType = MenuPtr->GetButton(PositionX, PositionY);
switch (ButtonType)
{
case enTotalThreadsLeft:
MenuPtr->NumberOfThreadsButtonClick(false);
break;
case enTotalThreadsRight:
MenuPtr->NumberOfThreadsButtonClick(true);
break;
case enShowDisplay:
MenuPtr->AllThreadsDisplayButtonClick();
break;
case enProcThreadLeft:
MenuPtr->ProcessingThreadButtonClick(false);
break;
case enProcThreadRight:
MenuPtr->ProcessingThreadButtonClick(true);
break;
case enApplyToAllThreads:
MenuPtr->ApplyToAllThreadsButtonClick();
break;
case enRunProcessing:
MenuPtr->ProcessingButtonClick();
break;
case enRunDisplay:
MenuPtr->CurrentThreadDisplayButtonClick();
break;
case enMemoryBankLeft:
if (MenuPtr->m_NumberOfProcessorCores>=MIN_MP_CORES)
MenuPtr->MemoryBankButtonClick(false);
break;
case enMemoryBankRight:
if (MenuPtr->m_NumberOfProcessorCores>=MIN_MP_CORES)
MenuPtr->MemoryBankButtonClick(true);
break;
case enMP:
if (MenuPtr->m_NumberOfProcessorCores>=MIN_MP_CORES)
MenuPtr->MPButtonClick();
break;
case enCoreMaxLeft:
if (MenuPtr->m_NumberOfProcessorCores>=MIN_MP_CORES)
MenuPtr->CoreMaxButtonClick(false);
break;
case enCoreMaxRight:
if (MenuPtr->m_NumberOfProcessorCores>=MIN_MP_CORES)
MenuPtr->CoreMaxButtonClick(true);
break;
case enCoreSharing:
if (MenuPtr->m_NumberOfProcessorCores>=MIN_MP_CORES)
MenuPtr->CoreSharingButtonClick();
break;
case enMPPriorityLeft:
if (MenuPtr->m_NumberOfProcessorCores>=MIN_MP_CORES)
MenuPtr->MPPriorityButtonClick(false);
break;
case enMPPriorityRight:
if (MenuPtr->m_NumberOfProcessorCores>=MIN_MP_CORES)
MenuPtr->MPPriorityButtonClick(true);
break;
case enCore0:case enCore1:case enCore2:case enCore3:
case enCore4:case enCore5:case enCore6:case enCore7:
case enCore8:case enCore9:case enCore10:case enCore11:
case enCore12:case enCore13:case enCore14:case enCore15:
case enCore16:case enCore17:case enCore18:case enCore19:
case enCore20:case enCore21:case enCore22:case enCore23:
case enCore24:case enCore25:case enCore26:case enCore27:
case enCore28:case enCore29:case enCore30:case enCore31:
if (MenuPtr->m_NumberOfProcessorCores>=MIN_MP_CORES)
MenuPtr->CoreAffinityButtonClick(ButtonType-FIRST_CORE);
break;
default:
break;
};
return 0;
}
MIL_UINT32 MFTYPE CMPMenu::UpdateInfoFunction(void* DataPtr)
{
CMPMenu* Menu = (CMPMenu*)DataPtr;
Menu->UpdateInfo();
return 0;
}