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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [libdbg64g/] [services/] [exec/] [cmd/] [cmd_cpi.cpp] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      Read CPU dport registers (step counter and clock
6
 *             counter) to compute CPI in run-time.
7
 */
8
 
9
#include "cmd_cpi.h"
10
 
11
namespace debugger {
12
 
13
CmdCpi::CmdCpi(ITap *tap, ISocInfo *info)
14
    : ICommand ("cpi", tap, info) {
15
 
16
    briefDescr_.make_string("Compute Clocks Per Instruction (CPI) rate");
17
    detailedDescr_.make_string(
18
        "Description:\n"
19
        "    This commands reads CPU registers: 'clock counter' and.\n"
20
        "    'step counter' and computes Clocks Per Instruction (CPI) rate\n"
21
        "    in run-time.\n"
22
        "Output format:\n"
23
        "    [i,i,i,i,d]\n"
24
        "         i - Current CPU clock counter value (int64_t).\n"
25
        "         i - Current CPU step counter value (int64_t).\n"
26
        "         i - (Current - Previous) CPU clock counter value (int64_t).\n"
27
        "         i - (Current - Previous) CPU step counter value (int64_t).\n"
28
        "         d - CPI rate (double) = (delta clocks)/(delta steps).\n"
29
        "Example:\n"
30
        "    cpi\n");
31
 
32
    stepCnt_z = 0;
33
    clockCnt_z = 0;
34
}
35
 
36
bool CmdCpi::isValid(AttributeType *args) {
37
    if ((*args)[0u].is_equal(cmdName_.to_string()) && args->size() == 1) {
38
        return CMD_VALID;
39
    }
40
    return CMD_INVALID;
41
}
42
 
43
void CmdCpi::exec(AttributeType *args, AttributeType *res) {
44
    res->make_list(5);
45
    (*res)[0u].make_uint64(0);
46
    (*res)[1].make_uint64(0);
47
    if (!isValid(args)) {
48
        generateError(res, "Wrong argument list");
49
        return;
50
    }
51
 
52
    struct CpiRegsType {
53
        Reg64Type clock_cnt;
54
        Reg64Type executed_cnt;
55
    };
56
    union CpiRegionType {
57
        CpiRegsType regs;
58
        uint8_t buf[sizeof(CpiRegsType)];
59
    } t1;
60
    DsuMapType *dsu = info_->getpDsu();
61
    uint64_t addr = reinterpret_cast<uint64_t>(&dsu->udbg.v.clock_cnt);
62
    uint64_t d1, d2;
63
    tap_->read(addr, 16, t1.buf);
64
 
65
    d1 = t1.regs.clock_cnt.val - clockCnt_z;
66
    d2 = t1.regs.executed_cnt.val - stepCnt_z;
67
 
68
    (*res)[0u].make_uint64(t1.regs.clock_cnt.val);
69
    (*res)[1].make_uint64(t1.regs.executed_cnt.val);
70
    (*res)[2].make_uint64(d1);
71
    (*res)[3].make_uint64(d2);
72
    if (d2 == 0) {
73
        if (t1.regs.executed_cnt.val == 0) {
74
            (*res)[4].make_floating(0);
75
        } else {
76
            (*res)[4].make_floating(1.0);
77
        }
78
    } else {
79
        (*res)[4].make_floating(
80
            static_cast<double>(d1) / static_cast<double>(d2));
81
    }
82
 
83
    clockCnt_z = t1.regs.clock_cnt.val;
84
    stepCnt_z = t1.regs.executed_cnt.val;
85
}
86
 
87
}  // namespace debugger

powered by: WebSVN 2.1.0

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