27 #include <sys/cdefs.h>
30 #include <sys/param.h>
31 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/mutex.h>
36 #include <sys/sysctl.h>
38 #include <sys/systm.h>
45 static MALLOC_DEFINE(M_KOBJ,
"kobj",
"Kernel object structures");
49 u_int kobj_lookup_hits;
50 u_int kobj_lookup_misses;
53 &kobj_lookup_hits, 0,
"");
54 SYSCTL_UINT(_kern, OID_AUTO, kobj_misses, CTLFLAG_RD,
55 &kobj_lookup_misses, 0,
"");
63 #define KOBJ_LOCK() mtx_lock(&kobj_mtx)
64 #define KOBJ_UNLOCK() mtx_unlock(&kobj_mtx)
65 #define KOBJ_ASSERT(what) mtx_assert(&kobj_mtx, what);
67 SYSCTL_INT(_kern, OID_AUTO, kobj_methodcount, CTLFLAG_RD,
112 for (i = 0, m = cls->methods; m->desc; i++, m++) {
113 if (m->desc->id == 0)
120 for (i = 0; i < KOBJ_CACHE_SIZE; i++)
136 ops =
malloc(
sizeof(
struct kobj_ops), M_KOBJ, M_NOWAIT);
138 panic(
"%s: out of memory", __func__);
162 (
"%s: only supported during early cycles", __func__));
171 static kobj_method_t*
174 kobj_method_t *methods = cls->methods;
177 for (ce = methods; ce && ce->desc; ce++) {
178 if (ce->desc == desc) {
186 static kobj_method_t*
197 basep = cls->baseclasses;
199 for (; *basep; basep++) {
222 kobj_lookup_misses++;
244 if (cls->refs == 0) {
265 struct malloc_type *mtype,
273 obj =
malloc(cls->size, mtype, mflags | M_ZERO);
320 (
"%s: only supported during early cycles", __func__));
328 kobj_class_t cls = obj->ops->cls;
SYSINIT(kobj, SI_SUB_LOCK, SI_ORDER_ANY, kobj_init_mutex, NULL)
static struct kobj_method null_method
kobj_method_t * kobj_lookup_method(kobj_class_t cls, kobj_method_t **cep, kobjop_desc_t desc)
static kobj_method_t * kobj_lookup_method_mi(kobj_class_t cls, kobjop_desc_t desc)
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
void kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops)
static void kobj_class_compile_common(kobj_class_t cls, kobj_ops_t ops)
void panic(const char *fmt,...)
SYSCTL_UINT(_kern_eventtimer, OID_AUTO, idletick, CTLFLAG_RW,&idletick, 0,"Run periodic events when idle")
void kobj_init_static(kobj_t obj, kobj_class_t cls)
static void kobj_init_mutex(void *arg)
static kobj_method_t * kobj_lookup_method_class(kobj_class_t cls, kobjop_desc_t desc)
void kobj_delete(kobj_t obj, struct malloc_type *mtype)
static void kobj_init_common(kobj_t obj, kobj_class_t cls)
void kobj_class_free(kobj_class_t cls)
SYSCTL_INT(_kern, OID_AUTO, kobj_methodcount, CTLFLAG_RD,&kobj_next_id, 0,"")
#define KOBJ_ASSERT(what)
void free(void *addr, struct malloc_type *mtp)
kobj_t kobj_create(kobj_class_t cls, struct malloc_type *mtype, int mflags)
void mtx_init(struct mtx *m, const char *name, const char *type, int opts)
int kobj_error_method(void)
void kobj_class_compile(kobj_class_t cls)
static int kobj_mutex_inited
void kobj_init(kobj_t obj, kobj_class_t cls)
static MALLOC_DEFINE(M_KOBJ,"kobj","Kernel object structures")
static struct mtx kobj_mtx