On Sat, Dec 14, 2019 at 02:25:14PM -0500, Neal Cardwell wrote: > On Fri, Dec 13, 2019 at 9:00 PM Eric Dumazet <eric.dumazet@xxxxxxxxx> wrote: > > > > > > > > On 12/13/19 4:47 PM, Martin KaFai Lau wrote: > > > This patch adds a helper to handle jiffies. Some of the > > > tcp_sock's timing is stored in jiffies. Although things > > > could be deduced by CONFIG_HZ, having an easy way to get > > > jiffies will make the later bpf-tcp-cc implementation easier. > > > > > > > ... > > > > > + > > > +BPF_CALL_2(bpf_jiffies, u64, in, u64, flags) > > > +{ > > > + if (!flags) > > > + return get_jiffies_64(); > > > + > > > + if (flags & BPF_F_NS_TO_JIFFIES) { > > > + return nsecs_to_jiffies(in); > > > + } else if (flags & BPF_F_JIFFIES_TO_NS) { > > > + if (!in) > > > + in = get_jiffies_64(); > > > + return jiffies_to_nsecs(in); > > > + } > > > + > > > + return 0; > > > +} > > > > This looks a bit convoluted :) > > > > Note that we could possibly change net/ipv4/tcp_cubic.c to no longer use jiffies at all. > > > > We have in tp->tcp_mstamp an accurate timestamp (in usec) that can be converted to ms. > > If the jiffies functionality stays, how about 3 simple functions that > correspond to the underlying C functions, perhaps something like: > > bpf_nsecs_to_jiffies(nsecs) > bpf_jiffies_to_nsecs(jiffies) > bpf_get_jiffies_64() > > Separate functions might be easier to read/maintain (and may even be > faster, given the corresponding reduction in branches). Yes. It could be different bpf helpers. I will take another look on these. I may not need the nsecs <=> jiffies with CONFIG_HZ and Andrii's recent extern var support. The first attempt I tried end-up a lot of codes on the bpf_prog side. I may not have done it right. I will give it another try on this side. Thanks for the feedbacks!