<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p
{mso-style-priority:99;
margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-NZ link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>Note that the patchset has only really been tested with RT_PREEMPT or otherwise standard user mode usage.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>In particular, there are some patches that change locks and callbacks in ways that I don’t think are entirely compatible with RTAI / Xenomai; there have previously been reported problems using those with this patchset.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>As I was neither the author of those patches nor do I use Xenomai (or EoE) myself, I don’t really know what needs to be done to resolve the issues (except just dropping them and possibly breaking the scenario they were originally authored to fix); additionally, I don’t have much time at the moment to work on EtherCAT. I welcome assistance in correcting this situation. </span><span style='font-size:11.0pt;font-family:Wingdings;mso-fareast-language:EN-US'>J</span><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>As far as I understand, ec_master_send/receive are only ever supposed to be invoked on one thread at a time; when you’re using the userspace library this is enforced by a Linux lock in the corresponding ioctl, but this doesn’t apply or is insufficient when using a kernel-mode application or RTAI/Xenomai. In those, you need to register callbacks and use your own appropriate locking mechanism to ensure that the send/receive are not called concurrently.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>In particular note that both the send callback and the receive callback are permitted to do nothing if called in a context where they can’t wait on a lock but something else is concurrently busy doing the same thing. So if you’re calling send/receive from an interrupt thread, you will need to keep track of this and force the EoE thread callback to block until the interrupt is done, <b>and also</b> to make the interrupt thread avoid send/receive without blocking if the EoE thread is already in the middle of it. Alternately you could probably make the interrupt handler responsible to do both of these things and have the EoE callbacks always do nothing, which might be better for your application performance. (Though like I said, I haven’t looked at the code much in this area so take these suggestions with a grain of salt; I could have something incorrect.)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'> etherlab-dev [mailto:etherlab-dev-bounces@etherlab.org] <b>On Behalf Of </b>Geller, Nir<br><b>Sent:</b> Wednesday, 18 January 2017 23:38<br><b>To:</b> etherlab-dev@etherlab.org; Slutsker, Rasty <rasty.slutsker@servotronix.com><br><b>Subject:</b> [etherlab-dev] EoE in OP mode<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div id=divtagdefaultwrapper><p><span style='font-family:"Calibri",sans-serif;color:black'>Hi,<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>I recently upgraded ethercat master to Gavin Patchset 20160804, adding to that, patch 0061.<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>EoE seems to be working fine while the master is idle, with heavy SDO traffic in parallel.<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>When the master is active our realtime application invokes ecrt_master_receive(master); and ecrt_master_send(master); from interrupt context, and NOT from <o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>ec_master_operation_thread() thread context.<o:p></o:p></span></p><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p></div><p><span style='font-family:"Calibri",sans-serif;color:black'>The problem comes up when the master is active.<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>Just as I issue<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>ifconfig eoe0a1 up<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>I get a bunch of UNMATCHED DATAGRAMS in the kernel log, and the master is released.<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324525] EtherCAT DEBUG 0: UNMATCHED datagram:<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324528] EtherCAT DEBUG: 0D 83 01 00 10 09 08 80 00 00 68 5A 4A 84 9C 9B <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324539] EtherCAT DEBUG: 84 11 01 00 <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324544] EtherCAT DEBUG 0: UNMATCHED datagram:<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324547] EtherCAT DEBUG: 04 84 01 00 90 09 08 80 00 00 B0 3D 4C 84 9C 9B <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324557] EtherCAT DEBUG: 84 11 01 00 <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324562] EtherCAT DEBUG 0: UNMATCHED datagram:<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324565] EtherCAT DEBUG: 0C 85 00 00 00 00 10 80 00 00 00 00 70 FF FF FF <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324575] EtherCAT DEBUG: 50 52 70 FF FF FF 00 00 31 00 03 00 <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324584] EtherCAT DEBUG 0: UNMATCHED datagram:<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324587] EtherCAT DEBUG: 07 86 01 00 30 01 02 00 00 00 08 00 01 00 <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324838] EtherCAT 0: fsm->slaves_responding[fsm->dev_idx]=1<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324843] EtherCAT 0: 0 slave(s) responding on main device.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324846] EtherCAT 0: datagram->working_counter=0 <------------------------- In wireshark capture WC is 1 !!!!<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324850] EtherCAT 0: datagram->state=4<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324853] EtherCAT 0: datagram->device_index=0<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324856] EtherCAT 0: datagram->device_origin=0<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324860] EtherCAT 0: datagram->index=134<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324863] EtherCAT 0: datagram->type=7<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 73.324866] EtherCAT DEBUG 0: Rescanning the bus<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p></div><p><span style='font-family:"Calibri",sans-serif;color:black'>This happens due to a timeout. When the EoE thread invokes<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>master->receive_cb(master->cb_data); which leads to invoke of ecrt_master_receive(master); it somehow messes up <o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>master->devices[EC_DEVICE_MAIN].cycles_poll<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>which leads to a negative time delta in the calculation master->devices[EC_DEVICE_MAIN].cycles_poll - datagram->cycles_sent.<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>Attempting to bypass that in the EoE thread, I commented out master->receive_cb(master->cb_data); and master->send_cb(master->cb_data);<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>and once I invoke<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>ifconfig eoe0a1 up<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>I get an explosion of<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 123.529911] EtherCAT WARNING 0-main-0: Failed to receive mbox check datagram for eoe0a1.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 123.529918] EtherCAT WARNING 0-main-0: Failed to receive mbox check datagram for eoe0a1.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 123.529925] EtherCAT WARNING 0-main-0: Failed to receive mbox check datagram for eoe0a1.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'>[ 123.529932] EtherCAT WARNING 0-main-0: Failed to receive mbox check datagram for eoe0a1.<o:p></o:p></span></p></div><p class=MsoNormal><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>If I comment out only master->receive_cb(master->cb_data);<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>I get no errors in dmesg, but then of course, EoE is not functional, and EoE thread starts gathering more and more CPU usage.<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>I understand that an invoke of master->send_cb(master->cb_data); leads to <o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>ec_master_internal_send_cb --> ecrt_master_send_ext(master); <o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>which pulls datagrams from master->ext_datagram_queue and pushes them forward with ec_master_queue_datagram(), and then<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>invokes ecrt_master_send(master); which will lead to a collision with ecrt_master_send() in the interrupt context.<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>So instead of invoking master->send_cb(master->cb_data); i tried only to pass datagrams from master->ext_datagram_queue,<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>but it caused a kernel panic.<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>So, if I want EoE to work when the master is active, how should I pass datagrams from EoE thread to the master?<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>Should I change the ethernet.c state machine?<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>Thanks a lot,<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'>Nir.<o:p></o:p></span></p><p><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p></div></div></div></body></html>