Re: svn commit: r355600 - in head: share/man/man9 sys/kern sys/sys
On 2019-12-11 10:26, Alexey Dokuchaev wrote: That's one of those things that make Linux so unpleasant to work with. Frankly, I don't think we want that for FreeBSD. The argument for the current callback is still a "void *". container_of() has some type checks at least. It is not a big deal though. --HPS ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r355600 - in head: share/man/man9 sys/kern sys/sys
On Tue, Dec 10, 2019 at 11:09:41PM +0100, Hans Petter Selasky wrote: > On 2019-12-10 22:58, John Baldwin wrote: > > While here, add to the manpage. > > FYI: > > Linux guys eliminated the "void *c_arg" in their timer implementation by > using container_of() to get callback argument. We could possibly do the > same! #define container_of(ptr, type, member) ({ \ void *__mptr = (void *)(ptr); \ BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \ !__same_type(*(ptr), void),\ "pointer type mismatch in container_of()");\ ((type *)(__mptr - offsetof(type, member))); }) That's one of those things that make Linux so unpleasant to work with. Frankly, I don't think we want that for FreeBSD. ./danfe ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r355600 - in head: share/man/man9 sys/kern sys/sys
On 2019-12-10 23:47, John Baldwin wrote: You mean passing the pointer to the callout itself and using that to get to the relevant pointer? Yes. --HPS ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r355600 - in head: share/man/man9 sys/kern sys/sys
In message , John Baldwin writes: >On 12/10/19 2:09 PM, Hans Petter Selasky wrote: >> On 2019-12-10 22:58, John Baldwin wrote: >>> While here, add to the manpage. >> >> FYI: >> >> Linux guys eliminated the "void *c_arg" in their timer implementation by >> using container_of() to get callback argument. We could possibly do the >> same! > >You mean passing the pointer to the callout itself and using that to get to the >relevant pointer? Before we start using macro-magic of that caliber, we should consider how/if it will impact the strength of static analysis. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 p...@freebsd.org | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r355600 - in head: share/man/man9 sys/kern sys/sys
On 12/10/19 2:09 PM, Hans Petter Selasky wrote: > On 2019-12-10 22:58, John Baldwin wrote: >> While here, add to the manpage. > > FYI: > > Linux guys eliminated the "void *c_arg" in their timer implementation by > using container_of() to get callback argument. We could possibly do the > same! You mean passing the pointer to the callout itself and using that to get to the relevant pointer? That seems less obvious from a code readability standpoint. We also don't actually guarantee that the 'struct callout' is still alive when the function is called currently (hence the need for the local variables that store a copy of the fields). -- John Baldwin ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r355600 - in head: share/man/man9 sys/kern sys/sys
On 2019-12-10 22:58, John Baldwin wrote: While here, add to the manpage. FYI: Linux guys eliminated the "void *c_arg" in their timer implementation by using container_of() to get callback argument. We could possibly do the same! --HPS ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r355600 - in head: share/man/man9 sys/kern sys/sys
Author: jhb Date: Tue Dec 10 21:58:30 2019 New Revision: 355600 URL: https://svnweb.freebsd.org/changeset/base/355600 Log: Add a callout_func_t typedef for functions used with callout_*(). This typedef is the same as timeout_t except that it is in the callout namespace and header. Use this typedef in various places of the callout implementation that were either using the raw type or timeout_t. While here, add to the manpage. Reviewed by: kib, imp MFC after:1 month Differential Revision:https://reviews.freebsd.org/D22751 Modified: head/share/man/man9/timeout.9 head/sys/kern/kern_timeout.c head/sys/sys/_callout.h Modified: head/share/man/man9/timeout.9 == --- head/share/man/man9/timeout.9 Tue Dec 10 21:56:44 2019 (r355599) +++ head/share/man/man9/timeout.9 Tue Dec 10 21:58:30 2019 (r355600) @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 27, 2016 +.Dd December 10, 2019 .Dt TIMEOUT 9 .Os .Sh NAME @@ -62,8 +62,10 @@ .Nd execute a function after a specified length of time .Sh SYNOPSIS .In sys/types.h +.In sys/callout.h .In sys/systm.h .Bd -literal +typedef void callout_func_t (void *); typedef void timeout_t (void *); .Ed .Ft int @@ -71,7 +73,7 @@ typedef void timeout_t (void *); .Ft void .Fn callout_deactivate "struct callout *c" .Ft int -.Fn callout_async_drain "struct callout *c" "timeout_t *drain" +.Fn callout_async_drain "struct callout *c" "callout_func_t *drain" .Ft int .Fn callout_drain "struct callout *c" .Ft void @@ -90,19 +92,24 @@ struct callout_handle handle = CALLOUT_HANDLE_INITIALI .Ft int .Fn callout_pending "struct callout *c" .Ft int -.Fn callout_reset "struct callout *c" "int ticks" "timeout_t *func" "void *arg" +.Fo callout_reset +.Fa "struct callout *c" +.Fa "int ticks" +.Fa "callout_func_t *func" +.Fa "void *arg" +.Fc .Ft int .Fo callout_reset_curcpu .Fa "struct callout *c" .Fa "int ticks" -.Fa "timeout_t *func" +.Fa "callout_func_t *func" .Fa "void *arg" .Fc .Ft int .Fo callout_reset_on .Fa "struct callout *c" .Fa "int ticks" -.Fa "timeout_t *func" +.Fa "callout_func_t *func" .Fa "void *arg" .Fa "int cpu" .Fc @@ -111,7 +118,7 @@ struct callout_handle handle = CALLOUT_HANDLE_INITIALI .Fa "struct callout *c" .Fa "sbintime_t sbt" .Fa "sbintime_t pr" -.Fa "timeout_t *func" +.Fa "callout_func_t *func" .Fa "void *arg" .Fa "int flags" .Fc @@ -120,7 +127,7 @@ struct callout_handle handle = CALLOUT_HANDLE_INITIALI .Fa "struct callout *c" .Fa "sbintime_t sbt" .Fa "sbintime_t pr" -.Fa "timeout_t *func" +.Fa "callout_func_t *func" .Fa "void *arg" .Fa "int flags" .Fc @@ -129,7 +136,7 @@ struct callout_handle handle = CALLOUT_HANDLE_INITIALI .Fa "struct callout *c" .Fa "sbintime_t sbt" .Fa "sbintime_t pr" -.Fa "timeout_t *func" +.Fa "callout_func_t *func" .Fa "void *arg" .Fa "int cpu" .Fa "int flags" Modified: head/sys/kern/kern_timeout.c == --- head/sys/kern/kern_timeout.cTue Dec 10 21:56:44 2019 (r355599) +++ head/sys/kern/kern_timeout.cTue Dec 10 21:58:30 2019 (r355600) @@ -145,11 +145,11 @@ static u_int __read_mostly callwheelmask; */ struct cc_exec { struct callout *cc_curr; - void(*cc_drain)(void *); + callout_func_t *cc_drain; void*cc_last_func; void*cc_last_arg; #ifdef SMP - void(*ce_migration_func)(void *); + callout_func_t *ce_migration_func; void*ce_migration_arg; sbintime_t ce_migration_time; sbintime_t ce_migration_prec; @@ -656,7 +656,7 @@ softclock_call_cc(struct callout *c, struct callout_cp int direct) { struct rm_priotracker tracker; - void (*c_func)(void *); + callout_func_t *c_func, *drain; void *c_arg; struct lock_class *class; struct lock_object *c_lock; @@ -664,7 +664,7 @@ softclock_call_cc(struct callout *c, struct callout_cp int c_iflags; #ifdef SMP struct callout_cpu *new_cc; - void (*new_func)(void *); + callout_func_t *new_func; void *new_arg; int flags, new_cpu; sbintime_t new_prec, new_time; @@ -673,7 +673,7 @@ softclock_call_cc(struct callout *c, struct callout_cp sbintime_t sbt1, sbt2; struct timespec ts2; static sbintime_t maxdt = 2 * SBT_1MS; /* 2 msec */ - static timeout_t *lastfunc; + static callout_func_t *lastfunc; #endif KASSERT((c->c_iflags & CALLOUT_PENDING) == CALLOUT_PENDING, @@ -768,8 +768,6 @@ skip: KASSERT(cc_exec_curr(cc, direct) == c, ("mishandled cc_curr")); cc_exec_curr(cc, direct) = NULL; if (cc_exec_drain(cc, direct)) { -