Skip to content

Initial LuaJIT interpreter load #1658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2023

Conversation

jturnsek
Copy link
Contributor

Summary

LuaJIT is Lua interpreter and Just-In-Time compiler. Originally it is not supporting Thumb instruction set (which all Cortex M processors are using), thus this PR is introducing ARMv7-M instruction set for LuaJIT. Because LuaJIT relies heavily on double precision floating point numbers, DFP unit is required. It has also Soft FPU configuration, but it was not tested on Cortex M devices.
Original LuaJIT uses MMU for machine code and Lua object memory allocation, but with NuttX configuration I have introduced two MM heap regions: one in ITCM for hotloop traces allocation, and one in RAM for Lua object allocation. All allocations are done with fixed size chunks, because LuaJIT is using its own heap allocation algorithm. MCode allocations are 8KB and object allocations are 32KB long. DTCM is used for standard data and heap.

Impact

Testing

LuaJIT was tested on imxrt1064-evk board with the following configuration:

CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="imxrt1064-evk"
CONFIG_ARCH_BOARD_IMXRT1064_EVK=y
CONFIG_ARCH_CHIP="imxrt"
CONFIG_ARCH_CHIP_IMXRT=y
CONFIG_ARCH_CHIP_MIMXRT1064DVL6A=y
CONFIG_ARCH_FLOAT_H=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_BASEPRI_WAR=y
CONFIG_ARMV7M_DCACHE=y
CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
CONFIG_ARMV7M_DTCM=y
CONFIG_ARMV7M_ICACHE=y
CONFIG_ARMV7M_ITCM=y
CONFIG_ARMV7M_USEBASEPRI=y
CONFIG_BOARD_LOOPSPERMSEC=104926
CONFIG_BUILTIN=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_GPIO=y
CONFIG_DEV_GPIO_NSIGNALS=20
CONFIG_FS_LITTLEFS=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_IMXRT_DTCM=256
CONFIG_IMXRT_FLEXSPI1=y
CONFIG_IMXRT_LPUART1=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=4096
CONFIG_INTELHEX_BINARY=y
CONFIG_INTERPRETERS_LUAJIT=y
CONFIG_LIBC_DLFCN=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBC_LOCALE=y
CONFIG_LPUART1_BAUD=9600
CONFIG_LPUART1_SERIAL_CONSOLE=y
CONFIG_MTD=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_DISABLE_IFUPDOWN=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_NSH_VARS=y
CONFIG_PIPES=y
CONFIG_PRIORITY_INHERITANCE=y
CONFIG_RAM_SIZE=262144
CONFIG_RAM_START=0x20000000
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_SERIAL_TERMIOS=y
CONFIG_SIG_DEFAULT=y
CONFIG_SIG_SIGALRM_ACTION=y
CONFIG_SIG_SIGPIPE_ACTION=y
CONFIG_SIG_SIGPROF_ACTION=y
CONFIG_SIG_SIGUSR1_ACTION=y
CONFIG_SIG_SIGUSR2_ACTION=y
CONFIG_START_DAY=14
CONFIG_START_MONTH=3
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_POPEN=y
CONFIG_SYSTEM_SYSTEM=y
CONFIG_SYSTEM_VI=y
CONFIG_TTY_SIGINT=y
CONFIG_TTY_SIGTSTP=y

WARNING: Original linker script flash.ld was changed to use dtcm, instead of sram. Following memory allocation was used: 128KB ITCM, 256KB DTCM, 640KB OCRAM.

@jturnsek jturnsek force-pushed the feature/luajit branch 3 times, most recently from ff60510 to b8a6610 Compare March 13, 2023 07:54
@xiaoxiang781216
Copy link
Contributor

@jturnsek do you have plan upstream amv7m support to luajit?

@jturnsek
Copy link
Contributor Author

do you have plan upstream amv7m support to luajit?

Uff, yes I have been thinking about it, but not in the near future due to high work load.

@jturnsek
Copy link
Contributor Author

@xiaoxiang781216 BTW, regarding the UNUSED macro, which was not working with LuaJIT code. I have undefed the macro in LuaJIT patch and then the builtin macro in LuaJIT is used. But for the future reference, I think the UNUSED macro in NuttX compiler.h is wrong. If it is not working for LuaJIT, it might not work for other libraries taken from Linux world.

@xiaoxiang781216
Copy link
Contributor

@xiaoxiang781216 BTW, regarding the UNUSED macro, which was not working with LuaJIT code. I have undefed the macro in LuaJIT patch and then the builtin macro in LuaJIT is used. But for the future reference, I think the UNUSED macro in NuttX compiler.h is wrong. If it is not working for LuaJIT, it might not work for other libraries taken from Linux world.

could you provide a patch to make both side happy?

@jturnsek
Copy link
Contributor Author

could you provide a patch to make both side happy?

What was wrong with plain old #define UNUSED(x) ((void)(x))?

@xiaoxiang781216
Copy link
Contributor

see the case here: apache/nuttx#6779

@jturnsek
Copy link
Contributor Author

jturnsek commented Mar 14, 2023

see the case here: apache/nuttx#6779

I would say let that library handle the special case when structure is passed as parameter to the function and leave the UNUSED macro as it was. One macro can never satisfy all the cases.
I do not get what an author of cmd_ifconfig did with UNUSED(gip6). If this gip6 is not used in function, it could get thrown out with simple ifdef and not with UNUSED macro. It seems to me that one was abusing UNUSED macro.

@xiaoxiang781216 xiaoxiang781216 merged commit e599bbc into apache:master Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants