Annotation of qemu/roms/ipxe/src/interface/linux/linux_timer.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (C) 2010 Piotr JaroszyƄski <[email protected]>
                      3:  *
                      4:  * This program is free software; you can redistribute it and/or
                      5:  * modify it under the terms of the GNU General Public License as
                      6:  * published by the Free Software Foundation; either version 2 of the
                      7:  * License, or any later version.
                      8:  *
                      9:  * This program is distributed in the hope that it will be useful, but
                     10:  * WITHOUT ANY WARRANTY; without even the implied warranty of
                     11:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     12:  * General Public License for more details.
                     13:  *
                     14:  * You should have received a copy of the GNU General Public License
                     15:  * along with this program; if not, write to the Free Software
                     16:  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
                     17:  */
                     18: 
                     19: FILE_LICENCE(GPL2_OR_LATER);
                     20: 
                     21: #include <ipxe/timer.h>
                     22: 
                     23: #include <linux_api.h>
                     24: 
                     25: /** @file
                     26:  *
                     27:  * iPXE timer API for linux
                     28:  *
                     29:  */
                     30: 
                     31: /**
                     32:  * Delay for a fixed number of microseconds
                     33:  *
                     34:  * @v usecs            Number of microseconds for which to delay
                     35:  */
                     36: static void linux_udelay(unsigned long usecs)
                     37: {
                     38:        linux_usleep(usecs);
                     39: }
                     40: 
                     41: /**
                     42:  * Get number of ticks per second
                     43:  *
                     44:  * @ret ticks_per_sec  Number of ticks per second
                     45:  */
                     46: static unsigned long linux_ticks_per_sec(void)
                     47: {
                     48:        return 1000;
                     49: }
                     50: 
                     51: /**
                     52:  * Get current system time in ticks
                     53:  *
                     54:  * linux doesn't provide an easy access to jiffies so implement it by measuring
                     55:  * the time since the first call to this function.
                     56:  *
                     57:  * @ret ticks          Current time, in ticks
                     58:  */
                     59: static unsigned long linux_currticks(void)
                     60: {
                     61:        static struct timeval start;
                     62:        static int initialized = 0;
                     63: 
                     64:        if (! initialized) {
                     65:                linux_gettimeofday(&start, NULL);
                     66:                initialized = 1;
                     67:        }
                     68: 
                     69:        struct timeval now;
                     70:        linux_gettimeofday(&now, NULL);
                     71: 
                     72:        unsigned long ticks = (now.tv_sec - start.tv_sec) * linux_ticks_per_sec();
                     73:        ticks += (now.tv_usec - start.tv_usec) / (long)(1000000 / linux_ticks_per_sec());
                     74: 
                     75:        return ticks;
                     76: }
                     77: 
                     78: PROVIDE_TIMER(linux, udelay, linux_udelay);
                     79: PROVIDE_TIMER(linux, currticks, linux_currticks);
                     80: PROVIDE_TIMER(linux, ticks_per_sec, linux_ticks_per_sec);

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.