Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lnet / selftest / timer.c
index 97d9297..c5b7764 100644 (file)
@@ -1,17 +1,45 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
- *   Author: Isaac Huang <isaac@clusterfs.com>
+ * GPL HEADER START
  *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lnet/selftest/timer.c
+ *
+ * Author: Isaac Huang <isaac@clusterfs.com>
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
 
-#include <libcfs/kp30.h>
-#include <libcfs/libcfs.h>
-#include <lnet/lib-lnet.h>
-
 #include "selftest.h"
 
 
@@ -36,6 +64,7 @@ struct st_timer_data {
         struct list_head stt_hash[STTIMER_NSLOTS];
         int              stt_shuttingdown;
 #ifdef __KERNEL__
+        cfs_waitq_t      stt_waitq;
         int              stt_nthreads;
 #endif
 } stt_data;
@@ -149,6 +178,7 @@ stt_check_timers (cfs_time_t *last)
 int
 stt_timer_main (void *arg)
 {
+        int rc = 0;
         UNUSED(arg);
 
         cfs_daemonize("st_timer");
@@ -157,9 +187,10 @@ stt_timer_main (void *arg)
         while (!stt_data.stt_shuttingdown) {
                 stt_check_timers(&stt_data.stt_prev_slot);
 
-                set_current_state(CFS_TASK_INTERRUPTIBLE);
-                cfs_schedule_timeout(CFS_TASK_INTERRUPTIBLE,
-                                     cfs_time_seconds(STTIMER_SLOTTIME));
+                cfs_waitq_wait_event_timeout(stt_data.stt_waitq,
+                                   stt_data.stt_shuttingdown,
+                                   cfs_time_seconds(STTIMER_SLOTTIME),
+                                   rc);
         }
 
         spin_lock(&stt_data.stt_lock);
@@ -216,9 +247,10 @@ stt_startup (void)
 
 #ifdef __KERNEL__
         stt_data.stt_nthreads = 0;
+        cfs_waitq_init(&stt_data.stt_waitq);
         rc = stt_start_timer_thread();
         if (rc != 0)
-                CERROR ("Can't spawn timer, stt_startup() has failed: %d\n", rc);
+                CERROR ("Can't spawn timer thread: %d\n", rc);
 #endif
 
         return rc;
@@ -237,6 +269,7 @@ stt_shutdown (void)
         stt_data.stt_shuttingdown = 1;
 
 #ifdef __KERNEL__
+        cfs_waitq_signal(&stt_data.stt_waitq);
         lst_wait_until(stt_data.stt_nthreads == 0, stt_data.stt_lock,
                        "waiting for %d threads to terminate\n",
                        stt_data.stt_nthreads);