1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2011 The Chromium OS Authors.
4  */
5 
6 #include <command.h>
7 
report_time(ulong cycles)8 static void report_time(ulong cycles)
9 {
10 	ulong minutes, seconds, milliseconds;
11 	ulong total_seconds, remainder;
12 
13 	total_seconds = cycles / CONFIG_SYS_HZ;
14 	remainder = cycles % CONFIG_SYS_HZ;
15 	minutes = total_seconds / 60;
16 	seconds = total_seconds % 60;
17 	/* approximate millisecond value */
18 	milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
19 
20 	printf("\ntime:");
21 	if (minutes)
22 		printf(" %lu minutes,", minutes);
23 	printf(" %lu.%03lu seconds\n", seconds, milliseconds);
24 }
25 
do_time(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])26 static int do_time(struct cmd_tbl *cmdtp, int flag, int argc,
27 		   char *const argv[])
28 {
29 	ulong cycles = 0;
30 	int retval = 0;
31 	int repeatable = 0;
32 
33 	if (argc == 1)
34 		return CMD_RET_USAGE;
35 
36 	retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
37 	report_time(cycles);
38 
39 	return retval;
40 }
41 
42 U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
43 		"run commands and summarize execution time",
44 		"command [args...]\n");
45