-
Notifications
You must be signed in to change notification settings - Fork 577
Safe signals slowdown #10222
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
Comments
From @nwc10Perl 5.8.0 introduced "safe" signals, which changed signal handling to have int TAINT_NOT; was changed to check for and dispatch pending signals between ops, by changing #ifndef PERL_ASYNC_CHECK to this: #ifndef PERL_MICRO #ifndef PERL_ASYNC_CHECK (PERL_ASYNC_CHECK was originally added for MacOS classic. Classic is now gone) PERL_ASYNC_CHECK is also present in the restart loops of various IO ops. At the time this was believed to cause a slowdown, and IIRC a figure given (Change PERL_ASYNC_CHECK to NOOP, and force unsafe signals. Quite a few Anyway, on IRC Reini Urban was investigating unrolling the OP loop, as part of IIRC some time ago Leo was working on JITting the parrot, and took the So I tried removing PERL_ASYNC_CHECK from the oploop, and putting into The last one might be overkill, but originally I didn't have POP_BLOCK, ######## because POB_BLOCK has already restored PL_curcop before Perl_leave_scope() So, with this, signal dispatch is now (effectively) at C<;>, C<}> and any But, all tests pass, and perlbench says: $ ./perlbench-run /home/nclark/Sandpit/snap5.9.x-v5.11.5-98-g243b158/bin/perl5.11.5-{vanilla,unsafe,safefast} /home/nclark/Sandpit/snap5.9.x-v5.11.5-98-g243b158/bin/perl5.11.5-{vanilla,safefast,unsafe} B) perl-5.11.5 C) perl-5.11.5 D) perl-5.11.5 E) perl-5.11.5 F) perl-5.11.5 A B C D E F AVERAGE 100 103 103 100 104 104 ^ unmodified blead ^ So it looks like this approach recovers *all* the speed lost by safe Nicholas Clark Inline Patchdiff --git a/cop.h b/cop.h
index 13ce794..0faf0b0 100644
--- a/cop.h
+++ b/cop.h
@@ -563,12 +563,13 @@ struct block {
(long)cxstack_ix, PL_block_type[CxTYPE(cx)]); )
/* Exit a block (RETURN and LAST). */
-#define POPBLOCK(cx,pm) cx = &cxstack[cxstack_ix--], \
- newsp = PL_stack_base + cx->blk_oldsp, \
- PL_curcop = cx->blk_oldcop, \
- PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp, \
- PL_scopestack_ix = cx->blk_oldscopesp, \
- pm = cx->blk_oldpm, \
+#define POPBLOCK(cx,pm) cx = &cxstack[cxstack_ix--]; \
+ PERL_ASYNC_CHECK(); \
+ newsp = PL_stack_base + cx->blk_oldsp; \
+ PL_curcop = cx->blk_oldcop; \
+ PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp; \
+ PL_scopestack_ix = cx->blk_oldscopesp; \
+ pm = cx->blk_oldpm; \
gimme = cx->blk_gimme; \
DEBUG_SCOPE("POPBLOCK"); \
DEBUG_l( PerlIO_printf(Perl_debug_log, "Leaving block %ld, type %s\n", \
diff --git a/dump.c b/dump.c
index bc1ba58..d1fa26e 100644
--- a/dump.c
+++ b/dump.c
@@ -2026,7 +2026,6 @@ Perl_runops_debug(pTHX)
DEBUG_l(Perl_deb(aTHX_ "Entering new RUNOPS level\n"));
do {
- PERL_ASYNC_CHECK();
if (PL_debug) {
if (PL_watchaddr && (*PL_watchaddr != PL_watchok))
PerlIO_printf(Perl_debug_log,
diff --git a/pp_ctl.c b/pp_ctl.c
index 742bc3d..9f8a6d5 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -264,6 +264,9 @@ PP(pp_substcont)
register REGEXP * const rx = cx->sb_rx;
SV *nsv = NULL;
REGEXP *old = PM_GETRE(pm);
+
+ PERL_ASYNC_CHECK();
+
if(old != rx) {
if(old)
ReREFCNT_dec(old);
@@ -1865,6 +1868,8 @@ PP(pp_dbstate)
PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
FREETMPS;
+ PERL_ASYNC_CHECK();
+
if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
|| SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
{
@@ -2647,6 +2652,8 @@ PP(pp_goto)
else
label = cPVOP->op_pv;
+ PERL_ASYNC_CHECK();
+
if (label && *label) {
OP *gotoprobe = NULL;
bool leaving_eval = FALSE;
diff --git a/pp_hot.c b/pp_hot.c
index 3371e88..9f70147 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -52,6 +52,7 @@ PP(pp_nextstate)
TAINT_NOT; /* Each statement is presumed innocent */
PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
FREETMPS;
+ PERL_ASYNC_CHECK();
return NORMAL;
}
@@ -98,6 +99,7 @@ PP(pp_gv)
PP(pp_and)
{
dVAR; dSP;
+ PERL_ASYNC_CHECK();
if (!SvTRUE(TOPs))
RETURN;
else {
@@ -203,6 +205,7 @@ PP(pp_sassign)
PP(pp_cond_expr)
{
dVAR; dSP;
+ PERL_ASYNC_CHECK();
if (SvTRUEx(POPs))
RETURNOP(cLOGOP->op_other);
else
@@ -416,6 +419,7 @@ PP(pp_preinc)
PP(pp_or)
{
dVAR; dSP;
+ PERL_ASYNC_CHECK();
if (SvTRUE(TOPs))
RETURN;
else {
@@ -434,6 +438,7 @@ PP(pp_defined)
const bool is_dor = (op_type == OP_DOR || op_type == OP_DORASSIGN);
if (is_dor) {
+ PERL_ASYNC_CHECK();
sv = TOPs;
if (!sv || !SvANY(sv)) {
if (op_type == OP_DOR)
@@ -2071,6 +2076,8 @@ PP(pp_subst)
#endif
SV *nsv = NULL;
+ PERL_ASYNC_CHECK();
+
/* known replacement string? */
register SV *dstr = (pm->op_pmflags & PMf_CONST) ? POPs : NULL;
if (PL_op->op_flags & OPf_STACKED)
diff --git a/run.c b/run.c
index be280ee..20c711a 100644
--- a/run.c
+++ b/run.c
@@ -38,7 +38,6 @@ Perl_runops_standard(pTHX)
{
dVAR;
while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX))) {
- PERL_ASYNC_CHECK();
}
TAINT_NOT;
diff --git a/scope.c b/scope.c
index ed4c835..b9b50bf 100644
--- a/scope.c
+++ b/scope.c
@@ -1113,6 +1113,8 @@ Perl_leave_scope(pTHX_ I32 base)
}
PL_tainted = was;
+
+ PERL_ASYNC_CHECK();
}
void |
From @rurbanNicholas Clark (via RT) schrieb:
BTW: Just for reference. Here is my updated runops jitter x86 for Great patch, Nick! |
From @rurban/* Jit.xs #include <EXTERN.h> #ifndef _WIN32 #define T_CHARARR static unsigned char /* threaded: not-threaded: #if (defined(__i386__) || defined(_M_IX86)) && defined(USE_ITHREADS) /* after calling Perl_despatch_signals, restore my_perl into ebx and push for next epilog after final Perl_despatch_signals /* my_perl already on stack, but force 16-alignment for stack */ # define PROLOG x86thr_prolog #endif /* prolog: T_CHARARR x86_prolog[] = {0x55,0x89,0xe5}; /* just save ebp,esp */ # define PROLOG x86_prolog /* only after io funcs? rumor says after each and every op */ /* All ops are unrolled in execution order for the CPU cache, For now only implemented for x86 with certain hardcoded my_perl offsets. /* quirky pass 1: need code size to allocate string. #define PUSHc(what) memcpy(code,what,sizeof(what)); code += sizeof(what) /* pass 2: jit */ /*I_ASSERT(size == (code - c));*/ code = c; /* gdb: disassemble code code+200 */ MODULE=Jit PACKAGE=Jit PROTOTYPES: DISABLE BOOT: |
The RT System itself - Status changed from 'new' to 'open' |
From @hvdsNicholas Clark (via RT) <perlbug-followup@perl.org> wrote: This is what I get for blead (gcc 4.4.2 with -O6, no threads) without and (Adapted from output generated by <http://crypt.org/hv/perl/disfunc>.) It is quite distressing that it doesn't avoid redundant reload of The patch at the end of this email could be applied over yours to give :AVERAGE 100 103 103 100 104 104 That's awesome. :) Do you address map and grep? I believe they can run a long time without It might also trip up modules that use perl ops but not flow control, :So it looks like this approach recovers *all* the speed lost by safe Offhand, I'd expect it to reduce the overhead by 1-2 orders of (decimal) I think you might still notice it on very simple loop bodies: Hugo Inline Patch--- run.c.old 2010-03-11 19:06:10.000000000 +0000
+++ run.c 2010-03-11 22:05:44.000000000 +0000
@@ -37,7 +37,8 @@
Perl_runops_standard(pTHX)
{
dVAR;
- while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX))) {
+ register OP* op = PL_op;
+ while ((PL_op = op = CALL_FPTR(op->op_ppaddr)(aTHX))) {
}
TAINT_NOT; |
From [email protected]On Mar 10, 2010, at 3:23 AM, Nicholas Clark (via RT) wrote:
Not entirely. MacPerl may be gone, but Lamp (Lamp ain't Mac POSIX) Josh |
From @nwc10On Thu, Mar 11, 2010 at 10:26:43PM +0000, hv@crypt.org wrote:
Mmm, yes
I believe so, as I explicitly looked for all ops that do flow control
I'm having a hard time too.
Aha. Right yes, that would make sense.
Right, let's try: A) perl-5.11.5 B) perl-5.11.5 C) perl-5.11.5 D) perl-5.11.5 E) perl-5.11.5 F) perl-5.11.5 G) perl-5.11.5 H) perl-5.11.5 I) perl-5.11.5 J) perl-5.11.5 A B C D E F G H I J AVERAGE 100 104 105 100 105 104 101 100 107 106 Yes, it makes it faster, but it's within the noise level. http://perl5.git.perl.org/perl.git/shortlog/refs/heads/nicholas/HvFILL-shrink which reduces struct XPVHV by one IV, but that doesn't speed it up further Nicholas Clark |
From @rurban2010/3/11 <hv@crypt.org>:
This mov PL_op, %eax should not be needed.
This test neither.
Thanks. I have this for my jitted x86 no-threads, prolog: call: epilog:
Ah, this is where the additional PL_op in eax is coming from. |
From @nwc10On Thu, Mar 11, 2010 at 10:26:43PM +0000, hv@crypt.org wrote:
"Applied" (by hand) as 339aac2. Nicholas Clark |
@nwc10 - Status changed from 'open' to 'resolved' |
From @rurban2010/4/15 Nicholas Clark <nick@ccl4.org>:
Oh! Did you time it? I am working on a version which passes down the local op as arg down |
From @nwc10On Thu, Apr 15, 2010 at 04:53:52PM +0200, Reini Urban wrote:
perlbench suggested '103', compared to '100' without. (Bigger is better). Nicholas Clark |
Migrated from rt.perl.org#73480 (status was 'resolved')
Searchable as RT73480$
The text was updated successfully, but these errors were encountered: