kernelsauce / turbo

Turbo is a framework built for LuaJIT 2 to simplify the task of building fast and scalable network applications. It uses a event-driven, non-blocking, no thread design to deliver excellent performance and minimal footprint to high-load applications while also providing excellent support for embedded uses.
http://turbo.readthedocs.io/
Apache License 2.0
528 stars 84 forks source link

MIPS not currently supported. #183

Closed ykhuang closed 9 years ago

ykhuang commented 9 years ago

I made a cross build on my MIPS box. Some error happened when including turbo package. This didn't happen on x86 environment.

# luajit helloworld.lua
luajit: /usr/local/share/lua/5.1/turbo/util.lua:92: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
        [C]: in function 'pairs'
        /usr/local/share/lua/5.1/turbo/util.lua:92: in function </usr/local/share/lua/5.1/turbo/util.lua:91>
        [C]: in function 'require'
        /usr/local/share/lua/5.1/turbo/fs.lua:18: in main chunk
        [C]: in function 'require'
        /usr/local/share/lua/5.1/turbo/web.lua:35: in main chunk
        [C]: in function 'require'
        /usr/local/share/lua/5.1/turbo.lua:98: in main chunk
        [C]: in function 'require'
        helloworld.lua:17: in main chunk
        [C]: at 0x00403e7c

Looks like it stuck at returning syscall

# luajit
LuaJIT 2.0.3 -- Copyright (C) 2005-2014 Mike Pall. http://luajit.org/
JIT: ON fold cse dce fwd dse narrow loop abc sink fuse
> local syscall = require "turbo.syscall"
/usr/local/share/lua/5.1/turbo/util.lua:92: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
        [C]: in function 'pairs'
        /usr/local/share/lua/5.1/turbo/util.lua:92: in function </usr/local/share/lua/5.1/turbo/util.lua:91>
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: at 0x00403e7c
>

In syscall, it calls util.mergetable. Seems the error happens while it tries to merge 2 tables in syscall.

Here's how I build turbo lua. CC=mipsel-linux-gcc SSL=none make CC=mipsel-linux-gcc SSL=none make install

And I build LuaJIT like make HOST_CC="gcc -m32" CROSS=mipsel-linux-

kernelsauce commented 9 years ago

Hi, yes MIPS is so far untested. I'm guessing it could work, but you would need to make sure that there are correct constant defs for Linux MIPS...

The error message is kind of misleading, what is actually happening is that the tail call in syscall.lua:

return tm(flags, cmds)

does a table merge of a non existing table. There are no section for "mips" in that file as you see. So feel free to add one and do a pull request. E.g:

elseif ffi.arch == "mips" then

I do not have a system to test mips. There could be other things, but I think that was the effort someone which used this on a ppc had to go through... https://github.com/kernelsauce/turbo/blob/master/turbo/syscall.lua

Ask me if there is something you do not understand.

ykhuang commented 9 years ago

Yes, you are correct.

I made some fix to syscall.lua & socket_ffi.lua and the helloworld example works. I'll check if the rest of the examples work well.

kernelsauce commented 9 years ago

Please put the changes in a pull request if you can. :)

ykhuang commented 9 years ago

Hi I'm testing static.lua and met some problem that might be platform dependent because it does not happen on x86. In fs.lua, ffi.typeof is called to get ctype of "struct stat" and I got below result. It looks like error from LuaJIT. Is there any way to fix it without making any change to LuaJIT? If we use a complete struct like "struct point { int a; int b }" and the call is fine. I think LuaJIT jsut can't find the definition of "struct stat".

.# luajit LuaJIT 2.0.3 -- Copyright (C) 2005-2014 Mike Pall. http://luajit.org/ JIT: ON MIPS32R2 fold cse dce fwd dse narrow loop abc sink fuse

ffi = require "ffi" stat_t = ffi.typeof("struct stat") stdin:1: undeclared or implicit tag 'stat' stack traceback:         [C]: in function 'typeof'         stdin:1: in main chunk         [C]: at 0x00403e7c

kernelsauce commented 9 years ago

Look at line 343 in cdef.lua.

struct stat is not declared there for this platform... Just add the correct definition got this platform any you should be good to go.

kernelsauce commented 9 years ago

@YuanPeir-Chen I suppose this is ready to go into v2.0?

YuanPeir-Chen commented 9 years ago

Yes, It works for me.