In libpthread, if the scheduler picks the current thread as the next to 
run, it still does the full save+restore of errno, FPU, and regs, saving 
them and then restoring the same values again.  That's kinda silly, so 
jump around that if switching to the current thread.

oks?

Philip Guenther


Index: uthread_kern.c
===================================================================
RCS file: /cvs/src/lib/libpthread/uthread/uthread_kern.c,v
retrieving revision 1.37
diff -u -p -r1.37 uthread_kern.c
--- uthread_kern.c      25 Jan 2011 22:55:14 -0000      1.37
+++ uthread_kern.c      2 Jul 2011 22:01:38 -0000
@@ -467,6 +467,13 @@ _thread_kern_sched(struct sigcontext * s
                                curthread->slice_usec = 0;
                        }
 
+                       /*
+                        * If we're 'switching' to the current thread,
+                        * then don't bother with the save/restore
+                        */
+                       if (curthread == old_thread_run)
+                               goto after_switch;
+
                        /* Restore errno. */
                        errno = curthread->error;
 
@@ -486,6 +493,8 @@ _thread_kern_sched(struct sigcontext * s
                         * before use.
                         */
                        curthread = _get_curthread();
+
+                 after_switch:
 
                        /* Allow signals again. */
                        _queue_signals = 0;

Reply via email to