DEVEL15-linux-2620-rc1-update-20061228
[openafs.git] / src / afs / LINUX / osi_sleep.c
index caf1799..1e87378 100644 (file)
@@ -8,37 +8,39 @@
  */
 
 #include <afsconfig.h>
-#include "../afs/param.h"
+#include "afs/param.h"
 
-RCSID("$Header$");
+RCSID
+    ("$Header$");
 
-#include "../afs/sysincludes.h"        /* Standard vendor system headers */
-#include "../afs/afsincludes.h"        /* Afs-based standard headers */
-#include "../afs/afs_stats.h"   /* afs statistics */
+#include "afs/sysincludes.h"   /* Standard vendor system headers */
+#include "afsincludes.h"       /* Afs-based standard headers */
+#include "afs/afs_stats.h"     /* afs statistics */
 
+#include <linux/freezer.h>
 
 static int osi_TimedSleep(char *event, afs_int32 ams, int aintok);
-void afs_osi_Wakeup(char *event);
-void afs_osi_Sleep(char *event);
 
 static char waitV, dummyV;
 
-
-void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle)
+void
+afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle)
 {
     AFS_STATCNT(osi_InitWaitHandle);
     achandle->proc = (caddr_t) 0;
 }
 
 /* cancel osi_Wait */
-void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle)
+void
+afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle)
 {
     caddr_t proc;
 
     AFS_STATCNT(osi_CancelWait);
     proc = achandle->proc;
-    if (proc == 0) return;
-    achandle->proc = (caddr_t) 0;   /* so dude can figure out he was signalled */
+    if (proc == 0)
+       return;
+    achandle->proc = (caddr_t) 0;      /* so dude can figure out he was signalled */
     afs_osi_Wakeup(&waitV);
 }
 
@@ -46,23 +48,22 @@ void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle)
  * Waits for data on ahandle, or ams ms later.  ahandle may be null.
  * Returns 0 if timeout and EINTR if signalled.
  */
-int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
+int
+afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
 {
+    afs_int32 endTime;
     int code;
-    afs_int32 endTime, tid;
-    struct timer_list *timer = NULL;
 
     AFS_STATCNT(osi_Wait);
-    endTime = osi_Time() + (ams/1000);
+    endTime = osi_Time() + (ams / 1000);
     if (ahandle)
        ahandle->proc = (caddr_t) current;
 
     do {
-        AFS_ASSERT_GLOCK();
-       code = 0;
-        code = osi_TimedSleep(&waitV, ams, aintok);
-
-        if (code) break;
+       AFS_ASSERT_GLOCK();
+       code = osi_TimedSleep(&waitV, ams, 1);
+       if (code)
+           break;
        if (ahandle && (ahandle->proc == (caddr_t) 0)) {
            /* we've been signalled */
            break;
@@ -79,8 +80,8 @@ typedef struct afs_event {
     char *event;               /* lwp event: an address */
     int refcount;              /* Is it in use? */
     int seq;                   /* Sequence number: this is incremented
-                                  by wakeup calls; wait will not return until
-                                  it changes */
+                                * by wakeup calls; wait will not return until
+                                * it changes */
 #if defined(AFS_LINUX24_ENV)
     wait_queue_head_t cond;
 #else
@@ -89,13 +90,14 @@ typedef struct afs_event {
 } afs_event_t;
 
 #define HASHSIZE 128
-afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */
+afs_event_t *afs_evhasht[HASHSIZE];    /* Hash table for events */
 #define afs_evhash(event)      (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1));
 int afs_evhashcnt = 0;
 
 /* Get and initialize event structure corresponding to lwp event (i.e. address)
  * */
-static afs_event_t *afs_getevent(char *event)
+static afs_event_t *
+afs_getevent(char *event)
 {
     afs_event_t *evp, *newp = 0;
     int hashcode;
@@ -132,11 +134,12 @@ static afs_event_t *afs_getevent(char *event)
  *     a deadlock).
  */
 
-static void afs_addevent(char *event)
+static void
+afs_addevent(char *event)
 {
     int hashcode;
     afs_event_t *newp;
-    
+
     AFS_ASSERT_GLOCK();
     hashcode = afs_evhash(event);
     newp = osi_linux_alloc(sizeof(afs_event_t), 0);
@@ -149,7 +152,7 @@ static void afs_addevent(char *event)
     init_waitqueue(&newp->cond);
 #endif
     newp->seq = 0;
-    newp->event = &dummyV;  /* Dummy address for new events */
+    newp->event = &dummyV;     /* Dummy address for new events */
     newp->refcount = 0;
 }
 
@@ -165,7 +168,8 @@ static void afs_addevent(char *event)
  * Waits for an event to be notified, returning early if a signal
  * is received.  Returns EINTR if signaled, and 0 otherwise.
  */
-int afs_osi_SleepSig(char *event)
+int
+afs_osi_SleepSig(void *event)
 {
     struct afs_event *evp;
     int seq, retval;
@@ -177,8 +181,8 @@ int afs_osi_SleepSig(char *event)
 
     evp = afs_getevent(event);
     if (!evp) {
-        afs_addevent(event);
-        evp = afs_getevent(event);
+       afs_addevent(event);
+       evp = afs_getevent(event);
     }
 
     seq = evp->seq;
@@ -186,10 +190,30 @@ int afs_osi_SleepSig(char *event)
 
     add_wait_queue(&evp->cond, &wait);
     while (seq == evp->seq) {
-        set_current_state(TASK_INTERRUPTIBLE);
+       set_current_state(TASK_INTERRUPTIBLE);
        AFS_ASSERT_GLOCK();
        AFS_GUNLOCK();
        schedule();
+#ifdef AFS_LINUX26_ENV
+#ifdef CONFIG_PM
+       if (
+#ifdef PF_FREEZE
+           current->flags & PF_FREEZE
+#else
+#if defined(STRUCT_TASK_STRUCT_HAS_TODO)
+           !current->todo
+#else
+            test_ti_thread_flag(current->thread_info, TIF_FREEZE)
+#endif
+#endif
+           )
+#ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
+           refrigerator(PF_FREEZE);
+#else
+           refrigerator();
+#endif
+#endif
+#endif
        AFS_GLOCK();
        if (signal_pending(current)) {
            retval = EINTR;
@@ -210,22 +234,23 @@ int afs_osi_SleepSig(char *event)
  *   caller that the wait has been interrupted and the stack should be cleaned
  *   up preparatory to signal delivery
  */
-void afs_osi_Sleep(char *event)
+void
+afs_osi_Sleep(void *event)
 {
     sigset_t saved_set;
 
-    spin_lock_irq(&current->sigmask_lock);
+    SIG_LOCK(current);
     saved_set = current->blocked;
     sigfillset(&current->blocked);
-    recalc_sigpending(current);
-    spin_unlock_irq(&current->sigmask_lock);
+    RECALC_SIGPENDING(current);
+    SIG_UNLOCK(current);
 
     afs_osi_SleepSig(event);
 
-    spin_lock_irq(&current->sigmask_lock);
+    SIG_LOCK(current);
     current->blocked = saved_set;
-    recalc_sigpending(current);
-    spin_unlock_irq(&current->sigmask_lock);
+    RECALC_SIGPENDING(current);
+    SIG_UNLOCK(current);
 }
 
 /* osi_TimedSleep
@@ -238,7 +263,8 @@ void afs_osi_Sleep(char *event)
  * Returns 0 if timeout, EINTR if signalled, and EGAIN if it might
  * have raced.
  */
-static int osi_TimedSleep(char *event, afs_int32 ams, int aintok)
+static int
+osi_TimedSleep(char *event, afs_int32 ams, int aintok)
 {
     int code = 0;
     long ticks = (ams * HZ / 1000) + 1;
@@ -251,21 +277,41 @@ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok)
 
     evp = afs_getevent(event);
     if (!evp) {
-        afs_addevent(event);
+       afs_addevent(event);
        evp = afs_getevent(event);
     }
 
     add_wait_queue(&evp->cond, &wait);
     set_current_state(TASK_INTERRUPTIBLE);
-               /* always sleep TASK_INTERRUPTIBLE to keep load average
-                  from artifically increasing. */
+    /* always sleep TASK_INTERRUPTIBLE to keep load average
+     * from artifically increasing. */
     AFS_GUNLOCK();
 
     if (aintok) {
-        if (schedule_timeout(ticks))
-            code = EINTR;
+       if (schedule_timeout(ticks))
+           code = EINTR;
     } else
-        schedule_timeout(ticks);
+       schedule_timeout(ticks);
+#ifdef AFS_LINUX26_ENV
+#ifdef CONFIG_PM
+    if (
+#ifdef PF_FREEZE
+           current->flags & PF_FREEZE
+#else
+#if defined(STRUCT_TASK_STRUCT_HAS_TODO)
+           !current->todo
+#else
+            test_ti_thread_flag(current->thread_info, TIF_FREEZE)
+#endif
+#endif
+           )
+#ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
+       refrigerator(PF_FREEZE);
+#else
+       refrigerator();
+#endif
+#endif
+#endif
 
     AFS_GLOCK();
     remove_wait_queue(&evp->cond, &wait);
@@ -277,17 +323,21 @@ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok)
 }
 
 
-void afs_osi_Wakeup(char *event)
+int
+afs_osi_Wakeup(void *event)
 {
+    int ret = 2;
     struct afs_event *evp;
 
     evp = afs_getevent(event);
-    if (!evp)                          /* No sleepers */
-       return;
+    if (!evp)                  /* No sleepers */
+       return 1;
 
     if (evp->refcount > 1) {
-       evp->seq++;    
+       evp->seq++;
        wake_up(&evp->cond);
+       ret = 0;
     }
     relevent(evp);
+    return ret;
 }