Decreasing Channel Latency

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Decreasing Channel Latency

Post by rp181 »

I am working on a program to process some data. On 1 thread, I read in 8 data points, in 4 pairs. I do some operations on each pair to result in 1 point, so 4 final points. Then, this thread sends this data to another thread for USB comms (on another core). However, this is going much to slow at the moment. The biggest slow-downs: division and channel communications. I am looking for alternatives on the division, but have no idea how to make the channel comms faster. This is the current code.

4 Threads of: (each with its own ADC)

Code: Select all

void processingThread(chanend usb) {

	
	char data[2];
	int ii;

        //read data and store
	for (ii = 0; ii < 4; ii++) {
		//process each pair and store. Each result is an int
	}
	for (ii = 0; ii < 4; ii++)
	{

usb		<: (d); //send each int out
	}

}
and the receiver thread:

Code: Select all

	int i = 0;
	int ii = 0;
	long d;
t	:> start;
	for (i = 0; i < 1; i++) {
		for (ii = 0; ii < 4; ii++) {
			dataIn [ii] :> d; //read in the data. This is what is slow.
		}
	}
}


User avatar
TSC
Experienced Member
Posts: 111
Joined: Sun Mar 06, 2011 11:39 pm

Post by TSC »

Maybe look into using transactions. A transaction is when a master and slave thread run without synchronization. It's faster than standard channel communication where every for every single communication, the sending thread must wait for the receiving thread to accept. Read Programming XC on XMOS Devices for more details.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Hi rp

TSC is correct using master slave transaction / transactor (transaction functions) could speed things up by reducing idle time, blocking and synchronising. Also I notice you are iterating through the data in 2 separate loops can that be reduced to a single loop?

You would also probably need a replicator for the 4 slave threads, its difficult to show you exactly without a bit more code. How is the data coming in? is it from a port? Can you show a bit more info?

regards
Al
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Perhaps even something like this on the receive side:

Code: Select all

transaction inAdc(chanend c,long data[],int d_size);
..
void procthread(chanend usb,chanend adc[x]){
  select {
  case slave {inAdc(adc[0],data,d_size)} :
    //process data?                                                             
    usb	<: {data,0};
    break;
  case slave {inAdc(adc[1],data,d_size)} :
    //process data?                                                             
    usb	<: {data,1};
    break;
...
...
  case slave {inAdc(adc[x]),data, d_size)} :
    //process data? 
    usb <: {data,x}
  break;
  }
}
Where x is the number of adc channels (I am assuming that's the source of data given your other posts)

But I would need more info to understand how the data gets read etc..

regards
Al