YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Periodically interrupt virtual machine
MicioMax
#1 Posted : Tuesday, October 24, 2017 9:05:10 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/16/2017(UTC)
Posts: 8

Thanks: 1 times
Was thanked: 0 time(s) in 0 post(s)
Hi,

working on an embedded environment I need to have the VM interrupted on e regular time base (no need for precision there).
So, executing the (just uploaded) code with :
Code:

    int res = SQ_SUCCEEDED(sq_call(_squirrelVM, 1, SQFalse, SQTrue));

The VM sould suspend after, for example, 500 mSec and be resumed with

Code:

    sq_wakeupvm(_squirrelVM, SQFalse, SQFalse, SQFalse, SQFalse);


I tried to hack Execute method like this :

Code:

        for(;;)
        {
            //@@ breakhook stuffs
            if(_sharedstate->_breakhook && (_sharedstate->_breakNext || !_sharedstate->_breakLoops--))
            {
                _sharedstate->_breakLoops = SQ_LOOPS_BEFORE_BREAK_CHECK;
                if((_sharedstate->_breakNext || millis() > _sharedstate->_breakTimer) && _sharedstate->_breakhook(this))
                {
                    _suspended = SQTrue;
                    _suspended_target = -1;
                    _suspended_root = ci->_root;
                    _suspended_traps = traps;
                   
                    _sharedstate->_breakTimer = millis() + _sharedstate->_breakTime;
                    _sharedstate->_breakNext = false;
                    return true;
                }
            }


where the _breakLoops stuff is a simple counter uset to not have to check the timeout too often, which would slow down the machine.
It works, but ONLY for main thread. If I use threads (coroutines) it will suspend the coroutine and NOT return from main call as I need.
Is there a way to have the VM stopped completely, so it returns from main call, even if stopped inside a thread, and resumed completely after ?

Ciao

Massimo
MicioMax
#2 Posted : Monday, October 30, 2017 9:04:34 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/16/2017(UTC)
Posts: 8

Thanks: 1 times
Was thanked: 0 time(s) in 0 post(s)
Almost solved :

- hacked the VM main loop with a "shutdown" flag in "shareddata" struct
- use coroutine to periodically interrupt the machine (once every 2-300 loops) and give back control to application
- when required the application sets the shutdown flag, which make all Execute() calls to return, both in main VM and in threads
- the coroutine then call backs into VM and wait till it returns from main closure evaluation
- the stack is then cleaned up restoring it as it was before the main closure evaluation

It seems working well, even if it's a bit hacky. Up to now I don't have memory leaks nor hangups.

Now I'd like to know if there's a way to reduce RAM usage... which is quite high.
Before starting the VM I've 120 KB of RAM free, after starting they become around 50-60, and I've still very few bindings.

Is there a way to instruct the system to use as much as possible Flash data without copying to RAM ?

Ciao

Massimo
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.069 seconds.