Author Topic: Unexpected delay in uTasker simulator  (Read 7849 times)

Offline aersek

  • Newbie
  • *
  • Posts: 17
    • View Profile
Unexpected delay in uTasker simulator
« on: April 08, 2010, 12:16:05 PM »
During testing of my application in uTasker simulator I found that data transfer between uTasker server application and client take 5 – 6 more time than same transfer between Windows server and client. I found in Wireshark log that every uTasker response (even on telnet, ping, ftp, web) happens 5 – 15 ms after received request, and that slows down data transfer speed dramatically. When I compile and download code to target processor all delays are around 1ms what is expected. I expected better response time from simulator which is running on XX GHz processor than response of 60MHz ColdFire. I understand that Windows are not real time system, but how then PC server application has immediate response and uTasker simulator has not?

Best regards

Andrija Ersek

Offline mhoneywill

  • Full Member
  • ***
  • Posts: 173
    • View Profile
Re: Unexpected delay in uTasker simulator
« Reply #1 on: April 08, 2010, 02:46:00 PM »
Hi Andrija,

I'm no expert but I think this may be due to the system clock in windows and also the TICK_RESOLUTION set for uTasker. You might want to define a different TICK_RESOLUTION when running in windows.

This post may help a bit http://www.utasker.com/forum/index.php?topic=612.msg2662#msg2662

I did try to speed up the uTasker simulator by increasing the windows system tick but my initial tests did not seem to work. If you want I can dig out more info on what I tried.

Cheers

Martin

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Unexpected delay in uTasker simulator
« Reply #2 on: April 08, 2010, 04:57:32 PM »
Hi Andrija

What reaction times do you get when you ping? Generally it should be sub-ms and so similar to the HW target.

The way that the Ethernet input works is by using a WinPCap thread, which responds very quickly. This injects the received frame into the memory of the simulator and invokes the interrupt handling routine. The routine flag scheduling of the Ethernet task.

If you check in WinSim.c you will find the following:

            argv[2] = (char *)fnSimulateEthernetIn((unsigned char*)argv[1], *(unsigned short *)argv[0], 0); // {39}
            if (argv[2] == 0) {                                          // {34}
                iOpSysActive = 0;                                        // {36}
                return 0;                                                // Ethernet frame not for us
            }
            iRun = 5;                                                    // allow the simulator to treat process frames immediately



Once the frame has been injected it sets iRun to 5. Just a few lines later it then calls the scheduler uTaskerSchedule(). This will immediately execute the Ethernet task and then any other tasks handling the frame at a higher level. This process is generally very fast and so is not dependent on the TICK setting (the TICK setting will increase the resolution when simulating timers but is not relevant for Ethernet). Generally I find the the simulator works as fast as or even faster than the real HW in relation to Ethernet.

However the WinPCap thread must not be able to inject frames when the simulator is already working. This is otherwise dangerous and can cause corruption. For this reason the frame is only injected when it is safe to do so. See WinPcap.cpp

            while (main(RX_ETHERNET, ptr) == WAIT_WHILE_BUSY) {          // {1}
                Sleep(1);
            }


Here is will hold off the injection for 1ms if the simulator is presently busy and then try again (whether the 1ms is accurate is another question - it may be more like 15ms for Windows). This may be an explanation for occasional delays but I would expect then to be irregular since the simulator tends to run for a few times once every 50ms (TICK).

I would monitor the sleep above since it should be quite rare. If it is occurring a lot or all of the time you may be able to identify why this is.

Regards

Mark



Offline aersek

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Unexpected delay in uTasker simulator
« Reply #3 on: April 08, 2010, 05:36:45 PM »
No, ping response times are between 4 and 15 ms, not less than ms like on target. It's from first day of using simulator but I didn't take care about it since now when I need to transfer few MB of data. I'll check Sleep function and test simulator on another PC.

Regards, Andrija Ersek