]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
DEVEL15-windows-dynamic-thread-priority-20060525
authorJeffrey Altman <jaltman@secure-endpoints.com>
Thu, 1 Jun 2006 16:40:04 +0000 (16:40 +0000)
committerDerrick Brashear <shadow@dementia.org>
Thu, 1 Jun 2006 16:40:04 +0000 (16:40 +0000)
Dynamically adjust the priority of server threads based upon the age
of the cifs request that is being processed.  Bump the priority one
level for each 15 seconds of age.

(cherry picked from commit 7ca1a339cb488fd97015e959e2a17e91e9b56409)

src/WINNT/afsd/cm_buf.c
src/WINNT/afsd/cm_scache.c
src/WINNT/afsd/smb.c
src/WINNT/afsd/smb.h

index cdfe13969225a4dd1973782c4f0266f5f97bcc8a..aa6610b3954656a97629b334432788bac0d28f72 100644 (file)
@@ -462,6 +462,9 @@ void buf_WaitIO(cm_scache_t * scp, cm_buf_t *bp)
             bp->waitCount = bp->waitRequests = 1;
         }
         osi_SleepM((LONG_PTR)bp, &bp->mx);
+
+       smb_UpdateServerPriority();
+
         lock_ObtainMutex(&bp->mx);
         osi_Log1(afsd_logp, "buf_WaitIO conflict wait done for 0x%p", bp);
         bp->waitCount--;
index 80d49aced289576f368e111c3929ca5a38ec3087..826b2697630198d7f8460aee4df5da5aa4c4c48d 100644 (file)
@@ -917,6 +917,9 @@ long cm_SyncOp(cm_scache_t *scp, cm_buf_t *bufp, cm_user_t *up, cm_req_t *reqp,
         if (bufLocked) 
             lock_ReleaseMutex(&bufp->mx);
         osi_SleepM((LONG_PTR) &scp->flags, &scp->mx);
+
+       smb_UpdateServerPriority();
+
         if (bufLocked) 
             lock_ObtainMutex(&bufp->mx);
         lock_ObtainMutex(&scp->mx);
index 89ab3def23a2d5e57a0962918ad4a3d9923c92d6..4b62388a418093869f460378583b546eaa67e059 100644 (file)
@@ -170,6 +170,8 @@ smb_username_t *usernamesp = NULL;
 
 smb_waitingLockRequest_t *smb_allWaitingLocks;
 
+DWORD smb_TlsRequestSlot = -1;
+
 /* forward decl */
 void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp,
                        NCB *ncbp, raw_write_cont_t *rwcp);
@@ -204,6 +206,40 @@ int smb_ServerLanManagerLength = sizeof(smb_ServerLanManager);
 /* Faux server GUID. This is never checked. */
 GUID smb_ServerGUID = { 0x40015cb8, 0x058a, 0x44fc, { 0xae, 0x7e, 0xbb, 0x29, 0x52, 0xee, 0x7e, 0xff }};
 
+void smb_ResetServerPriority()
+{
+    void * p = TlsGetValue(smb_TlsRequestSlot);
+    if (p) {
+       free(p);
+       TlsSetValue(smb_TlsRequestSlot, NULL);
+       SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
+    }
+}
+
+void smb_SetRequestStartTime()
+{
+    time_t * tp = malloc(sizeof(time_t));
+    if (tp) {
+       *tp = osi_Time();
+
+       if (!TlsSetValue(smb_TlsRequestSlot, tp))
+           free(tp);
+    }  
+}
+
+void smb_UpdateServerPriority()
+{      
+    time_t *tp = TlsGetValue(smb_TlsRequestSlot);
+
+    if (tp) {
+       time_t now = osi_Time();
+
+       /* Give one priority boost for each 15 seconds */
+       SetThreadPriority(GetCurrentThread(), (now - *tp) / 15);
+    }
+}
+
+
 const char * ncb_error_string(int code)
 {
     const char * s;
@@ -7570,6 +7606,9 @@ void smb_Server(VOID *parmp)
            smb_ReleaseVC(vcp);
            vcp = NULL;
        }
+
+       smb_ResetServerPriority();
+
         code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBreturns[myIdx],
                                                  FALSE, INFINITE);
 
@@ -7760,6 +7799,8 @@ void smb_Server(VOID *parmp)
             continue;
         }
 
+       smb_SetRequestStartTime();
+
         vcp->errorCount = 0;
         bufp = (struct smb_packet *) ncbp->ncb_buffer;
 #ifdef DJGPP
@@ -8363,6 +8404,8 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt,
     EVENT_HANDLE retHandle;
     char eventName[MAX_PATH];
 
+    smb_TlsRequestSlot = TlsAlloc();
+
 #ifndef DJGPP
     smb_MBfunc = aMBfunc;
 #endif /* DJGPP */
@@ -8886,6 +8929,8 @@ void smb_Shutdown(void)
         }
     }
     lock_ReleaseWrite(&smb_rctLock);
+
+    TlsFree(smb_TlsRequestSlot);
 }
 
 /* Get the UNC \\<servername>\<sharename> prefix. */
index 6cf67ed86047c27ff39c948f6cefe2c701a44b8c..856324509e277e20f1e0d6ab28540ae7baecb0cd 100644 (file)
@@ -698,6 +698,10 @@ extern char *smb_GetSharename(void);
 
 extern DWORD smb_ServerExceptionFilter(void);
 
+extern void smb_UpdateServerPriority(void);
+extern void smb_SetRequestStartTime(void);
+extern void smb_ResetServerPriority(void);
+
 /* include other include files */
 #include "smb3.h"
 #include "smb_ioctl.h"