Commit 7a751bf9 authored by Jens Korinth's avatar Jens Korinth

Fix ctrl+c handling in tapasco_benchmark

* unfortunately, ncurses needs to trap signals, so the last version did
  not work correctly
* now using raw mode to check for ctrl+c directly
* also moved ncurses initialization into main, instead of the
  measurement classes
parent 562a94ca
......@@ -43,40 +43,14 @@ public:
static constexpr long OP_COPYFROM = 1;
static constexpr long OP_COPYTO = 2;
/*double operator()(size_t const runtime_usecs) {
CumulativeAverage<double> cavg { 0 };
uint32_t clock_cycles = runtime_usecs * 100; // assuming 100Mhz clock
bool stop = false;
initscr(); noecho(); curs_set(0); timeout(0);
int x, y;
getyx(stdscr, y, x);
future<void> f = async(launch::async, [&]() { trigger(stop, clock_cycles, cavg); });
const size_t m_runs = 100.0 * pow(M_E, -log(runtime_usecs / 10000.0));
const size_t min_runs = m_runs > 100 ? m_runs : 100;
do {
mvprintw(y, x, "Runtime: %8zu us, Latency: %8.2f", runtime_usecs, cavg());
move(y, 0);
clrtoeol();
mvprintw(y, x, "Runtime: %8zu us, Latency: % 12.1f, Min: % 12.1f, Max: % 12.1f, Count: %zu/%zu",
runtime_usecs, cavg(), cavg.min(), cavg.max(), cavg.size(), min_runs);
refresh();
usleep(1000);
} while (getch() == ERR && (fabs(cavg.delta()) > 0.01 || cavg.size() < min_runs));
stop = true;
f.get();
move(y+1, 0);
endwin();
return cavg();
}*/
double atcycles(uint32_t const clock_cycles, size_t const min_runs = 100, double *min = NULL, double *max = NULL) {
CumulativeAverage<double> cavg { 0 };
bool stop = false;
initscr(); noecho(); curs_set(0); timeout(0);
int x, y, maxx, maxy;
getyx(stdscr, y, x);
getmaxyx(stdscr, maxy, maxx);
future<void> f = async(launch::async, [&]() { trigger(stop, clock_cycles, cavg); });
auto c = getch();
do {
move(y, 0);
clrtoeol();
......@@ -84,12 +58,14 @@ public:
clock_cycles, cavg(), cavg.min(), cavg.max(), cavg.size(), min_runs);
refresh();
usleep(1000000);
} while (getch() == ERR && (fabs(cavg.delta()) > 0.01 || cavg.size() < min_runs));
// exit gracefully on ctrl+c
c = getch();
if (c == 3) { endwin(); exit(3); }
} while (c == ERR && (fabs(cavg.delta()) > 0.01 || cavg.size() < min_runs));
stop = true;
f.get();
move((y+1) % maxy, 0);
endwin();
if (min) *min = cavg.min();
if (max) *max = cavg.max();
return cavg();
......
......@@ -33,13 +33,13 @@ public:
CumulativeAverage<double> cavg { 0 };
jobs.store(0U);
bool stop = false;
initscr(); noecho(); curs_set(0); timeout(0);
int x, y;
getyx(stdscr, y, x);
vector<future<void> > threads;
auto const t_start = steady_clock::now();
for (size_t t = 0; t < num_threads; ++t)
threads.push_back(async(launch::async, [&]() { run(stop, jobs); }));
auto c = getch();
do {
move(y, 0);
clrtoeol();
......@@ -52,12 +52,14 @@ public:
auto const s = duration_cast<seconds>(t - t_start);
auto const v = s.count() > 0 ? static_cast<double>(j) / static_cast<double>(s.count()) : 0.0;
if (v > 10.0) cavg.update(v);
c = getch();
// exit gracefully on ctrl+c
if (c == 3) { endwin(); exit(3); }
} while(getch() == ERR && (fabs(cavg.delta()) > 10.0 || cavg.size() < 5));
stop = true;
for (auto &f : threads)
f.get();
move(y+1, 0);
endwin();
return cavg();
}
......
......@@ -37,13 +37,13 @@ public:
CumulativeAverage<double> cavg { 0 };
bool stop = false;
bytes = 0;
initscr(); noecho(); curs_set(0); timeout(0);
int x, y;
getyx(stdscr, y, x);
auto tstart = steady_clock::now();
double b = 0.0;
duration<double> d = steady_clock::now() - tstart;
future<void> f = async(launch::async, [&]() { transfer(stop, chunk_sz, opmask); });
auto c = getch();
do {
mvprintw(y, x, "Chunk size: %8.2f KiB, Mask: %s, Speed: %8.2f MiB/s",
cs, ms.c_str(), cavg());
......@@ -51,11 +51,13 @@ public:
usleep(1000000);
b = bytes.load() / (1024.0 * 1024.0);
d = steady_clock::now() - tstart;
} while (getch() == ERR && (fabs(cavg.update(b / d.count())) > 0.1 || cavg.size() < 30));
// exit gracefully on ctrl+c
c = getch();
if (c == 3) { endwin(); exit(3); }
} while (c == ERR && (fabs(cavg.update(b / d.count())) > 0.1 || cavg.size() < 30));
stop = true;
f.get();
move(y+1, 0);
endwin();
return cavg();
}
......@@ -85,7 +87,7 @@ private:
static const std::string maskToString(long const opmask) {
stringstream tmp;
tmp << (opmask & OP_COPYFROM ? "r" : " ")
tmp << (opmask & OP_COPYFROM ? "r" : " ")
<< (opmask & OP_COPYTO ? "w" : " ");
return tmp.str();
}
......
......@@ -11,7 +11,6 @@
#include <sstream>
#include <chrono>
#include <ctime>
#include <csignal>
#include <vector>
#include <sys/utsname.h>
#include <tapasco_api.hpp>
......@@ -61,15 +60,8 @@ struct job_throughput_t {
}; }
};
void signalHandler(int sig) {
cerr << "Signal %d received, aborting." << endl;
endwin();
exit(1);
}
int main(int argc, const char *argv[]) {
// trap ctrl-c
signal(SIGINT, signalHandler);
initscr(); noecho(); curs_set(1); timeout(0); raw();
try {
Tapasco tapasco;
TransferSpeed tp { tapasco };
......@@ -179,5 +171,6 @@ int main(int argc, const char *argv[]) {
endwin();
throw;
}
endwin();
}
/* vim: set foldmarker=@{,@} foldlevel=0 foldmethod=marker : */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment