DEVEL15-windows-dynamic-thread-priority-20060525

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)
This commit is contained in:
Jeffrey Altman 2006-06-01 16:40:04 +00:00 committed by Derrick Brashear
parent 3b3f0704b1
commit 39b4525648
4 changed files with 55 additions and 0 deletions

View 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--;

View 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);

View 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. */

View 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"