-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(bpf): cleanup initialising structs and nested ifs #1444
Conversation
This commit changes all declarae and then initialise code of form below ``` struct foobar x; x.a = a; x.b = b; ``` to ``` struct foobar x = { .a = a, .b = b, }; ``` The difference in the code produced is as follows ``` ; new_pid_key.pid = cur_pid; | pid_time_t new_pid_key = {.pid = cur_pid }; 0: 63 6a fc ff 00 00 00 00 *(u32 *)(r10 - 0x4) = r6 | 0: 79 a1 68 ff 00 00 00 00 r1 = *(u64 *)(r10 - 0x98) 1: bf a2 00 00 00 00 00 00 r2 = r10 | 1: 63 1a fc ff 00 00 00 00 *(u32 *)(r10 - 0x4) = r1 2: 07 02 00 00 fc ff ff ff r2 += -0x4 | 2: bf a2 00 00 00 00 00 00 r2 = r10 3: bf a3 00 00 00 00 00 00 r3 = r10 | 3: 07 02 00 00 f0 ff ff ff r2 += -0x10 4: 07 03 00 00 70 ff ff ff r3 += -0x90 ``` Modifies calc_delta to remove unnecessary pointer deferencing of second arg - `val` Signed-off-by: Sunil Thaha <[email protected]> (cherry picked from commit ac43e26)
bpf_map_update_elem(&pid_time, &new_pid_key, &cur_ts, BPF_NOEXIST); | ||
return cpu_time; | ||
} | ||
|
||
static inline u64 calc_delta(u64 *prev_val, u64 *val) | ||
static inline u64 calc_delta(u64 *prev_val, u64 val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that the current implementation already assumes u64 *val
is not nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while you're here wouldn't it be better to make this calc_delta(u64 prev_val, u64 val)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, the original implementation handles prev_val (pointer) being nil/null. The caller may
- calc_delta(nil, 20) -> 0
- calc_delta(0xABCD (80) , 20) -> 0
- calc_delta(0xABCD (8) , 20) -> 12
So the caller does not worry about previous record being present. Also note, this is inlined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit but otherwise LGTM
bpf_map_update_elem(&pid_time, &new_pid_key, &cur_ts, BPF_NOEXIST); | ||
return cpu_time; | ||
} | ||
|
||
static inline u64 calc_delta(u64 *prev_val, u64 *val) | ||
static inline u64 calc_delta(u64 *prev_val, u64 val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while you're here wouldn't it be better to make this calc_delta(u64 prev_val, u64 val)
?
This commit changes all declarae and then initialise code of form below
to
The difference in the code produced is as follows
Modifies calc_delta to remove unnecessary pointer deferencing of second arg -
val