diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2011-08-04 14:49:33 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2011-08-04 14:49:33 +0200 |
commit | db879ec1a96df9ee35d89500a081177b485c3a8b (patch) | |
tree | 3b42bd81ea6c3e469f95043f769d0b1a80b89992 /commands | |
parent | 8949efd0e186ea5ab4ff9c0864dc5e85758ea94f (diff) | |
parent | 454f331bfecd72e25100af0bbccdf9a6dd707189 (diff) | |
download | barebox-db879ec1a96df9ee35d89500a081177b485c3a8b.tar.gz barebox-db879ec1a96df9ee35d89500a081177b485c3a8b.tar.xz |
Merge branch 'next'
Diffstat (limited to 'commands')
-rw-r--r-- | commands/Kconfig | 10 | ||||
-rw-r--r-- | commands/Makefile | 1 | ||||
-rw-r--r-- | commands/loads.c | 2 | ||||
-rw-r--r-- | commands/mem.c | 35 | ||||
-rw-r--r-- | commands/time.c | 57 |
5 files changed, 79 insertions, 26 deletions
diff --git a/commands/Kconfig b/commands/Kconfig index 5700dc2890..e9222601c4 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -97,6 +97,16 @@ endchoice endif +config CMD_TIME + bool "time" + help + Just like the unix time command this command allows to measure the + execution time of a command. Note: barebox does not use interrupts, + so the system timer can overrun during the execution of the command + resulting in incorrect results. The timer gets updated in the function + checking for ctrl-c, so the time command can be used with commands + which are interruptible with ctrl-c. + endmenu menu "file commands " diff --git a/commands/Makefile b/commands/Makefile index 8ee4aba726..7c88b488f2 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -57,3 +57,4 @@ obj-$(CONFIG_CMD_LOGIN) += login.o obj-$(CONFIG_CMD_LED) += led.o obj-$(CONFIG_CMD_LED_TRIGGER) += trigger.o obj-$(CONFIG_CMD_USB) += usb.o +obj-$(CONFIG_CMD_TIME) += time.o diff --git a/commands/loads.c b/commands/loads.c index 6e0dc7fabc..c6617a4e68 100644 --- a/commands/loads.c +++ b/commands/loads.c @@ -31,8 +31,6 @@ #include <exports.h> #include <xyzModem.h> -DECLARE_GLOBAL_DATA_PTR; - static ulong load_serial (ulong offset); static int read_record (char *buf, ulong len); static int do_echo = 1; diff --git a/commands/mem.c b/commands/mem.c index 8df5f0a89a..88af55c1b8 100644 --- a/commands/mem.c +++ b/commands/mem.c @@ -1,14 +1,12 @@ /* - * (C) Copyright 2000 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * Copyright (c) 2011 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix * * See file CREDITS for list of people who contributed to this * project. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * MA 02111-1307 USA */ @@ -485,6 +483,9 @@ static int do_mem_cp(struct command *cmdtp, int argc, char *argv[]) } count -= r; + + if (ctrlc()) + goto out; } if (count) { @@ -589,14 +590,13 @@ static struct file_operations memops = { static int mem_probe(struct device_d *dev) { - struct memory_platform_data *pdata = dev->platform_data; struct cdev *cdev; cdev = xzalloc(sizeof (*cdev)); dev->priv = cdev; - cdev->name = pdata->name; - cdev->size = dev->size; + cdev->name = (char*)dev->resource[0].name; + cdev->size = (unsigned long)dev->resource[0].size; cdev->ops = &memops; cdev->dev = dev; @@ -610,19 +610,6 @@ static struct driver_d mem_drv = { .probe = mem_probe, }; -static struct memory_platform_data mem_dev_pdata = { - .name = "mem", - .flags = DEVFS_RDWR, -}; - -static struct device_d mem_dev = { - .id = -1, - .name = "mem", - .map_base = 0, - .size = ~0, /* FIXME: should be 0x100000000, ahem... */ - .platform_data = &mem_dev_pdata, -}; - static int mem_init(void) { rw_buf = malloc(RW_BUF_SIZE); @@ -631,8 +618,8 @@ static int mem_init(void) return -1; } + add_mem_device("mem", 0, ~0, IORESOURCE_MEM_WRITEABLE); register_driver(&mem_drv); - register_device(&mem_dev); return 0; } diff --git a/commands/time.c b/commands/time.c new file mode 100644 index 0000000000..9a769451aa --- /dev/null +++ b/commands/time.c @@ -0,0 +1,57 @@ +#include <common.h> +#include <command.h> +#include <clock.h> +#include <asm-generic/div64.h> +#include <malloc.h> + +static int do_time(struct command *cmdtp, int argc, char *argv[]) +{ + int i; + unsigned char *buf; + u64 start, end, diff64; + unsigned long diff; + int len = 0; + + if (argc < 2) + return COMMAND_ERROR_USAGE; + + for (i = 1; i < argc; i++) + len += strlen(argv[i]) + 1; + + buf = xzalloc(len); + + for (i = 1; i < argc; i++) { + strcat(buf, argv[i]); + strcat(buf, " "); + } + + start = get_time_ns(); + + run_command(buf, 0); + + end = get_time_ns(); + + diff64 = end - start; + + do_div(diff64, 1000000); + + diff = diff64; + + printf("time: %ldms\n", diff); + + free(buf); + + return 0; +} + +BAREBOX_CMD_HELP_START(time) +BAREBOX_CMD_HELP_USAGE("time <command>\n") +BAREBOX_CMD_HELP_SHORT("note: This command depends on <command> being interruptible,\n") +BAREBOX_CMD_HELP_SHORT("Otherwise the timer may overrun resulting in incorrect results\n") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(time) + .cmd = do_time, + .usage = "measure execution time of a command", + BAREBOX_CMD_HELP(cmd_time_help) +BAREBOX_CMD_END |