Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-b authored and fntlnz committed Apr 30, 2020
1 parent 2b4a99f commit 47374b2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
26 changes: 25 additions & 1 deletion driver/bpf/fillers.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ or GPL2.txt for full copies of the license.
#include <linux/tty.h>
#include <linux/audit.h>

/*
* Linux 5.6 kernels no longer include the old 32-bit timeval
* structures. But the syscalls (might) still use them.
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
#include <linux/time64.h>
struct compat_timespec {
int32_t tv_sec;
int32_t tv_nsec;
};

struct timespec {
int32_t tv_sec;
int32_t tv_nsec;
};

struct timeval {
int32_t tv_sec;
int32_t tv_usec;
};
#else
#define timeval64 timeval
#endif

#define FILLER_RAW(x) \
static __always_inline int __bpf_##x(struct filler_data *data); \
\
Expand Down Expand Up @@ -537,7 +561,7 @@ FILLER(sys_writev_pwritev_x, true)
}

static __always_inline int timespec_parse(struct filler_data *data,
unsigned long val)
unsigned long val)
{
u64 longtime;
struct timespec ts;
Expand Down
8 changes: 4 additions & 4 deletions driver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ do { \
pr_info(fmt, ##__VA_ARGS__); \
} while (0)

nanoseconds ppm_nsecs(void)
static inline nanoseconds ppm_nsecs(void)
{
return ktime_get_real_ns();
}
Expand Down Expand Up @@ -1521,8 +1521,8 @@ static inline int drop_event(struct ppm_consumer_t *consumer,
return 1;
}

if (consumer->sampling_interval < second_in_ns &&
(ns % second_in_ns) >= consumer->sampling_interval) {
if (consumer->sampling_interval < SECOND_IN_NS &&
(ns % SECOND_IN_NS) >= consumer->sampling_interval) {
if (consumer->is_dropping == 0) {
consumer->is_dropping = 1;
record_drop_e(consumer, ns, drop_flags);
Expand Down Expand Up @@ -1863,7 +1863,7 @@ static int record_event_consumer(struct ppm_consumer_t *consumer,
}
}

if (more_than_one_second_ahead(ns, ring->last_print_time + 1) && !(drop_flags & UF_ATOMIC)) {
if (MORE_THAN_ONE_SECOND_AHEAD(ns, ring->last_print_time + 1) && !(drop_flags & UF_ATOMIC)) {
vpr_info("consumer:%p CPU:%d, use:%d%%, ev:%llu, dr_buf:%llu, dr_pf:%llu, pr:%llu, cs:%llu\n",
consumer->consumer_id,
smp_processor_id(),
Expand Down
8 changes: 3 additions & 5 deletions driver/ppm.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ extern const enum ppm_syscall_code g_syscall_ia32_code_routing_table[];

extern void ppm_syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, unsigned long *args);

extern nanoseconds ppm_nsecs(void);

#define ns_to_sec(_ns) ((_ns) / 1000000000)
#define more_than_one_second_ahead(_ns1, _ns2) ((_ns1) - (_ns2) > 1000000000)
#define second_in_ns 1000000000
#define NS_TO_SEC(_ns) ((_ns) / 1000000000)
#define MORE_THAN_ONE_SECOND_AHEAD(_ns1, _ns2) ((_ns1) - (_ns2) > 1000000000)
#define SECOND_IN_NS 1000000000

#endif /* PPM_H_ */
3 changes: 1 addition & 2 deletions driver/ppm_fillers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,11 +1388,10 @@ static int parse_sockopt(struct event_filler_arguments *args, int level, int opt
#ifdef SO_SNDTIMEO
case SO_SNDTIMEO:
#endif
ASSERT(optlen == sizeof(struct timeval));
if (unlikely(ppm_copy_from_user(&u.tv, optval, sizeof(u.tv)))) {
return PPM_FAILURE_INVALID_USER_MEMORY;
}
ns = u.tv.tv_sec * second_in_ns + u.tv.tv_usec * 1000;
ns = u.tv.tv_sec * SECOND_IN_NS + u.tv.tv_usec * 1000;
return val_to_ring(args, ns, 0, false, PPM_SOCKOPT_IDX_TIMEVAL);

#ifdef SO_COOKIE
Expand Down

0 comments on commit 47374b2

Please sign in to comment.