sys: Avoid relying on pollution from refcount.h

Fix up headers which previously assumed that refcount.h includes
systm.h, and make them more self-contained.  Then, replace the systm.h
include in refcount with kassert.h.

Reviewed by:	imp, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D47450
This commit is contained in:
Mark Johnston 2024-11-05 14:31:50 +00:00
parent 625835c8b5
commit d14c38ceb8
11 changed files with 37 additions and 15 deletions

View File

@ -100,6 +100,8 @@ counter_u64_add(counter_u64_t c, int64_t inc)
#else /* !64bit */ #else /* !64bit */
#include <sys/systm.h>
#define counter_enter() critical_enter() #define counter_enter() critical_enter()
#define counter_exit() critical_exit() #define counter_exit() critical_exit()

View File

@ -33,8 +33,8 @@
struct lock_object { struct lock_object {
const char *lo_name; /* Individual lock name. */ const char *lo_name; /* Individual lock name. */
u_int lo_flags; unsigned int lo_flags;
u_int lo_data; /* General class specific data. */ unsigned int lo_data; /* General class specific data. */
struct witness *lo_witness; /* Data for witness. */ struct witness *lo_witness; /* Data for witness. */
}; };

View File

@ -31,6 +31,8 @@
#ifndef _SYS__MUTEX_H_ #ifndef _SYS__MUTEX_H_
#define _SYS__MUTEX_H_ #define _SYS__MUTEX_H_
#include <sys/_types.h>
#include <sys/_lock.h>
#include <machine/param.h> #include <machine/param.h>
/* /*
@ -44,7 +46,7 @@
*/ */
struct mtx { struct mtx {
struct lock_object lock_object; /* Common lock properties. */ struct lock_object lock_object; /* Common lock properties. */
volatile uintptr_t mtx_lock; /* Owner and flags. */ volatile __uintptr_t mtx_lock; /* Owner and flags. */
}; };
/* /*
@ -58,7 +60,7 @@ struct mtx {
*/ */
struct mtx_padalign { struct mtx_padalign {
struct lock_object lock_object; /* Common lock properties. */ struct lock_object lock_object; /* Common lock properties. */
volatile uintptr_t mtx_lock; /* Owner and flags. */ volatile __uintptr_t mtx_lock; /* Owner and flags. */
} __aligned(CACHE_LINE_SIZE); } __aligned(CACHE_LINE_SIZE);
#endif /* !_SYS__MUTEX_H_ */ #endif /* !_SYS__MUTEX_H_ */

View File

@ -32,6 +32,14 @@
#ifndef _SYS__RMLOCK_H_ #ifndef _SYS__RMLOCK_H_
#define _SYS__RMLOCK_H_ #define _SYS__RMLOCK_H_
#include <sys/_cpuset.h>
#include <sys/_lock.h>
#include <sys/_mutex.h>
#include <sys/queue.h>
#include <sys/_sx.h>
struct thread;
/* /*
* Mostly reader/occasional writer lock. * Mostly reader/occasional writer lock.
*/ */
@ -66,8 +74,6 @@ struct rm_priotracker {
LIST_ENTRY(rm_priotracker) rmp_qentry; LIST_ENTRY(rm_priotracker) rmp_qentry;
}; };
#include <sys/_mutex.h>
struct rmslock_pcpu; struct rmslock_pcpu;
struct rmslock { struct rmslock {

View File

@ -28,6 +28,8 @@
#ifndef _SYS__RWLOCK_H_ #ifndef _SYS__RWLOCK_H_
#define _SYS__RWLOCK_H_ #define _SYS__RWLOCK_H_
#include <sys/_types.h>
#include <sys/_lock.h>
#include <machine/param.h> #include <machine/param.h>
/* /*
@ -41,7 +43,7 @@
*/ */
struct rwlock { struct rwlock {
struct lock_object lock_object; struct lock_object lock_object;
volatile uintptr_t rw_lock; volatile __uintptr_t rw_lock;
}; };
/* /*
@ -55,7 +57,7 @@ struct rwlock {
*/ */
struct rwlock_padalign { struct rwlock_padalign {
struct lock_object lock_object; struct lock_object lock_object;
volatile uintptr_t rw_lock; volatile __uintptr_t rw_lock;
} __aligned(CACHE_LINE_SIZE); } __aligned(CACHE_LINE_SIZE);
#endif /* !_SYS__RWLOCK_H_ */ #endif /* !_SYS__RWLOCK_H_ */

View File

@ -31,12 +31,15 @@
#ifndef _SYS__SX_H_ #ifndef _SYS__SX_H_
#define _SYS__SX_H_ #define _SYS__SX_H_
#include <sys/_types.h>
#include <sys/_lock.h>
/* /*
* Shared/exclusive lock main structure definition. * Shared/exclusive lock main structure definition.
*/ */
struct sx { struct sx {
struct lock_object lock_object; struct lock_object lock_object;
volatile uintptr_t sx_lock; volatile __uintptr_t sx_lock;
}; };
#endif /* !_SYS__SX_H_ */ #endif /* !_SYS__SX_H_ */

View File

@ -37,13 +37,16 @@
#include <sys/fcntl.h> #include <sys/fcntl.h>
#include <sys/unistd.h> #include <sys/unistd.h>
#else #else
#include <sys/queue.h> #include <sys/errno.h>
#include <sys/refcount.h>
#include <sys/_lock.h> #include <sys/_lock.h>
#include <sys/_mutex.h> #include <sys/_mutex.h>
#include <sys/_null.h>
#include <sys/queue.h>
#include <sys/refcount.h>
#include <vm/vm.h> #include <vm/vm.h>
struct filedesc; struct filedesc;
struct proc;
struct stat; struct stat;
struct thread; struct thread;
struct uio; struct uio;

View File

@ -28,8 +28,11 @@
#define _SYS_KTLS_H_ #define _SYS_KTLS_H_
#ifdef _KERNEL #ifdef _KERNEL
#include <sys/_null.h>
#include <sys/refcount.h> #include <sys/refcount.h>
#include <sys/_task.h> #include <sys/_task.h>
#include <machine/param.h>
#endif #endif
struct tls_record_layer { struct tls_record_layer {

View File

@ -28,13 +28,14 @@
#ifndef __SYS_REFCOUNT_H__ #ifndef __SYS_REFCOUNT_H__
#define __SYS_REFCOUNT_H__ #define __SYS_REFCOUNT_H__
#include <machine/atomic.h> #include <sys/types.h>
#include <sys/kassert.h>
#include <sys/systm.h>
#if !defined(_KERNEL) && !defined(_STANDALONE) #if !defined(_KERNEL) && !defined(_STANDALONE)
#include <stdbool.h> #include <stdbool.h>
#endif #endif
#include <machine/atomic.h>
#define REFCOUNT_SATURATED(val) (((val) & (1U << 31)) != 0) #define REFCOUNT_SATURATED(val) (((val) & (1U << 31)) != 0)
#define REFCOUNT_SATURATION_VALUE (3U << 30) #define REFCOUNT_SATURATION_VALUE (3U << 30)

View File

@ -55,6 +55,7 @@ struct sglist {
struct bio; struct bio;
struct mbuf; struct mbuf;
struct thread;
struct uio; struct uio;
static __inline void static __inline void

View File

@ -100,7 +100,6 @@ BADHDRS= \
sys/prng.h \ sys/prng.h \
sys/qmath.h \ sys/qmath.h \
sys/racct.h \ sys/racct.h \
sys/refcount.h \
sys/resourcevar.h \ sys/resourcevar.h \
sys/rman.h \ sys/rman.h \
sys/rmlock.h \ sys/rmlock.h \