GithubHelp home page GithubHelp logo

Comments (15)

azoitl avatar azoitl commented on September 13, 2024

The problem is that this code handles the fact when opener is blocked by the operating system longer then the OPENER_TIMER_TICK. This helps to keep the overall timing behavior stable. The problem now with step changes is that this code wants to compensate for the step change. Because for OpENer it looks like the operating system has blocked OpENer for a long time.

In order to handle this correctly the process of making the step change would need to update lasttime. or that the getmilliseconds uses a timer which is not effected by the step change.

from opener.

swebb2066 avatar swebb2066 commented on September 13, 2024

I do not see why multiple calls to manageConnections() (in a busy loop) is the right thing to do.

How about passing "elapsedtime" to manageConnections() so the "InnacitvityWatchdogTimer" and "TransmissionTriggerTimer" are updated all at once and changing "while" to an "if"? Then TheNetworkStatus.elapsedtime can be zeroed.

from opener.

azoitl avatar azoitl commented on September 13, 2024

Never thought about given the full time elapsed to manageConnections. Maybe even passing the current time could help simplifying the implementations of the timers because now instead of performing calculations every time only simple comparisons could be done.

This would at least help if the step change is positive. For negative step changes a different solution needs to be found.

Also applications depending on certain cycle times may get in trouble.

But it is definitely worth a try.

from opener.

liftoff-sr avatar liftoff-sr commented on September 13, 2024

No. The solution is to use a bug free getmilliseconds(). Fundamentally, this is one implemented such that it not even see the change in the calendar time. You need to use a monotonically increasing function, devoid of influence from changes in calendar time. The rest of the logic is probably fine, I've kept it in my implementation.

from opener.

MartinMelikMerkumians avatar MartinMelikMerkumians commented on September 13, 2024

I like your solution. This would also solve the problem if the step change is negative due to time synchronization.

from opener.

swebb2066 avatar swebb2066 commented on September 13, 2024

I still do not see why multiple calls to manageConnections() (in a busy loop) is the right thing to do.

from opener.

liftoff-sr avatar liftoff-sr commented on September 13, 2024

unsigned GetMilliSeconds( void )
{
struct timespec now;

clock_gettime( CLOCK_MONOTONIC, &now );

unsigned msecs = ((unsigned)now.tv_nsec)/(1000*1000) + now.tv_sec * 1000;
return msecs;

}

Dick

from opener.

azoitl avatar azoitl commented on September 13, 2024

@swebb2066: the problem is that select may be blocked longer then the given time. As the manageConnections does internal some sums with expected cycle times the some can drift more and more away from the real time. This can lead to cases that timers are then much longer then they should be. The mulitple mangeConnection invocation does compensate this behavior.

from opener.

swebb2066 avatar swebb2066 commented on September 13, 2024

Why would multiple calls to m_pfTimeOutFunc and m_pfSendDataFunc from manageConnections() be the correct thing to do when cycle times drift?

Why would using the (bug free) elapsedtime to update timers in manageConnections() be worse than using the fixed constant OPENER_TIMER_TICK in manageConnections()?

from opener.

azoitl avatar azoitl commented on September 13, 2024

You are right when changing the interface to give manageConnections the elapsed time you don't need to multiple call manageConnections. Still you need the correct time function as presented above by @liftoff-sr

from opener.

MartinMelikMerkumians avatar MartinMelikMerkumians commented on September 13, 2024

@swebb2066 I am with you that your suggested fix should also be applied, but as I had troubles with negative time steps already in the original implementation, so a fix for that is also needed.

from opener.

liftoff-sr avatar liftoff-sr commented on September 13, 2024

To top most CMakeLists.txt, please add these two lines:

enable clock_gettime:

add_definitions( -D_POSIX_C_SOURCE=199309L )

in order for clock_gettime( CLOCK_MONOTONIC, &now ); to compile with the C language. (C++ does not need this.)

Then you may have to link to library "rt" additionally to provide that clock_gettime() function on linux.

from opener.

MartinMelikMerkumians avatar MartinMelikMerkumians commented on September 13, 2024

Putting the definition in the top most CMakeLists.txt would add the define also to the Windows build.

I added it to the POSIX specific CMake file, and applied your suggested fix to the GetMicroSeconds function. At least on my machine I didn't need the rt library.

from opener.

MartinMelikMerkumians avatar MartinMelikMerkumians commented on September 13, 2024

@swebb2066 I'm not sure, but this could also fix your issue as well, as CLOCK_MONOTONIC should not experience discontinuities due to NTP. (At least thats what I have interpreted from the description I found of CLOCK_MONOTONIC behavior)

But a fix for the Windows version is still missing.

from opener.

MartinMelikMerkumians avatar MartinMelikMerkumians commented on September 13, 2024

After digging into the topic if the Windows implementation also needs changes, I found out that the use performance counter is behaving monotonic.
So the Windows implementation does not need to change.

from opener.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.