This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GateMP E_NOTFOUND

Hi

I have some code where I'm creating a custom GateMP instance, and trying to access it from another core.  Opening the GateMP instance on the core that it was created on works perfectly.  Opening it on another processor, however, returns the GateMP_E_NOTFOUND error code.

This is the source code that has the error.  I have tried it both with and without the test block on lines 254-259:

/*
 * copier.c
 *
 *  Created on: 10 Jul 2013
 *      Author: Scott
 */

#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Memory.h>
#include <xdc/runtime/IHeap.h>
#include <xdc/runtime/Error.h>
#include <ti/ipc/MultiProc.h>
#include <ti/ipc/Notify.h>
#include <ti/ipc/Ipc.h>
#include <ti/ipc/GateMP.h>
#include <ti/ipc/HeapMemMP.h>
#include <ti/sdo/ipc/SharedRegion.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/BIOS.h>
#include <xdc/cfg/global.h>
#include <stdio.h>

GateMP_Handle gmph_1, gmph_2;
HeapMemMP_Handle hmph_1, hmph_2;
int *loc1, *loc2;
UInt32 payload_gbl;
char *g1n = "Gate1";
char *g2n = "Gate2";

#define EVENT_ID 10
#define INTERRUPT_LINE 0
#define ARRAY_LENGTH 10


int func1(int input) {
	return input - 1;
}
int func2(int input) {
	return input << 1;
}
int (*funcs[2])(int input) = {func1, func2 };

void reg_func(UInt32 recvProcId, UInt32 lineId, UInt32 evtId, UArg arg,
		UInt32 payload) {
	if (loc1 == NULL)
		loc1 = (int *) payload;
	else if (loc2 == NULL)
		loc2 = (int *) payload;
	else
		payload_gbl = payload;
	Semaphore_post(semHandle);
}

void tsk0_func(UArg a1, UArg a2) {
	System_printf("Starting tsk0\n");
	//Proc0 allocates memory
	UInt32 self = MultiProc_self();
	Error_Block eb;
	Int status;
	IArg key1, key2;
	if (self == 0) {
		System_printf("Running proc0 code\n");
		//put a lock on data
		key1 = GateMP_enter(gmph_1);
		key2 = GateMP_enter(gmph_2);
		//allocate space
		loc1 = Memory_alloc((IHeap_Handle) hmph_1, 0x100000, 0x80, &eb);
		loc2 = Memory_alloc((IHeap_Handle) hmph_2, 0x100000, 0x80, &eb);
		//check memory has been allocated
		if (loc1 == NULL || loc2 == NULL) {
			System_abort("Error: Could not assign memory\n");
		}
		System_printf("Memory allocated\n");
		Int i;
		for (i = 0; i < ARRAY_LENGTH; i++) {
			*(loc1 + i) = i + 2;
			*(loc2 + i) = i + 4;
		}
		System_printf("Memory initialised\n");
		//finished with data
		GateMP_leave(gmph_1, key1);
		GateMP_leave(gmph_2, key2);
		//tell each processor the location of each block of memory
		i = 0;
		do {
			status = 0;
			System_printf("Evt1, Loc1, attempt %i\n", i++);
			status = Notify_sendEvent(1, INTERRUPT_LINE, EVENT_ID,
					(UInt32) loc1, 1);

		} while (status < 0);
		i = 0;
		do {
			status = 0;
			System_printf("Evt1, Loc2, attempt %i\n", i++);
			status = Notify_sendEvent(1, INTERRUPT_LINE, EVENT_ID,
					(UInt32) loc2, 1);
		} while (status < 0);
		i = 0;
		do {
			status = 0;
			System_printf("Evt2, Loc1, attempt %i\n", i++);
			status = Notify_sendEvent(2, INTERRUPT_LINE, EVENT_ID,
					(UInt32) loc1, 1);
		} while (status < 0);
		i = 0;
		do {
			status = 0;
			System_printf("Evt2, Loc2, attempt %i\n", i++);
			status = Notify_sendEvent(2, INTERRUPT_LINE, EVENT_ID,
					(UInt32) loc2, 1);
		} while (status < 0);
		System_printf("Entering loop\n");
		while (payload_gbl != 0xcafe) {
			//wait for 2 processes to finish processing their block
			System_printf("Pending on semaphores\n");
			Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
			Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
			System_printf("Finished pending\n");
			//tell them both that the other is finished
			i = 0;
			do {
				status = 0;
				System_printf("Evt1, Loc1, attempt %i\n", i++);
				status = Notify_sendEvent(1, INTERRUPT_LINE, EVENT_ID, 0, 1);
			} while (status < 0);
			i = 0;
			do {
				status = 0;
				System_printf("Evt1, Loc1, attempt %i\n", i++);
				status = Notify_sendEvent(2, INTERRUPT_LINE, EVENT_ID, 0, 1);
			} while (status < 0);
		}
		System_printf("Finished proc0 code\n");
	} else {
		System_printf("Starting proc1/2 code\n");
		//wait for loc1 and loc2 to be filled
		Int i = 0;
		do {
			System_printf("Attempting gate1 open: %i\n", i++);
			status = GateMP_open(g1n, &gmph_1);
			if(i > 500 && status == GateMP_E_NOTFOUND) System_abort("Gate 1 not found");
		} while (status < 0);
		i = 0;
		do {
			System_printf("Attempting gate2 open: %i\n", i++);
			status = GateMP_open(g2n, &gmph_2);
			if(i > 100 && status == GateMP_E_NOTFOUND) System_abort("Gate 1 not found");
		} while (status < 0);
		System_printf("Pending on semaphores\n");
		Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
		Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
		System_printf("Finished pending");
		int *loc, *aloc, *tloc;
		GateMP_Handle gmph, agmph, tgmph;
		//proc1 processes loc1 first
		if (self == 1) {
			loc = loc1;
			aloc = loc2;
			gmph = gmph_1;
			agmph = gmph_2;
		}
		//proc2 processes loc2 first
		else {
			loc = loc2;
			aloc = loc1;
			gmph = gmph_2;
			agmph = gmph_1;
		}
		System_printf("Entering loop\n");
		while (*loc < 20 && payload_gbl != 0xcafe) {
			//Make sure no memory conflicts (there shouldn't be!)
			System_printf("Entering gate\n");
			key1 = GateMP_enter(gmph);
			//Do some processing
			System_printf("Going round array: ");
			for (i = 0; i < ARRAY_LENGTH; i++) {
				*(loc + i) = (*(funcs + self))(*(loc + i));
				System_printf("%i, ", i);
			}
			System_printf("\n");
			//finished with loc
			GateMP_leave(gmph, key1);
			System_printf("Left gate");
			//Tell p0 you're finished
			i = 0;
			do {
				status = 0;
				System_printf("Sending finished notify, attempt %i\n", i++);
				status = Notify_sendEvent(0, INTERRUPT_LINE, EVENT_ID, 0, 1);
			} while (status < 0);
			//Teacups!!!
			tloc = loc;
			loc = aloc;
			aloc = tloc;
			tgmph = gmph;
			gmph = agmph;
			agmph = tgmph;
			//Wait for others to finish
			System_printf("Pending on semaphore\n");
			Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
		}
		i = 0;
		do {
			status = 0;
			System_printf("Sending finished to other procs (0), attempt %i\n", i++);
			status = Notify_sendEvent(0, INTERRUPT_LINE, EVENT_ID, 0xcafe, 1);
		} while (status < 0);
		i = 0;
		do {
			status = 0;
			System_printf("Sending finished to other procs (%i), attempt %i\n", 3-self, i++);
			status = Notify_sendEvent(3 - self, INTERRUPT_LINE, EVENT_ID,
					0xcafe, 1);
		} while (status < 0);
		System_printf("Finished proc1/2 code\n");
	}
	System_printf("Quitting\n");
	BIOS_exit(0);
}

int main(Int argc, char *argv) {
	GateMP_Params gp1, gp2;
	HeapMemMP_Params hp1, hp2;
	System_printf("Starting main\n");
	Int status = Ipc_start();
	Int lp1 = (MultiProc_self() + 1) % 3;
	Int lp2 = (MultiProc_self() + 2) % 3;
	if (status < 0) {
		System_abort("Unable to start IPC\n");
	}
	status = Notify_registerEvent(lp1, INTERRUPT_LINE, EVENT_ID,
			(Notify_FnNotifyCbck) reg_func, NULL);
	if (status < 0) {
		System_abort("Unable to register event 1\n");
	}
	status = Notify_registerEvent(lp2, INTERRUPT_LINE, EVENT_ID,
			(Notify_FnNotifyCbck) reg_func, NULL);
	if (status < 0) {
		System_abort("Unable to register event 2\n");
	}
	if (MultiProc_self() == 0) {
		GateMP_Params_init(&gp1);
		GateMP_Params_init(&gp2);
		gp1.name = g1n;
		gp2.name = g2n;
		gp1.regionId = 1;
		gp2.regionId = 2;
		gp1.sharedAddr = (Ptr) 0xc100000;
		gp2.sharedAddr = (Ptr) 0xc280000;
		gmph_1 = GateMP_create(&gp1);
		gmph_2 = GateMP_create(&gp2);
		{
			GateMP_Handle gmph_x;
			status = GateMP_open(g1n, &gmph_x);
			if(status < 0)System_abort("Not opened");
		}
		HeapMemMP_Params_init(&hp1);
		HeapMemMP_Params_init(&hp2);
		hp1.gate = gmph_1;
		hp2.gate = gmph_2;
		hp1.name = "Heap1";
		hp2.name = "Heap2";
		//The next four lines were taken from SharedRegion_setEntry.
		hp2.sharedAddr = (Ptr)ti_sdo_ipc_SharedRegion_reserveMemory(2, 0);
		hp1.sharedAddr = (Ptr)ti_sdo_ipc_SharedRegion_reserveMemory(1, 0);
		hp1.sharedBufSize = 0x140000;
		hp2.sharedBufSize = 0x140000;
		hmph_1 = HeapMemMP_create(&hp1);
		hmph_2 = HeapMemMP_create(&hp2);
		System_printf("All heaps and gates created\n");
	}
	BIOS_start();
	System_printf("Finished main\n");
	return 0;
}

This is the config file used:

5305.MSMCCOPY.cfg

Thanks

Scott Tanocck