From ba540c30269c3f502b5cf86844cf485d7e1fe825 Mon Sep 17 00:00:00 2001 From: NicJA Date: Tue, 28 Feb 2017 06:27:04 +0000 Subject: [PATCH] wip commit. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@53959 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- test/exec/smp/main.c | 147 +++++++++++++++++++++++++++++++++++++------------ test/exec/smp/worker.c | 75 ++++++++++++++----------- 2 files changed, 153 insertions(+), 69 deletions(-) diff --git a/test/exec/smp/main.c b/test/exec/smp/main.c index eedaa5e3ca..e8b83ac2a3 100644 --- a/test/exec/smp/main.c +++ b/test/exec/smp/main.c @@ -10,6 +10,8 @@ #include #include +#include + #include #include #include @@ -34,6 +36,8 @@ int main() { 0, (IPTR)NULL } }; ULONG signals; + struct Screen *pubScreen; + struct Window *displayWin; ProcessorBase = OpenResource(PROCESSORNAME); if (!ProcessorBase) @@ -50,7 +54,10 @@ int main() struct MemList *coreML; struct SMPWorker *coreWorker; struct SMPWorkMessage *workMsg; - IPTR workerNameArg[1]; + IPTR rawArgs[2]; + char buffer[100]; + int count = 0; + BOOL complete = FALSE; /* Create a port that workers/masters will signal us using .. */ if ((workMaster.smpm_MasterPort = CreateMsgPort()) == NULL) @@ -81,8 +88,8 @@ int main() { coreML->ml_NumEntries = 2; - workerNameArg[0] = core; - RawDoFmt("SMP-Test Worker.#%03u", (RAWARG)workerNameArg, RAWFMTFUNC_STRING, coreML->ml_ME[1].me_Addr); + rawArgs[0] = core; + RawDoFmt("SMP-Test Worker.#%03u", (RAWARG)rawArgs, RAWFMTFUNC_STRING, coreML->ml_ME[1].me_Addr); D(bug("[SMP-Test] %s: Worker Task Name '%s'\n", __func__, coreML->ml_ME[1].me_Addr);) coreWorker->smpw_MasterPort = workMaster.smpm_MasterPort; @@ -97,6 +104,7 @@ int main() if (coreWorker->smpw_Task) { + count++; AddTail(&workMaster.smpm_Workers, &coreWorker->smpw_Node); AddHead(&coreWorker->smpw_Task->tc_MemEntry, &coreML->ml_Node); } @@ -114,59 +122,126 @@ int main() } } - D(bug("[SMP-Test] %s: Sending out work to do ...\n", __func__);) + D(bug("[SMP-Test] %s: Waiting for workers to become ready ...\n", __func__);) + + complete = TRUE; + do { + ForeachNode(&workMaster.smpm_Workers, coreWorker) + { + if (coreWorker->smpw_Node.ln_Type != 1) + complete = FALSE; + } + } while (!complete); /* * We now have our workers all launched, * and a node for each on our list. * lets get them to do some work ... */ - workMaster.smpm_Master = NewCreateTask(TASKTAG_NAME , "SMP-Test Master", - TASKTAG_AFFINITY, TASKAFFINITY_ANY, - TASKTAG_PRI , 0, - TASKTAG_PC , SMPTestMaster, - TASKTAG_ARG1 , SysBase, - TASKTAG_USERDATA , &workMaster, - TAG_DONE); - - D(bug("[SMP-Test] %s: Waiting for the work to be done ...\n", __func__);) + D(bug("[SMP-Test] %s: Sending out work to do ...\n", __func__);) - /* Wait for the workers to finish processing the data ... */ - while ((signals = Wait(SIGBREAKF_CTRL_D)) != 0) + rawArgs[0] = count; + rawArgs[1] = coreCount; + RawDoFmt("SMP Test Output (%d workers on %d cores)", (RAWARG)rawArgs, RAWFMTFUNC_STRING, buffer); + + complete = FALSE; + pubScreen = LockPubScreen(0); + if ((displayWin = OpenWindowTags(0, + WA_PubScreen, (IPTR)pubScreen, + WA_Left, 0, + WA_Top, (pubScreen) ? pubScreen->BarHeight : 10, + WA_Width, (pubScreen) ? pubScreen->Width : 320, + WA_Height, (pubScreen) ? (pubScreen->Height - pubScreen->BarHeight ) : 200, + WA_Title, (IPTR)buffer, + WA_SimpleRefresh, TRUE, + WA_CloseGadget, TRUE, + WA_DepthGadget, TRUE, + WA_DragBar, TRUE, + WA_SizeGadget, FALSE, + WA_SizeBBottom, FALSE, + WA_SizeBRight, FALSE, + WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW, + TAG_DONE)) != NULL) { - if (signals & SIGBREAKF_CTRL_D) - { - BOOL complete = TRUE; + BOOL working = TRUE; - /* Is work still being issued? */ - if (workMaster.smpm_Master) - complete = FALSE; + if (pubScreen) + UnlockPubScreen(0, pubScreen); - /* Are workers still working ? */ - ForeachNode(&workMaster.smpm_Workers, coreWorker) + workMaster.smpm_Master = NewCreateTask(TASKTAG_NAME , "SMP-Test Master", + TASKTAG_AFFINITY, TASKAFFINITY_ANY, + TASKTAG_PRI , 0, + TASKTAG_PC , SMPTestMaster, + TASKTAG_ARG1 , SysBase, + TASKTAG_USERDATA , &workMaster, + TAG_DONE); + + D(bug("[SMP-Test] %s: Waiting for the work to be done ...\n", __func__);) + + /* Wait for the workers to finish processing the data ... */ + + while ((working) && ((signals = Wait(SIGBREAKF_CTRL_D | displayWin->UserPort->mp_SigBit)) != 0)) + { + if ((signals & SIGBREAKF_CTRL_D) && (!complete)) { - if (!IsListEmpty(&coreWorker->smpw_MsgPort->mp_MsgList)) + complete = TRUE; + + /* Is work still being issued? */ + if (workMaster.smpm_Master) complete = FALSE; + + /* Are workers still working ? */ + ForeachNode(&workMaster.smpm_Workers, coreWorker) + { + if (!IsListEmpty(&coreWorker->smpw_MsgPort->mp_MsgList)) + complete = FALSE; + } + + if (complete) + { + working = FALSE; + break; + } + } + else if (signals & displayWin->UserPort->mp_SigBit) + { + struct IntuiMessage *msg; + while ((msg = (struct IntuiMessage *)GetMsg(displayWin->UserPort))) + { + switch(msg->Class) + { + case IDCMP_CLOSEWINDOW: + working = FALSE; + break; + + case IDCMP_REFRESHWINDOW: +#if (0) + BeginRefresh(win); + EndRefresh(win,TRUE); +#endif + break; + } + ReplyMsg((struct Message *)msg); + } } - if (complete) - break; + /* update the output... */ } - /* update the output... */ - } - - D(bug("[SMP-Test] %s: Letting workers know we are finished ...\n", __func__);) + D(bug("[SMP-Test] %s: Letting workers know we are finished ...\n", __func__);) - ForeachNode(&workMaster.smpm_Workers, coreWorker) - { - /* Tell the workers they are finished ... */ - if ((workMsg = (struct SMPWorkMessage *)AllocMem(sizeof(struct SMPWorkMessage), MEMF_CLEAR)) != NULL) + ForeachNode(&workMaster.smpm_Workers, coreWorker) { - workMsg->smpwm_Type = SPMWORKTYPE_FINISHED; - PutMsg(coreWorker->smpw_MsgPort, (struct Message *)workMsg); + /* Tell the workers they are finished ... */ + if ((workMsg = (struct SMPWorkMessage *)AllocMem(sizeof(struct SMPWorkMessage), MEMF_CLEAR)) != NULL) + { + workMsg->smpwm_Type = SPMWORKTYPE_FINISHED; + PutMsg(coreWorker->smpw_MsgPort, (struct Message *)workMsg); + } } + CloseWindow(displayWin); } + if (pubScreen) UnlockPubScreen(0, pubScreen); } D(bug("[SMP-Test] %s: Waiting for workers to finish ...\n", __func__);) diff --git a/test/exec/smp/worker.c b/test/exec/smp/worker.c index aca232a84b..2109899253 100644 --- a/test/exec/smp/worker.c +++ b/test/exec/smp/worker.c @@ -14,7 +14,7 @@ #include "work.h" -#define MAXITERATIONS 100 +#define MAXITERATIONS 10000 /* * define a complex number with @@ -120,53 +120,62 @@ void SMPTestWorker(struct ExecBase *SysBase) if ((worker) && (worker->smpw_MasterPort)) { + worker->smpw_Node.ln_Type = 0; + D(bug("[SMP-Test:Worker.%03d] work Master MsgPort @ 0x%p\n", cpunum, worker->smpw_MasterPort);) worker->smpw_MsgPort = CreateMsgPort(); D(bug("[SMP-Test:Worker.%03d] work MsgPort @ 0x%p\n", cpunum, worker->smpw_MsgPort);) workPrivate = AllocMem(sizeof(struct WorkersWork) + (MAXITERATIONS * sizeof(complexno_t)), MEMF_CLEAR|MEMF_ANY); - workPrivate->workMax = MAXITERATIONS; + + D(bug("[SMP-Test:Worker.%03d] worker private data @ 0x%p\n", cpunum, workPrivate);) - while (doWork) + if (workPrivate) { - IPTR workType; - - /* we are ready for work .. */ - worker->smpw_Node.ln_Type = 1; - WaitPort(worker->smpw_MsgPort); + workPrivate->workMax = MAXITERATIONS; - while((workMsg = (struct SMPWorkMessage *) GetMsg(worker->smpw_MsgPort))) + while (doWork) { - D(bug("[SMP-Test:Worker.%03d] work received (Msg @ 0x%p)\n", cpunum, workMsg);) - - /* cache the requested work and free the message ... */ - workType = workMsg->smpwm_Type; - FreeMem(workMsg, sizeof(struct SMPWorkMessage)); - - /* now process it .. */ - if (workType == SPMWORKTYPE_FINISHED) - { - D(bug("[SMP-Test:Worker.%03d] Finished! exiting ...\n", cpunum);) + IPTR workType; - doWork = FALSE; - break; - } - else if (workType == SPMWORKTYPE_PROCESS) - { - /* - * Lets do some work! - */ - D(bug("[SMP-Test:Worker.%03d] Processing requested work!\n", cpunum);) + /* we are ready for work .. */ + worker->smpw_Node.ln_Type = 1; + WaitPort(worker->smpw_MsgPort); - processWork(workPrivate, workMsg); - - /* let our "parent" know we are done .. */ - Signal(worker->smpw_MasterPort->mp_SigTask, SIGBREAKF_CTRL_D); + while((workMsg = (struct SMPWorkMessage *) GetMsg(worker->smpw_MsgPort))) + { + D(bug("[SMP-Test:Worker.%03d] work received (Msg @ 0x%p)\n", cpunum, workMsg);) + + /* cache the requested work and free the message ... */ + workType = workMsg->smpwm_Type; + FreeMem(workMsg, sizeof(struct SMPWorkMessage)); + + /* now process it .. */ + if (workType == SPMWORKTYPE_FINISHED) + { + D(bug("[SMP-Test:Worker.%03d] Finished! exiting ...\n", cpunum);) + + doWork = FALSE; + break; + } + else if (workType == SPMWORKTYPE_PROCESS) + { + /* + * Lets do some work! + */ + D(bug("[SMP-Test:Worker.%03d] Processing requested work!\n", cpunum);) + + processWork(workPrivate, workMsg); + + /* let our "parent" know we are done .. */ + Signal(worker->smpw_MasterPort->mp_SigTask, SIGBREAKF_CTRL_D); + } } } + FreeMem(workPrivate, sizeof(struct WorkersWork) + (workPrivate->workMax * sizeof(complexno_t))); } - DeleteMsgPort(worker->smpw_MsgPort); Remove(&worker->smpw_Node); + DeleteMsgPort(worker->smpw_MsgPort); Signal(worker->smpw_MasterPort->mp_SigTask, SIGBREAKF_CTRL_C); } } -- 2.11.4.GIT