commands: Add dhrystone
PATCH 1/1 commands: Add dhrystone
This tool will help to measure the system performance.
Some SoCs haven't the possibility to route their clocks to the output pins. So you can use dhrystone to get a feedback about the clock speed.
---
Changes:
v1:
applied RFC suggestions:
-removed 'default n' in Kconfig
-refactored time defines with default time units -only print variable values when values are wrong -added units to printf
-the iteration parameter is now optional. The programm starts with 10000 iterations and adjust higher, when execution time is too short.
-changed variable name (microseconds -> nanoseconds) -corrected the command description
commands/Kconfig | 6 + commands/Makefile | 1 + commands/dhrystone.c | 466 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 473 insertions(+) create mode 100644 commands/dhrystone.c
commands/Kconfig +6 -0
@@ -2102,6 +2102,12 @@ config CMD_STATE depends on STATE prompt "state" +config CMD_DHRYSTONE + bool + prompt "dhrystone" + help + CPU benchmark tool + # end Miscellaneous commands endmenu
commands/Makefile +1 -0
@@ -112,3 +112,4 @@ obj-$(CONFIG_CMD_NV) += nv.o obj-$(CONFIG_CMD_DEFAULTENV) += defaultenv.o obj-$(CONFIG_CMD_STATE) += state.o obj-$(CONFIG_CMD_DHCP) += dhcp.o +obj-$(CONFIG_CMD_DHRYSTONE) += dhrystone.o
commands/dhrystone.c new file +466 -0
466 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 8 lines · Daniel Schultz
This tool will help to measure the system performance.
Some SoCs haven't the possibility to route their clocks to the output pins. So you can use dhrystone to get a feedback about the clock speed.
Signed-off-by Daniel Schultz <[email protected]>---
Quoted 10 lines
Changes:
v1:
applied RFC suggestions:
-removed 'default n' inKconfig
-refactored time defines with default time units -only print variable values when values are wrong -added units to printf
-the iteration parameter is now optional. The programm starts with 10000 iterations and adjust higher, when execution time is too short.
I can see that the parameter is now optional, but I can't find the code which adjusts the number of iterations. Am I missing something?
Quoted 95 lines
-changed variable name (microseconds -> nanoseconds) -corrected the command descriptioncommands/Kconfig | 6 + commands/Makefile | 1 + commands/dhrystone.c | 466 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 473 insertions(+) create mode 100644 commands/dhrystone.ccommands/Kconfig +6
-0@@ -2102,6 +2102,12 @@ config CMD_STATE depends on STATE prompt "state" +config CMD_DHRYSTONE + bool + prompt "dhrystone" + help + CPU benchmark tool + # end Miscellaneous commands endmenucommands/Makefile +1
-0@@ -112,3 +112,4 @@ obj-$(CONFIG_CMD_NV) += nv.o obj-$(CONFIG_CMD_DEFAULTENV) += defaultenv.o obj-$(CONFIG_CMD_STATE) += state.o obj-$(CONFIG_CMD_DHCP) += dhcp.o +obj-$(CONFIG_CMD_DHRYSTONE) += dhrystone.ocommands/dhrystone.c new file +54
-0@@ -0,0 +1,466 @@ +/* +* (C) Copyright 2014 - 2015 Phytec Messtechnik GmbH +* Author: Stefan Müller-Klieser <[email protected]> +* Author: Daniel Schultz <[email protected]> +* +* based on "DHRYSTONE" Benchmark Program +* Version: C, Version 2.1 +* Date: May 25, 1988 +* Author: Reinhold P. Weicker +* +* 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 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <common.h> +#include <command.h> +#include <errno.h> +#include <clock.h> +#include <asm-generic/div64.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> /* for strcpy, strcmp */ + +enum idents {ident_1, ident_2, ident_3, ident_4, ident_5}; + +/* General definitions: */ + +struct record { +struct record *ptr_comp; +enum idents discr; +union { +struct { +enum idents enum_comp; +int int_comp; +char str_comp[31 ]; + } var_1; +struct { +enum idents enum_comp_2; +char str_2_comp[31 ]; + } var_2; +struct { +char char_1_Comp; +char char_2_Comp; + } var_3; + } variant; +}; +
commands/dhrystone.c line 64
Quoted 10 lines
commands/dhrystone.c new file +10
-0+/* Global Variables: */ + +struct record *record_glob; +struct record *next_record_glob; +int int_glob; +bool bool_glob; +char char_1_glob; +char char_2_glob; +int arr_1_glob[50 ]; +int arr_2_glob[50 ][50 ];
These should all be static.
commands/dhrystone.c line 76
Quoted 12 lines
commands/dhrystone.c new file +12
-0+ +/* variables for time measurement: */ + +#define TOO_SMALL_TIME (50 * MSECOND) +/* Measurements should last at least 50mseconds */ +#define TOO_LARGE_TIME (2 * SECOND) + +u64 begin_time; +u64 end_time; +u64 user_time; +u64 nanoseconds; +u64 dhrystones_per_second;
These should probably be local variables in do_dhrystone().
Quoted 145 lines
commands/dhrystone.c new file +145
-0+/* end of variables for time measurement */ + +enum idents compare_chars (char char_1,char char_2) +{ +if (char_1 != char_2) { +return ident_1; + }else {/* should not executed */ + char_1_glob = char_1; +return ident_2; + } +} + +bool compare_strs (char str_1[31 ],char str_2[31 ]) +{ +int offset; + + offset =2 ; +while (offset <=2 ) +if (compare_chars (str_1[offset], str_2[offset+1 ]) == ident_1) + ++offset; +if (strcmp (str_1, str_2) >0 ) { + int_glob = offset +7 ; +return true; + }else { +return false; + } + +} + +bool check_ident (enum idents ident) +{ +if (ident == ident_3) +return true; +else +return false; +} + +void proc_7 (int input_1,int input_2,int *out) +{ + *out = input_2 + input_1 +2 ; +} + +void proc_6 (enum idents ident,enum idents *ident_out) +{ + *ident_out = ident; +if (!check_ident (ident)) + *ident_out = ident_4; +switch (ident) { +case ident_1: + *ident_out = ident_1; +break ; +case ident_2: +if (int_glob >100 ) + *ident_out = ident_1; +else + *ident_out = ident_4; +break ; +case ident_3: + *ident_out = ident_2; +break ; +case ident_4: +break ; +case ident_5: + *ident_out = ident_3; +break ; + } +} + +void fill_record (struct record *record) +{ +struct record *next_record = record->ptr_comp; + + *record->ptr_comp = *record_glob; + record->variant.var_1.int_comp =5 ; + next_record->variant.var_1.int_comp = record->variant.var_1.int_comp; + next_record->ptr_comp = record->ptr_comp; +proc_7 (10 , int_glob, &record_glob->variant.var_1.int_comp); +/* Ptr_Val_Par->ptr_comp->ptr_comp == record_glob->ptr_comp */ +if (next_record->discr == ident_1) {/* then, executed */ + next_record->variant.var_1.int_comp =6 ; +proc_6 (record->variant.var_1.enum_comp, + &next_record->variant.var_1.enum_comp); + next_record->ptr_comp = record_glob->ptr_comp; +proc_7 (next_record->variant.var_1.int_comp,10 , + &next_record->variant.var_1.int_comp); + }else {/* not executed */ + *record = *record->ptr_comp; + } +} + +void proc_2 (int *out) +{ +if (char_1_glob =='A' ) + *out = *out +9 - int_glob; +} + +void proc_4 (void ) +{ + bool_glob = (char_1_glob =='A' ) | bool_glob; + char_2_glob ='B' ; +} + +void proc_5 (void ) +{ + char_1_glob ='A' ; + bool_glob = false; +} + +/* dhry_2.c */ + +void fill_array (int arr_1[50 ],int arr_2[50 ][50 ],int val_1,int val_2) +{ +int i; +int offset; + + offset = val_1 +5 ; + arr_1[offset] = val_2; + arr_1[offset+1 ] = arr_1[offset]; + arr_1[offset+30 ] = offset; +for (i = offset; i <= offset+1 ; ++i) + arr_2[offset][i] = offset; + arr_2[offset][offset-1 ] +=1 ; + arr_2[offset+20 ][offset] = arr_1[offset]; + int_glob =5 ; +} + +static int do_dhrystone (int argc,char *argv[]) +{ +/* main program, corresponds to procedures */ +/* Main and Proc_0 in the Ada version */ +int int_1; +int int_2; +int int_3; +char char_i; +enum idents ident; +char str_1[31 ]; +char str_2[31 ]; +int i; +int number_of_runs; +char *new_argv[2 ]; +char tmp_str[10 ]; + +/* barebox cmd */ +if (argc ==2 ) + number_of_runs =simple_strtoul (argv[1 ],NULL ,10 );
commands/dhrystone.c line 231
Quoted 10 lines
commands/dhrystone.c new file +10
-0+else + number_of_runs =10000 ; + +/* Initializations */ + ident = ident_2;/* prevent compiler warning */ + int_2 =0 ;/* prevent compiler warning */ + int_3 =0 ;/* prevent compiler warning */ + + next_record_glob =malloc (sizeof (struct record )); + record_glob =malloc (sizeof (struct record ));
xmalloc please. Also
next_record_glob = xmalloc(sizeof(*next_record_glob));
Allows to change the type of next_record_glob without accidently missing to change the sizeof().
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Am 24.07.2015 um 09:41 schrieb Sascha Hauer:
Quoted 20 lines · Daniel Schultz
Quoted 8 lines
This tool will help to measure the system performance.
Some SoCs haven't the possibility to route their clocks to the output pins. So you can use dhrystone to get a feedback about the clock speed.
Signed-off-by Daniel Schultz <[email protected]>---
Quoted 10 lines
Changes:
v1:
applied RFC suggestions:
-removed 'default n' inKconfig
-refactored time defines with default time units -only print variable values when values are wrong -added units to printf
-the iteration parameter is now optional. The programm starts with 10000 iterations and adjust higher, when execution time is too short.
Quoted 3 lines
I can see that the parameter is now optional, but I can't find the code which adjusts the number of iterations. Am I missing something?
At the end of the do_dhrystone function:
if (user_time < TOO_SMALL_TIME) {
number_of_runs = number_of_runs * 10;
new_argv[0] = argv[0];
sprintf(tmp_str, "%i", number_of_runs);
new_argv[1] = tmp_str;
printf("Measured time too small to obtain meaningful results\n");
printf("or a timer wrap happend. I will increase the number\n");
printf("of runs by *10 to %d\n", number_of_runs);
printf("user_time: %llu ns\n", user_time);
do_dhrystone(2, new_argv);
...I'm sure there is a better solution.
Kind regards,
Daniel Schultz
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Quoted 14 lines · Daniel Schultz
At the end of the
do_dhrystonefunction:if (user_time < TOO_SMALL_TIME) { number_of_runs = number_of_runs * 10; new_argv[0] = argv[0]; sprintf(tmp_str, "%i", number_of_runs); new_argv[1] = tmp_str; printf("Measured time too small to obtain meaningful results\n"); printf("or a timer wrap happend. I will increase the number\n"); printf("of runs by *10 to %d\n", number_of_runs); printf("user_time: %llu ns\n", user_time); do_dhrystone(2, new_argv); ...
Quoted 1 line
I'm sure there is a better solution.
Why not just loop for a few seconds?
Regards,
Jan
Signature · 10 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox