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 4

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 4 sergeykhbr
    briefDescr_.make_string("Read per master bus utilization in percentage "
20
                            "of time");
21 3 sergeykhbr
    detailedDescr_.make_string(
22
        "Description:\n"
23
        "    Read and normalize per master bus utilization statistic\n"
24
        "    using information about total number of clocks and counters\n"
25
        "    of clocks spending on read/write transactions.\n"
26
        "Warning:\n"
27
        "    For functional simulation accumulated utilization may exceed\n"
28
        "    100.0 percentage of bus because all masters can request data\n"
29
        "    at the same step without arbiter implementation.\n"
30
        "Output format:\n"
31
        "    [[d,d]*]\n"
32
        "         d - Write access for master[0] in range 0 to 100.\n"
33
        "         d - Read access for master[0] in range 0 to 100.\n"
34
        "         * - For each master.\n"
35
        "Example:\n"
36
        "    busutil\n");
37
 
38
    clock_cnt_z_ = 0;
39
    memset(bus_util_z_, 0, sizeof(bus_util_z_));
40
}
41
 
42
bool CmdBusUtil::isValid(AttributeType *args) {
43
    if ((*args)[0u].is_equal(cmdName_.to_string()) && args->size() == 1) {
44
        return CMD_VALID;
45
    }
46
    return CMD_INVALID;
47
}
48
 
49
void CmdBusUtil::exec(AttributeType *args, AttributeType *res) {
50 4 sergeykhbr
    unsigned mst_total = 4;//info_->getMastersTotal();
51 3 sergeykhbr
    res->make_list(mst_total);
52
    if (!isValid(args)) {
53
        generateError(res, "Wrong argument list");
54
        return;
55
    }
56
 
57
    struct MasterStatType {
58
        Reg64Type w_cnt;
59
        Reg64Type r_cnt;
60
    } mst_stat;
61
    Reg64Type cnt_total;
62
    DsuMapType *dsu = info_->getpDsu();
63
    uint64_t addr = reinterpret_cast<uint64_t>(&dsu->udbg.v.clock_cnt);
64
    tap_->read(addr, 8, cnt_total.buf);
65
    double d_cnt_total = static_cast<double>(cnt_total.val - clock_cnt_z_);
66
    if (d_cnt_total == 0) {
67
        return;
68
    }
69
 
70
    addr = reinterpret_cast<uint64_t>(dsu->ulocal.v.bus_util);
71
    for (unsigned i = 0; i < mst_total; i++) {
72
        AttributeType &mst = (*res)[i];
73
        if (!mst.is_list() || mst.size() != 2) {
74
            mst.make_list(2);
75
        }
76
        tap_->read(addr, 16, mst_stat.w_cnt.buf);
77
        mst[0u].make_floating(100.0 *
78
            static_cast<double>(mst_stat.w_cnt.val - bus_util_z_[i].w_cnt)
79
            / d_cnt_total);
80
        mst[1].make_floating(100.0 *
81
            static_cast<double>(mst_stat.r_cnt.val - bus_util_z_[i].r_cnt)
82
            / d_cnt_total);
83
 
84
        bus_util_z_[i].w_cnt = mst_stat.w_cnt.val;
85
        bus_util_z_[i].r_cnt = mst_stat.r_cnt.val;
86
        addr += 16;
87
    }
88
    clock_cnt_z_ = cnt_total.val;
89
}
90
 
91
}  // namespace debugger

powered by: WebSVN 2.1.0

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