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_busutil.cpp] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      Bus utilization computation
6
 *
7
 * @details    Read CPU dport registers: clock counter and per
8
 *             master counters with read/write transactions to compute
9
 *             utilization characteristic.
10
 */
11
 
12
#include "cmd_busutil.h"
13
 
14
namespace debugger {
15
 
16
CmdBusUtil::CmdBusUtil(ITap *tap, ISocInfo *info)
17
    : ICommand ("busutil", tap, info) {
18
 
19
    briefDescr_.make_string("Compute Clocks Per Instruction (CPI) rate");
20
    detailedDescr_.make_string(
21
        "Description:\n"
22
        "    Read and normalize per master bus utilization statistic\n"
23
        "    using information about total number of clocks and counters\n"
24
        "    of clocks spending on read/write transactions.\n"
25
        "Warning:\n"
26
        "    For functional simulation accumulated utilization may exceed\n"
27
        "    100.0 percentage of bus because all masters can request data\n"
28
        "    at the same step without arbiter implementation.\n"
29
        "Output format:\n"
30
        "    [[d,d]*]\n"
31
        "         d - Write access for master[0] in range 0 to 100.\n"
32
        "         d - Read access for master[0] in range 0 to 100.\n"
33
        "         * - For each master.\n"
34
        "Example:\n"
35
        "    busutil\n");
36
 
37
    clock_cnt_z_ = 0;
38
    memset(bus_util_z_, 0, sizeof(bus_util_z_));
39
}
40
 
41
bool CmdBusUtil::isValid(AttributeType *args) {
42
    if ((*args)[0u].is_equal(cmdName_.to_string()) && args->size() == 1) {
43
        return CMD_VALID;
44
    }
45
    return CMD_INVALID;
46
}
47
 
48
void CmdBusUtil::exec(AttributeType *args, AttributeType *res) {
49
    unsigned mst_total = info_->getMastersTotal();
50
    res->make_list(mst_total);
51
    if (!isValid(args)) {
52
        generateError(res, "Wrong argument list");
53
        return;
54
    }
55
 
56
    struct MasterStatType {
57
        Reg64Type w_cnt;
58
        Reg64Type r_cnt;
59
    } mst_stat;
60
    Reg64Type cnt_total;
61
    DsuMapType *dsu = info_->getpDsu();
62
    uint64_t addr = reinterpret_cast<uint64_t>(&dsu->udbg.v.clock_cnt);
63
    tap_->read(addr, 8, cnt_total.buf);
64
    double d_cnt_total = static_cast<double>(cnt_total.val - clock_cnt_z_);
65
    if (d_cnt_total == 0) {
66
        return;
67
    }
68
 
69
    addr = reinterpret_cast<uint64_t>(dsu->ulocal.v.bus_util);
70
    for (unsigned i = 0; i < mst_total; i++) {
71
        AttributeType &mst = (*res)[i];
72
        if (!mst.is_list() || mst.size() != 2) {
73
            mst.make_list(2);
74
        }
75
        tap_->read(addr, 16, mst_stat.w_cnt.buf);
76
        mst[0u].make_floating(100.0 *
77
            static_cast<double>(mst_stat.w_cnt.val - bus_util_z_[i].w_cnt)
78
            / d_cnt_total);
79
        mst[1].make_floating(100.0 *
80
            static_cast<double>(mst_stat.r_cnt.val - bus_util_z_[i].r_cnt)
81
            / d_cnt_total);
82
 
83
        bus_util_z_[i].w_cnt = mst_stat.w_cnt.val;
84
        bus_util_z_[i].r_cnt = mst_stat.r_cnt.val;
85
        addr += 16;
86
    }
87
    clock_cnt_z_ = cnt_total.val;
88
}
89
 
90
}  // namespace debugger

powered by: WebSVN 2.1.0

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