Skip to content
Snippets Groups Projects

pulse: busy loop when evenly introducing work

Open Florian Fischer requested to merge aj46ezos/emper:improve-even-pulse into master
1 file
+ 18
16
Compare changes
  • Side-by-side
  • Inline
+ 18
16
@@ -63,6 +63,13 @@ static unsigned iterations = 30;
// Utilization of the runtime in percent
static unsigned utilization = 80;
template <class Timeunit>
static void loopFor(Timeunit time) {
const auto deadline = Clock::now() + time;
while (Clock::now() < deadline) {
}
}
class Work {
public:
static Work** doneWork;
@@ -75,10 +82,7 @@ class Work {
Work() : start(Clock::now()) {}
void run() {
const auto deadline = Clock::now() + std::chrono::microseconds(pulse);
while (Clock::now() < deadline) {
}
loopFor(std::chrono::microseconds(pulse));
finish();
}
@@ -93,28 +97,26 @@ Work** Work::doneWork;
thread_local Work** Work::localDoneWork;
static void pulser(Runtime& runtime) {
const workerid_t workerCount = runtime.getWorkerCount();
const workerid_t workerCount = runtime.getWorkerCount() - (pulseMode == PulseMode::Even ? 1 : 0);
;
const workerid_t workItems = (workerCount * utilization) / 100;
struct timespec ts {
0, 0
};
// TODO: better calculate the time until the next burst
if (pulseMode == PulseMode::Burst)
ts.tv_nsec = pulse * 1000;
else
ts.tv_nsec = (pulse * 1000) / workItems;
CPS cps;
for (unsigned i = 0; i < iterations; ++i) {
for (unsigned w = 0; w < workItems; ++w) {
Work* work = new Work();
spawn([=] { work->run(); }, cps);
if (pulseMode == PulseMode::Even) emper::nanosleep(&ts);
if (pulseMode == PulseMode::Even)
loopFor(std::chrono::nanoseconds((pulse * 1000) / workItems));
}
// TODO: Think about busy looping for small times
if (pulseMode == PulseMode::Burst) emper::nanosleep(&ts);
if (pulseMode == PulseMode::Burst) {
struct timespec ts {
.tv_sec = 0, .tv_nsec = pulse * 1000
};
emper::nanosleep(&ts);
}
}
cps.wait();
runtime.initiateTermination();
Loading