Whamcloud - gitweb
LU-4423 lnet: use 64-bit time for selftest
[fs/lustre-release.git] / lnet / selftest / timer.c
index 84ce098..ff016e9 100644 (file)
  *
  * 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.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -63,10 +59,8 @@ static struct st_timer_data {
        cfs_time_t              stt_prev_slot;
        struct list_head        stt_hash[STTIMER_NSLOTS];
        int                     stt_shuttingdown;
-#ifdef __KERNEL__
        wait_queue_head_t       stt_waitq;
        int                     stt_nthreads;
-#endif
 } stt_data;
 
 void
@@ -76,19 +70,17 @@ stt_add_timer(stt_timer_t *timer)
 
        spin_lock(&stt_data.stt_lock);
 
-#ifdef __KERNEL__
        LASSERT(stt_data.stt_nthreads > 0);
-#endif
        LASSERT(!stt_data.stt_shuttingdown);
        LASSERT(timer->stt_func != NULL);
        LASSERT(list_empty(&timer->stt_list));
-       LASSERT(cfs_time_after(timer->stt_expires, cfs_time_current_sec()));
+       LASSERT(timer->stt_expires > ktime_get_real_seconds());
 
        /* a simple insertion sort */
        list_for_each_prev(pos, STTIMER_SLOT(timer->stt_expires)) {
                stt_timer_t *old = list_entry(pos, stt_timer_t, stt_list);
 
-               if (cfs_time_aftereq(timer->stt_expires, old->stt_expires))
+               if (timer->stt_expires >= old->stt_expires)
                        break;
        }
        list_add(&timer->stt_list, pos);
@@ -112,9 +104,7 @@ stt_del_timer(stt_timer_t *timer)
 
        spin_lock(&stt_data.stt_lock);
 
-#ifdef __KERNEL__
        LASSERT(stt_data.stt_nthreads > 0);
-#endif
        LASSERT(!stt_data.stt_shuttingdown);
 
        if (!list_empty(&timer->stt_list)) {
@@ -128,7 +118,7 @@ stt_del_timer(stt_timer_t *timer)
 
 /* called with stt_data.stt_lock held */
 static int
-stt_expire_list(struct list_head *slot, cfs_time_t now)
+stt_expire_list(struct list_head *slot, time64_t now)
 {
        int          expired = 0;
        stt_timer_t *timer;
@@ -136,7 +126,7 @@ stt_expire_list(struct list_head *slot, cfs_time_t now)
        while (!list_empty(slot)) {
                timer = list_entry(slot->next, stt_timer_t, stt_list);
 
-               if (cfs_time_after(timer->stt_expires, now))
+               if (timer->stt_expires > now)
                        break;
 
                list_del_init(&timer->stt_list);
@@ -152,13 +142,13 @@ stt_expire_list(struct list_head *slot, cfs_time_t now)
 }
 
 static int
-stt_check_timers (cfs_time_t *last)
+stt_check_timers(cfs_time_t *last)
 {
-        int        expired = 0;
-        cfs_time_t now;
+       int expired = 0;
+       time64_t now;
         cfs_time_t this_slot;
 
-        now = cfs_time_current_sec();
+       now = ktime_get_real_seconds();
         this_slot = now & STTIMER_SLOTTIMEMASK;
 
        spin_lock(&stt_data.stt_lock);
@@ -173,7 +163,6 @@ stt_check_timers (cfs_time_t *last)
        return expired;
 }
 
-#ifdef __KERNEL__
 
 static int
 stt_timer_main (void *arg)
@@ -213,21 +202,6 @@ stt_start_timer_thread (void)
        return 0;
 }
 
-#else /* !__KERNEL__ */
-
-int
-stt_check_events (void)
-{
-        return stt_check_timers(&stt_data.stt_prev_slot);
-}
-
-int
-stt_poll_interval (void)
-{
-        return STTIMER_SLOTTIME;
-}
-
-#endif
 
 int
 stt_startup (void)
@@ -236,19 +210,17 @@ stt_startup (void)
         int i;
 
         stt_data.stt_shuttingdown = 0;
-        stt_data.stt_prev_slot = cfs_time_current_sec() & STTIMER_SLOTTIMEMASK;
+       stt_data.stt_prev_slot = ktime_get_real_seconds() & STTIMER_SLOTTIMEMASK;
 
        spin_lock_init(&stt_data.stt_lock);
         for (i = 0; i < STTIMER_NSLOTS; i++)
                INIT_LIST_HEAD(&stt_data.stt_hash[i]);
 
-#ifdef __KERNEL__
        stt_data.stt_nthreads = 0;
        init_waitqueue_head(&stt_data.stt_waitq);
        rc = stt_start_timer_thread();
        if (rc != 0)
                CERROR ("Can't spawn timer thread: %d\n", rc);
-#endif
 
         return rc;
 }
@@ -265,12 +237,10 @@ stt_shutdown(void)
 
        stt_data.stt_shuttingdown = 1;
 
-#ifdef __KERNEL__
        wake_up(&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);
-#endif
 
        spin_unlock(&stt_data.stt_lock);
 }