Page MenuHomeFreeBSD

tcp: cleanup timer initialisations
ClosedPublic

Authored by tuexen on Jun 13 2025, 10:04 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jul 6, 11:42 PM
Unknown Object (File)
Thu, Jun 26, 8:28 PM
Unknown Object (File)
Wed, Jun 25, 7:15 PM
Unknown Object (File)
Tue, Jun 24, 5:51 PM
Unknown Object (File)
Tue, Jun 24, 5:44 PM
Unknown Object (File)
Wed, Jun 18, 5:37 PM
Unknown Object (File)
Tue, Jun 17, 8:15 PM
Unknown Object (File)
Mon, Jun 16, 8:29 PM
Subscribers

Details

Summary

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.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Mon, Jun 16, 7:46 PM

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.

This revision was automatically updated to reflect the committed changes.

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).

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.

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.

See D50912.