X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=libcfs%2Finclude%2Flibcfs%2Fwinnt%2Fwinnt-time.h;h=0a376b74dfc76eaf13eb7c6a50f836933bb81e02;hp=a7a570cf4083f377867366b0678a33c717671241;hb=9f8e9741e1cc770c766cf714f8327254c0d5fed0;hpb=e1b3d71a27c166bebd26ab33f7299c41bd75dab5 diff --git a/libcfs/include/libcfs/winnt/winnt-time.h b/libcfs/include/libcfs/winnt/winnt-time.h index a7a570c..0a376b7 100644 --- a/libcfs/include/libcfs/winnt/winnt-time.h +++ b/libcfs/include/libcfs/winnt/winnt-time.h @@ -1,25 +1,41 @@ -/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=4:tabstop=4: +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: * - * Copyright (C) 2004 Cluster File Systems, Inc. + * GPL HEADER START * - * This file is part of Lustre, http://www.lustre.org. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Lustre is free software; you can redistribute it and/or modify it under the - * terms of version 2 of the GNU General Public License as published by the - * Free Software Foundation. + * 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. * - * Lustre 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 for more - * details. + * 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 along - * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass - * Ave, Cambridge, MA 02139, USA. + * 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 * - * Implementation of portable time API for Winnt (kernel and user-level). + * 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. + * + * libcfs/include/libcfs/winnt/winnt-time.h * + * Implementation of portable time API for Winnt (kernel and user-level). */ #ifndef __LIBCFS_WINNT_LINUX_TIME_H__ @@ -68,33 +84,36 @@ * */ -#define ONE_BILLION ((u_int64_t)1000000000) -#define ONE_MILLION ((u_int64_t) 1000000) - -#define HZ (100) - struct timeval { - time_t tv_sec; /* seconds */ - suseconds_t tv_usec; /* microseconds */ + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* microseconds */ }; -struct timespec { - ulong_ptr tv_sec; - ulong_ptr tv_nsec; -}; +typedef time_t cfs_time_t; +typedef time_t cfs_duration_t; #ifdef __KERNEL__ #include +#define HZ (100) + +struct timespec { + __u32 tv_sec; + __u32 tv_nsec; +}; +typedef struct timeval cfs_fs_time_t; + + +#define ONE_BILLION ((u_int64_t)1000000000) +#define ONE_MILLION ((u_int64_t) 1000000) + /* * Generic kernel stuff */ -typedef struct timeval cfs_fs_time_t; - -typedef u_int64_t cfs_time_t; -typedef int64_t cfs_duration_t; +#define jiffies (ULONG_PTR)JIFFIES() +#define cfs_jiffies (ULONG_PTR)JIFFIES() static inline void do_gettimeofday(struct timeval *tv) { @@ -102,11 +121,13 @@ static inline void do_gettimeofday(struct timeval *tv) KeQuerySystemTime(&Time); - tv->tv_sec = (long_ptr) (Time.QuadPart / 10000000); - tv->tv_usec = (long_ptr) (Time.QuadPart % 10000000) / 10; + tv->tv_sec = (time_t) (Time.QuadPart / 10000000); + tv->tv_usec = (suseconds_t) (Time.QuadPart % 10000000) / 10; } -static inline cfs_time_t JIFFIES() +#define cfs_do_gettimeofday(tv) do_gettimeofday(tv) + +static inline LONGLONG JIFFIES() { LARGE_INTEGER Tick; LARGE_INTEGER Elapse; @@ -121,33 +142,16 @@ static inline cfs_time_t JIFFIES() static inline cfs_time_t cfs_time_current(void) { - return JIFFIES(); -} - -static inline cfs_time_t cfs_time_current_sec(void) -{ - return (JIFFIES() / HZ); -} - -static inline cfs_time_t cfs_time_add(cfs_time_t t, cfs_duration_t d) -{ - return (t + d); -} - -static inline cfs_duration_t cfs_time_sub(cfs_time_t t1, cfs_time_t t2) -{ - return (t1 - t2); + return (cfs_time_t)JIFFIES(); } -static inline int cfs_time_before(cfs_time_t t1, cfs_time_t t2) +static inline time_t cfs_time_current_sec(void) { - return ((int64_t)t1 - (int64_t)t2) < 0; + return (time_t)(JIFFIES() / HZ); } -static inline int cfs_time_beforeq(cfs_time_t t1, cfs_time_t t2) -{ - return ((int64_t)t1 - (int64_t)t2) <= 0; -} +#define time_before(t1, t2) (((signed)(t1) - (signed)(t2)) < 0) +#define time_before_eq(t1, t2) (((signed)(t1) - (signed)(t2)) <= 0) static inline void cfs_fs_time_current(cfs_fs_time_t *t) { @@ -162,14 +166,21 @@ static inline void cfs_fs_time_current(cfs_fs_time_t *t) t->tv_usec = (Sys.LowPart % 10000000) / 10; } +static inline unsigned long get_seconds(void) +{ + cfs_fs_time_t t; + cfs_fs_time_current(&t); + return (unsigned long) t.tv_sec; +} + static inline cfs_time_t cfs_fs_time_sec(cfs_fs_time_t *t) { - return t->tv_sec; + return (cfs_time_t)t->tv_sec; } -static inline u_int64_t __cfs_fs_time_flat(cfs_fs_time_t *t) +static inline unsigned long __cfs_fs_time_flat(cfs_fs_time_t *t) { - return ((u_int64_t)t->tv_sec) * ONE_MILLION + t->tv_usec; + return (unsigned long)(t->tv_sec) * ONE_MILLION + t->tv_usec; } static inline int cfs_fs_time_before(cfs_fs_time_t *t1, cfs_fs_time_t *t2) @@ -182,126 +193,95 @@ static inline int cfs_fs_time_beforeq(cfs_fs_time_t *t1, cfs_fs_time_t *t2) return (__cfs_fs_time_flat(t1) <= __cfs_fs_time_flat(t2)); } -static inline cfs_duration_t cfs_time_seconds(int seconds) +static inline cfs_duration_t cfs_time_seconds(cfs_duration_t seconds) { - return (cfs_duration_t)seconds * HZ; + return (cfs_duration_t)(seconds * HZ); } -static inline cfs_time_t cfs_duration_sec(cfs_duration_t d) +static inline time_t cfs_duration_sec(cfs_duration_t d) { - return d / HZ; + return (time_t)(d / HZ); } static inline void cfs_duration_usec(cfs_duration_t d, struct timeval *s) { - s->tv_sec = (suseconds_t) (d / HZ); - s->tv_usec = (time_t)((d - (cfs_duration_t)s->tv_sec * HZ) * + s->tv_sec = (__u32)(d / HZ); + s->tv_usec = (__u32)((d - (cfs_duration_t)s->tv_sec * HZ) * ONE_MILLION / HZ); } static inline void cfs_duration_nsec(cfs_duration_t d, struct timespec *s) { - s->tv_sec = (suseconds_t) (d / HZ); - s->tv_nsec = (time_t)((d - (cfs_duration_t)s->tv_sec * HZ) * - ONE_BILLION / HZ); + s->tv_sec = (__u32) (d / HZ); + s->tv_nsec = (__u32)((d - (cfs_duration_t)s->tv_sec * HZ) * + ONE_BILLION / HZ); } static inline void cfs_fs_time_usec(cfs_fs_time_t *t, struct timeval *v) { - *v = *t; + *v = *t; } static inline void cfs_fs_time_nsec(cfs_fs_time_t *t, struct timespec *s) { - s->tv_sec = t->tv_sec; - s->tv_nsec = t->tv_usec * 1000; + s->tv_sec = (__u32) t->tv_sec; + s->tv_nsec = (__u32) t->tv_usec * 1000; } -#define cfs_time_current_64 cfs_time_current -#define cfs_time_add_64 cfs_time_add -#define cfs_time_shift_64 cfs_time_shift -#define cfs_time_before_64 cfs_time_before -#define cfs_time_beforeq_64 cfs_time_beforeq - -/* - * One jiffy - */ -#define CFS_TICK (1) - -#define LTIME_S(t) (t) - -#define CFS_TIME_T "%I64u" -#define CFS_DURATION_T "%I64d" - -#else /* !__KERNEL__ */ - -/* - * Liblustre. time(2) based implementation. - */ -#include - -// -// Time routines ... -// +#define cfs_time_current_64 JIFFIES -NTSYSAPI -CCHAR -NTAPI -NtQuerySystemTime( - OUT PLARGE_INTEGER CurrentTime - ); - - -NTSYSAPI -BOOLEAN -NTAPI -RtlTimeToSecondsSince1970( - IN PLARGE_INTEGER Time, - OUT PULONG ElapsedSeconds - ); - - -NTSYSAPI -VOID -NTAPI -RtlSecondsSince1970ToTime( - IN ULONG ElapsedSeconds, - OUT PLARGE_INTEGER Time - ); +static inline __u64 cfs_time_add_64(__u64 t, __u64 d) +{ + return t + d; +} -NTSYSAPI -VOID -NTAPI -Sleep( - DWORD dwMilliseconds // sleep time in milliseconds -); +static inline __u64 cfs_time_shift_64(cfs_duration_t seconds) +{ + return cfs_time_add_64(cfs_time_current_64(), + cfs_time_seconds(seconds)); +} +static inline int cfs_time_before_64(__u64 t1, __u64 t2) +{ + return (__s64)t2 - (__s64)t1 > 0; +} -static inline void sleep(int time) +static inline int cfs_time_beforeq_64(__u64 t1, __u64 t2) { - DWORD Time = 1000 * time; - Sleep(Time); + return (__s64)t2 - (__s64)t1 >= 0; } +/* + * One jiffy + */ +#define CFS_TICK (1) +#define LTIME_S(t) *((__u64 *)&(t)) -static inline void do_gettimeofday(struct timeval *tv) -{ - LARGE_INTEGER Time; +#define CFS_TIME_T "%u" +#define CFS_DURATION_T "%d" - NtQuerySystemTime(&Time); +#else /* !__KERNEL__ */ - tv->tv_sec = (long_ptr) (Time.QuadPart / 10000000); - tv->tv_usec = (long_ptr) (Time.QuadPart % 10000000) / 10; -} +#include +#ifdef HAVE_LIBPTHREAD +#include +#else +struct timespec { + unsigned long tv_sec; + unsigned long tv_nsec; +}; +#endif /* HAVE_LIBPTHREAD */ -static inline int gettimeofday(struct timeval *tv, void * tz) -{ - do_gettimeofday(tv); - return 0; -} +#include "../user-time.h" + +/* liblustre. time(2) based implementation. */ +int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); +void sleep(int time); +void do_gettimeofday(struct timeval *tv); +int gettimeofday(struct timeval *tv, void * tz); -#endif /* __KERNEL__ */ +#endif /* !__KERNEL__ */ /* __LIBCFS_LINUX_LINUX_TIME_H__ */ #endif