Can't recover from out of memory
-
- Posts: 47
- Joined: Wed Oct 04, 2017 1:44 am
Can't recover from out of memory
I have been steadily increasing my scripts complexity. I now have run out of memory, which I have been expecting.
However, I can no longer over write that script. It appears to write the new script successfully, but even a tiny script like setTickRate(1) returns an out of memory error. If I then read the configuration back, I see my old huge script is back.
This script has now survived a firmware upgrade and an attempt at a factory reset (because it clearly didn't work).
What now?
Here is log from attempted reset:
RaceCapture/Pro MK3 > resetConfig
Flashing Default Logger Config: PASS
Flashing Default Script: FAILED
Flashing Default Tracks: PASS
result="error";code=-4;cu: Got hangup signal
Here are the lua logs:
[lua] Initializing Lua state
[lua] memory usage: 17KB
[lua] Starting Lua Task
[wifi] Initializing...
[lua] Loading script. Length: 4986
[lua] Memory ceiling hit: 51391 > 51200
[lua] Startup script error: (not enough memory)
[lua] Failure: Failed to load script
Then on writing a new tiny script, I get this debug message:
lua: Failed to allocate memory for script buffer.
However, I can no longer over write that script. It appears to write the new script successfully, but even a tiny script like setTickRate(1) returns an out of memory error. If I then read the configuration back, I see my old huge script is back.
This script has now survived a firmware upgrade and an attempt at a factory reset (because it clearly didn't work).
What now?
Here is log from attempted reset:
RaceCapture/Pro MK3 > resetConfig
Flashing Default Logger Config: PASS
Flashing Default Script: FAILED
Flashing Default Tracks: PASS
result="error";code=-4;cu: Got hangup signal
Here are the lua logs:
[lua] Initializing Lua state
[lua] memory usage: 17KB
[lua] Starting Lua Task
[wifi] Initializing...
[lua] Loading script. Length: 4986
[lua] Memory ceiling hit: 51391 > 51200
[lua] Startup script error: (not enough memory)
[lua] Failure: Failed to load script
Then on writing a new tiny script, I get this debug message:
lua: Failed to allocate memory for script buffer.
Hi Rod,
Try to flash an older version of the firmware, which should trigger a factory reset - it's an alternative to the command line option.
https://wiki.autosportlabs.com/RaceCapt ... aceCapture
Is this happening with 2.16.0?
Try to flash an older version of the firmware, which should trigger a factory reset - it's an alternative to the command line option.
https://wiki.autosportlabs.com/RaceCapt ... aceCapture
Is this happening with 2.16.0?
-
- Posts: 47
- Joined: Wed Oct 04, 2017 1:44 am
The original problem happened with 2.15.1. Since then I upgraded to 2.16.0 and then back down to 2.15.1 again.
I also tried using the "resetConfig" command at the serial command line interface, which is where it looks like its trying to restore 3 partitions: Logger and Tracks are OK. But Script fails be be re-flashed.
Should I try a much older firmware? Is it worth trying 2.13?
I also tried using the "resetConfig" command at the serial command line interface, which is where it looks like its trying to restore 3 partitions: Logger and Tracks are OK. But Script fails be be re-flashed.
Should I try a much older firmware? Is it worth trying 2.13?
Thanks. So - does going between 2.15.x and 2.16.x not reset the lua script?
You can try going to an older firmware version as well. Starting with 2.15.x we reduced the amount of Lua memory available in order to enhance system stability. An older version of the firmware may let you get past that in order un-wedge things.
You can try going to an older firmware version as well. Starting with 2.15.x we reduced the amount of Lua memory available in order to enhance system stability. An older version of the firmware may let you get past that in order un-wedge things.
-
- Posts: 47
- Joined: Wed Oct 04, 2017 1:44 am
-
- Posts: 47
- Joined: Wed Oct 04, 2017 1:44 am
I seem to have managed to clear the oversized script.
The downgrade to 2.13.0 didn't clear the script, but I was able to overwrite the script with this version.
Now upgraded to 2.16.0. The small script I loaded in 2.13 is still resident.
I'll go back to my debugging for now, but I hope that don't have to downgrade my firmware every time I run out of memory.
Thanks for the suggestions brent.
The downgrade to 2.13.0 didn't clear the script, but I was able to overwrite the script with this version.
Now upgraded to 2.16.0. The small script I loaded in 2.13 is still resident.
I'll go back to my debugging for now, but I hope that don't have to downgrade my firmware every time I run out of memory.
Thanks for the suggestions brent.
-
- Posts: 47
- Joined: Wed Oct 04, 2017 1:44 am
So it happened again, although it doesn't happen very often.
I did try the factory reset under 2.16.0 but it didn't allow me to rewrite the stuck script.
However, this time during the firmware downgrade to 2.13 it lost connection around 40%. Now RCP3 does not boot.
It creates the serial connection. I can see that a /dev/ttyACM0 is created but it doesn't respond.
Solid green light power light, rapid flashing amber SDCard light.
Is there a recovery procedure from here?
Thanks.
I did try the factory reset under 2.16.0 but it didn't allow me to rewrite the stuck script.
However, this time during the firmware downgrade to 2.13 it lost connection around 40%. Now RCP3 does not boot.
It creates the serial connection. I can see that a /dev/ttyACM0 is created but it doesn't respond.
Solid green light power light, rapid flashing amber SDCard light.
Is there a recovery procedure from here?
Thanks.
Hi Rod,
It looks like it failed the firmware update. When this happens, the system just starts up in bootloader mode so you can flash firmware again. Give it another try to see if it goes from 0-100%.
Note, you'll need to load a previously saved config under Setup to access the firmware update page.
Do you have an example script you can attach here that causes the problem to happen, so we can reproduce it?
Thanks,
It looks like it failed the firmware update. When this happens, the system just starts up in bootloader mode so you can flash firmware again. Give it another try to see if it goes from 0-100%.
Note, you'll need to load a previously saved config under Setup to access the firmware update page.
Do you have an example script you can attach here that causes the problem to happen, so we can reproduce it?
Thanks,
-
- Posts: 47
- Joined: Wed Oct 04, 2017 1:44 am
Nice. I managed to find my way back into the firmware page. (It should not require a config file to access this). And it went smoothly back to 2.16
I should have thought to save the script for you. If it happens again. I will make a copy.
My recollection is that seemed to contain a mix of 2 different write/run attempts. One which had been run through minify and one that had not. I guess this could have been a user selection error where my Ctl-A didn't happen or it could have be copy paste error in the App (1.14.2 linux) or it could have been memory corruption on the rcp.
Happy to have my rcp back up. Disappointed it stayed home today while my car and I were at the track.
I should have thought to save the script for you. If it happens again. I will make a copy.
My recollection is that seemed to contain a mix of 2 different write/run attempts. One which had been run through minify and one that had not. I guess this could have been a user selection error where my Ctl-A didn't happen or it could have be copy paste error in the App (1.14.2 linux) or it could have been memory corruption on the rcp.
Happy to have my rcp back up. Disappointed it stayed home today while my car and I were at the track.
-
- Posts: 47
- Joined: Wed Oct 04, 2017 1:44 am
Here is the script that now refuses to be overwritten:
Code: Select all
_c="count"
lastRPM=0
rpmInc=false
function isWOT()
if(-getImu(0))>0.06 then
local ay=getImu(1)
if ay*ay<0.01 then return true end
end
local ret=false
if getGpsSpeed()<5.0 then
local rpm=getChannel("RPM")
if rpm<lastRPM then
rpmInc=false
elseif rpm>lastRPM then
rpmInc=true
end
lastRPM=rpm
ret=rpmInc
if rpm<950 then ret=false end
end
return ret
end
acList={}
acListN=0
acChansN=0
acChans={}
function acAddRange(name,min,max)
local t={}
t.chanDt=addChannel("dT_"..name,10,2,0,10,"ms/rpm")
t.name=name
t.chans={}
t.minRPM=min
t.maxRPM=max
acResetTimer(t)
acList[acListN]=t
acListN=acListN+1
end
function acAddChannel(name,logHz,prec,min,max,units,updateFn)
acChans[acChansN]={}
acChans[acChansN].updateFn=updateFn
acChans[acChansN].name=name
for i=0,acListN-1 do
local t=acList[i]
local tChan={}
tChan.chan=addChannel(name..t.name,logHz,prec,min,max,units)
t.chans[acChansN]=tChan
end
acChansN=acChansN+1
end
function acResetTimer(t)
t.startT=0
t.startRPM=0
for i=0,acChansN-1 do
t.chans[i].afSum=0
t.chans[i].afCount=0
end
end
function acUpdateTimer(t,rpm)
if rpm>=t.minRPM then
if rpm<t.maxRPM then
if t.startRPM==0 then
println("start:"..t.name)
t.startRPM=rpm
t.startT=getUptime()
else
println("update")
local dR=rpm-t.startRPM
if dR>0 then
local dT=getUptime()-t.startT
local acc=dT/dR
setChannel(t.chanDt,acc)
end
end
for i=0,acChansN-1 do
acSampleAFR(t,acChans[i].updateFn())
end
elseif t.startRPM~=0 then
println("finished:"..t.name)
acResetTimer(t)
end
end
end
function acSampleChan(t,v)
if v~=nil then
t.afCount=t.afCount+1
t.afSum=t.afSum+v
local av=t.afSum/t.afCount
println("afrac:"..t.name..","..t.afSum..","..t.afCount..","..av)
setChannel(t.chanAF,av)
end
end
function acOnTick()
local wot=isWOT()
local rpm=getChannel("RPM")
for i=0,acListN-1 do
local t=acList[i]
if wot then
acUpdateTimer(t,rpm)
else
if t.startRPM~=0 then acResetTimer(t)end;
end
end
end
afChan=-1
ispAFR=nil
ispHiBuf=nil
ispAFx=nil
function ispHlrHh(h)
if bit.band(h,(0xA2))==(0xA2)then
ispHiBuf=h
ispNxtBHdlr=ispHlrHl
end
end
function ispHlrHl(l)
if bit.band(l,(0x80))==(0x80)then
ispNxtBHdlr=ispHlrAFh
else
ispNxtBHdlr=ispHlrHh
end
end
function ispHlrAFh(h)
ispHiBuf=h
ispNxtBHdlr=ispHlrAFl
end
function ispHlrAFl(l)
ispNxtBHdlr=ispHlrLh
ispFunc=bit.band(bit.rshift(ispHiBuf,2),7)
ispAFx=bit.band(ispHiBuf,1)*0x80+
bit.band(l,0x7F)
end
function ispHlrLh(h)
ispHiBuf=h
ispNxtBHdlr=ispHlrLl
end
function ispHlrLl(l)
local lambda=bit.band(ispHiBuf,0x7F)*0x80+bit.band(l,0x7F)
if ispFunc==0 then
ispAFR=(lambda+500.0)*ispAFx*0.0001
elseif ispFunc==1 then
ispAFR=lambda*0.1
else
println("afr:func"..ispFunc.."mult:"..ispAFx.."lambda:"..lambda)
end
ispNxtBHdlr=ispHlrHh
end
function afOnTick()
local c=readCSer(6,0)
while c~=nil do
ispNxtBHdlr(c)
c=readCSer(6,0)
end
if ispAFR~=nil then
setChannel(afChan,ispAFR)
ispAFR=nil
end
end
function onTick()
afOnTick()
acOnTick()
end
function getAF()
return getChannel(afChan)
end
println("mem:"..collectgarbage(_c))
acAddRange("3",2500,3500)
println("mem:"..collectgarbage(_c))
acAddRange("4",3500,4500)
println("mem:"..collectgarbage(_c))
acAddRange("5",4500,5500)
println("mem:"..collectgarbage(_c))
acAddRange("6",5500,6500)
println("mem:"..collectgarbage(_c))
acAddChannel("AF",10,1,7,25,"%O2",getAF)
if initSer(6,19200,8,0,1)then println('serial initialized')else println('initSer failed:port'..6)end afChan=addChannel("AFR",10,1,8,23)ispNxtBHdlr=ispHlrHh
setTickRate(60)
Last edited by lightningrod on Sat Jun 01, 2019 3:31 am, edited 1 time in total.
-
- Posts: 47
- Joined: Wed Oct 04, 2017 1:44 am
Here is the output from my attempt to do a factory reset (resetConfig). Note the "Flashing Default Script: FAILED" line.
Code: Select all
cu -l /dev/ttyACM1
Connected.
=============================================
Welcome to RaceCapture/Pro MK3 version 2.16.0
=============================================
Available Commands:
resetConfig : Resets All configuration Data to factory default Usage: resetConfig
testSD : Test Write to SD card. Usage: testSD <lineWrites> <periodicFlush> <quietMode>
startTerminal : Starts a debugging terminal session on the specified port. Usage: startTerminal <port> <baud> [echo 1|0]
setLogLevel : Sets the log level Usage: setLogLevel <level>
viewLog : Prints out logging messages to the terminal as they happen Usage: viewLog
setSerialLog : Enables/disables logging of serial device for debug purposes Usage: setSerialLog <port> <0|1>
flashConfig : Flashes the NVRAM with the current configuration of the LoggerConfig Usage: flashConfig
showTasks : Show status of running tasks Usage: showTasks
version : Gets the version numbers Usage: version
showStats : Info on system statistics. Usage: showStats
sysReset : Reset the system Usage: sysReset [bootloader 0|1]
lua : Enter the lua script interpreter. Usage: lua
reloadScript : Reloads the current script. Usage: reloadScript
RaceCapture/Pro MK3 > resetConfig
Flashing Default Logger Config: PASS
Flashing Default Script: FAILED
Flashing Default Tracks: PASS
result="error";code=-4;cu: Got hangup signal
Disconnected.
-
- Posts: 47
- Joined: Wed Oct 04, 2017 1:44 am