Skip to content

Commit 1946d2c

Browse files
committed
basic: code cleanup
Signed-off-by: Hengqi Chen <[email protected]>
1 parent d419031 commit 1946d2c

File tree

4 files changed

+5
-12
lines changed

4 files changed

+5
-12
lines changed

basic01-xdp-pass/xdp_pass_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ int main(int argc, char **argv)
162162
if (err)
163163
return err;
164164

165-
/* This step is not really needed , BPF-info via bpf-syscall */
165+
/* This step is not really needed , BPF-info via bpf-syscall */
166166
err = bpf_obj_get_info_by_fd(prog_fd, &info, &info_len);
167167
if (err) {
168168
fprintf(stderr, "ERR: can't get prog info - %s\n",

basic03-map-counter/xdp_load_and_stats.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int find_map_fd(struct bpf_object *bpf_obj, const char *mapname)
6767

6868
/* Lesson#3: bpf_object to bpf_map */
6969
map = bpf_object__find_map_by_name(bpf_obj, mapname);
70-
if (!map) {
70+
if (!map) {
7171
fprintf(stderr, "ERR: cannot find map by name: %s\n", mapname);
7272
goto out;
7373
}
@@ -85,7 +85,7 @@ static __u64 gettime(void)
8585

8686
res = clock_gettime(CLOCK_MONOTONIC, &t);
8787
if (res < 0) {
88-
fprintf(stderr, "Error with gettimeofday! (%i)\n", res);
88+
fprintf(stderr, "Error with clock_gettime! (%i)\n", res);
8989
exit(EXIT_FAIL);
9090
}
9191
return (__u64) t.tv_sec * NANOSEC_PER_SEC + t.tv_nsec;
@@ -131,7 +131,7 @@ static void stats_print(struct stats_record *stats_rec,
131131

132132
period = calc_period(rec, prev);
133133
if (period == 0)
134-
return;
134+
return;
135135

136136
packets = rec->total.rx_packets - prev->total.rx_packets;
137137
pps = packets / period;

basic04-pinning-maps/xdp_prog_kern.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ struct bpf_map_def SEC("maps") xdp_stats_map = {
1515
.max_entries = XDP_ACTION_MAX,
1616
};
1717

18-
/* LLVM maps __sync_fetch_and_add() as a built-in function to the BPF atomic add
19-
* instruction (that is BPF_STX | BPF_XADD | BPF_W for word sizes)
20-
*/
21-
#ifndef lock_xadd
22-
#define lock_xadd(ptr, val) ((void) __sync_fetch_and_add(ptr, val))
23-
#endif
24-
2518
static __always_inline
2619
__u32 xdp_stats_record_action(struct xdp_md *ctx, __u32 action)
2720
{

basic04-pinning-maps/xdp_stats.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static __u64 gettime(void)
4646

4747
res = clock_gettime(CLOCK_MONOTONIC, &t);
4848
if (res < 0) {
49-
fprintf(stderr, "Error with gettimeofday! (%i)\n", res);
49+
fprintf(stderr, "Error with clock_gettime! (%i)\n", res);
5050
exit(EXIT_FAIL);
5151
}
5252
return (__u64) t.tv_sec * NANOSEC_PER_SEC + t.tv_nsec;

0 commit comments

Comments
 (0)