svn commit: r232044 - projects/pf/head/sys/sys

Bruce Evans brde at optusnet.com.au
Thu Feb 23 20:15:35 UTC 2012


On Thu, 23 Feb 2012, Gleb Smirnoff wrote:

> Log:
>  Expose NetBSD/OpenBSD compat defines to kernel code, too.

These should be removed instead of used further.

In another commit, you made changes make the use of the FreeBSD
API clearer.  This change makes it possible to not even use the
FreeBSD API.

> Modified: projects/pf/head/sys/sys/time.h
> ==============================================================================
> --- projects/pf/head/sys/sys/time.h	Thu Feb 23 10:18:28 2012	(r232043)
> +++ projects/pf/head/sys/sys/time.h	Thu Feb 23 10:19:24 2012	(r232044)
> @@ -199,8 +199,7 @@ timeval2bintime(const struct timeval *tv
>
> #endif /* _KERNEL */
>
> -#ifndef _KERNEL			/* NetBSD/OpenBSD compatible interfaces */
> -
> +/* NetBSD/OpenBSD compatible interfaces. */
> #define	timerclear(tvp)		((tvp)->tv_sec = (tvp)->tv_usec = 0)
> #define	timerisset(tvp)		((tvp)->tv_sec || (tvp)->tv_usec)
> #define	timercmp(tvp, uvp, cmp)					\
> @@ -225,7 +224,6 @@ timeval2bintime(const struct timeval *tv
> 			(vvp)->tv_usec += 1000000;			\
> 		}							\
> 	} while (0)
> -#endif

This is the old Net/2 and 4.4BSD API (extended).  One of the bugs in
it is that it users the generic name `timer' for just one of the types
of time-related structures, and even that type is time-related, not
always timer-related.  This timeval type should have gone away with POSIX
timespecs in 1988, so it is the one least deserving of the generic name.

FreeBSD started fixing this in 1998 by renaming the above to timeval*()
in the kernel.  Unfortunately, the old APIs remained as compatibility
cruft for userland (now under ifdefs).  FreeBSD also added timespec*()
macros in 1998.

timevaladd() and timevalsub() were correctly spelled and correctly
implemented as functions in FreeBSD-1.  FreeBSD extended the old
mistakes in 1996 by adding timeradd() and timersub() macros for NetBSD
userland compatibility.  These are heavier-weight and otherwise more
suitable for being functions than the others, so they were only
functions, and were correctly named too.  timespecadd() and
timespecsub() are simalarly better implemented as functions, but FreeBSD
added macros for them in 1998, while intentionally not doing this for
timevaladd() and timevalsub().  But there is a problem with any of
these API being functions in userland, since the functions have never
been in libc.  Hacking on time.h is easier than adding them in libc.
Even correct hacking on time.h for them would be easier than changing
libc.  The 1996-2012 hacking is missing visibility ifdefs, and gives
unsafe macros although their names indicate that they are safe.

POSIX extended the lifetime of timevals by standardizing them 2001.
13 years wasn't long enough for them to go away.  Now, 24 years hasn't
been long enough.

Bruce


More information about the svn-src-projects mailing list