On Fri, Dec 13, 2019 at 05:59:54PM -0800, Eric Dumazet 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. Thanks for the feedbacks! I have a few questions that need some helps. Does it mean tp->tcp_mstamp can be used as the "now" in cubic? or tcp_clock_ns() should still be called in cubic, e.g. to replace bictcp_clock() and tcp_jiffies32? BPF currently has a helper calling ktime_get_mono_fast_ns() which looks different from tcp_clock_ns(). The lsndtime is in jiffies. I think it can probably be converted to ms before using it in cubic. There are some BICTCP_HZ logic in bictcp_update() that is not obvious to me how to convet them to ms base also. > > > Have you thought of finding a way to not duplicate the code for cubic and dctcp, maybe > by including a template ? > > Maintaining two copies means that future changes need more maintenance work. At least for bpf_dctcp.c, I did not expect it could be that close to tcp_dctcp.c when I just started converted it. tcp_cubic/bpf_cubic still has some TBD on jiffies/msec. Agree that it is beneficial to have one copy. It is likely I need to make some changes on the tcp_*.c side also. Hence, I prefer to give it a try in a separate series, e.g. revert the kernel side changes will be easier.