-
Notifications
You must be signed in to change notification settings - Fork 0
/
netgpu_util.h
55 lines (43 loc) · 1.76 KB
/
netgpu_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#define stop_here(...) do { \
fprintf(stderr, "%s:%d:%s ", \
__FILE__, __LINE__, __func__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
exit(1); \
} while (0)
#define err_with(e, ...) do { \
fprintf(stderr, "%s:%d:%s %s(%d) ", \
__FILE__, __LINE__, __func__, strerror(e), e); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
exit(1); \
} while (0)
#define err_exit(...) err_with(errno, __VA_ARGS__)
#define ERROR_HERE(s, e, ...) \
error_at_line(s, e, __FILE__, __LINE__, __VA_ARGS__);
#define CHK_SYS(fcn) ({ \
if ((fcn) < 0) \
ERROR_HERE(1, errno, "%s", #fcn); \
})
#define CHK_ERR(fcn) ({ \
int err = fcn; \
if (err < 0) \
ERROR_HERE(1, -err, "%s", #fcn); \
})
#define CHECK_MSG(val, ...) ({ \
if (!(val)) \
ERROR_HERE(1, 0, __VA_ARGS__); \
})
#define CHECK(val) ({ \
if (!(val)) \
ERROR_HERE(1, 0, "%s", #val); \
})
#define array_size(x) (sizeof(x) / sizeof((x)[0]))
/* kernel shims */
#define ____cacheline_aligned_in_smp
#define READ_ONCE(var) (*((volatile __typeof(var) *)(&(var))))
#define WRITE_ONCE(var, val) (*((volatile __typeof(val) *)(&(var))) = (val))
#define smp_mb() libbpf_smp_rwmb()
#define smp_rmb() libbpf_smp_rmb()
#define smp_wmb() libbpf_smp_wmb()