Skip to content

Commit

Permalink
Merge branch 'raptorjit/master' into auditlog
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Aug 6, 2018
2 parents 53eb6ae + a4f36d3 commit 7e74425
Show file tree
Hide file tree
Showing 7 changed files with 770 additions and 744 deletions.
20 changes: 19 additions & 1 deletion src/lj_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,23 @@ static void asm_setup_regsp(ASMState *as)

/* -- Assembler core ------------------------------------------------------ */

/* Do we want the profiler to attribute VM time to this trace?
*
* Not if the root of this trace is a Lua function. We assume that the
* root cause of running the interpreter is a loop that failed to
* compile somewhere and that entry/exit through function traces is
* only noise that should be filtered out.
*
* This helps the profiler to point out the code that needs to be
* changed to reduce time spent in the interpreter.
*/
static int asm_should_profile_exit(jit_State *J, GCtrace *T)
{
GCtrace *root = traceref(J, T->root ? T->root : T->traceno);
BCOp op = bc_op(root->startins);
return op != BC_FUNCF && op != BC_FUNCV;
}

/* Assemble a trace. */
void lj_asm_trace(jit_State *J, GCtrace *T)
{
Expand Down Expand Up @@ -2107,7 +2124,8 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
T->mcode = as->mcp;
T->mcloop = as->mcloop ? (MSize)((char *)as->mcloop - (char *)as->mcp) : 0;
if (!as->loopref)
asm_tail_fixup(as, T->link); /* Note: this may change as->mctop! */
/* Note: this may change as->mctop! */
asm_tail_fixup(as, T->link, asm_should_profile_exit(J, T));
T->szmcode = (MSize)((char *)as->mctop - (char *)as->mcp);
lj_mcode_sync(T->mcode, origtop);
}
Expand Down
6 changes: 4 additions & 2 deletions src/lj_asm_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -2273,7 +2273,7 @@ static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)
/* -- Tail of trace ------------------------------------------------------- */

/* Fixup the tail code. */
static void asm_tail_fixup(ASMState *as, TraceNo lnk)
static void asm_tail_fixup(ASMState *as, TraceNo lnk, int track)
{
/* Note: don't use as->mcp swap + emit_*: emit_op overwrites more bytes. */
MCode *p = as->mctop;
Expand Down Expand Up @@ -2304,7 +2304,9 @@ static void asm_tail_fixup(ASMState *as, TraceNo lnk)
}
}
/* Patch exit branch. */
target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;
target = (lnk ? traceref(as->J, lnk)->mcode :
(track ? (MCode *)lj_vm_exit_interp :
(MCode *)lj_vm_exit_interp_notrack));
*(int32_t *)(p-4) = jmprel(p, target);
p[-5] = XI_JMP;
/* Drop unused mcode tail. Fill with NOPs to make the prefetcher happy. */
Expand Down
1 change: 1 addition & 0 deletions src/lj_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ LJ_ASMF void lj_vm_callhook(void);
/* Trace exit handling. */
LJ_ASMF void lj_vm_exit_handler(void);
LJ_ASMF void lj_vm_exit_interp(void);
LJ_ASMF void lj_vm_exit_interp_notrack(void);

/* Internal math helper functions. */
LJ_ASMF double lj_vm_floor(double);
Expand Down
8 changes: 4 additions & 4 deletions src/lj_vmprofile.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ static void start_timer(int interval)
struct sigaction sa;
tm.it_value.tv_sec = tm.it_interval.tv_sec = interval / 1000;
tm.it_value.tv_usec = tm.it_interval.tv_usec = (interval % 1000) * 1000;
setitimer(ITIMER_PROF, &tm, NULL);
setitimer(ITIMER_VIRTUAL, &tm, NULL);
sa.sa_flags = SA_SIGINFO | SA_RESTART;
sa.sa_sigaction = vmprofile_signal;
sigemptyset(&sa.sa_mask);
sigaction(SIGPROF, &sa, &state.oldsa);
sigaction(SIGVTALRM, &sa, &state.oldsa);
}

static void stop_timer()
{
struct itimerval tm;
tm.it_value.tv_sec = tm.it_interval.tv_sec = 0;
tm.it_value.tv_usec = tm.it_interval.tv_usec = 0;
setitimer(ITIMER_PROF, &tm, NULL);
sigaction(SIGPROF, NULL, &state.oldsa);
setitimer(ITIMER_VIRTUAL, &tm, NULL);
sigaction(SIGVTALRM, NULL, &state.oldsa);
}

/* -- State that the application can manage via FFI ----------------------- */
Expand Down
Loading

0 comments on commit 7e74425

Please sign in to comment.