Skip to content

Commit

Permalink
Merge snabbco#98 branch 'szirmcode' into auditlog
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Sep 3, 2017
2 parents 48be218 + ad14f45 commit e4a76f8
Show file tree
Hide file tree
Showing 28 changed files with 487 additions and 303 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ default all $(INSTALL_DEP):
$(MAKE) -C src
@echo "==== Successfully built RaptorJIT $(VERSION) ===="

reusevm:
$(MAKE) -C src reusevm

install: $(INSTALL_DEP)
@echo "==== Installing RaptorJIT $(VERSION) to $(PREFIX) ===="
$(MKDIR) $(INSTALL_DIRS)
Expand Down
79 changes: 31 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,31 @@

[![Build Status](https://travis-ci.org/raptorjit/raptorjit.svg?branch=master)](https://travis-ci.org/raptorjit/raptorjit)

**RaptorJIT** is a fork of LuaJIT targeting Linux/x86-64 server applications.
**RaptorJIT** is a fork of LuaJIT focused on _predictably high performance_.

Initial changes (ongoing work):
Making performance predictable for application developers brings new requirements:

- Support only Linux/x86-64 with `+JIT +FFI +GC64 +NO_UNWIND` and `-GDBJIT
-PERFTOOLS -VMEVENT -PROFILE` and otherwise canonical settings.
Remove the ~50,000 lines of code for other architectures, operating
systems, and features.
- Remove features that are not the right thing for my use cases:
built-in disassemblers, `jit.v`, `jit.p`, `jit.dump`, and the VM
features required to support them. These need to be replaced with
simple and low-overhead mechanisms that provide data to be analyzed
be external tools. (Tools will be developed in
the [Studio](https://github.com/studio) project.)
- Continuous Integration testing
with [Travis-CI](https://travis-ci.org/raptorjit/raptorjit) and
with [automatic performance regression tests](https://hydra.snabb.co/job/luajit/branchmarks/benchmarkResults/latest/download/2).
- Minimizing the performance impact of non-deterministic JIT decisions.
- Providing an accurate mental model of how the JIT works and which programming techniques are effective.
- Providing diagnostic tools ([Studio](https://hydra.snabb.co/job/lukego/studio-manual/studio-manual-html/latest/download-by-type/file/Manual#view-hot-traces)) consistent with this mental model to make the actual operation transparent.
- Making profiling completely ubiquitous in development, testing, and production environments.

PRs welcome! Shock me with your radical ideas! :-)
The development process has to support moving quickly in these directions:

### CPU support
- Quality assurance based on repeatable standard benchmarks executed by CI.
- Streamlined codebase: x86-64 architecture, 64-bit heap (GC64), "no `#ifdef`."
- Distributed development ("Linux-style") with many maintainers, forks, and merges.

RaptorJIT is narrowly focused:

- [Intel Core](https://en.wikipedia.org/wiki/Intel_Core) (i3/i5/i7/Xeon-E) is the only supported CPU family.
- The latest microarchitecture (currently Skylake) is targetted for all new optimizations.
- The previous microarchitecture (currently Haswell) is supported without regressions.
- Older microarchitectures (currently Sandy Bridge and Nehalem) are not supported at all.

We are flexible during the transitions between processor generations
e.g. when the latest microarchitecture is not readily available in all
product families.

Forks focused on other CPU families (Atom, Xeon Phi, AMD, VIA, etc)
are encouraged and may be merged in the future.
Once these requirements have been thoroughly satisfied then new
requirements can be introduced. For example, ARM64 and other platforms
can be supported as the project matures.

### Performance

RaptorJIT takes a quantitive approach to performance. The value of an
optimization must be demonstrated by a reproducible benchmark.
Optimizations that are not demonstrably beneficial for the currently
supported CPUs are removed.
optimization must be demonstrated with a reproducible benchmark.
Optimizations that are not demonstrably beneficial on recent CPU
generations are removed.

This makes the following classes of pull requests very welcome:

Expand All @@ -53,21 +36,6 @@ This makes the following classes of pull requests very welcome:

The CI benchmark suite will evolve over time starting from the [standard LuaJIT benchmarks](https://hydra.snabb.co/job/luajit/branchmarks/benchmarkResults/latest/download/2) (already covers RaptorJIT) and the [Snabb end-to-end benchmark suite](https://hydra.snabb.co/job/snabb-new-tests/benchmarks-murren-large/benchmark-reports.report-full-matrix/latest/download/2) (must be updated to cover RaptorJIT.)

### Optimization resources

These are the authoritative optimization resources for processors
supported by RaptorJIT. If you are confused by references to CPU
details in discussions then these are the places to look for answers.

- [Computer Architecture: A Quantitiave Approach](https://www.amazon.com/Computer-Architecture-Fifth-Quantitative-Approach/dp/012383872X) by Hennessy and Patterson.
- [Intel Architectures Optimization Reference Manual](http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-optimization-manual.html).
- Agner Fog's [software optimization resources](http://www.agner.org/optimize/):
- [Instruction latency and throughput tables](http://www.agner.org/optimize/instruction_tables.pdf).
- [Microarchitecture of Intel, AMD, and VIA CPUs](http://www.agner.org/optimize/microarchitecture.pdf).
- [Optimizing subroutines in assembly language for x86](http://www.agner.org/optimize/optimizing_assembly.pdf).

The [AnandTech review of the Haswell microarchitecture](http://www.anandtech.com/show/6355/intels-haswell-architecture) is also excellent lighter reading.

### Compilation for users

Simple build:
Expand Down Expand Up @@ -165,6 +133,21 @@ as [Hydra](https://nixos.org/hydra/) then the tests can be
automatically parallelized and distributed across a suitable build
farm.

### Optimization resources

These are the authoritative optimization resources for processors
supported by RaptorJIT. If you are confused by references to CPU
details in discussions then these are the places to look for answers.

- [Computer Architecture: A Quantitiave Approach](https://www.amazon.com/Computer-Architecture-Fifth-Quantitative-Approach/dp/012383872X) by Hennessy and Patterson.
- [Intel Architectures Optimization Reference Manual](http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-optimization-manual.html).
- Agner Fog's [software optimization resources](http://www.agner.org/optimize/):
- [Instruction latency and throughput tables](http://www.agner.org/optimize/instruction_tables.pdf).
- [Microarchitecture of Intel, AMD, and VIA CPUs](http://www.agner.org/optimize/microarchitecture.pdf).
- [Optimizing subroutines in assembly language for x86](http://www.agner.org/optimize/optimizing_assembly.pdf).

The [AnandTech review of the Haswell microarchitecture](http://www.anandtech.com/show/6355/intels-haswell-architecture) is also excellent lighter reading.

### Quotes

Here are some borrowed words to put this branch into context:
Expand Down
3 changes: 1 addition & 2 deletions doc/ext_ffi_semantics.html
Original file line number Diff line number Diff line change
Expand Up @@ -1221,13 +1221,12 @@ <h2 id="status">Current Status</h2>
suboptimal performance, especially when used in inner loops:
</p>
<ul>
<li>Bitfield accesses and initializations.</li>
<li>Vector operations.</li>
<li>Table initializers.</li>
<li>Initialization of nested <tt>struct</tt>/<tt>union</tt> types.</li>
<li>Non-default initialization of VLA/VLS or large C&nbsp;types
(&gt; 128&nbsp;bytes or &gt; 16 array elements.</li>
<li>Conversions from lightuserdata to <tt>void&nbsp;*</tt>.</li>
<li>Bitfield initializations.</li>
<li>Pointer differences for element sizes that are not a power of
two.</li>
<li>Calls to C&nbsp;functions with aggregates passed or returned by
Expand Down
24 changes: 24 additions & 0 deletions doc/extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,26 @@ <h2 id="lua52">Extensions from Lua 5.2</h2>
<li><tt>debug.getupvalue()</tt> and <tt>debug.setupvalue()</tt> handle
C&nbsp;functions.</li>
<li><tt>debug.upvalueid()</tt> and <tt>debug.upvaluejoin()</tt>.</li>
<li>Lua/C API extensions:
<tt>lua_version()</tt>
<tt>lua_upvalueid()</tt>
<tt>lua_upvaluejoin()</tt>
<tt>lua_loadx()</tt>
<tt>lua_copy()</tt>
<tt>lua_tonumberx()</tt>
<tt>lua_tointegerx()</tt>
<tt>luaL_fileresult()</tt>
<tt>luaL_execresult()</tt>
<tt>luaL_loadfilex()</tt>
<tt>luaL_loadbufferx()</tt>
<tt>luaL_traceback()</tt>
<tt>luaL_setfuncs()</tt>
<tt>luaL_pushmodule()</tt>
<tt>luaL_newlibtable()</tt>
<tt>luaL_newlib()</tt>
<tt>luaL_testudata()</tt>
<tt>luaL_setmetatable()</tt>
</li>
<li>Command line option <tt>-E</tt>.</li>
<li>Command line checks <tt>__tostring</tt> for errors.</li>
</ul>
Expand All @@ -338,6 +358,7 @@ <h2 id="lua52">Extensions from Lua 5.2</h2>
<li><tt>debug.getuservalue()</tt> and <tt>debug.setuservalue()</tt>.</li>
<li>Remove <tt>math.mod()</tt>, <tt>string.gfind()</tt>.</li>
<li><tt>package.searchers</tt>.</li>
<li><tt>module()</tt> returns the module table.</li>
</ul>
<p>
Note: this provides only partial compatibility with Lua 5.2 at the
Expand All @@ -355,6 +376,9 @@ <h2 id="lua53">Extensions from Lua 5.3</h2>
<li><tt>io.read()</tt> and <tt>file:read()</tt> accept formats with or without a leading <tt>*</tt>.</li>
<li><tt>table.move(a1, f, e, t [,a2])</tt>.</li>
<li><tt>coroutine.isyieldable()</tt>.</li>
<li>Lua/C API extensions:
<tt>lua_isyieldable()</tt>
</li>
</ul>

<h2 id="exceptions">C++ Exception Interoperability</h2>
Expand Down
34 changes: 14 additions & 20 deletions src/lauxlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include "lua.h"


#define luaL_getn(L,i) ((int)lua_objlen(L, i))
#define luaL_setn(L,i,j) ((void)0) /* no op! */

/* extra error code for `luaL_load' */
#define LUA_ERRFILE (LUA_ERRERR+1)

Expand Down Expand Up @@ -58,6 +55,10 @@ LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
const char *const lst[]);

/* pre-defined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)

LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);

Expand All @@ -84,6 +85,11 @@ LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
const char *name, const char *mode);
LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
int level);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
int sizehint);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);


/*
Expand Down Expand Up @@ -113,6 +119,11 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,

#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))

/* From Lua 5.2. */
#define luaL_newlibtable(L, l) \
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
#define luaL_newlib(L, l) (luaL_newlibtable(L, l), luaL_setfuncs(L, l, 0))

/*
** {======================================================
** Generic Buffer manipulation
Expand Down Expand Up @@ -147,21 +158,4 @@ LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);

/* }====================================================== */


/* compatibility with ref system */

/* pre-defined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)

#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
(lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))

#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))

#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))


#define luaL_reg luaL_Reg

#endif
57 changes: 34 additions & 23 deletions src/lib_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,38 +97,36 @@ LUALIB_API const char *luaL_findtable(lua_State *L, int idx,
static int libsize(const luaL_Reg *l)
{
int size = 0;
for (; l->name; l++) size++;
for (; l && l->name; l++) size++;
return size;
}

LUALIB_API void luaL_pushmodule(lua_State *L, const char *modname, int sizehint)
{
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
lua_getfield(L, -1, modname);
if (!lua_istable(L, -1)) {
lua_pop(L, 1);
if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, sizehint) != NULL)
lj_err_callerv(L, LJ_ERR_BADMODN, modname);
lua_pushvalue(L, -1);
lua_setfield(L, -3, modname); /* _LOADED[modname] = new table. */
}
lua_remove(L, -2); /* Remove _LOADED table. */
}

LUALIB_API void luaL_openlib(lua_State *L, const char *libname,
const luaL_Reg *l, int nup)
{
lj_lib_checkfpu(L);
if (libname) {
int size = libsize(l);
/* check whether lib already exists */
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
lua_getfield(L, -1, libname); /* get _LOADED[libname] */
if (!lua_istable(L, -1)) { /* not found? */
lua_pop(L, 1); /* remove previous result */
/* try global variable (and create one if it does not exist) */
if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
lj_err_callerv(L, LJ_ERR_BADMODN, libname);
lua_pushvalue(L, -1);
lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
}
lua_remove(L, -2); /* remove _LOADED table */
lua_insert(L, -(nup+1)); /* move library table to below upvalues */
}
for (; l->name; l++) {
int i;
for (i = 0; i < nup; i++) /* copy upvalues to the top */
lua_pushvalue(L, -nup);
lua_pushcclosure(L, l->func, nup);
lua_setfield(L, -(nup+2), l->name);
luaL_pushmodule(L, libname, libsize(l));
lua_insert(L, -(nup + 1)); /* Move module table below upvalues. */
}
lua_pop(L, nup); /* remove upvalues */
if (l)
luaL_setfuncs(L, l, nup);
else
lua_pop(L, nup); /* Remove upvalues. */
}

LUALIB_API void luaL_register(lua_State *L, const char *libname,
Expand All @@ -137,6 +135,19 @@ LUALIB_API void luaL_register(lua_State *L, const char *libname,
luaL_openlib(L, libname, l, 0);
}

LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
{
luaL_checkstack(L, nup, "too many upvalues");
for (; l->name; l++) {
int i;
for (i = 0; i < nup; i++) /* Copy upvalues to the top. */
lua_pushvalue(L, -nup);
lua_pushcclosure(L, l->func, nup);
lua_setfield(L, -(nup + 2), l->name);
}
lua_pop(L, nup); /* Remove upvalues. */
}

LUALIB_API const char *luaL_gsub(lua_State *L, const char *s,
const char *p, const char *r)
{
Expand Down
8 changes: 4 additions & 4 deletions src/lib_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ LJLIB_ASM_(xpcall) LJLIB_REC(.)

static int load_aux(lua_State *L, int status, int envarg)
{
if (status == 0) {
if (status == LUA_OK) {
if (tvistab(L->base+envarg-1)) {
GCfunc *fn = funcV(L->top-1);
GCtab *t = tabV(L->base+envarg-1);
Expand Down Expand Up @@ -401,7 +401,7 @@ LJLIB_CF(dofile)
GCstr *fname = lj_lib_optstr(L, 1);
setnilV(L->top);
L->top = L->base+1;
if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != 0)
if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != LUA_OK)
lua_error(L);
lua_call(L, 0, LUA_MULTRET);
return (int)(L->top - L->base) - 1;
Expand Down Expand Up @@ -519,7 +519,7 @@ LJLIB_CF(coroutine_status)
co = threadV(L->base);
if (co == L) s = "running";
else if (co->status == LUA_YIELD) s = "suspended";
else if (co->status != 0) s = "dead";
else if (co->status != LUA_OK) s = "dead";
else if (co->base > tvref(co->stack)+1+LJ_FR2) s = "normal";
else if (co->top == co->base) s = "dead";
else s = "suspended";
Expand Down Expand Up @@ -565,7 +565,7 @@ LJLIB_ASM(coroutine_yield)
static int ffh_resume(lua_State *L, lua_State *co, int wrap)
{
if (co->cframe != NULL || co->status > LUA_YIELD ||
(co->status == 0 && co->top == co->base)) {
(co->status == LUA_OK && co->top == co->base)) {
ErrMsg em = co->cframe ? LJ_ERR_CORUN : LJ_ERR_CODEAD;
if (wrap) lj_err_caller(L, em);
setboolV(L->base-1-LJ_FR2, 0);
Expand Down
4 changes: 0 additions & 4 deletions src/lib_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ LUALIB_API int luaopen_math(lua_State *L)
rs = (RandomState *)lua_newuserdata(L, sizeof(RandomState));
rs->valid = 0; /* Use lazy initialization to save some time on startup. */
LJ_LIB_REG(L, LUA_MATHLIBNAME, math);
#if defined(LUA_COMPAT_MOD) && !LJ_52
lua_getfield(L, -1, "fmod");
lua_setfield(L, -2, "mod");
#endif
return 1;
}

Loading

0 comments on commit e4a76f8

Please sign in to comment.