/* * ======== serverTask ======== */ Void serverTask(UArg arg0, UArg arg1) { MessageQ_Handle serverMessageQ; MessageQ_QueueId replyQueue; MessageQ_Msg msg; UInt16 msgId; Int status; serverMessageQ = MessageQ_create(SERVERNAME, NULL); /* Loop forever processing requests */ System_printf("Server is ready to set processing requests\n"); while (TRUE) { /* Wait for a request. */ status = MessageQ_get(serverMessageQ, &msg, MessageQ_FOREVER); if (status < 0) { System_abort("Stopping test\n"); } /* Get the id and increment it to send back as validation */ msgId = MessageQ_getMsgId(msg); msgId += NUMCLIENTS; MessageQ_setMsgId(msg, msgId); /* Use the embedded reply destination */ replyQueue = MessageQ_getReplyQueue(msg); /* Send the response back */ status = MessageQ_put(replyQueue, msg); if (status < 0) { System_abort("MessageQ_put was not successful\n"); } } }
/* * ======== main ======== */ Int main(Int argc, Char* argv[]) { selfId = MultiProc_self(); System_printf("Core (\"%s\") starting\n", MultiProc_getName(selfId)); if (numCores == 0) { numCores = MultiProc_getNumProcessors(); } attachAll(numCores); System_sprintf(localQueueName, "CORE%d", selfId); System_sprintf(nextQueueName, "CORE%d", ((selfId + 1) % numCores)); System_sprintf(prevQueueName, "CORE%d", (selfId - 1 + numCores) % numCores); /* Create a message queue. */ messageQ = MessageQ_create(localQueueName, NULL); if (messageQ == NULL) { System_abort("MessageQ_create failed\n" ); } BIOS_start(); return (0); }
/* * ======== loopbackFxn======== * Receive and return messages. * Run at priority lower than tsk1Fxn above. * Inputs: * - arg0: number of the thread, appended to MessageQ host and slave names. */ Void loopbackFxn(UArg arg0, UArg arg1) { MessageQ_Msg getMsg; MessageQ_Handle messageQ; MessageQ_QueueId remoteQueueId; Int status; UInt16 msgId = 0; Char localQueueName[64]; Char hostQueueName[64]; System_printf("Thread loopbackFxn: %d\n", arg0); System_sprintf(localQueueName, "%s_%d", SLAVE_MESSAGEQNAME, arg0); System_sprintf(hostQueueName, "%s_%d", HOST_MESSAGEQNAME, arg0); /* Create a message queue. */ messageQ = MessageQ_create(localQueueName, NULL); if (messageQ == NULL) { System_abort("MessageQ_create failed\n"); } System_printf("loopbackFxn: created MessageQ: %s; QueueID: 0x%x\n", localQueueName, MessageQ_getQueueId(messageQ)); System_printf("Start the main loop: %d\n", arg0); while (msgId < NUMLOOPS) { /* Get a message */ status = MessageQ_get(messageQ, &getMsg, MessageQ_FOREVER); if (status != MessageQ_S_SUCCESS) { System_abort("This should not happen since timeout is forever\n"); } remoteQueueId = MessageQ_getReplyQueue(getMsg); #ifndef BENCHMARK System_printf("%d: Received message #%d from core %d\n", arg0, MessageQ_getMsgId(getMsg), MessageQ_getProcId(remoteQueueId)); #endif /* test id of message received */ if (MessageQ_getMsgId(getMsg) != msgId) { System_abort("The id received is incorrect!\n"); } #ifndef BENCHMARK /* Send it back */ System_printf("%d: Sending message Id #%d to core %d\n", arg0, msgId, MessageQ_getProcId(remoteQueueId)); #endif status = MessageQ_put(remoteQueueId, getMsg); if (status != MessageQ_S_SUCCESS) { System_abort("MessageQ_put had a failure/error\n"); } msgId++; } MessageQ_delete(&messageQ); numTests += NUMLOOPS; System_printf("Test thread %d complete!\n", arg0); }
int init_message_q() { /* Create the local message queue */ h_receive_queue = MessageQ_create(MASTER_QUEUE_NAME, NULL); if (h_receive_queue == NULL) { logout("MessageQ_create failed\n" ); return -1; } return 0; }
/** * Handler for messageq create API. * * \param ctp Thread's associated context information. * \param msg The actual devctl() message. * \param ocb OCB associated with client's session. * * \return POSIX errno value. * * \retval EOK Success. * \retval ENOTSUP Unsupported devctl(). */ int syslink_messageq_create(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) { MessageQDrv_CmdArgs * cargs = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i)); MessageQDrv_CmdArgs * out = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->o)); MessageQ_Params *local_createparams = NULL; String local_createname = NULL; out->apiStatus = MessageQ_S_SUCCESS; if (cargs->args.create.params) { local_createparams = (MessageQ_Params *)(cargs+1); if (cargs->args.create.name) local_createname = (String)(local_createparams+1); } else { if (cargs->args.create.name) local_createname = (String)(cargs+1); } out->args.create.handle = MessageQ_create (local_createname, local_createparams); GT_assert (curTrace, (out->args.create.handle != NULL)); /* Set failure status if create has failed. */ if (out->args.create.handle == NULL) { out->apiStatus = MessageQ_E_FAIL; } else { out->apiStatus = MessageQ_S_SUCCESS; } if (out->args.create.handle != NULL) { out->args.create.queueId = MessageQ_getQueueId ( out->args.create.handle); } if (out->apiStatus >= 0) { /* At this call to the list to be cleaned-up */ add_ocb_res(ocb, DCMD_MESSAGEQ_DELETE, (int)out->args.create.handle, NULL); } SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(MessageQDrv_CmdArgs)); return _RESMGR_NPARTS(1); }
/* * ======== Server_create ======== */ Int Server_create() { Int status = 0; MessageQ_Params msgqParams; GateMP_Params gateParams; /* enable some log events */ Diags_setMask(MODULE_NAME"+EXF"); /* create GateMP */ GateMP_Params_init(&gateParams); gateParams.name = GATEMP_SLAVE_NAME; gateParams.localProtect = GateMP_LocalProtect_PROCESS; gateParams.remoteProtect = GateMP_RemoteProtect_SYSTEM; Module.slaveGateMPHandle = GateMP_create (&gateParams); if (Module.slaveGateMPHandle == NULL) { status = GATEMPAPP_E_FAILURE; Log_print0(Diags_INFO, "Server_create: Failed to create GateMP"); goto leave; } /* create local message queue (inbound messages) */ MessageQ_Params_init(&msgqParams); Module.slaveQue = MessageQ_create(GateMPApp_SlaveMsgQueName, &msgqParams); if (Module.slaveQue == NULL) { status = -1; Log_print0(Diags_INFO, "Server_create: Failed to create MessageQ"); GateMP_delete(&Module.slaveGateMPHandle); goto leave; } Log_print0(Diags_INFO,"Server_create: Slave is ready"); leave: Log_print1(Diags_EXIT, "<-- Server_create: %d", (IArg)status); return (status); }
/****************************************************************************** * MAIN FUNCTION *****************************************************************************/ Int main(Int argc, Char* argv[]){ srand(time(NULL)); selfId = CSL_chipReadReg(CSL_CHIP_DNUM); if (numCores == 0){ numCores = MultiProc_getNumProcessors(); } /* Attach All Cores */ attachAll(numCores); /* Create a MessageQ */ System_sprintf(localQueueName, "%s", MultiProc_getName(MultiProc_self())); messageQ = MessageQ_create(localQueueName, NULL); if (messageQ == NULL){ System_abort("MessageQ_create failed\n"); } BIOS_start(); return (0); }
/* * ======== clientTask ======== */ Void clientTask(UArg arg0, UArg arg1) { MessageQ_Handle messageQ; MessageQ_QueueId serverQueue; MessageQ_Msg msg; UInt16 msgId = arg0; Int status; Int i; /* * Create client's MessageQ. * * Use 'NULL' for name since no since this queueId is passed by * referene and no one opens it by name. * Use 'NULL' for params to get default parameters. */ messageQ = MessageQ_create(NULL, NULL); if (messageQ == NULL) { System_abort("Failed to create MessageQ\n"); } /* Open the server's MessageQ */ do { status = MessageQ_open(SERVERNAME, &serverQueue); if (status < 0) { Task_sleep(1); /* give server a chance to create queue */ } } while (status < 0); msg = MessageQ_alloc(HEAPID, sizeof(MessageQ_MsgHeader)); if (msg == NULL) { System_abort("MessageQ_alloc failed\n" ); } /* Have the remote processor reply to this message queue */ MessageQ_setReplyQueue(messageQ, msg); /* Loop requesting information from the server task */ System_printf("Client #%d is starting to send requests\n", arg0); for (i = 0; i < NUMMSGS; i++) { /* Server will increment and send back */ MessageQ_setMsgId(msg, msgId); msgId += NUMCLIENTS; /* Send the message off */ status = MessageQ_put(serverQueue, msg); if (status < 0) { MessageQ_free(msg); System_abort("MessageQ_put failed\n"); } /* Wait for the reply... */ status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER); if (status < 0) { System_abort("MessageQ_get had an error\n"); } /* Validate the returned message. */ if (MessageQ_getMsgId(msg) != msgId) { System_abort("Unexpected value\n"); } System_printf("Client #%d received response #%d\n", arg0, i + 1); /* To make some variation in the execution order */ Task_sleep(500 * (arg0 + 1)); } System_printf("Client #%d is done sending requests\n", arg0); numCompleted++; if (numCompleted == 3) { /* All client tasks are done sending requests */ BIOS_exit(0); } }
Int App_create(UInt16 remoteProcId) { Int status =0; int retStatus =0; UInt32 event =0; HeapBufMP_Params heapParams; MessageQ_Params msgqParams; printf("--> App_create:\n"); /* setting default values */ Module.remoteProcId = remoteProcId; Module.lineId = SystemCfg_LineId; Module.eventId = SystemCfg_AppEventId; Module.head = 0; Module.tail = 0; Module.error = 0; Module.msgHeap = NULL; Module.hostQue = NULL; Module.videoQue = MessageQ_INVALIDMESSAGEQ; Module.heapId = App_MsgHeapId; Module.msgSize = sizeof(App_Msg); /* 1. create sync object */ retStatus = sem_init(&Module.semH, 0, 0); if (retStatus == -1) { printf("App_create: Failed to create a semaphore\n"); goto leave; } /* 2. register notify callback */ status = Notify_registerEventSingle(Module.remoteProcId, Module.lineId, Module.eventId, App_notifyCB, (UArg)&Module); if (status < 0) { printf("App_create: Host failed to register an event\n"); goto leave; } /* 3. wait until remote core has also registered notify callback */ do { status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_NOP, TRUE); if (status == Notify_E_EVTNOTREGISTERED) { sleep(1); } } while (status == Notify_E_EVTNOTREGISTERED); if (status < 0) { printf("App_create: Failed to send event\n"); goto leave; } /* 4. create local & shared resources (to be opened by remote processor) */ /* create heap for messages */ HeapBufMP_Params_init(&heapParams); heapParams.name = App_MsgHeapName; heapParams.regionId = App_MsgHeapSrId; heapParams.blockSize = 64; heapParams.numBlocks = 10; Module.msgHeap = HeapBufMP_create(&heapParams); if (Module.msgHeap == NULL) { printf("App_create: Failed to create a HeapBufMP\n"); status = -1; goto leave; } /* register heap with MessageQ */ status = MessageQ_registerHeap((Ptr)(Module.msgHeap), App_MsgHeapId); if (status < 0) { printf("App_create: Failed to register HeapBufMP with MessageQ\n"); goto leave; } /* create local message queue (inbound messages) */ MessageQ_Params_init(&msgqParams); Module.hostQue = MessageQ_create(App_HostMsgQueName, &msgqParams); if (Module.hostQue == NULL) { printf("App_create: Failed creating MessageQ\n"); status = -1; goto leave; } /* 5. send resource ready event */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_RESRDY, TRUE); if (status < 0) { printf("App_create: Failed to send event\n"); goto leave; } /* 6. wait for remote resource ready event */ do { event = App_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; printf("App_create: Failed waiting for event\n"); goto leave; } } while (event != App_CMD_RESRDY); /* 7. open remote resources */ /* open the video message queue */ status = MessageQ_open(App_VideoMsgQueName, &Module.videoQue); if (status < 0) { printf("App_create: Failed opening MessageQ\n"); goto leave; } /* 8. send application ready event */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_READY, TRUE); if (status < 0) { printf("App_create: Failed to send event\n"); goto leave; } /* 9. wait for remote server ready event */ do { event = App_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; printf("App_create: Failed waiting for event\n"); goto leave; } } while (event != App_CMD_READY); printf("App_create: Host is ready\n"); leave: printf("<-- App_create:\n"); return(status); }
/* * ======== tsk1_func ======== * A local message queue is created and two remote message queues are opened. * Messages are sent to the remote message queues and retrieved from the * local message queue. */ Void tsk1_func(UArg arg0, UArg arg1) { MessageQ_Msg msg; MessageQ_Handle messageQ; MessageQ_QueueId core1QueueId, dspQueueId; Int status; UInt16 msgId = 0; /* Create a message queue */ messageQ = MessageQ_create(CORE0_MESSAGEQNAME, NULL); if (messageQ == NULL) { System_abort("MessageQ_create failed\n" ); } /* Open the DSP message queue. Spin until it is ready. */ do { status = MessageQ_open(DSP_MESSAGEQNAME, &dspQueueId); /* * Sleep for 1 clock tick to avoid inundating remote processor * with interrupts if open failed */ if (status < 0) { Task_sleep(1); } } while (status < 0); /* Open the CORE1 message queue. Spin until it is ready. */ do { status = MessageQ_open(CORE1_MESSAGEQNAME, &core1QueueId); /* * Sleep for 1 clock tick to avoid inundating remote processor * with interrupts if open failed */ if (status < 0) { Task_sleep(1); } } while (status < 0); /* Allocate a message to be ping-ponged around the processors */ msg = MessageQ_alloc(HEAPID, HEAP_MSGSIZE); if (msg == NULL) { System_abort("MessageQ_alloc failed\n" ); } /* Send the message to the DSP and wait for a response */ System_printf("Start the main loop\n"); while (msgId < NUMLOOPS) { /* Increment...the remote side will check this */ msgId++; MessageQ_setMsgId(msg, msgId); System_printf("Sending a message #%d to CORE1\n", msgId); /* send the message to the remote processor */ status = MessageQ_put(core1QueueId, msg); if (status < 0) { System_abort("MessageQ_put had an error\n"); } /* Get a message */ status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER); if (status < 0) { System_abort("This should not happen since timeout is forever\n"); } System_printf("Sending a message #%d to DSP\n", msgId); status = MessageQ_put(dspQueueId, msg); if (status < 0) { System_abort("MessageQ_put had an error\n"); } /* Get another message */ status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER); if (status < 0) { System_abort("This should not happen since timeout is forever\n"); } } System_printf("The test is complete\n"); BIOS_exit(0); }
/* * ======== tsk0_func ======== * Allocates a message and ping-pongs the message around the processors. * A local message queue is created and a remote message queue is opened. * Messages are sent to the remote message queue and retrieved from the * local MessageQ. */ Void tsk0_func(UArg arg0, UArg arg1) { MessageQ_Msg msg; MessageQ_Handle messageQ; MessageQ_QueueId remoteQueueId; Int status; UInt16 msgId = 0; Ptr buf; HeapBuf_Handle heapHandle; HeapBuf_Params hbparams; SizeT blockSize; UInt numBlocks; /* Compute the blockSize & numBlocks for the HeapBuf */ numBlocks = 2; blockSize = sizeof(MessageQ_MsgHeader); /* Alloc a buffer from the default heap */ buf = Memory_alloc(0, numBlocks * blockSize, 0, NULL); /* * Create the heap that is used for allocating MessageQ messages. */ HeapBuf_Params_init(&hbparams); hbparams.align = 0; hbparams.numBlocks = numBlocks; hbparams.blockSize = blockSize; hbparams.bufSize = numBlocks * blockSize; hbparams.buf = buf; heapHandle = HeapBuf_create(&hbparams, NULL); if (heapHandle == NULL) { System_abort("HeapBuf_create failed\n" ); } /* Register default system heap with MessageQ */ MessageQ_registerHeap((IHeap_Handle)(heapHandle), HEAPID); /* Create the local message queue */ messageQ = MessageQ_create(localQueueName, NULL); if (messageQ == NULL) { System_abort("MessageQ_create failed\n" ); } /* Open the remote message queue. Spin until it is ready. */ do { status = MessageQ_open(remoteQueueName, &remoteQueueId); /* * Sleep for 1 clock tick to avoid inundating remote processor * with interrupts if open failed */ if (status < 0) { Task_sleep(1); } } while (status < 0); if (MultiProc_self() == 0) { /* Allocate a message to be ping-ponged around the processors */ msg = MessageQ_alloc(HEAPID, sizeof(MessageQ_MsgHeader)); if (msg == NULL) { System_abort("MessageQ_alloc failed\n" ); } /* * Send the message to the remote processor and wait for a message * from the previous processor. */ System_printf("Start the main loop\n"); while (msgId < NUMLOOPS) { /* Increment...the remote side will check this */ msgId++; MessageQ_setMsgId(msg, msgId); System_printf("Sending a message #%d to %s\n", msgId, remoteQueueName); /* send the message to the remote processor */ status = MessageQ_put(remoteQueueId, msg); if (status < 0) { System_abort("MessageQ_put had a failure/error\n"); } /* Get a message */ status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER); if (status < 0) { System_abort("This should not happen since timeout is forever\n"); } } } else { /* * Wait for a message from the previous processor and * send it to the remote processor */ System_printf("Start the main loop\n"); while (TRUE) { /* Get a message */ status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER); if (status < 0) { System_abort("This should not happen since timeout is forever\n"); } System_printf("Sending a message #%d to %s\n", MessageQ_getMsgId(msg), remoteQueueName); /* Get the message id */ msgId = MessageQ_getMsgId(msg); /* send the message to the remote processor */ status = MessageQ_put(remoteQueueId, msg); if (status < 0) { System_abort("MessageQ_put had a failure/error\n"); } /* test done */ if (msgId >= NUMLOOPS) { break; } } } System_printf("The test is complete\n"); BIOS_exit(0); }
Int RcmClient_Instance_init(RcmClient_Object *obj, String server, const RcmClient_Params *params) { Error_Block eb; MessageQ_Params mqParams; SyncSemThread_Params syncParams; SemThread_Params semParams; SemThread_Handle semHndl; List_Params listP; Int rval; Int status = RcmClient_S_SUCCESS; Log_print2(Diags_ENTRY, "--> %s: (obj=0x%x)", (IArg)FXNN, (IArg)obj); /* must initialize error block */ Error_init(&eb); /* initialize instance data */ obj->msgId = 0xFFFF; obj->sync = NULL; obj->serverMsgQ = MessageQ_INVALIDMESSAGEQ; obj->msgQue = NULL; obj->errorMsgQue = NULL; obj->mbxLock = NULL; obj->queueLock = NULL; obj->recipients = NULL; obj->newMail = NULL; /* create the instance gate */ GateThread_construct(&obj->gate, NULL, &eb); if (Error_check(&eb)) { Log_error0(FXNN": could not create gate object"); status = RcmClient_E_FAIL; goto leave; } /* create a synchronizer for the message queue */ SyncSemThread_Params_init(&syncParams); obj->sync = SyncSemThread_create(&syncParams, &eb); if (Error_check(&eb)) { status = RcmClient_E_FAIL; goto leave; } /* create the message queue for return messages */ MessageQ_Params_init(&mqParams); obj->msgQue = MessageQ_create(NULL, &mqParams); if (obj->msgQue == NULL) { Log_error0(FXNN": could not create return message queue"); status = RcmClient_E_MSGQCREATEFAILED; goto leave; } /* create the message queue for error messages */ MessageQ_Params_init(&mqParams); obj->errorMsgQue = MessageQ_create(NULL, &mqParams); if (NULL == obj->errorMsgQue) { Log_error0(FXNN": could not create error message queue"); status = RcmClient_E_MSGQCREATEFAILED; goto leave; } /* locate server message queue */ rval = MessageQ_open(server, (MessageQ_QueueId *)(&obj->serverMsgQ)); if (MessageQ_E_NOTFOUND == rval) { Log_error1(FXNN": given server not found, server=0x%x", (IArg)server); status = RcmClient_E_SERVERNOTFOUND; goto leave; } else if (status < 0) { Log_error1(FXNN": could not open server message queue, server=0x%x", (IArg)server); status = RcmClient_E_MSGQOPENFAILED; goto leave; } /* create callback server */ if ((obj->cbNotify = params->callbackNotification)) { /* TODO create callback server thread */ /* make sure to free resources acquired by thread */ Error_raise(&eb, Error_E_generic, "Not Implemented", 0); goto leave; } /* register the heapId used for message allocation */ if ((obj->heapId = params->heapId) == RcmClient_INVALIDHEAPID) { Log_error0(FXNN": must specify a heap id in create params"); status = RcmClient_E_INVALIDHEAPID; goto leave; } /* create the mailbox lock */ SemThread_Params_init(&semParams); semHndl = SemThread_create(1, &semParams, &eb); if (Error_check(&eb)) { status = RcmClient_E_FAIL; goto leave; } obj->mbxLock = SemThread_Handle_upCast(semHndl); /* create the message queue lock */ SemThread_Params_init(&semParams); semHndl = SemThread_create(1, &semParams, &eb); if (Error_check(&eb)) { status = RcmClient_E_FAIL; goto leave; } obj->queueLock = SemThread_Handle_upCast(semHndl); /* create the return message recipient list */ #if defined(RCM_ti_ipc) List_Params_init(&listP); obj->recipients = List_create(&listP, &eb); if (Error_check(&eb)) { Log_error0(FXNN": could not create list object"); status = RcmClient_E_LISTCREATEFAILED; goto leave; } #elif defined(RCM_ti_syslink) List_Params_init(&listP); obj->recipients = List_create(&listP, NULL); if (NULL == obj->recipients) { Log_error0(FXNN": could not create list object"); status = RcmClient_E_LISTCREATEFAILED; goto leave; } #endif /* create list of undelivered messages (new mail) */ #if defined(RCM_ti_ipc) List_Params_init(&listP); obj->newMail = List_create(&listP, &eb); if (Error_check(&eb)) { Log_error0(FXNN": could not create list object"); status = RcmClient_E_LISTCREATEFAILED; goto leave; } #elif defined(RCM_ti_syslink) List_Params_init(&listP); obj->newMail = List_create(&listP, NULL); if (NULL == obj->newMail) { Log_error0(FXNN": could not create list object"); status = RcmClient_E_LISTCREATEFAILED; goto leave; } #endif leave: Log_print2(Diags_EXIT, "<-- %s: %d", (IArg)FXNN, (IArg)status); return(status); }
Int32 System_ipcMsgQCreate() { UInt32 i; UInt32 procId; Int32 status; Int32 retryCount; MessageQ_Params msgQParams; char msgQName[64]; char ackMsgQName[64]; i=0; while(gSystem_ipcMsgQEnableProcId[i]!=SYSTEM_PROC_MAX) { procId = gSystem_ipcMsgQEnableProcId[i]; if (procId != SYSTEM_PROC_INVALID) { System_ipcGetMsgQName(procId, msgQName, ackMsgQName); if(procId==System_getSelfProcId()) { /* create MsgQ */ MessageQ_Params_init(&msgQParams); /* printf(" %u: SYSTEM: Creating MsgQ [%s] ...\n", OSA_getCurTimeInMsec(), msgQName ); */ gSystem_ipcObj.selfMsgQ = MessageQ_create(msgQName, &msgQParams); UTILS_assert(gSystem_ipcObj.selfMsgQ!=NULL); MessageQ_Params_init(&msgQParams); /* printf(" %u: SYSTEM: Creating MsgQ [%s] ...\n", OSA_getCurTimeInMsec(), ackMsgQName ); */ gSystem_ipcObj.selfAckMsgQ = MessageQ_create(ackMsgQName, &msgQParams); UTILS_assert(gSystem_ipcObj.selfMsgQ!=NULL); } else { /* open MsgQ */ retryCount=10; while(retryCount) { // printf(" %u: SYSTEM: Opening MsgQ [%s] ...\n", // OSA_getCurTimeInMsec(), // msgQName // ); status = MessageQ_open(msgQName, &gSystem_ipcObj.remoteProcMsgQ[procId]); if(status==MessageQ_E_NOTFOUND) OSA_waitMsecs(1000); else if(status==MessageQ_S_SUCCESS) break; retryCount--; if(retryCount<=0) UTILS_assert(0); } /* no need to open ack msgq, since ack msgq id is embeeded in the received message */ } } i++; } return OSA_SOK; }
static Void * pingThreadFxn(void *arg) { Int threadNum = *(int *)arg; Int32 status = 0; MessageQ_Msg msg = NULL; MessageQ_Params msgParams; UInt16 i; MessageQ_Handle handle; MessageQ_QueueId queueId = MessageQ_INVALIDMESSAGEQ; char remoteQueueName[64]; char hostQueueName[64]; printf ("Entered pingThreadFxn: %d\n", threadNum); sprintf(remoteQueueName, "%s_%d%d", SLAVE_MESSAGEQNAME, threadNum, (threadNum % (MultiProc_getNumProcessors() - 1)) + 1); sprintf(hostQueueName, "%s_%d", HOST_MESSAGEQNAME, threadNum ); /* Create the local Message Queue for receiving. */ MessageQ_Params_init (&msgParams); handle = MessageQ_create (hostQueueName, &msgParams); if (handle == NULL) { printf ("Error in MessageQ_create\n"); goto exit; } else { printf ("thread: %d, Local Message: %s, QId: 0x%x\n", threadNum, hostQueueName, MessageQ_getQueueId(handle)); } /* Poll until remote side has it's messageQ created before we send: */ do { status = MessageQ_open (remoteQueueName, &queueId); sleep (1); } while (status == MessageQ_E_NOTFOUND); if (status < 0) { printf ("Error in MessageQ_open [0x%x]\n", status); goto cleanup; } else { printf ("thread: %d, Remote queue: %s, QId: 0x%x\n", threadNum, remoteQueueName, queueId); } printf ("\nthread: %d: Exchanging messages with remote processor...\n", threadNum); for (i = 0 ; i < numLoops ; i++) { /* Allocate message. */ msg = MessageQ_alloc (HEAPID, MSGSIZE); if (msg == NULL) { printf ("Error in MessageQ_alloc\n"); break; } MessageQ_setMsgId (msg, i); /* Have the remote proc reply to this message queue */ MessageQ_setReplyQueue (handle, msg); status = MessageQ_put (queueId, msg); if (status < 0) { printf ("Error in MessageQ_put [0x%x]\n", status); break; } status = MessageQ_get(handle, &msg, MessageQ_FOREVER); if (status < 0) { printf ("Error in MessageQ_get [0x%x]\n", status); break; } else { /* Validate the returned message. */ if ((msg != NULL) && (MessageQ_getMsgId (msg) != i)) { printf ("Data integrity failure!\n" " Expected %d\n" " Received %d\n", i, MessageQ_getMsgId (msg)); break; } status = MessageQ_free (msg); } printf ("thread: %d: Exchanged %d msgs\n", threadNum, (i+1)); } printf ("thread: %d: pingThreadFxn successfully completed!\n", threadNum); MessageQ_close (&queueId); cleanup: /* Clean-up */ status = MessageQ_delete (&handle); if (status < 0) { printf ("Error in MessageQ_delete [0x%x]\n", status); } exit: return ((void *)status); }
Int MessageQApp_execute(UInt32 numLoops, UInt16 procId) { Int32 status = 0; MessageQ_Msg msg = NULL; MessageQ_Params msgParams; UInt32 i; MessageQ_QueueId queueId = MessageQ_INVALIDMESSAGEQ; MessageQ_Handle msgqHandle; char remoteQueueName[64]; UInt32 msgId; printf("Entered MessageQApp_execute\n"); /* Create the local Message Queue for receiving. */ MessageQ_Params_init(&msgParams); msgqHandle = MessageQ_create(MPU_MESSAGEQNAME, &msgParams); if (msgqHandle == NULL) { printf("Error in MessageQ_create\n"); goto exit; } else { printf("Local MessageQId: 0x%x\n", MessageQ_getQueueId(msgqHandle)); } sprintf(remoteQueueName, "%s_%s", SLAVE_MESSAGEQNAME, MultiProc_getName(procId)); /* Poll until remote side has it's messageQ created before we send: */ do { status = MessageQ_open(remoteQueueName, &queueId); sleep (1); } while (status == MessageQ_E_NOTFOUND); if (status < 0) { printf("Error in MessageQ_open [%d]\n", status); goto cleanup; } else { printf("Remote queueId [0x%x]\n", queueId); } msg = MessageQ_alloc(HEAPID, sizeof(SyncMsg)); if (msg == NULL) { printf("Error in MessageQ_alloc\n"); MessageQ_close(&queueId); goto cleanup; } /* handshake with remote to set the number of loops */ MessageQ_setReplyQueue(msgqHandle, msg); ((SyncMsg *)msg)->numLoops = numLoops; ((SyncMsg *)msg)->print = FALSE; MessageQ_put(queueId, msg); MessageQ_get(msgqHandle, &msg, MessageQ_FOREVER); printf("Exchanging %d messages with remote processor %s...\n", numLoops, MultiProc_getName(procId)); for (i = 1 ; i <= numLoops; i++) { ((SyncMsg *)msg)->numLoops = i; /* Have the remote proc reply to this message queue */ MessageQ_setReplyQueue(msgqHandle, msg); status = MessageQ_put(queueId, msg); if (status < 0) { printf("Error in MessageQ_put [%d]\n", status); MessageQ_free(msg); break; } status = MessageQ_get(msgqHandle, &msg, MessageQ_FOREVER); if (status < 0) { printf("Error in MessageQ_get [%d]\n", status); break; } else { /* validate the returned message */ msgId = ((SyncMsg *)msg)->numLoops; if ((msg != NULL) && (msgId != i)) { printf("Data integrity failure!\n" " Expected %d\n" " Received %d\n", i, msgId); break; } } if (numLoops <= 200) { printf("MessageQ_get #%d Msg = 0x%x\n", i, (UInt)msg); } else if ((i % 1000) == 0) { printf("MessageQ_get #%d Msg = 0x%x\n", i, (UInt)msg); } } printf("Exchanged %d messages with remote processor %s\n", (i-1), MultiProc_getName(procId)); if (status >= 0) { printf("Sample application successfully completed!\n"); MessageQ_free(msg); } MessageQ_close(&queueId); cleanup: /* Clean-up */ status = MessageQ_delete(&msgqHandle); if (status < 0) { printf("Error in MessageQ_delete [%d]\n", status); } exit: printf("Leaving MessageQApp_execute\n\n"); return (status); }
/* * ======== tsk1_func ======== * Send and receive messages */ Void tsk1_func(UArg arg0, UArg arg1) { MessageQ_Msg msg; MessageQ_Handle messageQ; MessageQ_QueueId remoteQueueId; HeapBufMP_Handle heapHandle; Int status; UInt16 msgId; /* * Open the heap that is created on the other processor. Loop until opened. * Not using the name since the interrupts are not enabled yet! */ do { status = HeapBufMP_open(HEAP_NAME, &heapHandle); /* * Sleep for 1 clock tick to avoid inundating remote processor * with interrupts if open failed */ if (status < 0) { Task_sleep(1); } } while (status < 0); /* Register this heap with MessageQ */ MessageQ_registerHeap((IHeap_Handle)heapHandle, HEAPID); /* Create a local message queue */ messageQ = MessageQ_create(DSP_MESSAGEQNAME, NULL); if (messageQ == NULL) { System_abort("MessageQ_create failed\n" ); } /* Open the core0 message queue. Spin until it is ready. */ do { status = MessageQ_open(CORE0_MESSAGEQNAME, &remoteQueueId); /* * Sleep for 1 clock tick to avoid inundating remote processor * with interrupts if open failed */ if (status < 0) { Task_sleep(1); } } while (status < 0); /* Wait for a message and send it to core0 */ System_printf("Start the main loop\n"); while (TRUE) { /* Get a message */ status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER); if (status < 0) { System_abort("This should not happen since timeout is forever\n"); } System_printf("Sending a message #%d to CORE0\n", MessageQ_getMsgId(msg)); /* Get the message id */ msgId = MessageQ_getMsgId(msg); /* send the message to the remote processor */ status = MessageQ_put(remoteQueueId, msg); if (status < 0) { System_abort("MessageQ_put had a failure/error\n"); } /* test done */ if (msgId == NUMLOOPS) { System_printf("Test complete!\n"); BIOS_exit(0); } } }
Int MessageQApp_execute(UInt32 numLoops, UInt32 payloadSize, UInt16 procId) { Int32 status = 0; MessageQ_Msg msg = NULL; MessageQ_Params msgParams; UInt32 i; MessageQ_QueueId queueId = MessageQ_INVALIDMESSAGEQ; MessageQ_Handle msgqHandle; char remoteQueueName[64]; struct timespec start, end; long elapsed; UInt32 msgId; printf("Entered MessageQApp_execute\n"); /* Create the local Message Queue for receiving. */ MessageQ_Params_init(&msgParams); msgqHandle = MessageQ_create(MPU_MESSAGEQNAME, &msgParams); if (msgqHandle == NULL) { printf("Error in MessageQ_create\n"); goto exit; } else { printf("Local MessageQId: 0x%x\n", MessageQ_getQueueId(msgqHandle)); } sprintf(remoteQueueName, "%s_%s", SLAVE_MESSAGEQNAME, MultiProc_getName(procId)); /* Poll until remote side has its messageQ created before we send: */ do { status = MessageQ_open(remoteQueueName, &queueId); sleep (1); } while (status == MessageQ_E_NOTFOUND); if (status < 0) { printf("Error in MessageQ_open [%d]\n", status); goto cleanup; } else { printf("Remote queueId [0x%x]\n", queueId); } msg = MessageQ_alloc(HEAPID, sizeof(SyncMsg) + payloadSize); if (msg == NULL) { printf("Error in MessageQ_alloc\n"); MessageQ_close(&queueId); goto cleanup; } /* handshake with remote to set the number of loops */ MessageQ_setReplyQueue(msgqHandle, msg); ((SyncMsg *)msg)->numLoops = numLoops; ((SyncMsg *)msg)->print = FALSE; MessageQ_put(queueId, msg); MessageQ_get(msgqHandle, &msg, MessageQ_FOREVER); printf("Exchanging %d messages with remote processor %s...\n", numLoops, MultiProc_getName(procId)); clock_gettime(CLOCK_REALTIME, &start); for (i = 1 ; i <= numLoops; i++) { ((SyncMsg *)msg)->numLoops = i; /* Have the remote proc reply to this message queue */ MessageQ_setReplyQueue(msgqHandle, msg); status = MessageQ_put(queueId, msg); if (status < 0) { printf("Error in MessageQ_put [%d]\n", status); break; } status = MessageQ_get(msgqHandle, &msg, MessageQ_FOREVER); if (status < 0) { printf("Error in MessageQ_get [%d]\n", status); break; } else { /* Validate the returned message */ msgId = ((SyncMsg *)msg)->numLoops; if ((msg != NULL) && (msgId != i)) { printf("Data integrity failure!\n" " Expected %d\n" " Received %d\n", i, msgId); break; } } } clock_gettime(CLOCK_REALTIME, &end); elapsed = diff(start, end); if (numLoops > 0) { printf("%s: Avg round trip time: %ld usecs\n", MultiProc_getName(procId), elapsed / numLoops); } MessageQ_free(msg); MessageQ_close(&queueId); cleanup: status = MessageQ_delete(&msgqHandle); if (status < 0) { printf ("Error in MessageQ_delete [%d]\n", status); } exit: printf("Leaving MessageQApp_execute\n\n"); return (status); }
/* * ======== tsk0_func ======== * Allocates a message and ping-pongs the message around the processors. * A local message queue is created and a remote message queue is opened. * Messages are sent to the remote message queue and retrieved from the * local MessageQ. */ Void tsk0_func(UArg arg0, UArg arg1) { MessageQ_Msg msg; MessageQ_Handle messageQ; MessageQ_QueueId remoteQueueId; Int status; UInt16 msgId = 0; HeapBufMP_Handle heapHandle; HeapBufMP_Params heapBufParams; if (MultiProc_self() == 0) { /* * Create the heap that will be used to allocate messages. */ HeapBufMP_Params_init(&heapBufParams); heapBufParams.regionId = 0; heapBufParams.name = HEAP_NAME; heapBufParams.numBlocks = 1; heapBufParams.blockSize = sizeof(MessageQ_MsgHeader); heapHandle = HeapBufMP_create(&heapBufParams); if (heapHandle == NULL) { System_abort("HeapBufMP_create failed\n" ); } } else { /* Open the heap created by the other processor. Loop until opened. */ do { status = HeapBufMP_open(HEAP_NAME, &heapHandle); /* * Sleep for 1 clock tick to avoid inundating remote processor * with interrupts if open failed */ if (status < 0) { Task_sleep(1); } } while (status < 0); } /* Register this heap with MessageQ */ MessageQ_registerHeap((IHeap_Handle)heapHandle, HEAPID); /* Create the local message queue */ messageQ = MessageQ_create(localQueueName, NULL); if (messageQ == NULL) { System_abort("MessageQ_create failed\n" ); } /* Open the remote message queue. Spin until it is ready. */ do { status = MessageQ_open(nextQueueName, &remoteQueueId); /* * Sleep for 1 clock tick to avoid inundating remote processor * with interrupts if open failed */ if (status < 0) { Task_sleep(1); } } while (status < 0); if (MultiProc_self() == 0) { /* Allocate a message to be ping-ponged around the processors */ msg = MessageQ_alloc(HEAPID, sizeof(MessageQ_MsgHeader)); if (msg == NULL) { System_abort("MessageQ_alloc failed\n" ); } /* * Send the message to the next processor and wait for a message * from the previous processor. */ System_printf("Start the main loop\n"); while (msgId < NUMLOOPS) { /* Increment...the remote side will check this */ msgId++; MessageQ_setMsgId(msg, msgId); System_printf("Sending a message #%d to %s\n", msgId, nextQueueName); /* send the message to the remote processor */ status = MessageQ_put(remoteQueueId, msg); if (status < 0) { System_abort("MessageQ_put had a failure/error\n"); } /* Get a message */ status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER); if (status < 0) { System_abort("This should not happen since timeout is forever\n"); } } } else { /* * Wait for a message from the previous processor and * send it to the next processor */ System_printf("Start the main loop\n"); while (TRUE) { /* Get a message */ status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER); if (status < 0) { System_abort("This should not happen since timeout is forever\n"); } System_printf("Sending a message #%d to %s\n", MessageQ_getMsgId(msg), nextQueueName); /* Get the message id */ msgId = MessageQ_getMsgId(msg); /* send the message to the remote processor */ status = MessageQ_put(remoteQueueId, msg); if (status < 0) { System_abort("MessageQ_put had a failure/error\n"); } /* test done */ if (msgId >= NUMLOOPS) { break; } } } System_printf("The test is complete\n"); BIOS_exit(0); }
void slave_main(void) { process_message_t * p_msg = 0; MessageQ_Handle h_receive_queue = 0; MessageQ_QueueId reply_queue_id = 0; HeapBufMP_Handle heapHandle; Int status; char receive_queue_name[16]; GET_SLAVE_QUEUE_NAME(receive_queue_name, DNUM); /* Open the heap created by the other processor. Loop until opened. */ do { status = HeapBufMP_open(IMAGE_PROCESSING_HEAP_NAME, &heapHandle); if (status < 0) { Task_sleep(1); } } while (status < 0); /* Register this heap with MessageQ */ MessageQ_registerHeap((IHeap_Handle)heapHandle, IMAGE_PROCESSING_HEAPID); /* Create the local message queue */ h_receive_queue = MessageQ_create(receive_queue_name, NULL); if (h_receive_queue == NULL) { logout("MessageQ_create failed\n" ); goto close_n_exit; } for (;;) { if (MessageQ_get(h_receive_queue, (MessageQ_Msg *)&p_msg, MessageQ_FOREVER) < 0) { logout("%s: This should not happen since timeout is forever\n", receive_queue_name); goto close_n_exit; } reply_queue_id = MessageQ_getReplyQueue(p_msg); if (reply_queue_id == MessageQ_INVALIDMESSAGEQ) { logout("receive_queue_name: Ignoring the message as reply queue is not set.\n", receive_queue_name); continue; } //Execute calculation #ifdef _TRACE_MC_ logout("[core_%u] Execute process (processing_type=%u)\n", p_msg->core_id, p_msg->info.processing_type); //trace #endif switch(p_msg->info.processing_type) { case pt_ssd: //Call calculation code exec_ssd(p_msg); break; case pt_ssdJacHess: //Call calculation code exec_ssdJacHess(p_msg); break; case pt_cacheinval: CacheInvalTotalMemory(p_msg); break; case pt_shrink: //Call image shrink code exec_shrinkImage(p_msg); break; default: logout("Invalid IPC processing type: %u", p_msg->info.processing_type); } /* send the message to the remote processor */ #ifdef _TRACE_MC_ logout("[core_%u] Putting slave response to the MessageQ, then going idle again ...\n", p_msg->core_id); #endif if (MessageQ_put(reply_queue_id, (MessageQ_Msg)p_msg) < 0) { logout("%s: MessageQ_put had a failure error\n", receive_queue_name); } } close_n_exit: if(h_receive_queue) MessageQ_delete(&h_receive_queue); }