OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [test_suite0/] [src/] [perf/] [cycles.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Test cpu cycles using platform timer
3
 * ticks.
4
 *
5
 * Copyright (C) 2010 B Labs Ltd.
6
 *
7
 * Author: Bahadir Balban
8
 */
9
#include <l4lib/macros.h>
10
#include L4LIB_INC_ARCH(syslib.h)
11
#include L4LIB_INC_ARCH(syscalls.h)
12
#include <l4lib/lib/thread.h>
13
#include <l4lib/perfmon.h>
14
#include <perf.h>
15
#include <tests.h>
16
#include <string.h>
17
#include <timer.h>
18
 
19
 
20
void platform_measure_cpu_cycles()
21
{
22
        /* Initialize the timer */
23
        const int load_value = 1000;
24
        int mhz_top, mhz_bot, temp;
25
        int cyccnt;
26
 
27
        /* Make sure timer is disabled */
28
        timer_stop(timer_base);
29
 
30
        /* Load the timer with ticks value */
31
        timer_load(load_value, timer_base);
32
 
33
        /* One shot, 32 bits, no irqs */
34
        timer_init_oneshot(timer_base);
35
 
36
        /* Start the timer */
37
        timer_start(timer_base);
38
 
39
        /* Start counter */
40
        perfmon_reset_start_cyccnt();
41
 
42
        /* Wait until 0 */
43
        while (timer_read(timer_base) != 0)
44
                ;
45
 
46
        cyccnt = perfmon_read_cyccnt();
47
 
48
        /* Fixed-point accuracy on bottom digit */
49
        temp = cyccnt * 64 * 10 / load_value;
50
        mhz_top = temp / 10;
51
        mhz_bot = temp - mhz_top * 10;
52
 
53
        //printk("Perfmon: %u cycles/%dMhz\n",
54
        //       cyccnt * 64, timer_load);
55
        printk("%s: %d.%d MHz CPU speed measured by timer REFCLK at 1MHz\n",
56
               __KERNELNAME__, mhz_top, mhz_bot);
57
}
58
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.