Hi,

while trying to speed up Xing DVD Player I came across the following rather
uncool problem:

Critical Sections take way too much time. I have added the appended patch
to EnterCriticalSection():

It prints an S every 20 seconds on my K6-200, meaning it did at least 
3*1000 (wine->wineserver->wine) process context switches (not counting
the switches caused by the owning thread).

I can't say for sure, but this might be sucking up way too expensive CPU 
power ;)

A solution would be too change handling of local critical sections to use
either UNIX IPC semaphores direct or 'busy wait' using a local wait
(like usleep(), select() and/or sched_yield()).

Both would avoid 2 of 3 process context switches.

But before I start hacking like madly for myself... Any opinions?

Ciao, Marcus

Index: critsection.c
===================================================================
RCS file: /home/wine/wine/scheduler/critsection.c,v
retrieving revision 1.20
diff -u -r1.20 critsection.c
--- critsection.c       2000/06/07 02:15:40     1.20
+++ critsection.c       2000/07/28 14:09:48
@@ -69,6 +69,8 @@
  */
 void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit )
 {
+    static int slowpathhit = 0;
+
     if (InterlockedIncrement( &crit->LockCount ))
     {
         if (crit->OwningThread == GetCurrentThreadId())
@@ -76,6 +78,13 @@
             crit->RecursionCount++;
             return;
         }
+
+       if (!HIWORD(crit->LockSemaphore)) {
+           slowpathhit++;
+           if (slowpathhit>1000) {
+               fprintf(stderr,"S");slowpathhit = 0;
+           }
+       }
 
         /* Now wait for it */
         for (;;)

Reply via email to