Avoiding ET_LOAD_STORE errors in c code

If you have a simple question and just want an answer.
Post Reply
Mike Cole
Member
Posts: 11
Joined: Tue Oct 03, 2017 1:30 am

Avoiding ET_LOAD_STORE errors in c code

Post by Mike Cole »

Hello! I am currently debugging an ET_LOAD_STORE error in my codebase. I have read the documentation at https://www.xmos.ai/download/xCORE-200: ... )(1.1).pdf and understand this to be an alignment issue. from the doc:
A memory operation was performed that was not properly aligned. This could be a
word load or word store to an address where the least significant log2 Bpw bits
were not zero, or access to a 16-bit number using LD16S or ST16 where the least
significant bit of the address was one.
the code in question is c code that allocs a memory pool to be used for the purpose of a cross-tile messaging API developed by one of our ex devs. I do not run into the ET_LOAD_STORE issue on some xs2a applications (usually different hardware targets), but I am seeing it on one particular device. I am hoping for some insight on why this particular code may be triggering this error. It occurs in memoryPoolAllocate as outlined below.

Code: Select all

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "memorypool.h"

struct MemoryPool
{
	struct MemoryPool* head;
};

void memoryPoolInit(struct MemoryPool* pool, uint32_t* memory, int count, int size)
{
	memset (memory, 0, sizeof(memory[0]) * count * size);
	pool->head = (struct MemoryPool*)memory;
	pool->head->head = NULL;
	for(int i = 1; i < count; i += 1)
	{
		struct MemoryPool* p = (struct MemoryPool*)(&memory[i * size]);
		p->head = pool->head->head;
		pool->head->head = p;
	}
}

void* memoryPoolAllocate(struct MemoryPool* pool)
{
	struct MemoryPool* p = pool->head;
	if(p)
	{
		pool->head = p->head; //ET_LOAD_STORE happening here!
	}
	return p;
}

void memoryPoolFree(struct MemoryPool* pool, void* block)
{
	struct MemoryPool* p = block;
	p->head = pool->head;
	pool->head = p;
}


User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Try changing the optimization to level 2 in your build options.

Reference:

viewtopic.php?t=7762

Please post your results.
Mike Cole
Member
Posts: 11
Joined: Tue Oct 03, 2017 1:30 am

Post by Mike Cole »

Oh - I should clarify. This is an error that occurs at optimization level -O0.

When using -O2/-03 I dont see this particular error but instead an ILLEGAL_RESOURCE error in a channel that is attempting to use the data referenced here.. that is the true bug im working on fixing.

With -O3, I lose some debug info, so I turned optimization off. That is when I saw the LOAD_STORE appear. Do you feel it is a red herring? Why would changing optimization level affect this?
leobodnar
Member
Posts: 12
Joined: Mon May 07, 2018 9:26 am

Post by leobodnar »

Try disabling XSCOPE inclusion if you have it compiled in.
Leo
Mike Cole
Member
Posts: 11
Joined: Tue Oct 03, 2017 1:30 am

Post by Mike Cole »

Thank you for the suggestions!

Unfortunately they don't really seem to be ellucidating anything. Though changing debug level does yield a different error, I have no insight into the root cause of the LOAD_STORE nor the ILLEGAL_RESOURCE error.

Here's what's very much baffling to me. I am declaring a chan to be used by this message passing scheme and passing it to a function in the main.xc. Whenever I try to use the chan, however, I get the ILLEGAL_RESOURCE error. Looking at the dissassembly, I see the following: https://imgur.com/a/gQmjELj

note that I hit the ILLEGAL_RESOURCE error when I try to transmit using the channel. looking at the reference for the outct instruction where the PC is, we see that the following:
Outputs a control token to a channel.
The instruction pauses if the control token cannot be accepted by the channel.
Each OUTCT must have a matching CHKCT or INCT
The instruction has two operands:

op1 r Operand register, one of r0... r11
op2 s Operand register, one of r0... r11

Mnemonic and operands:
OUTCT r, s

Conditions that raise an exception:
ET_RESOURCE_DEP Resource illegally shared between threads
ET_ILLEGAL_RESOURCE r is not a channel end, or not in use.
ET_LINK_ERROR r is a channel end, and the destination has not been set.
ET_LINK_ERROR r is a channel end, and the control token is a reserved
hardware token.
looking at the registers, it appears the channel value is stored in r4, has a value of -2147350784 which is clearly invalid.

But why is there an invalid value? I declared the chan in main.xc and passed it to the function via the main. I cannot find anything in the documentation as to why this might occur. Can anyone help?
Mike Cole
Member
Posts: 11
Joined: Tue Oct 03, 2017 1:30 am

Post by Mike Cole »

mystery solved!

it had zero to do with channel allocation.

The issue was due to memory corruption. There was an snprintf elsewhere in the code that was overflowing due to incorrectly sized buffers. This overflow corrupted the location of the chan data and caused the errors!

Moral of the story: don't trust the debugger to give you the answers and don't trust the docs to provide a complete picture.

huge thanks to ers35 on this one.
Post Reply