Check return values of read, write and pipe in benchmarks.
GitOrigin-RevId: f6ebba80d0b2c09a9918fde5a14afd532f61897a
This commit is contained in:
parent
d0a6ef1f5b
commit
df71b93768
@ -122,24 +122,23 @@ class PipeBench : public Benchmark {
|
|||||||
public:
|
public:
|
||||||
int p[2];
|
int p[2];
|
||||||
|
|
||||||
PipeBench() {
|
|
||||||
pipe(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
string get_description() const override {
|
string get_description() const override {
|
||||||
return "pipe write + read int32";
|
return "pipe write + read int32";
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_up() override {
|
void start_up() override {
|
||||||
pipe(p);
|
int res = pipe(p);
|
||||||
|
CHECK(res == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(int n) override {
|
void run(int n) override {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
int val = 1;
|
int val = 1;
|
||||||
write(p[1], &val, sizeof(val));
|
auto write_len = write(p[1], &val, sizeof(val));
|
||||||
read(p[0], &val, sizeof(val));
|
CHECK(write_len == sizeof(val));
|
||||||
|
auto read_len = read(p[0], &val, sizeof(val));
|
||||||
|
CHECK(read_len == sizeof(val));
|
||||||
res += val;
|
res += val;
|
||||||
}
|
}
|
||||||
do_not_optimize_away(res);
|
do_not_optimize_away(res);
|
||||||
|
@ -57,18 +57,21 @@ class PipeQueue {
|
|||||||
public:
|
public:
|
||||||
void init() {
|
void init() {
|
||||||
int new_pipe[2];
|
int new_pipe[2];
|
||||||
pipe(new_pipe);
|
int res = pipe(new_pipe);
|
||||||
|
CHECK(res == 0);
|
||||||
output = new_pipe[0];
|
output = new_pipe[0];
|
||||||
input = new_pipe[1];
|
input = new_pipe[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
void put(qvalue_t value) {
|
void put(qvalue_t value) {
|
||||||
write(input, &value, sizeof(value));
|
auto len = write(input, &value, sizeof(value));
|
||||||
|
CHECK(len == sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
qvalue_t get() {
|
qvalue_t get() {
|
||||||
qvalue_t res;
|
qvalue_t res;
|
||||||
read(output, &res, sizeof(res));
|
auto len = read(output, &res, sizeof(res));
|
||||||
|
CHECK(len == sizeof(res));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,11 +196,14 @@ class EventfdQueue {
|
|||||||
void put(qvalue_t value) {
|
void put(qvalue_t value) {
|
||||||
q.put(value);
|
q.put(value);
|
||||||
td::int64 x = 1;
|
td::int64 x = 1;
|
||||||
write(fd, &x, sizeof(x));
|
auto len = write(fd, &x, sizeof(x));
|
||||||
|
CHECK(len == sizeof(x));
|
||||||
}
|
}
|
||||||
qvalue_t get() {
|
qvalue_t get() {
|
||||||
td::int64 x;
|
td::int64 x;
|
||||||
read(fd, &x, sizeof(x));
|
auto len = read(fd, &x, sizeof(x));
|
||||||
|
CHECK(len == sizeof(x));
|
||||||
|
CHECK(x == 1);
|
||||||
return q.get();
|
return q.get();
|
||||||
}
|
}
|
||||||
void destroy() {
|
void destroy() {
|
||||||
@ -351,7 +357,8 @@ class BufferedFdQueue {
|
|||||||
td::int64 x = 1;
|
td::int64 x = 1;
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
if (wait_flag.load(MODE)) {
|
if (wait_flag.load(MODE)) {
|
||||||
write(fd, &x, sizeof(x));
|
auto len = write(fd, &x, sizeof(x));
|
||||||
|
CHECK(len == sizeof(x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void put_noflush(qvalue_t value) {
|
void put_noflush(qvalue_t value) {
|
||||||
@ -362,7 +369,8 @@ class BufferedFdQueue {
|
|||||||
td::int64 x = 1;
|
td::int64 x = 1;
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
if (wait_flag.load(MODE)) {
|
if (wait_flag.load(MODE)) {
|
||||||
write(fd, &x, sizeof(x));
|
auto len = write(fd, &x, sizeof(x));
|
||||||
|
CHECK(len == sizeof(x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void flush_reader() {
|
void flush_reader() {
|
||||||
@ -393,7 +401,8 @@ class BufferedFdQueue {
|
|||||||
wait_flag.store(1, MODE);
|
wait_flag.store(1, MODE);
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
while (!(res = q.update_reader())) {
|
while (!(res = q.update_reader())) {
|
||||||
read(fd, &x, sizeof(x));
|
auto len = read(fd, &x, sizeof(x));
|
||||||
|
CHECK(len == sizeof(x));
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
}
|
}
|
||||||
wait_flag.store(0, MODE);
|
wait_flag.store(0, MODE);
|
||||||
@ -416,7 +425,8 @@ class BufferedFdQueue {
|
|||||||
wait_flag.store(1, MODE);
|
wait_flag.store(1, MODE);
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
while (!q.update_reader()) {
|
while (!q.update_reader()) {
|
||||||
read(fd, &x, sizeof(x));
|
auto len = read(fd, &x, sizeof(x));
|
||||||
|
CHECK(len == sizeof(x));
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
}
|
}
|
||||||
wait_flag.store(0, MODE);
|
wait_flag.store(0, MODE);
|
||||||
@ -445,12 +455,14 @@ class FdQueue {
|
|||||||
td::int64 x = 1;
|
td::int64 x = 1;
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
if (wait_flag.load(MODE)) {
|
if (wait_flag.load(MODE)) {
|
||||||
write(fd, &x, sizeof(x));
|
auto len = write(fd, &x, sizeof(x));
|
||||||
|
CHECK(len == sizeof(x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qvalue_t get() {
|
qvalue_t get() {
|
||||||
// td::int64 x;
|
// td::int64 x;
|
||||||
// read(fd, &x, sizeof(x));
|
// auto len = read(fd, &x, sizeof(x));
|
||||||
|
// CHECK(len == sizeof(x));
|
||||||
// return q.get();
|
// return q.get();
|
||||||
|
|
||||||
Backoff backoff;
|
Backoff backoff;
|
||||||
@ -467,13 +479,13 @@ class FdQueue {
|
|||||||
wait_flag.store(1, MODE);
|
wait_flag.store(1, MODE);
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
// std::fprintf(stderr, "!\n");
|
// std::fprintf(stderr, "!\n");
|
||||||
// while (res == -1 && read(fd, &x, sizeof(x))) {
|
// while (res == -1 && read(fd, &x, sizeof(x)) == sizeof(x)) {
|
||||||
// res = q.try_get();
|
// res = q.try_get();
|
||||||
//}
|
//}
|
||||||
do {
|
do {
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
res = q.try_get();
|
res = q.try_get();
|
||||||
} while (res == -1 && read(fd, &x, sizeof(x)));
|
} while (res == -1 && read(fd, &x, sizeof(x)) == sizeof(x));
|
||||||
q.acquire();
|
q.acquire();
|
||||||
wait_flag.store(0, MODE);
|
wait_flag.store(0, MODE);
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user