[OpenAFS-devel] [PATCH] log setpag throttling (take 2)

John S. Bucy bucy-openafs-devel@gloop.org
Thu, 7 Oct 2004 13:50:20 -0400


--n8g4imXOkfNTN/H1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


This patch logs once per "edge" -- when the number of processes
sleeping in k_setpag() goes from zero to nonzero.  It also refactors
the sleeping logic out of setpag_val() and setpag().

It still doesn't do anything about EINTR.  I think every bit of code
I've seen that calls k_setpag() doesn't check the return value ... but
I wonder how much of it expects to catch a signal instead of being
killed by it...





john

--n8g4imXOkfNTN/H1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="openafs-1.3.71-setpag-log.diff"

--- openafs-1.3.71/src/afs/afs_osi_pag.c	2004-07-28 23:13:37.000000000 -0400
+++ openafs-1.3.71-cur/src/afs/afs_osi_pag.c	2004-10-05 16:49:39.000000000 -0400
@@ -139,6 +139,43 @@
  * 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(void)
 #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)
@@ -156,18 +202,10 @@
 #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 @@
 #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(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 @@
 #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)

--n8g4imXOkfNTN/H1--