From 98a7c79f2f9fee1ac66d4ab96a9acf6258f58ff7 Mon Sep 17 00:00:00 2001 From: John Bucy Date: Mon, 18 Oct 2004 07:49:45 +0000 Subject: [PATCH] setpag-print-throttled-20041012 kernel printf when we start throttling for time --- src/afs/afs_osi_pag.c | 87 ++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/src/afs/afs_osi_pag.c b/src/afs/afs_osi_pag.c index 12b7d54ec..7f191b472 100644 --- a/src/afs/afs_osi_pag.c +++ b/src/afs/afs_osi_pag.c @@ -139,6 +139,43 @@ getpag(void) * activates tokens repeatedly) for that entire period. */ +static int afs_pag_sleepcnt = 0; + +static int +afs_pag_sleep(struct AFS_UCRED **acred) +{ + int rv = 0; + if(!afs_suser(acred)) { + if(osi_Time() - pag_epoch < pagCounter) { + rv = 1; + } + } + + return rv; +} + +static int +afs_pag_wait(struct AFS_UCRED **acred) +{ + if(afs_pag_sleep(acred)) { + if(!afs_pag_sleepcnt) { + printf("%s() PAG throttling triggered, pid %d... sleeping. sleepcnt %d\n", + __func__, getpid(), afs_pag_sleepcnt); + } + + afs_pag_sleepcnt++; + + do { + /* XXX spins on EINTR */ + afs_osi_Wait(1000, (struct afs_osi_WaitHandle *)0, 0); + } while(afs_pag_sleep(acred)); + + afs_pag_sleepcnt--; + } + + return 0; +} + int #if defined(AFS_SUN5_ENV) afs_setpag(struct AFS_UCRED **credpp) @@ -148,6 +185,15 @@ afs_setpag(struct proc *p, void *args, int *retval) afs_setpag(void) #endif { + +#if defined(AFS_SUN5_ENV) + struct AFS_UCRED **acred = *credpp; +#elif defined(AFS_OBSD_ENV) + struct AFS_UCRED **acred = p->p_ucred; +#else + struct AFS_UCRED **acred = NULL; +#endif + int code = 0; #if defined(AFS_SGI53_ENV) && defined(MP) @@ -156,18 +202,10 @@ afs_setpag(void) #endif /* defined(AFS_SGI53_ENV) && defined(MP) */ AFS_STATCNT(afs_setpag); -#if defined(AFS_SUN5_ENV) - if (!afs_suser(*credpp)) -#elif defined(AFS_OBSD_ENV) - if (!afs_osi_suser(p->p_ucred)) -#else - if (!afs_suser(NULL)) -#endif - { - while (osi_Time() - pag_epoch < pagCounter) { - afs_osi_Wait(1000, (struct afs_osi_WaitHandle *)0, 0); - } - } + + afs_pag_wait(acred); + + #if defined(AFS_SUN5_ENV) code = AddPag(genpag(), credpp); #elif defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV) @@ -213,13 +251,16 @@ afs_setpag(void) #endif afs_Trace1(afs_iclSetp, CM_TRACE_SETPAG, ICL_TYPE_INT32, code); + #if defined(KERNEL_HAVE_UERROR) if (!getuerror()) setuerror(code); #endif + #if defined(AFS_SGI53_ENV) && defined(MP) AFS_GUNLOCK(); #endif /* defined(AFS_SGI53_ENV) && defined(MP) */ + return (code); } @@ -240,6 +281,15 @@ afs_setpag_val(struct proc *p, void *args, int *retval, int pagval) afs_setpag_val(int pagval) #endif { + +#if defined(AFS_SUN5_ENV) + struct AFS_UCRED **acred = *credp; +#elif defined(AFS_OBSD_ENV) + struct AFS_UCRED **acred = p->p_ucred; +#else + struct AFS_UCRED **acred = NULL; +#endif + int code = 0; #if defined(AFS_SGI53_ENV) && defined(MP) @@ -248,16 +298,9 @@ afs_setpag_val(int pagval) #endif /* defined(AFS_SGI53_ENV) && defined(MP) */ AFS_STATCNT(afs_setpag); -#ifdef AFS_SUN5_ENV - if (!afs_suser(*credpp)) -#else - if (!afs_suser(NULL)) -#endif - { - while (osi_Time() - pag_epoch < pagCounter) { - afs_osi_Wait(1000, (struct afs_osi_WaitHandle *)0, 0); - } - } + + afs_pag_wait(acred); + #if defined(AFS_SUN5_ENV) code = AddPag(pagval, credpp); #elif defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV) -- 2.39.5