Deleted Added
full compact
kern_mtxpool.c (170035) kern_mtxpool.c (184205)
1/*-
2 * Copyright (c) 2001 Matthew Dillon. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 30 unchanged lines hidden (view full) ---

39 *
40 * Disadvantages:
41 * - should generally only be used as leaf mutexes.
42 * - pool/pool dependancy ordering cannot be depended on.
43 * - possible L1 cache mastersip contention between cpus.
44 */
45
46#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Matthew Dillon. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 30 unchanged lines hidden (view full) ---

39 *
40 * Disadvantages:
41 * - should generally only be used as leaf mutexes.
42 * - pool/pool dependancy ordering cannot be depended on.
43 * - possible L1 cache mastersip contention between cpus.
44 */
45
46#include <sys/cdefs.h>
47__FBSDID("$FreeBSD: head/sys/kern/kern_mtxpool.c 170035 2007-05-27 20:50:23Z rwatson $");
47__FBSDID("$FreeBSD: head/sys/kern/kern_mtxpool.c 184205 2008-10-23 15:53:51Z des $");
48
49#include <sys/param.h>
50#include <sys/proc.h>
51#include <sys/kernel.h>
52#include <sys/ktr.h>
53#include <sys/lock.h>
54#include <sys/malloc.h>
55#include <sys/mutex.h>

--- 85 unchanged lines hidden (view full) ---

141{
142 struct mtx_pool *pool;
143
144 if (pool_size <= 0 || !powerof2(pool_size)) {
145 printf("WARNING: %s pool size is not a power of 2.\n",
146 mtx_name);
147 pool_size = 128;
148 }
48
49#include <sys/param.h>
50#include <sys/proc.h>
51#include <sys/kernel.h>
52#include <sys/ktr.h>
53#include <sys/lock.h>
54#include <sys/malloc.h>
55#include <sys/mutex.h>

--- 85 unchanged lines hidden (view full) ---

141{
142 struct mtx_pool *pool;
143
144 if (pool_size <= 0 || !powerof2(pool_size)) {
145 printf("WARNING: %s pool size is not a power of 2.\n",
146 mtx_name);
147 pool_size = 128;
148 }
149 MALLOC(pool, struct mtx_pool *,
150 sizeof (struct mtx_pool) + ((pool_size - 1) * sizeof (struct mtx)),
149 pool = malloc( sizeof (struct mtx_pool) + ((pool_size - 1) * sizeof (struct mtx)),
151 M_MTXPOOL, M_WAITOK | M_ZERO);
152 mtx_pool_initialize(pool, mtx_name, pool_size, opts);
153 return pool;
154}
155
156void
157mtx_pool_destroy(struct mtx_pool **poolp)
158{
159 int i;
160 struct mtx_pool *pool = *poolp;
161
162 for (i = pool->mtx_pool_size - 1; i >= 0; --i)
163 mtx_destroy(&pool->mtx_pool_ary[i]);
150 M_MTXPOOL, M_WAITOK | M_ZERO);
151 mtx_pool_initialize(pool, mtx_name, pool_size, opts);
152 return pool;
153}
154
155void
156mtx_pool_destroy(struct mtx_pool **poolp)
157{
158 int i;
159 struct mtx_pool *pool = *poolp;
160
161 for (i = pool->mtx_pool_size - 1; i >= 0; --i)
162 mtx_destroy(&pool->mtx_pool_ary[i]);
164 FREE(pool, M_MTXPOOL);
163 free(pool, M_MTXPOOL);
165 *poolp = NULL;
166}
167
168static void
169mtx_pool_setup_static(void *dummy __unused)
170{
171 mtx_pool_initialize((struct mtx_pool *)&lockbuilder_pool,
172 "lockbuilder mtxpool", MTX_POOL_LOCKBUILDER_SIZE,

--- 30 unchanged lines hidden (view full) ---

203}
204
205/*
206 * The lockbuilder pool must be initialized early because the lockmgr
207 * and sx locks depend on it. The sx locks are used in the kernel
208 * memory allocator. The lockmgr subsystem is initialized by
209 * SYSINIT(..., SI_SUB_LOCKMGR, ...).
210 *
164 *poolp = NULL;
165}
166
167static void
168mtx_pool_setup_static(void *dummy __unused)
169{
170 mtx_pool_initialize((struct mtx_pool *)&lockbuilder_pool,
171 "lockbuilder mtxpool", MTX_POOL_LOCKBUILDER_SIZE,

--- 30 unchanged lines hidden (view full) ---

202}
203
204/*
205 * The lockbuilder pool must be initialized early because the lockmgr
206 * and sx locks depend on it. The sx locks are used in the kernel
207 * memory allocator. The lockmgr subsystem is initialized by
208 * SYSINIT(..., SI_SUB_LOCKMGR, ...).
209 *
211 * We can't call MALLOC() to dynamically allocate the sleep pool
210 * We can't call malloc() to dynamically allocate the sleep pool
212 * until after kmeminit() has been called, which is done by
213 * SYSINIT(..., SI_SUB_KMEM, ...).
214 */
215SYSINIT(mtxpooli1, SI_SUB_MTX_POOL_STATIC, SI_ORDER_FIRST,
216 mtx_pool_setup_static, NULL);
217SYSINIT(mtxpooli2, SI_SUB_MTX_POOL_DYNAMIC, SI_ORDER_FIRST,
218 mtx_pool_setup_dynamic, NULL);
211 * until after kmeminit() has been called, which is done by
212 * SYSINIT(..., SI_SUB_KMEM, ...).
213 */
214SYSINIT(mtxpooli1, SI_SUB_MTX_POOL_STATIC, SI_ORDER_FIRST,
215 mtx_pool_setup_static, NULL);
216SYSINIT(mtxpooli2, SI_SUB_MTX_POOL_DYNAMIC, SI_ORDER_FIRST,
217 mtx_pool_setup_dynamic, NULL);