From patchwork Mon Dec 3 16:28:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 203397 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 6EE822C0080 for ; Tue, 4 Dec 2012 03:36:19 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C457F4A0C7; Mon, 3 Dec 2012 17:36:15 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iZF870D8+qE0; Mon, 3 Dec 2012 17:36:15 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D6CFD4A0B0; Mon, 3 Dec 2012 17:36:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5E26B4A0B0 for ; Mon, 3 Dec 2012 17:36:09 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kEj8BiXI8EWv for ; Mon, 3 Dec 2012 17:36:08 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-wg0-f54.google.com (mail-wg0-f54.google.com [74.125.82.54]) by theia.denx.de (Postfix) with ESMTPS id 5E4664A0AB for ; Mon, 3 Dec 2012 17:36:07 +0100 (CET) Received: by mail-wg0-f54.google.com with SMTP id fg15so1636183wgb.9 for ; Mon, 03 Dec 2012 08:36:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=PyDdBqt6q9dMvpPNcE8tIaz93tK5qk9FKiTzjPUU0+c=; b=PY0NKwWk5zI98L1taUQ0D76Ax7CwZS+jZd/vKI6F4QcQMVW5nqLAqWSpJmB/NWkjUl 1A9ggN5m44P5MJOuqee8u0Ui5qg9S11vF8Yoy9vEPOwMC3FLPd3VvHy+Pdqs21gVzL7m Mo2s1ujv1A4oRGdnVCfeW8x1Mcu+YJIWjxuUWLuKnSghr3jidS75P6teTHHex+fq7dMM zejKpYfj+fwDRFEGWuox+peD8apMsCXfLsCofRkP3+EEHAUdB5e5tIXuA3iBtDCmoqov DuPoYXtHBjuJ/4zpOqoqA4QbNqy/cA7rA08SbJw8obKDBk/jjefunQiMlJ9R2pk7PPG7 7ofg== Received: by 10.216.212.2 with SMTP id x2mr3631955weo.32.1354552121336; Mon, 03 Dec 2012 08:28:41 -0800 (PST) Received: from localhost.localdomain (lyon.paratronic.fr. [213.41.177.106]) by mx.google.com with ESMTPS id gz3sm11588278wib.2.2012.12.03.08.28.40 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 03 Dec 2012 08:28:40 -0800 (PST) From: Richard Genoud To: u-boot@lists.denx.de Date: Mon, 3 Dec 2012 17:28:28 +0100 Message-Id: <1354552108-5966-1-git-send-email-richard.genoud@gmail.com> X-Mailer: git-send-email 1.7.2.5 Cc: trini@ti.com Subject: [U-Boot] [PATCHv2] cmd_time: merge run_command_and_time_it with cmd_process X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de As far as every arch has a get_timer function, run_command_and_time_it code can now disappear. Signed-off-by: Richard Genoud Acked-By: Che-Liang Chiou --- common/cmd_time.c | 33 ++------------------------------- common/command.c | 6 +++++- common/hush.c | 2 +- common/main.c | 2 +- include/command.h | 4 +++- 5 files changed, 12 insertions(+), 35 deletions(-) diff --git a/common/cmd_time.c b/common/cmd_time.c index 6dbdbbf..9808cd6 100644 --- a/common/cmd_time.c +++ b/common/cmd_time.c @@ -22,36 +22,6 @@ #include #include -/* - * TODO(clchiou): This function actually minics the bottom-half of the - * run_command() function. Since this function has ARM-dependent timer - * codes, we cannot merge it with the run_command() for now. - */ -static int run_command_and_time_it(int flag, int argc, char * const argv[], - ulong *cycles) -{ - cmd_tbl_t *cmdtp = find_cmd(argv[0]); - int retval = 0; - - if (!cmdtp) { - printf("%s: command not found\n", argv[0]); - return 1; - } - if (argc > cmdtp->maxargs) - return CMD_RET_USAGE; - - /* - * TODO(clchiou): get_timer_masked() is only defined in certain ARM - * boards. We could use the new timer API that Graeme is proposing - * so that this piece of code would be arch-independent. - */ - *cycles = get_timer_masked(); - retval = cmdtp->cmd(cmdtp, flag, argc, argv); - *cycles = get_timer_masked() - *cycles; - - return retval; -} - static void report_time(ulong cycles) { ulong minutes, seconds, milliseconds; @@ -75,11 +45,12 @@ static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong cycles = 0; int retval = 0; + int repeatable; if (argc == 1) return CMD_RET_USAGE; - retval = run_command_and_time_it(0, argc - 1, argv + 1, &cycles); + retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles); report_time(cycles); return retval; diff --git a/common/command.c b/common/command.c index 50c8429..305a236 100644 --- a/common/command.c +++ b/common/command.c @@ -513,7 +513,7 @@ static int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } enum command_ret_t cmd_process(int flag, int argc, char * const argv[], - int *repeatable) + int *repeatable, ulong *ticks) { enum command_ret_t rc = CMD_RET_SUCCESS; cmd_tbl_t *cmdtp; @@ -543,7 +543,11 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[], /* If OK so far, then do the command */ if (!rc) { + if (ticks) + *ticks = get_timer(0); rc = cmd_call(cmdtp, flag, argc, argv); + if (ticks) + *ticks = get_timer(*ticks); *repeatable &= cmdtp->repeatable; } if (rc == CMD_RET_USAGE) diff --git a/common/hush.c b/common/hush.c index eb6c879..cc81c9c 100644 --- a/common/hush.c +++ b/common/hush.c @@ -1665,7 +1665,7 @@ static int run_pipe_real(struct pipe *pi) } /* Process the command */ return cmd_process(flag, child->argc, child->argv, - &flag_repeat); + &flag_repeat, NULL); #endif } #ifndef __U_BOOT__ diff --git a/common/main.c b/common/main.c index 5362781..7bdba3e 100644 --- a/common/main.c +++ b/common/main.c @@ -1442,7 +1442,7 @@ static int builtin_run_command(const char *cmd, int flag) continue; } - if (cmd_process(flag, argc, argv, &repeatable)) + if (cmd_process(flag, argc, argv, &repeatable, NULL)) rc = -1; /* Did the user stop this? */ diff --git a/include/command.h b/include/command.h index 10bc260..1344d71 100644 --- a/include/command.h +++ b/include/command.h @@ -139,10 +139,12 @@ enum command_ret_t { * @param repeatable This function sets this to 0 if the command is not * repeatable. If the command is repeatable, the value * is left unchanged. + * @param ticks If ticks is not null, this function set it to the + * number of ticks the command took to complete. * @return 0 if the command succeeded, 1 if it failed */ int cmd_process(int flag, int argc, char * const argv[], - int *repeatable); + int *repeatable, ulong *ticks); #endif /* __ASSEMBLY__ */