Esempio n. 1
0
/*
 *  ======== NameServerMessageQ_Module_startup ========
 */
Int NameServerMessageQ_Module_startup(Int phase)
{
    MessageQ_Params2  messageQParams;

    /* Ensure MessageQ and SyncSwi Module_startup() have completed */
    if ((ti_sdo_ipc_MessageQ_Module_startupDone() == FALSE) ||
        (ti_sysbios_syncs_SyncSwi_Module_startupDone() == FALSE)) {
        return (Startup_NOTDONE);
    }

    /* Create the message queue for NameServer using SyncSwi */
    MessageQ_Params2_init(&messageQParams);
    messageQParams.synchronizer = NameServerMessageQ_module->syncSwiHandle;
    messageQParams.queueIndex = MESSAGEQ_INDEX;
    NameServerMessageQ_module->msgHandle =
        (ti_sdo_ipc_MessageQ_Handle)MessageQ_create2(NULL, &messageQParams);
    
    /* assert msgHandle is not null */
    Assert_isTrue(NameServerMessageQ_module->msgHandle != NULL,
        Ipc_A_nullPointer);

    /* assert this is the first MessageQ created */
    Assert_isTrue((MessageQ_getQueueId((MessageQ_Handle)
        NameServerMessageQ_module->msgHandle) & 0xffff) == MESSAGEQ_INDEX,
        NameServerMessageQ_A_reservedMsgQueueId);

    return (Startup_DONE);
}
Esempio n. 2
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);
}
Esempio n. 3
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);
}
Esempio n. 4
0
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);
}
Esempio n. 5
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);
}
Esempio n. 6
0
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);
}