The following patch (included just once! :) speeds up threaded perl
on Alpha VMS systems by about 2-3 percent. It should, in theory, work
the same on Tru64 versions 4.0 and up, but I didn't know the right
preprocessor symbol, so it's not in. 

Note that *all* this patch does is change over to using an unchecked
fetch of thread-specific data from a checked one. It would fail if
the key were bogus, but if the key were bogus then Really Bad Things
would be happening anyway.

This points out two things:

1) Dave Butenhof is The Man. (He's the one who pointed out this function)
2) We call pthread_getspecific on the thread key way, *way* too much. A
change this trivial ought not make this big a performance difference, but
according to perlbench (across several runs) it consistently does.

I don't know if this'll affect an ITHREAD perl build or not. Probably not.

Cc any replies to me, please--I'm not on p5p at the moment.

--- thread.h;-5 Mon Apr 30 10:51:42 2001
+++ thread.h    Wed May 16 16:53:58 2001
@@ -246,7 +246,12 @@
 #endif /* JOIN */
 
 #ifndef PERL_GET_CONTEXT
-#  define PERL_GET_CONTEXT     pthread_getspecific(PL_thr_key)
+/* True for Tru64 version 4.0 and up as well */
+#  if defined(__ALPHA) && (__VMS_VER >= 70000000)
+#    define PERL_GET_CONTEXT   pthread_unchecked_getspecific_np(PL_thr_key)
+#  else
+#    define PERL_GET_CONTEXT   pthread_getspecific(PL_thr_key)
+#  endif
 #endif
 
 #ifndef PERL_SET_CONTEXT

--- util.c;-2   Fri Apr  6 05:38:46 2001
+++ util.c      Wed May 16 17:00:51 2001
@@ -3339,10 +3339,14 @@
        Perl_croak_nocontext("panic: pthread_getspecific");
     return (void*)t;
 #  else
-#  ifdef I_MACH_CTHREADS
-    return (void*)cthread_data(cthread_self());
-#  else
-    return (void*)pthread_getspecific(PL_thr_key);
+#    ifdef I_MACH_CTHREADS
+      return (void*)cthread_data(cthread_self());
+#    else
+#      if defined(__ALPHA) && (__VMS_VER >= 70000000)
+         return (void*)pthread_unchecked_getspecific_np(PL_thr_key);
+#      else
+         return (void*)pthread_getspecific(PL_thr_key);
+#      endif 
 #  endif
 #  endif
 #else
--- thread.h;-5 Mon Apr 30 10:51:42 2001
+++ thread.h    Wed May 16 16:53:58 2001
@@ -246,7 +246,12 @@
 #endif /* JOIN */
 
 #ifndef PERL_GET_CONTEXT
-#  define PERL_GET_CONTEXT     pthread_getspecific(PL_thr_key)
+/* True for Tru64 version 4.0 and up as well */
+#  if defined(__ALPHA) && (__VMS_VER >= 70000000)
+#    define PERL_GET_CONTEXT   pthread_unchecked_getspecific_np(PL_thr_key)
+#  else
+#    define PERL_GET_CONTEXT   pthread_getspecific(PL_thr_key)
+#  endif
 #endif
 
 #ifndef PERL_SET_CONTEXT

--- util.c;-2   Fri Apr  6 05:38:46 2001
+++ util.c      Wed May 16 17:00:51 2001
@@ -3339,10 +3339,14 @@
        Perl_croak_nocontext("panic: pthread_getspecific");
     return (void*)t;
 #  else
-#  ifdef I_MACH_CTHREADS
-    return (void*)cthread_data(cthread_self());
-#  else
-    return (void*)pthread_getspecific(PL_thr_key);
+#    ifdef I_MACH_CTHREADS
+      return (void*)cthread_data(cthread_self());
+#    else
+#      if defined(__ALPHA) && (__VMS_VER >= 70000000)
+         return (void*)pthread_unchecked_getspecific_np(PL_thr_key);
+#      else
+         return (void*)pthread_getspecific(PL_thr_key);
+#      endif 
 #  endif
 #  endif
 #else


## End of Patch ##

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                     teddy bears get drunk

Reply via email to