Annotation of qemu/roms/ipxe/src/hci/commands/time_cmd.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (C) 2009 Daniel Verkamp <[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., 675 Mass Ave, Cambridge, MA 02139, USA.
        !            17:  *
        !            18:  * March-19-2009 @ 02:44: Added sleep command.
        !            19:  * Shao Miller <[email protected]>.
        !            20:  */
        !            21: 
        !            22: FILE_LICENCE ( GPL2_OR_LATER );
        !            23: 
        !            24: #include <stdio.h>
        !            25: #include <stdlib.h>
        !            26: #include <string.h>
        !            27: #include <unistd.h>
        !            28: #include <ipxe/command.h>
        !            29: #include <ipxe/parseopt.h>
        !            30: #include <ipxe/nap.h>
        !            31: #include <ipxe/timer.h>
        !            32: 
        !            33: /** @file
        !            34:  *
        !            35:  * Time commands
        !            36:  *
        !            37:  */
        !            38: 
        !            39: /** "time" options */
        !            40: struct time_options {};
        !            41: 
        !            42: /** "time" option list */
        !            43: static struct option_descriptor time_opts[] = {};
        !            44: 
        !            45: /** "time" command descriptor */
        !            46: static struct command_descriptor time_cmd =
        !            47:        COMMAND_DESC ( struct time_options, time_opts, 1, MAX_ARGUMENTS,
        !            48:                       "<command>" );
        !            49: 
        !            50: /**
        !            51:  * "time" command
        !            52:  *
        !            53:  * @v argc             Argument count
        !            54:  * @v argv             Argument list
        !            55:  * @ret rc             Return status code
        !            56:  */
        !            57: static int time_exec ( int argc, char **argv ) {
        !            58:        struct time_options opts;
        !            59:        unsigned long start;
        !            60:        int secs;
        !            61:        int rc;
        !            62: 
        !            63:        /* Parse options */
        !            64:        if ( ( rc = parse_options ( argc, argv, &time_cmd, &opts ) ) != 0 )
        !            65:                return rc;
        !            66: 
        !            67:        start = currticks();
        !            68:        rc = execv ( argv[1], argv + 1 );
        !            69:        secs = (currticks() - start) / ticks_per_sec();
        !            70: 
        !            71:        printf ( "%s: %ds\n", argv[0], secs );
        !            72: 
        !            73:        return rc;
        !            74: }
        !            75: 
        !            76: /** "time" command */
        !            77: struct command time_command __command = {
        !            78:        .name = "time",
        !            79:        .exec = time_exec,
        !            80: };
        !            81: 
        !            82: /** "sleep" options */
        !            83: struct sleep_options {};
        !            84: 
        !            85: /** "sleep" option list */
        !            86: static struct option_descriptor sleep_opts[] = {};
        !            87: 
        !            88: /** "sleep" command descriptor */
        !            89: static struct command_descriptor sleep_cmd =
        !            90:        COMMAND_DESC ( struct sleep_options, sleep_opts, 1, 1, "<seconds>" );
        !            91: 
        !            92: /**
        !            93:  * "sleep" command
        !            94:  *
        !            95:  * @v argc             Argument count
        !            96:  * @v argv             Argument list
        !            97:  * @ret rc             Return status code
        !            98:  */
        !            99: static int sleep_exec ( int argc, char **argv ) {
        !           100:        struct sleep_options opts;
        !           101:        unsigned long start, delay;
        !           102:        int rc;
        !           103: 
        !           104:        /* Parse options */
        !           105:        if ( ( rc = parse_options ( argc, argv, &sleep_cmd, &opts ) ) != 0 )
        !           106:                return rc;
        !           107: 
        !           108:        start = currticks();
        !           109:        delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec();
        !           110:        while ( ( currticks() - start ) <= delay )
        !           111:                cpu_nap();
        !           112:        return 0;
        !           113: }
        !           114: 
        !           115: /** "sleep" command */
        !           116: struct command sleep_command __command = {
        !           117:        .name = "sleep",
        !           118:        .exec = sleep_exec,
        !           119: };

unix.superglobalmegacorp.com

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