Embedded Ethernet applications

Technical discussions around xCORE processors (e.g. xcore-200 & xcore.ai).
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Embedded Ethernet applications

Post by Folknology »

Couple of quick questions around Ethernet on XS1

1) What is the minimum number of threads required to run embedded ethernet applications:

Looking at the provided examples Test3.xc

Code: Select all

int main() 
{
  chan rx[1], tx[1];

  par
    {
      on stdcore[2]:
      {
        int mac_address[2];
        ethernet_getmac_otp((mac_address, char[]));
        phy_init(clk_smi, clk_mii_ref, 
#ifdef PORT_ETH_RST_N               
               p_mii_resetn,
#else
               null,
#endif
                 smi,
                 mii);
        ethernet_server(mii, clk_mii_ref, mac_address, 
                        rx, 1,
                        tx, 1,
                        null,
                        null);
      }

      on stdcore[0] : demo(tx[0], rx[0]);
    }

	return 0;
}
which starts 2 main threads one on core 0 and the ethernet gubbins on core2. looking down the chain at the ethernet server code :

Code: Select all

void ethernet_server(mii_interface_t &m,
                     clock clk_mii_ref,
                     int mac_address[],
                     chanend rx[],
                     int num_rx,
                     chanend tx[],
                     int num_tx,
                     smi_interface_t &?smi,
                     chanend ?connect_status)
{
  streaming chan c;
  init_mii_mem();
  par {
    // These thrads all communicate internally via shared memory
    // packet queues
    mii_rx_pins(m.p_mii_rxdv, m.p_mii_rxd, 0, c);
    mii_tx_pins(m.p_mii_txd, 0);
    ethernet_rx_server(rx, num_rx);
    ethernet_tx_server(mac_address, tx, 1, num_tx, smi, null, connect_status);  
    one_port_filter(mac_address, c);
  }
}
Which indicates 5 threads on core 2.

Thus Am I right in saying that embedded ethernet requires a minimum of 5 threads plus the embedded specific threads? or can it be done with less?

2) If I want to build an embedded app that uses TCP/IP over ethernet then how many threads do I need? looking at the examples it likes like I need minimum 1 more thread maybe 2, depending on usage?

3) If I need to use http (non industrial app) then I will need at least another thread, looking at the example provided in xmos_tcpip_1v0 i see:

Code: Select all

int main(void) 
{
  chan mac_rx[1], mac_tx[1], xtcp[1], connect_status;
  par {
    on stdcore[2]: uip_server(mac_rx[0], mac_tx[0], 
                              xtcp, 1, ipconfig, connect_status);
  
    on stdcore[2]: xhttpd(xtcp[0]);

    on stdcore[2]:
    {
      int mac_address[2];
      ethernet_getmac_otp((mac_address, char[]));
      phy_init(clk_smi, clk_mii_ref, 
#ifdef PORT_ETH_RST_N               
               p_mii_resetn,
#else
               null,
#endif
               smi,
               mii);
      ethernet_server(mii, clk_mii_ref, mac_address, 
                      mac_rx, 1, 
                      mac_tx, 1,
                      smi,
                      connect_status);
    }
    
  }
}
Which looks like 7 threads on core2 to me:
1 for TCPIP (uip_serever)
1 for xhttpd
and 5 for the ethernet server

Is this correct or am I missing something?

4) Given the the above running an embedded app on a G4 or even G2 isn't a problem, but what is possible on an L1?
Just running ethernet uses 5 of the threads leaving just 3 threads to run the embedded app. In fact at leas another thread is required for the comms over ethernet like TCP/IP or something else. But it indicates that running embedded ethernet apps is possible on an L1. Are there any other examples out there that you can share, please let me know.

5) If I need to build a simple http embedded app on an L1 is that possible, can I squeeze some of the threads together to leave enough room for a simple app? Anyone tried doing this? or am I completely insane?

regards
Al
User avatar
otitov
XCore Addict
Posts: 207
Joined: Thu Dec 10, 2009 11:00 pm
Location: Mexico

Post by otitov »

I feel that you are looking at v10 tcpip code, please, try to locate newest v1.2. as it was told on this forum it should be much more optimized.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Thanks for the heads up on the new TCP/IP stack otitov, its much better, much more in there..

However the questions about threads remain, as it doesn't appear the change the number of threads, anyone got any ideas or feedback on cramming an app like this into an L1?
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

My first idea for optimising for threads rather than performance was to integrate 'one_port_filter(mac_address, c)' into either 'mii_rx_pins(m.p_mii_rxdv, m.p_mii_rxd, 0, c)' or more likely 'one_port_filter(mac_address, c)' that would get my Ethernet down to 4 threads

Code: Select all

par{
    mii_rx_pins(m.p_mii_rxdv, m.p_mii_rxd, 0, c);
    mii_tx_pins(m.p_mii_txd, 0);
    ethernet_rx_server(rx, num_rx);
    ethernet_tx_server(mac_address, tx, 1, num_tx, smi, null, connect_status); 
    one_port_filter(mac_address, c);
}
Could become

Code: Select all

par{
    mii_rx_pins(m.p_mii_rxdv, m.p_mii_rxd, 0, c);
    mii_tx_pins(m.p_mii_txd, 0);
    ethernet_rx_server(mac_address, rx, num_rx);
    ethernet_tx_server(mac_address, tx, 1, num_tx, smi, null, connect_status); 
}
The maybe integrate the TCP/IP and HTTP threads in some limited/narrow performance way.

Thoughts?