Skip to content

Commit

Permalink
monitor: cleanup and fix an issue in getexepath
Browse files Browse the repository at this point in the history
- directory name was not retrieved successfully on linux, use
string manipulation to retrieve the exe path instead of dirname()
which has a conflict with another symbol in Qbox.
- remove reset button and API method from monitor.cc as it is already
handled by the qemu monitor in qmp model.
- remove unneeded commented code lines from monitor.cc.

Signed-off-by: Mahmoud Kamel <quic_mkamel@quicinc.com>
  • Loading branch information
Mahmoud Kamel committed Oct 31, 2024
1 parent 445c93a commit 1c61204
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 59 deletions.
76 changes: 25 additions & 51 deletions systemc-components/monitor/src/monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,32 @@ platform["monitor_0"] = {
#include <exception>
#include <cciutils.h>
#include <algorithm>
#include <unistd.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif

/*
* pre declaration for getexepath
* NB this has to be done like this because of a nasty conflicting #def in libgen.h
*/
std::string getexepath();
std::string getexepath()
{
char result[1024] = { 0 };
#ifdef __APPLE__
uint32_t size = sizeof(result);
if (_NSGetExecutablePath(result, &size) != 0) {
std::cerr << "error executing _NSGetExecutablePath() in monitor.cc" << std::endl;
exit(EXIT_FAILURE);
}
#elif __linux__
ssize_t count = readlink("/proc/self/exe", result, 1024);
if (count < 0) {
std::cerr << "error executing readlink(\"/proc/self/exe\") in monitor.cc: " << strerror(errno) << std::endl;
exit(EXIT_FAILURE);
}
#else
#error monitor supports only Mac OS and linux for now!
#endif
std::string exec_path = result;
return exec_path.substr(0, exec_path.rfind("/"));
}

namespace gs {

Expand Down Expand Up @@ -210,8 +230,6 @@ void monitor<BUSWIDTH>::init_monitor()
CROW_ROUTE(m_app, "/pause")
([&]() {
crow::json::wvalue ret;
// std::string msg = R"({ "execute": "stop" })";
// write_to_qmp_socket(msg);
m_sc.run_on_sysc([&] {
sc_core::sc_suspend_all();
ret["sc_time_stamp"] = sc_core::sc_time_stamp().to_seconds();
Expand All @@ -221,22 +239,12 @@ void monitor<BUSWIDTH>::init_monitor()
CROW_ROUTE(m_app, "/continue")
([&]() {
crow::json::wvalue ret;
// std::string msg = R"({ "execute": "cont" })";
// write_to_qmp_socket(msg);
m_sc.run_on_sysc([&] {
sc_core::sc_unsuspend_all();
ret["sc_time_stamp"] = sc_core::sc_time_stamp().to_seconds();
});
return ret;
});
CROW_ROUTE(m_app, "/reset")
([&]() {
crow::json::wvalue ret;
// std::string msg = R"({ "execute": "system_reset" })";
// write_to_qmp_socket(msg);
m_sc.run_on_sysc([&] { ret["sc_time_stamp"] = sc_core::sc_time_stamp().to_seconds(); });
return ret;
});
CROW_ROUTE(m_app, "/object/")
([&]() {
std::vector<crow::json::wvalue> cr;
Expand Down Expand Up @@ -380,38 +388,4 @@ template class monitor<32>;
template class monitor<64>;
} // namespace gs
typedef gs::monitor<32> monitor;

/* Helper function to get the executable path
* This needs to be at the end of this file, to prevent conflicts with 'basename' which seems to be
* defined in libgen.h
*/
#include <unistd.h>
#include <libgen.h>
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#endif

std::string getexepath()
{
char result[1024] = { 0 };
#ifdef __APPLE__
uint32_t size = sizeof(result);
if (_NSGetExecutablePath(result, &size) != 0) {
std::cerr << "error executing _NSGetExecutablePath() in python-binder-bench.h" << std::endl;
exit(EXIT_FAILURE);
}
return std::string(dirname(result));
#elif __linux__
ssize_t count = readlink("/proc/self/exe", result, 1024);
if (count < 0) {
std::cerr << "error executing readlink() in python-binder-bench.h: " << strerror(errno) << std::endl;
exit(EXIT_FAILURE);
}
return std::string(dirname(result), count);

#else
#error monitor supports only Mac OS and linux for now!
#endif
}

void module_register() { GSC_MODULE_REGISTER_C(monitor); }
8 changes: 0 additions & 8 deletions systemc-components/monitor/static/monitor.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
<body>
SystemC time : <span id="sc_time">Loading...</span> SystemC Running : <input type=checkbox id="sc_status" checked>
<br>
<button id="reset">
Reset Platform
</button><BR>
<br>

<select id="biflowsDropdown">
<option value="" disabled selected>Select a biflow</option>
</select>
Expand Down Expand Up @@ -123,10 +119,6 @@ <h3>Registers</h3>
}
}

document.getElementById('reset').onclick = () => {
const rsp = fetch('/reset');
};

async function fetchFlag() {
try {
const response = await fetch('/sc_time'); // API URL
Expand Down

0 comments on commit 1c61204

Please sign in to comment.