pp_tms should use a local struct tms, instead of PL_timesbuf.
authorNicholas Clark <nick@ccl4.org>
Sat, 1 Mar 2014 16:40:05 +0000 (17:40 +0100)
committerNicholas Clark <nick@ccl4.org>
Sat, 1 Mar 2014 16:40:05 +0000 (17:40 +0100)
PL_timesbuf is effectively a vestige of Perl 1, and doesn't actually need to
be an interpreter variable. It will be removed early in v5.21.x, but it's a
good idea to refactor the code not to use it before then. A local struct tms
will be on the C stack, which will be in the CPU's L1 cache, whereas the
relevant part of the interpreter struct may well not be in the CPU cache at
all. Therefore this change might reduce cache pressure fractionally. A local
variable access should also be simpler machine code on most CPU architectures.

intrpvar.h
pp_sys.c
sv.c

index 2c1b73e..5d27ad5 100644 (file)
@@ -174,6 +174,7 @@ PERLVAR(I, statgv,  GV *)
 PERLVARI(I, statname,  SV *,   NULL)
 
 #ifdef HAS_TIMES
+/* Will be removed soon after v5.21.0. See RT #121351 */
 PERLVAR(I, timesbuf,   struct tms)
 #endif
 
index 6c4e2c7..f1eabba 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -4397,20 +4397,23 @@ PP(pp_tms)
 #ifdef HAS_TIMES
     dVAR;
     dSP;
-    EXTEND(SP, 4);
-#ifndef VMS
-    (void)PerlProc_times(&PL_timesbuf);
+#ifdef VMS
+    /* time.h uses different name for struct tms, though the same data is
+       returned.
+     */
+    struct tbuffer_t timesbuf;
 #else
-    (void)PerlProc_times((tbuffer_t *)&PL_timesbuf);  /* time.h uses different name for */
-                                                   /* struct tms, though same data   */
-                                                   /* is returned.                   */
+    struct tms timesbuf;
 #endif
 
-    mPUSHn(((NV)PL_timesbuf.tms_utime)/(NV)PL_clocktick);
+    EXTEND(SP, 4);
+    (void)PerlProc_times(&timesbuf);
+
+    mPUSHn(((NV)timesbuf.tms_utime)/(NV)PL_clocktick);
     if (GIMME == G_ARRAY) {
-       mPUSHn(((NV)PL_timesbuf.tms_stime)/(NV)PL_clocktick);
-       mPUSHn(((NV)PL_timesbuf.tms_cutime)/(NV)PL_clocktick);
-       mPUSHn(((NV)PL_timesbuf.tms_cstime)/(NV)PL_clocktick);
+       mPUSHn(((NV)timesbuf.tms_stime)/(NV)PL_clocktick);
+       mPUSHn(((NV)timesbuf.tms_cutime)/(NV)PL_clocktick);
+       mPUSHn(((NV)timesbuf.tms_cstime)/(NV)PL_clocktick);
     }
     RETURN;
 #else
diff --git a/sv.c b/sv.c
index b7563b9..dcb1d5e 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -13559,10 +13559,6 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
     PL_statbuf         = proto_perl->Istatbuf;
     PL_statcache       = proto_perl->Istatcache;
 
-#ifdef HAS_TIMES
-    PL_timesbuf                = proto_perl->Itimesbuf;
-#endif
-
 #ifndef NO_TAINT_SUPPORT
     PL_tainted         = proto_perl->Itainted;
 #else