1a6f1bef2SFrançois Tigeot /* 2a6f1bef2SFrançois Tigeot * Copyright (c) 2014 François Tigeot 3a6f1bef2SFrançois Tigeot * All rights reserved. 4a6f1bef2SFrançois Tigeot * 5a6f1bef2SFrançois Tigeot * Redistribution and use in source and binary forms, with or without 6a6f1bef2SFrançois Tigeot * modification, are permitted provided that the following conditions 7a6f1bef2SFrançois Tigeot * are met: 8a6f1bef2SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright 9a6f1bef2SFrançois Tigeot * notice unmodified, this list of conditions, and the following 10a6f1bef2SFrançois Tigeot * disclaimer. 11a6f1bef2SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright 12a6f1bef2SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the 13a6f1bef2SFrançois Tigeot * documentation and/or other materials provided with the distribution. 14a6f1bef2SFrançois Tigeot * 15a6f1bef2SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16a6f1bef2SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17a6f1bef2SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18a6f1bef2SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19a6f1bef2SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20a6f1bef2SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21a6f1bef2SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22a6f1bef2SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23a6f1bef2SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24a6f1bef2SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25a6f1bef2SFrançois Tigeot */ 26a6f1bef2SFrançois Tigeot 27a6f1bef2SFrançois Tigeot #ifndef _LINUX_JIFFIES_H_ 28a6f1bef2SFrançois Tigeot #define _LINUX_JIFFIES_H_ 29a6f1bef2SFrançois Tigeot 30a6f1bef2SFrançois Tigeot #include <linux/time.h> 31*e3440f96SFrançois Tigeot #include <sys/kernel.h> 32*e3440f96SFrançois Tigeot #include <machine/limits.h> 33*e3440f96SFrançois Tigeot 34*e3440f96SFrançois Tigeot #define HZ hz 35a6f1bef2SFrançois Tigeot 36a6f1bef2SFrançois Tigeot #define jiffies_to_msecs(x) (((int64_t)(x)) * 1000 / hz) 37a6f1bef2SFrançois Tigeot #define msecs_to_jiffies(x) (((int64_t)(x)) * hz / 1000) 38a6f1bef2SFrançois Tigeot #define jiffies ticks 39a6f1bef2SFrançois Tigeot #define time_after(a,b) ((long)(b) - (long)(a) < 0) 40a6f1bef2SFrançois Tigeot #define time_after_eq(a,b) ((long)(b) - (long)(a) <= 0) 41a6f1bef2SFrançois Tigeot 42a6f1bef2SFrançois Tigeot static inline unsigned long 43a6f1bef2SFrançois Tigeot timespec_to_jiffies(const struct timespec *ts) 44a6f1bef2SFrançois Tigeot { 45a6f1bef2SFrançois Tigeot unsigned long result; 46a6f1bef2SFrançois Tigeot 47a6f1bef2SFrançois Tigeot result = ((unsigned long)hz * ts->tv_sec) + (ts->tv_nsec / NSEC_PER_SEC); 48a6f1bef2SFrançois Tigeot if (result > LONG_MAX) 49a6f1bef2SFrançois Tigeot result = LONG_MAX; 50a6f1bef2SFrançois Tigeot 51a6f1bef2SFrançois Tigeot return result; 52a6f1bef2SFrançois Tigeot } 53a6f1bef2SFrançois Tigeot 54a6f1bef2SFrançois Tigeot #endif /* _LINUX_JIFFIES_H_ */ 55