]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
STABLE14-windows-dynamic-thread-priority-20060525
authorJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 26 May 2006 07:38:05 +0000 (07:38 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 26 May 2006 07:38:05 +0000 (07:38 +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 7ed08c0bfe40908228ccf4e426563cb6353aa08c..42f16d9bdad32757f9f14e1faaa0719923335334 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) bp, &bp->mx);
+
+       smb_UpdateServerPriority();
+
         lock_ObtainMutex(&bp->mx);
         osi_Log1(afsd_logp, "buf_WaitIO conflict wait done for 0x%x", bp);
         bp->waitCount--;
index 87488a5c858d564f2f5c546087c1c339a05417ac..71d94bb5c5ff163528273d5efdbd4d8cd61585fa 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) &scp->flags, &scp->mx);
+
+       smb_UpdateServerPriority();
+
         if (bufLocked) 
             lock_ObtainMutex(&bufp->mx);
         lock_ObtainMutex(&scp->mx);
index c59fca46427a94308515cb6878bf691b0086c979..6283e3af8f699c0640d56d5182034a93bab26c9f 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,39 @@ 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);
+    }
+}
+
 char * myCrt_Dispatch(int i)
 {
     switch (i)
@@ -7575,6 +7610,9 @@ void smb_Server(VOID *parmp)
            smb_ReleaseVC(vcp);
            vcp = NULL;
        }
+
+       smb_ResetServerPriority();
+
         code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBreturns[myIdx],
                                                  FALSE, INFINITE);
 
@@ -7907,6 +7945,8 @@ void smb_Server(VOID *parmp)
             continue;
         }
 
+       smb_SetRequestStartTime();
+
         vcp->errorCount = 0;
         bufp = (struct smb_packet *) ncbp->ncb_buffer;
 #ifdef DJGPP
@@ -8538,6 +8578,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 */
@@ -9061,6 +9103,8 @@ void smb_Shutdown(void)
         }
     }
     lock_ReleaseWrite(&smb_rctLock);
+
+    TlsFree(smb_TlsRequestSlot);
 }
 
 /* Get the UNC \\<servername>\<sharename> prefix. */
index 840ff92cd582f52236c0f9d74c6a6926bd711abc..b2b52f33bc956cf1186bea1f862eff8dd0aab9e5 100644 (file)
@@ -696,6 +696,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"