Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Che-liang Chiou | ca366d0 | 2011-10-06 23:40:48 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Che-liang Chiou | ca366d0 | 2011-10-06 23:40:48 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <command.h> |
| 8 | |
Che-liang Chiou | ca366d0 | 2011-10-06 23:40:48 +0000 | [diff] [blame] | 9 | static void report_time(ulong cycles) |
| 10 | { |
| 11 | ulong minutes, seconds, milliseconds; |
| 12 | ulong total_seconds, remainder; |
| 13 | |
| 14 | total_seconds = cycles / CONFIG_SYS_HZ; |
| 15 | remainder = cycles % CONFIG_SYS_HZ; |
| 16 | minutes = total_seconds / 60; |
| 17 | seconds = total_seconds % 60; |
| 18 | /* approximate millisecond value */ |
| 19 | milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ; |
| 20 | |
| 21 | printf("\ntime:"); |
| 22 | if (minutes) |
| 23 | printf(" %lu minutes,", minutes); |
Masahiro Yamada | 1d64377 | 2014-04-18 17:46:13 +0900 | [diff] [blame] | 24 | printf(" %lu.%03lu seconds\n", seconds, milliseconds); |
Che-liang Chiou | ca366d0 | 2011-10-06 23:40:48 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 27 | static int do_time(struct cmd_tbl *cmdtp, int flag, int argc, |
| 28 | char *const argv[]) |
Che-liang Chiou | ca366d0 | 2011-10-06 23:40:48 +0000 | [diff] [blame] | 29 | { |
| 30 | ulong cycles = 0; |
| 31 | int retval = 0; |
Tom Rini | 146dda3 | 2017-09-26 21:12:05 -0400 | [diff] [blame] | 32 | int repeatable = 0; |
Che-liang Chiou | ca366d0 | 2011-10-06 23:40:48 +0000 | [diff] [blame] | 33 | |
| 34 | if (argc == 1) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 35 | return CMD_RET_USAGE; |
Che-liang Chiou | ca366d0 | 2011-10-06 23:40:48 +0000 | [diff] [blame] | 36 | |
Richard Genoud | 34765e8 | 2012-12-03 06:28:28 +0000 | [diff] [blame] | 37 | retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles); |
Che-liang Chiou | ca366d0 | 2011-10-06 23:40:48 +0000 | [diff] [blame] | 38 | report_time(cycles); |
| 39 | |
| 40 | return retval; |
| 41 | } |
| 42 | |
| 43 | U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time, |
| 44 | "run commands and summarize execution time", |
| 45 | "command [args...]\n"); |