UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
205 Views
Registered: ‎02-06-2019

Shared memory across processors only works while debugging.

Hello this is my first post so I am sorry if this is not the correct location to post. I am running a different program on each core. 

Screenshot from 2019-08-21 16-23-38.png

 

I just started this project and I have created test code to verify I am on the right track using shared memory. 

 

void testLock(PROC proc)
{
	XSharedResources resources;
	// processor 0 will lock and unlock the shared resources
	if (proc == 0)
	{
		for (int i = 0; i < TEST_LOOPS; i++)
		{
			std::cout << "PROC[" << proc << "] has UNLOCKED resources"
					<< std::endl;
			resources.unlock();
			sleep(5);
			std::cout << "PROC[" << proc << "] has LOCKED resources"
					<< std::endl;
			resources.lock();
			sleep(5);
		}

	}
	// processor 1 will print out the state of the lock
	else
	{

		std::cout << std::boolalpha;
		for (int i = 0; i < TEST_LOOPS*2; i++)
		{
			bool state = resources.isLocked();
			std::cout << "PROC[" << proc << "] LOCKED = "<< bool(resources.isLocked()) << std::endl;
			sleep(2);
		}
	}
}
...........................................................................................................................
void XSharedResources::lock() { Xil_Out8(BASEADDR + LOCK_OFFSET, true); } void XSharedResources::unlock() { Xil_Out8(BASEADDR + LOCK_OFFSET, false); } bool XSharedResources::isLocked() { return (bool) Xil_In8(BASEADDR + LOCK_OFFSET); }

I see the desired output only when I 'Debug As'.

PROC[0] has LOCKED resources
PROC[1] LOCKED = true
PROC[1] LOCKED = true
PROC[0] has UNLOCKED resources
PROC[1] LOCKED = false
PROC[1] LOCKED = false
PROC[1] LOCKED = false
PROC[0] has LOCKED resources
PROC[1] LOCKED = true
PROC[1] LOCKED = true
PROC[0] has UNLOCKED resources
PROC[1] LOCKED = false
PROC[1] LOCKED = false
PROC[1] LOCKED = false
PROC[0] has LOCKED resources
PROC[1] LOCKED = true

When I do a 'Run As' it doesn't seem to work correctly and I get this output.

PROC[0] has LOCKED resources
PROC[1] LOCKED = true
PROC[1] LOCKED = true
PROC[0] has UNLOCKED resources
PROC[1] LOCKED = true
PROC[1] LOCKED = true
PROC[1] LOCKED = true
PROC[0] has LOCKED resources
PROC[1] LOCKED = true
PROC[1] LOCKED = true
PROC[0] has UNLOCKED resources
PROC[1] LOCKED = true
PROC[1] LOCKED = true
PROC[1] LOCKED = true
PROC[0] has LOCKED resources

Been banging my head on this one for awhile and would appreciate any ideas.

 

0 Kudos
3 Replies
Moderator
Moderator
156 Views
Registered: ‎10-06-2016

Re: Shared memory across processors only works while debugging.

Hi ashton.allen.ctr@ncte.hpc.mil ,

It seems that you might be facing a cache "issue". The write operations are done in the cache but unless you flush the cache manually there is no guarantee that it has been written in the DDR memory, that´s why the second processor does not read the latest value.

Regards


Ibai
Don’t forget to reply, kudo, and accept as solution.
128 Views
Registered: ‎02-06-2019

Re: Shared memory across processors only works while debugging.

ibaie, 

That fixed the issue I was having thank you so much!! Would it be acceptable to just disable cache? what would the rammifications be?

0 Kudos
Moderator
Moderator
104 Views
Registered: ‎10-06-2016

Re: Shared memory across processors only works while debugging.

Hi ashton.allen.ctr@ncte.hpc.mil 

The apprach you want to follow depens on your needs or basically your application needs. You could find lot of information about caches in the processors (not specific to Xilinx) but in a nutshell the cache allows you to have better performance on the memory access (as you don't need to go up to the DDR to read/write your data). The issues is that with an heterogeneous system (i.e. two processors) the data gets "unsynchronized" on the cores.

Regards


Ibai
Don’t forget to reply, kudo, and accept as solution.
0 Kudos