From owner-freebsd-smp Thu Apr 19 14:38:37 2001 Delivered-To: freebsd-smp@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id A012637B42C for ; Thu, 19 Apr 2001 14:38:26 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id HAA31291; Fri, 20 Apr 2001 07:38:04 +1000 Date: Fri, 20 Apr 2001 07:35:24 +1000 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Mark Murray Cc: smp@FreeBSD.ORG Subject: Re: Please review - header cleanups In-Reply-To: <200104190634.f3J6Xvw99980@gratis.grondar.za> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On Thu, 19 Apr 2001, Mark Murray wrote: > Said Bruce Evans : > > Possible implementations: > > 1) Do the same things as are planned for `struct timespec': use a tiny > > header that declares just `struct mtx' and include this header as > > necessary. > > Ok so this would be a header with only the "struct mtx { ... };" in it, > and it would be included in all the headers that need to know the size > and shape of struct mtx (including sys/mutex.h)? --- diff -c2 mutex_types.h~ mutex_types.h *** mutex_types.h~ Fri Apr 20 06:09:31 2001 --- mutex_types.h Thu Apr 19 21:13:40 2001 *************** *** 0 **** --- 1,27 ---- + #ifndef _SYS_MUTEX_TYPES_H_ + #define _SYS_MUTEX_TYPES_H_ + + struct lock_object { + struct lock_class *lo_class; + const char *lo_name; + const char *lo_file; /* File and line of last acquire. */ + int lo_line; + u_int lo_flags; + STAILQ_ENTRY(lock_object) lo_list; /* List of all locks in system. */ + struct witness *lo_witness; + }; + + /* + * Sleep/spin mutex + */ + + struct mtx { + struct lock_object mtx_object; /* Common lock properties. */ + volatile uintptr_t mtx_lock; /* owner (and state for sleep locks) */ + volatile u_int mtx_recurse; /* number of recursive holds */ + critical_t mtx_savecrit; /* saved flags (for spin locks) */ + TAILQ_HEAD(, proc) mtx_blocked; /* threads blocked on this lock */ + LIST_ENTRY(mtx) mtx_contested; /* list of all contested locks */ + }; + + #endif /* !_SYS_MUTEX_TYPES_H_ */ Index: lock.h =================================================================== RCS file: /home/ncvs/src/sys/sys/lock.h,v retrieving revision 1.29 diff -c -2 -r1.29 lock.h *** lock.h 2001/04/06 21:37:52 1.29 --- lock.h 2001/04/19 11:02:46 *************** *** 40,43 **** --- 40,44 ---- #include + #include /* *************** *** 60,75 **** #define LC_SLEEPABLE 0x00000004 /* Sleeping allowed with this lock. */ #define LC_RECURSABLE 0x00000008 /* Locks of this type may recurse. */ - - struct witness; - - struct lock_object { - struct lock_class *lo_class; - const char *lo_name; - const char *lo_file; /* File and line of last acquire. */ - int lo_line; - u_int lo_flags; - STAILQ_ENTRY(lock_object) lo_list; /* List of all locks in system. */ - struct witness *lo_witness; - }; #define LO_CLASSFLAGS 0x0000ffff /* Class specific flags. */ --- 61,64 ---- Index: mbuf.h =================================================================== RCS file: /home/ncvs/src/sys/sys/mbuf.h,v retrieving revision 1.76 diff -c -2 -r1.76 mbuf.h *** mbuf.h 2001/04/05 03:55:27 1.76 --- mbuf.h 2001/04/19 11:03:22 *************** *** 39,46 **** #ifdef _KERNEL ! #include /* XXX */ ! #include /* XXX */ ! #include /* XXX */ ! #endif /* _KERNEL */ /* --- 39,45 ---- #ifdef _KERNEL ! #include /* XXX */ ! #include ! #endif /* Index: mutex.h =================================================================== RCS file: /home/ncvs/src/sys/sys/mutex.h,v retrieving revision 1.29 diff -c -2 -r1.29 mutex.h *** mutex.h 2001/03/28 09:03:24 1.29 --- mutex.h 2001/04/19 11:02:38 *************** *** 35,38 **** --- 35,39 ---- #ifndef LOCORE #include + #include #ifdef _KERNEL *************** *** 79,97 **** /* - * Sleep/spin mutex - */ - - struct lock_object; - - struct mtx { - struct lock_object mtx_object; /* Common lock properties. */ - volatile uintptr_t mtx_lock; /* owner (and state for sleep locks) */ - volatile u_int mtx_recurse; /* number of recursive holds */ - critical_t mtx_savecrit; /* saved flags (for spin locks) */ - TAILQ_HEAD(, proc) mtx_blocked; /* threads blocked on this lock */ - LIST_ENTRY(mtx) mtx_contested; /* list of all contested locks */ - }; - - /* * XXX: Friendly reminder to fix things in MP code that is presently being * XXX: worked on. --- 80,83 ---- Index: resourcevar.h =================================================================== RCS file: /home/ncvs/src/sys/sys/resourcevar.h,v retrieving revision 1.21 diff -c -2 -r1.21 resourcevar.h *** resourcevar.h 2001/03/28 09:17:56 1.21 --- resourcevar.h 2001/04/19 11:04:07 *************** *** 40,45 **** #include #include ! #include /* XXX */ ! #include /* XXX */ /* --- 40,46 ---- #include #include ! #ifdef _KERNEL ! #include ! #endif /* Index: sx.h =================================================================== RCS file: /home/ncvs/src/sys/sys/sx.h,v retrieving revision 1.6 diff -c -2 -r1.6 sx.h *** sx.h 2001/03/28 09:03:24 1.6 --- sx.h 2001/04/19 11:04:44 *************** *** 32,40 **** #ifndef LOCORE ! #include /* XXX */ ! #include /* XXX */ #include /* XXX */ - - struct lock_object; struct sx { --- 32,37 ---- #ifndef LOCORE ! #include #include /* XXX */ struct sx { Index: ucred.h =================================================================== RCS file: /home/ncvs/src/sys/sys/ucred.h,v retrieving revision 1.22 diff -c -2 -r1.22 ucred.h *** ucred.h 2001/03/28 09:17:56 1.22 --- ucred.h 2001/04/19 11:22:22 *************** *** 38,43 **** #define _SYS_UCRED_H_ ! #include /* XXX */ ! #include /* XXX */ /* --- 38,43 ---- #define _SYS_UCRED_H_ ! #include ! #include /* Index: user.h =================================================================== RCS file: /home/ncvs/src/sys/sys/user.h,v retrieving revision 1.36 diff -c -2 -r1.36 user.h *** user.h 2001/03/28 09:17:56 1.36 --- user.h 2001/04/19 11:05:13 *************** *** 46,51 **** #include #include ! #include /* XXX */ ! #include /* XXX */ #include #include /* XXX */ --- 46,50 ---- #include #include ! #include #include #include /* XXX */ Index: vnode.h =================================================================== RCS file: /home/ncvs/src/sys/sys/vnode.h,v retrieving revision 1.143 diff -c -2 -r1.143 vnode.h *** vnode.h 2001/04/17 04:33:33 1.143 --- vnode.h 2001/04/19 11:16:37 *************** *** 38,43 **** #define _SYS_VNODE_H_ - #include - #include #include #include --- 38,43 ---- #define _SYS_VNODE_H_ #include + #include /* XXX */ + #include #include --- This removes all the nested includes of except the one in (the inline functions there should probably not be inline). It only removes a couple of nested includes of (ones related to ). LINT compiles after adding includes of (and sometimes ) to "only" about 50 .c files. Many more probably depend on the pollution in :-(. About 1/2 of the 50 really should include . The others mostly use the PROC_* locking macros in these expand to mtx_lock(), etc. mtx_lock() is another macro so it can't just be declared. It needs the MPASS() macros from , so everything that uses the PROC_* macros needs both and . > > 2) Do the same things as are done for size_t: define a macro that declares > > `struct mtx' in a not so tiny secondary header; include this header and > > expand it as necessary. This is uglier than (1), but doesn't require > > so many headers. > > I think I prefer 1). I've put 2 structs in to test things quickly. Strictly, struct lock_object belongs in a header by itself. > > 3) Combination/variation of on (1)-(2): conditionally declare various > > structs and types in a not so tiny secondary header; include this > > header with only the required declarations selected. This method is > > used in glibc. This is not as ugly as (2), but I think it is slower > > than both (1) and (2). > > ONE header to declare _all_/lots_of the "internal" structures? Hmmm... See glibc or stddef.h under contrib/gcc. The __need_foo_t stuff selects the types that will be declared. Ugly, isn't it. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message