Skip to content

Commit 28ba128

Browse files
committed
Comments and format
1 parent 81bc5a3 commit 28ba128

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

tests/jitter/jitter.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11

2-
#include <vector>
2+
#include "CpuUtils.h"
3+
#include "MicroStats.h"
4+
#include "StringUtils.h"
5+
#include "TimingUtils.h"
36
#include <cstdint>
7+
#include <cstring>
48
#include <iostream>
59
#include <set>
6-
#include <cstring>
710
#include <unistd.h>
8-
9-
#include "CpuUtils.h"
10-
#include "MicroStats.h"
11-
#include "TimingUtils.h"
12-
#include "StringUtils.h"
11+
#include <vector>
1312

1413
using Histogram = MicroStats<8>;
1514
const uint64_t ROUGHLY_ONE_SECOND_IN_TICKS = 3000000000;
1615

1716
struct Stats {
18-
std::size_t wait_ticks = 3 * ROUGHLY_ONE_SECOND_IN_TICKS;
19-
std::size_t core;
20-
int policy;
21-
int prio;
22-
pthread_t tid;
23-
bool print;
24-
bool async;
25-
Histogram hist;
26-
uint64_t pause;
27-
uint64_t events;
17+
std::size_t wait_ticks; // number of ticks to run test
18+
std::size_t core; // core number the thread is assigned
19+
int policy; // Thread policy (RR,FIFO,OTHER)
20+
int prio; // Thread priority
21+
pthread_t tid; // The thread id
22+
bool print; // Print stats as it's collected?
23+
bool async; // Collect asynchronously or ordered?
24+
Histogram hist; // MicroStats histogram
25+
uint64_t pause; // 99.9 percentile pauses
26+
uint64_t events; // number of anomalies
2827
};
2928

3029
double calcFrequencyGHz(uint64_t ticks) {
@@ -40,7 +39,7 @@ uint64_t calcQuantum(uint64_t ticks) {
4039
uint64_t quantum = std::numeric_limits<uint64_t>::max();
4140
uint64_t last = 0;
4241
auto update = [&last, &quantum, &cpu](uint64_t now) {
43-
uint64_t diff = now - last; // forward_difference(now, last);
42+
uint64_t diff = forward_difference(now, last);
4443
if (diff < quantum) {
4544
quantum = diff;
4645
}
@@ -60,7 +59,7 @@ uint64_t calcQuantum(uint64_t ticks) {
6059
uint64_t quantum = calcQuantum(ROUGHLY_ONE_SECOND_IN_TICKS);
6160
double freqGHz = calcFrequencyGHz(ROUGHLY_ONE_SECOND_IN_TICKS);
6261

63-
void collectJitterSamples(Stats& opt) {
62+
void collectJitterSamples(Stats &opt) {
6463
uint64_t threshold = 10 * quantum;
6564
uint64_t last = tic();
6665
busyWait(opt.wait_ticks, [&last, &opt, threshold](uint64_t now) {
@@ -81,13 +80,13 @@ void collectJitterSamples(Stats& opt) {
8180
opt.events = opt.hist.count();
8281
}
8382

84-
static void* runtest(void* args) {
85-
Stats& opt = *((Stats*)args);
83+
static void *runtest(void *args) {
84+
Stats &opt = *((Stats *)args);
8685
collectJitterSamples(opt);
8786
return nullptr;
8887
}
8988

90-
void runJitterTestInCore(Stats& opt) {
89+
void runJitterTestInCore(Stats &opt) {
9190
// Sets affinity to given core, and scheduling policy + priority.
9291
pthread_attr_t attr;
9392
pthread_attr_init(&attr);
@@ -125,7 +124,7 @@ void runJitterTestInCore(Stats& opt) {
125124
usleep(10000);
126125
} else {
127126
// Wait for thread to finish
128-
void* retval;
127+
void *retval;
129128
pthread_join(opt.tid, &retval);
130129
}
131130
}
@@ -136,7 +135,7 @@ void runAllTests(bool async) {
136135

137136
std::vector<Stats> stats(numcores);
138137
for (int core = 0; core < numcores; ++core) {
139-
Stats& opt(stats[core]);
138+
Stats &opt(stats[core]);
140139
opt.core = core;
141140
opt.wait_ticks = wait_ticks;
142141
opt.policy = SCHED_FIFO;
@@ -150,9 +149,9 @@ void runAllTests(bool async) {
150149
uint64_t min_events = std::numeric_limits<uint64_t>::max();
151150
uint64_t min_pause = std::numeric_limits<uint64_t>::max();
152151
std::vector<uint64_t> isol_pause;
153-
for (Stats& s : stats) {
152+
for (Stats &s : stats) {
154153
if (async) {
155-
void* retval;
154+
void *retval;
156155
pthread_join(s.tid, &retval);
157156
}
158157
min_events = std::min(min_events, s.events);
@@ -172,7 +171,7 @@ void runAllTests(bool async) {
172171

173172
int min_sd_prio = sched_get_priority_min(SCHED_OTHER);
174173
for (int core = 0; core < numcores; ++core) {
175-
Stats& opt(stats[core]);
174+
Stats &opt(stats[core]);
176175
opt.core = core;
177176
opt.wait_ticks = wait_ticks;
178177
opt.policy = SCHED_OTHER;
@@ -182,9 +181,9 @@ void runAllTests(bool async) {
182181
runJitterTestInCore(opt);
183182
}
184183

185-
for (Stats& s : stats) {
184+
for (Stats &s : stats) {
186185
if (async) {
187-
void* retval;
186+
void *retval;
188187
pthread_join(s.tid, &retval);
189188
}
190189
double wait_secs = s.wait_ticks / (freqGHz * 1E9);
@@ -209,9 +208,11 @@ int main() {
209208
printf("%ld ", core);
210209
}
211210
printf("\n");
211+
212212
if (numcores == affinity.size()) {
213213
printf(
214-
"*** There are no isolated cores to get reliable stats on. Results may be "
214+
"*** There are no isolated cores to get reliable stats on. Results "
215+
"may be "
215216
"misleading.\n");
216217
}
217218
printf("\n\n*********** Running asynchronous tests \n\n");

0 commit comments

Comments
 (0)