X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lnet%2Fselftest%2Ftimer.c;h=2b569dc6bc4dfe72f4e4add5b3361139947319d3;hp=28edcaed0e249905bd2c56d299e7939bdeb62f26;hb=54320d7f52e6dd2b32e64997e2f7ae1ff1060f6f;hpb=70e80ade90af09300396706b8910e196a7928520 diff --git a/lnet/selftest/timer.c b/lnet/selftest/timer.c index 28edcae..2b569dc 100644 --- a/lnet/selftest/timer.c +++ b/lnet/selftest/timer.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -16,8 +14,8 @@ * 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 [sun.com URL with a - * copy of GPLv2]. + * 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 @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2011, Whamcloud, Inc. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -58,10 +58,10 @@ (STTIMER_NSLOTS - 1))]) struct st_timer_data { - spinlock_t stt_lock; + cfs_spinlock_t stt_lock; /* start time of the slot processed previously */ - cfs_time_t stt_prev_slot; - struct list_head stt_hash[STTIMER_NSLOTS]; + cfs_time_t stt_prev_slot; + cfs_list_t stt_hash[STTIMER_NSLOTS]; int stt_shuttingdown; #ifdef __KERNEL__ cfs_waitq_t stt_waitq; @@ -72,28 +72,28 @@ struct st_timer_data { void stt_add_timer (stt_timer_t *timer) { - struct list_head *pos; + cfs_list_t *pos; - spin_lock(&stt_data.stt_lock); + cfs_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_list_empty(&timer->stt_list)); LASSERT (cfs_time_after(timer->stt_expires, cfs_time_current_sec())); /* 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); + cfs_list_for_each_prev (pos, STTIMER_SLOT(timer->stt_expires)) { + stt_timer_t *old = cfs_list_entry(pos, stt_timer_t, stt_list); if (cfs_time_aftereq(timer->stt_expires, old->stt_expires)) break; } - list_add(&timer->stt_list, pos); + cfs_list_add(&timer->stt_list, pos); - spin_unlock(&stt_data.stt_lock); + cfs_spin_unlock(&stt_data.stt_lock); } /* @@ -110,42 +110,42 @@ stt_del_timer (stt_timer_t *timer) { int ret = 0; - spin_lock(&stt_data.stt_lock); + cfs_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)) { + if (!cfs_list_empty(&timer->stt_list)) { ret = 1; - list_del_init(&timer->stt_list); + cfs_list_del_init(&timer->stt_list); } - spin_unlock(&stt_data.stt_lock); + cfs_spin_unlock(&stt_data.stt_lock); return ret; } /* called with stt_data.stt_lock held */ int -stt_expire_list (struct list_head *slot, cfs_time_t now) +stt_expire_list (cfs_list_t *slot, cfs_time_t now) { int expired = 0; stt_timer_t *timer; - while (!list_empty(slot)) { - timer = list_entry(slot->next, stt_timer_t, stt_list); + while (!cfs_list_empty(slot)) { + timer = cfs_list_entry(slot->next, stt_timer_t, stt_list); if (cfs_time_after(timer->stt_expires, now)) break; - list_del_init(&timer->stt_list); - spin_unlock(&stt_data.stt_lock); + cfs_list_del_init(&timer->stt_list); + cfs_spin_unlock(&stt_data.stt_lock); expired++; (*timer->stt_func) (timer->stt_data); - spin_lock(&stt_data.stt_lock); + cfs_spin_lock(&stt_data.stt_lock); } return expired; @@ -161,7 +161,7 @@ stt_check_timers (cfs_time_t *last) now = cfs_time_current_sec(); this_slot = now & STTIMER_SLOTTIMEMASK; - spin_lock(&stt_data.stt_lock); + cfs_spin_lock(&stt_data.stt_lock); while (cfs_time_aftereq(this_slot, *last)) { expired += stt_expire_list(STTIMER_SLOT(this_slot), now); @@ -169,7 +169,7 @@ stt_check_timers (cfs_time_t *last) } *last = now & STTIMER_SLOTTIMEMASK; - spin_unlock(&stt_data.stt_lock); + cfs_spin_unlock(&stt_data.stt_lock); return expired; } @@ -178,8 +178,11 @@ stt_check_timers (cfs_time_t *last) int stt_timer_main (void *arg) { + int rc = 0; UNUSED(arg); + SET_BUT_UNUSED(rc); + cfs_daemonize("st_timer"); cfs_block_allsigs(); @@ -188,12 +191,13 @@ stt_timer_main (void *arg) cfs_waitq_wait_event_timeout(stt_data.stt_waitq, stt_data.stt_shuttingdown, - cfs_time_seconds(STTIMER_SLOTTIME)); + cfs_time_seconds(STTIMER_SLOTTIME), + rc); } - spin_lock(&stt_data.stt_lock); + cfs_spin_lock(&stt_data.stt_lock); stt_data.stt_nthreads--; - spin_unlock(&stt_data.stt_lock); + cfs_spin_unlock(&stt_data.stt_lock); return 0; } @@ -204,13 +208,13 @@ stt_start_timer_thread (void) LASSERT (!stt_data.stt_shuttingdown); - pid = cfs_kernel_thread(stt_timer_main, NULL, 0); + pid = cfs_create_thread(stt_timer_main, NULL, 0); if (pid < 0) return (int)pid; - spin_lock(&stt_data.stt_lock); + cfs_spin_lock(&stt_data.stt_lock); stt_data.stt_nthreads++; - spin_unlock(&stt_data.stt_lock); + cfs_spin_unlock(&stt_data.stt_lock); return 0; } @@ -239,7 +243,7 @@ stt_startup (void) stt_data.stt_shuttingdown = 0; stt_data.stt_prev_slot = cfs_time_current_sec() & STTIMER_SLOTTIMEMASK; - spin_lock_init(&stt_data.stt_lock); + cfs_spin_lock_init(&stt_data.stt_lock); for (i = 0; i < STTIMER_NSLOTS; i++) CFS_INIT_LIST_HEAD(&stt_data.stt_hash[i]); @@ -259,10 +263,10 @@ stt_shutdown (void) { int i; - spin_lock(&stt_data.stt_lock); + cfs_spin_lock(&stt_data.stt_lock); for (i = 0; i < STTIMER_NSLOTS; i++) - LASSERT (list_empty(&stt_data.stt_hash[i])); + LASSERT (cfs_list_empty(&stt_data.stt_hash[i])); stt_data.stt_shuttingdown = 1; @@ -273,6 +277,6 @@ stt_shutdown (void) stt_data.stt_nthreads); #endif - spin_unlock(&stt_data.stt_lock); + cfs_spin_unlock(&stt_data.stt_lock); return; }