]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/performance_test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / performance_test.c
1 /* performance_test.c */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2006-2010  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /*
20  * author: Daniel Otte
21  * email:  daniel.otte@rub.de
22  * license: GPLv3
23  *
24  *
25  **/
26
27 #include <string.h>
28 #include <stdint.h>
29 #include <stdlib.h>
30 #include "hw_regs.h"
31 #include "hw_gptm.h"
32 #include "cli.h"
33 #include "string-extras.h"
34 #include "performance_test.h"
35
36
37 static volatile uint32_t ovfcounter;
38
39 static uint32_t const_overhead=0;
40 static uint32_t int_overhead=0;
41
42 void calibrateTimer(void){
43         uint64_t t;
44         startTimer(1);
45         t=stopTimer();
46         const_overhead = (uint32_t)t;
47 }
48
49 void initTimer(void){
50         gptm_set_timer_32periodic(PERF_TIMER);
51 }
52
53 void startTimer(uint8_t granularity){
54         gptm_stop_timer(PERF_TIMER, 0);
55         gptm_write_timer(PERF_TIMER, 0, 0);
56         if(granularity>0){
57                 gptm_set_timer_prescaler(PERF_TIMER, 0, granularity-1);
58                 gptm_start_timer(PERF_TIMER, 0);
59         }else{
60                 gptm_set_timer_prescaler(PERF_TIMER, 0, 0);
61         }
62 }
63
64 uint64_t stopTimer(void){
65         gptm_stop_timer(PERF_TIMER, 0);
66         uint64_t ret;
67         ret = gptm_read_timer(PERF_TIMER, 0);
68         ret -= const_overhead;
69         ret -= ovfcounter * int_overhead;
70         return ret;
71 }
72
73 void getOverhead(uint32_t* constoh, uint32_t* intoh){
74         *constoh = const_overhead;
75         *intoh   = int_overhead;
76 }
77
78 void print_time(const char* s, uint64_t t){
79         char sv[22];
80         uint8_t c;
81         cli_putstr("\r\n");
82         cli_putstr(s);
83         ulltoa(t, sv, 10);
84         for(c=strlen(sv); c<11; ++c){
85                 cli_putc(' ');
86         }
87         cli_putstr(sv);
88 }
89
90 void print_overhead(void){
91         char str[11];
92         cli_putstr("\r\n\r\n=== benchmark ===");
93         ultoa(const_overhead, str, 10);
94         cli_putstr("\r\n\tconst overhead:     ");
95         cli_putstr(str);
96         ultoa(int_overhead, str, 10);
97         cli_putstr("\r\n\tinterrupt overhead: ");
98         cli_putstr(str);
99 }
100
101