remove system lua VM (#3864)
* well, that was a fun experiment * don't need that file * s Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
7ff0f0d3e6
commit
9f15218089
|
@ -275,7 +275,6 @@
|
||||||
#if defined(EFI_HAS_EXT_SDRAM)
|
#if defined(EFI_HAS_EXT_SDRAM)
|
||||||
#define ENABLE_PERF_TRACE TRUE
|
#define ENABLE_PERF_TRACE TRUE
|
||||||
#define LUA_USER_HEAP (1 * 1024 * 1024)
|
#define LUA_USER_HEAP (1 * 1024 * 1024)
|
||||||
#define LUA_SYSTEM_HEAP (1 * 1024 * 1024)
|
|
||||||
#elif defined(EFI_IS_F42x)
|
#elif defined(EFI_IS_F42x)
|
||||||
// F42x has more memory, so we can:
|
// F42x has more memory, so we can:
|
||||||
// - use compressed USB MSD image (requires 32k of memory)
|
// - use compressed USB MSD image (requires 32k of memory)
|
||||||
|
@ -284,13 +283,11 @@
|
||||||
#define ENABLE_PERF_TRACE TRUE
|
#define ENABLE_PERF_TRACE TRUE
|
||||||
|
|
||||||
#define LUA_USER_HEAP 25000
|
#define LUA_USER_HEAP 25000
|
||||||
#define LUA_SYSTEM_HEAP 20000
|
|
||||||
#else
|
#else
|
||||||
// small memory F40x can't fit perf trace
|
// small memory F40x can't fit perf trace
|
||||||
#define ENABLE_PERF_TRACE FALSE
|
#define ENABLE_PERF_TRACE FALSE
|
||||||
|
|
||||||
#define LUA_USER_HEAP 25000
|
#define LUA_USER_HEAP 25000
|
||||||
#define LUA_SYSTEM_HEAP 12000
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef EFI_LUA
|
#ifndef EFI_LUA
|
||||||
|
|
|
@ -68,5 +68,3 @@
|
||||||
|
|
||||||
#undef LUA_USER_HEAP
|
#undef LUA_USER_HEAP
|
||||||
#define LUA_USER_HEAP 100000
|
#define LUA_USER_HEAP 100000
|
||||||
#undef LUA_SYSTEM_HEAP
|
|
||||||
#define LUA_SYSTEM_HEAP 100000
|
|
||||||
|
|
|
@ -43,5 +43,3 @@
|
||||||
|
|
||||||
#undef LUA_USER_HEAP
|
#undef LUA_USER_HEAP
|
||||||
#define LUA_USER_HEAP 100000
|
#define LUA_USER_HEAP 100000
|
||||||
#undef LUA_SYSTEM_HEAP
|
|
||||||
#define LUA_SYSTEM_HEAP 100000
|
|
||||||
|
|
|
@ -16,17 +16,11 @@
|
||||||
#define LUA_USER_HEAP 1
|
#define LUA_USER_HEAP 1
|
||||||
#endif // LUA_USER_HEAP
|
#endif // LUA_USER_HEAP
|
||||||
|
|
||||||
#ifndef LUA_SYSTEM_HEAP
|
static char luaUserHeap[LUA_USER_HEAP]
|
||||||
#define LUA_SYSTEM_HEAP 1
|
#ifdef EFI_HAS_EXT_SDRAM
|
||||||
#endif // LUA_SYSTEM_HEAP
|
SDRAM_OPTIONAL
|
||||||
|
|
||||||
#ifndef EFI_HAS_EXT_SDRAM
|
|
||||||
static char luaUserHeap[LUA_USER_HEAP];
|
|
||||||
static char luaSystemHeap[LUA_SYSTEM_HEAP];
|
|
||||||
#else
|
|
||||||
static char luaUserHeap[LUA_USER_HEAP] SDRAM_OPTIONAL;
|
|
||||||
static char luaSystemHeap[LUA_SYSTEM_HEAP] SDRAM_OPTIONAL;
|
|
||||||
#endif
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
class Heap {
|
class Heap {
|
||||||
public:
|
public:
|
||||||
|
@ -95,28 +89,17 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static Heap heaps[] = { luaUserHeap,
|
static Heap userHeap(luaUserHeap);
|
||||||
#if LUA_SYSTEM_HEAP > 1
|
|
||||||
luaSystemHeap
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
template <int HeapIdx>
|
|
||||||
static void* myAlloc(void* /*ud*/, void* ptr, size_t osize, size_t nsize) {
|
static void* myAlloc(void* /*ud*/, void* ptr, size_t osize, size_t nsize) {
|
||||||
static_assert(HeapIdx < efi::size(heaps));
|
|
||||||
|
|
||||||
if (engineConfiguration->debugMode == DBG_LUA) {
|
if (engineConfiguration->debugMode == DBG_LUA) {
|
||||||
switch (HeapIdx) {
|
engine->outputChannels.debugIntField1 = userHeap.used();
|
||||||
case 0: engine->outputChannels.debugIntField1 = heaps[HeapIdx].used(); break;
|
|
||||||
case 1: engine->outputChannels.debugIntField2 = heaps[HeapIdx].used(); break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return heaps[HeapIdx].realloc(ptr, osize, nsize);
|
return userHeap.realloc(ptr, osize, nsize);
|
||||||
}
|
}
|
||||||
#else // not EFI_PROD_CODE
|
#else // not EFI_PROD_CODE
|
||||||
// Non-MCU code can use plain realloc function instead of custom implementation
|
// Non-MCU code can use plain realloc function instead of custom implementation
|
||||||
template <int /*ignored*/>
|
|
||||||
static void* myAlloc(void* /*ud*/, void* ptr, size_t /*osize*/, size_t nsize) {
|
static void* myAlloc(void* /*ud*/, void* ptr, size_t /*osize*/, size_t nsize) {
|
||||||
if (!nsize) {
|
if (!nsize) {
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
@ -197,35 +180,6 @@ static bool loadScript(LuaHandle& ls, const char* scriptStr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static LuaHandle systemLua;
|
|
||||||
|
|
||||||
const char* getSystemLuaScript();
|
|
||||||
|
|
||||||
void initSystemLua() {
|
|
||||||
#if LUA_SYSTEM_HEAP > 1
|
|
||||||
efiAssertVoid(OBD_PCM_Processor_Fault, !systemLua, "system lua already init");
|
|
||||||
|
|
||||||
Timer startTimer;
|
|
||||||
startTimer.reset();
|
|
||||||
|
|
||||||
systemLua = setupLuaState(myAlloc<1>);
|
|
||||||
|
|
||||||
efiAssertVoid(OBD_PCM_Processor_Fault, systemLua, "system lua init fail");
|
|
||||||
|
|
||||||
if (!loadScript(systemLua, getSystemLuaScript())) {
|
|
||||||
firmwareError(OBD_PCM_Processor_Fault, "system lua script load fail");
|
|
||||||
systemLua = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto startTime = startTimer.getElapsedSeconds();
|
|
||||||
|
|
||||||
#if !EFI_UNIT_TEST
|
|
||||||
efiPrintf("System Lua loaded in %.2f ms using %d bytes", startTime * 1'000, heaps[1].used());
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !EFI_UNIT_TEST
|
#if !EFI_UNIT_TEST
|
||||||
static bool interactivePending = false;
|
static bool interactivePending = false;
|
||||||
static char interactiveCmd[100];
|
static char interactiveCmd[100];
|
||||||
|
@ -352,10 +306,8 @@ static bool runOneLua(lua_Alloc alloc, const char* script) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaThread::ThreadTask() {
|
void LuaThread::ThreadTask() {
|
||||||
//initSystemLua();
|
|
||||||
|
|
||||||
while (!chThdShouldTerminateX()) {
|
while (!chThdShouldTerminateX()) {
|
||||||
bool wasOk = runOneLua(myAlloc<0>, config->luaScript);
|
bool wasOk = runOneLua(myAlloc, config->luaScript);
|
||||||
|
|
||||||
// Reset any lua adjustments the script made
|
// Reset any lua adjustments the script made
|
||||||
engine->engineState.luaAdjustments = {};
|
engine->engineState.luaAdjustments = {};
|
||||||
|
@ -382,7 +334,7 @@ void startLua() {
|
||||||
// cute hack: let's check at runtime if you are a lucky owner of microRusEFI with extra RAM and use that extra RAM for extra Lua
|
// cute hack: let's check at runtime if you are a lucky owner of microRusEFI with extra RAM and use that extra RAM for extra Lua
|
||||||
if (isStm32F42x()) {
|
if (isStm32F42x()) {
|
||||||
char *buffer = (char *)0x20020000;
|
char *buffer = (char *)0x20020000;
|
||||||
heaps[0].reinit(buffer, 60000);
|
userHeap.reinit(buffer, 60000);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -409,27 +361,23 @@ void startLua() {
|
||||||
});
|
});
|
||||||
|
|
||||||
addConsoleAction("luamemory", [](){
|
addConsoleAction("luamemory", [](){
|
||||||
for (size_t i = 0; i < efi::size(heaps); i++) {
|
auto heapSize = userHeap.size();
|
||||||
auto heapSize = heaps[i].size();
|
auto memoryUsed = userHeap.used();
|
||||||
auto memoryUsed = heaps[i].used();
|
float pct = 100.0f * memoryUsed / heapSize;
|
||||||
float pct = 100.0f * memoryUsed / heapSize;
|
efiPrintf("Lua memory heap usage: %d / %d bytes = %.1f%%", memoryUsed, heapSize, pct);
|
||||||
efiPrintf("Lua memory heap %d: %d / %d bytes = %.1f%%", i, memoryUsed, heapSize, pct);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // not EFI_UNIT_TEST
|
#else // not EFI_UNIT_TEST
|
||||||
|
|
||||||
void startLua() {
|
void startLua() { }
|
||||||
initSystemLua();
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
static LuaHandle runScript(const char* script) {
|
static LuaHandle runScript(const char* script) {
|
||||||
auto ls = setupLuaState(myAlloc<0>);
|
auto ls = setupLuaState(myAlloc);
|
||||||
|
|
||||||
if (!ls) {
|
if (!ls) {
|
||||||
throw std::logic_error("Call to setupLuaState failed, returned null");
|
throw std::logic_error("Call to setupLuaState failed, returned null");
|
||||||
|
@ -495,7 +443,7 @@ int testLuaReturnsInteger(const char* script) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void testLuaExecString(const char* script) {
|
void testLuaExecString(const char* script) {
|
||||||
auto ls = setupLuaState(myAlloc<0>);
|
auto ls = setupLuaState(myAlloc);
|
||||||
|
|
||||||
if (!ls) {
|
if (!ls) {
|
||||||
throw std::logic_error("Call to setupLuaState failed, returned null");
|
throw std::logic_error("Call to setupLuaState failed, returned null");
|
||||||
|
|
|
@ -6,7 +6,6 @@ ALLCPPSRC += $(LUA_DIR)/lua.cpp \
|
||||||
$(LUA_DIR)/lua_hooks_util.cpp \
|
$(LUA_DIR)/lua_hooks_util.cpp \
|
||||||
$(LUA_DIR)/generated/output_lookup_generated.cpp \
|
$(LUA_DIR)/generated/output_lookup_generated.cpp \
|
||||||
$(LUA_DIR)/generated/value_lookup_generated.cpp \
|
$(LUA_DIR)/generated/value_lookup_generated.cpp \
|
||||||
$(LUA_DIR)/system_lua.cpp \
|
|
||||||
$(LUA_DIR)/lua_can_rx.cpp \
|
$(LUA_DIR)/lua_can_rx.cpp \
|
||||||
|
|
||||||
ALLINC += $(LUA_DIR) $(LUA_DIR)/luaaa $(LUA_EXT)
|
ALLINC += $(LUA_DIR) $(LUA_DIR)/luaaa $(LUA_EXT)
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
const char* getSystemLuaScript() {
|
|
||||||
return R"LUASCRIPT(
|
|
||||||
|
|
||||||
function getConfig(x)
|
|
||||||
return x
|
|
||||||
end
|
|
||||||
|
|
||||||
primeTimer = Timer.new()
|
|
||||||
primeTimer:reset();
|
|
||||||
|
|
||||||
function pumpLogic()
|
|
||||||
local prime = primeTimer:getElapsedSeconds() > getConfig(0)
|
|
||||||
local spinning = getTimeSinceTrigger() < 1
|
|
||||||
|
|
||||||
return prime or spinning
|
|
||||||
end
|
|
||||||
|
|
||||||
)LUASCRIPT";
|
|
||||||
}
|
|
Loading…
Reference in New Issue