Use MSEC_2_TICKS() to make clearer, which values are used and to ensure that the value stored is at least one tick. This also avoids the need of some protection code.
Details
- Reviewers
glebius cc lstewart peter.lei_ieee.org - Group Reviewers
transport - Commits
- rG0b33b25b1403: tcp: cleanup timer initialisations
rGc13f4b1574da: tcp: cleanup timer initialisations
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
This might break build of some userland programs that stupidly include tcp_timer.h. But this is fine. They need to be filtered anyway. And the header should \#error for such a misuse, IMHO.
It breaks compiling contrib/bsnmp/snmp_mibII/mibII_tcp.c in userland, since it includes tcp_timer.h and MSEC_2_TICKS() is defined in sys/time.h only for kernel land.
So moving the various #defines inside a #idef _KERNEL breaks the kernel interface. So what about defining something like
#define TCP_MSEC_TO_TICKS(m) max(1, (uint32_t)((hz == 1000) ? \ (m) : ((uint64_t)(m) * (uint64_t)hz)/(uint64_t)1000))
in tcp_timer.h and use it. It duplicates code but would provide compatibility...
An alternative is to fix the in-tree consumers of tcp_timer.h. Some of them actually don't need it at all. But this would not fix the out-of-tree consumers...
Hold on. I'd rather fix bsnmpd. I'm in this area anyway (for a different reason, though).
OK. Will do. And will have a look at the other consumers.
To be consistent we should put the #defines in tcp_timer.h, which will use MSEC_2_TICKS(), under #ifdef _KERNEL, since only in this case MSEC_2_TICKS() is defined. bsnmpd should actually query the sysctl interface, not some defines.
bsnmpd done. We can put the entire header under _KERNEL. We also can add #error in there to catch all incorrect inclusions of this header.