Deleted Added
full compact
kern_lock.c (227309) kern_lock.c (227588)
1/*-
2 * Copyright (c) 2008 Attilio Rao <attilio@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

26 * DAMAGE.
27 */
28
29#include "opt_adaptive_lockmgrs.h"
30#include "opt_ddb.h"
31#include "opt_kdtrace.h"
32
33#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2008 Attilio Rao <attilio@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

26 * DAMAGE.
27 */
28
29#include "opt_adaptive_lockmgrs.h"
30#include "opt_ddb.h"
31#include "opt_kdtrace.h"
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/kern/kern_lock.c 227309 2011-11-07 15:43:11Z ed $");
34__FBSDID("$FreeBSD: head/sys/kern/kern_lock.c 227588 2011-11-16 21:51:17Z pjd $");
35
36#include <sys/param.h>
37#include <sys/ktr.h>
38#include <sys/lock.h>
39#include <sys/lock_profile.h>
40#include <sys/lockmgr.h>
41#include <sys/mutex.h>
42#include <sys/proc.h>

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

126 ((f) & LK_SLEEPFAIL) == 0)
127
128#define lockmgr_disowned(lk) \
129 (((lk)->lk_lock & ~(LK_FLAGMASK & ~LK_SHARE)) == LK_KERNPROC)
130
131#define lockmgr_xlocked(lk) \
132 (((lk)->lk_lock & ~(LK_FLAGMASK & ~LK_SHARE)) == (uintptr_t)curthread)
133
35
36#include <sys/param.h>
37#include <sys/ktr.h>
38#include <sys/lock.h>
39#include <sys/lock_profile.h>
40#include <sys/lockmgr.h>
41#include <sys/mutex.h>
42#include <sys/proc.h>

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

126 ((f) & LK_SLEEPFAIL) == 0)
127
128#define lockmgr_disowned(lk) \
129 (((lk)->lk_lock & ~(LK_FLAGMASK & ~LK_SHARE)) == LK_KERNPROC)
130
131#define lockmgr_xlocked(lk) \
132 (((lk)->lk_lock & ~(LK_FLAGMASK & ~LK_SHARE)) == (uintptr_t)curthread)
133
134static void assert_lockmgr(struct lock_object *lock, int how);
134static void assert_lockmgr(const struct lock_object *lock, int how);
135#ifdef DDB
135#ifdef DDB
136static void db_show_lockmgr(struct lock_object *lock);
136static void db_show_lockmgr(const struct lock_object *lock);
137#endif
137#endif
138static void lock_lockmgr(struct lock_object *lock, int how);
138static void lock_lockmgr(struct lock_object *lock, int how);
139#ifdef KDTRACE_HOOKS
139#ifdef KDTRACE_HOOKS
140static int owner_lockmgr(struct lock_object *lock, struct thread **owner);
140static int owner_lockmgr(const struct lock_object *lock,
141 struct thread **owner);
141#endif
142#endif
142static int unlock_lockmgr(struct lock_object *lock);
143static int unlock_lockmgr(struct lock_object *lock);
143
144struct lock_class lock_class_lockmgr = {
145 .lc_name = "lockmgr",
146 .lc_flags = LC_RECURSABLE | LC_SLEEPABLE | LC_SLEEPLOCK | LC_UPGRADABLE,
147 .lc_assert = assert_lockmgr,
148#ifdef DDB
149 .lc_ddb_show = db_show_lockmgr,
150#endif

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

160static u_int alk_loops = 10000;
161static SYSCTL_NODE(_debug, OID_AUTO, lockmgr, CTLFLAG_RD, NULL,
162 "lockmgr debugging");
163SYSCTL_UINT(_debug_lockmgr, OID_AUTO, retries, CTLFLAG_RW, &alk_retries, 0, "");
164SYSCTL_UINT(_debug_lockmgr, OID_AUTO, loops, CTLFLAG_RW, &alk_loops, 0, "");
165#endif
166
167static __inline struct thread *
144
145struct lock_class lock_class_lockmgr = {
146 .lc_name = "lockmgr",
147 .lc_flags = LC_RECURSABLE | LC_SLEEPABLE | LC_SLEEPLOCK | LC_UPGRADABLE,
148 .lc_assert = assert_lockmgr,
149#ifdef DDB
150 .lc_ddb_show = db_show_lockmgr,
151#endif

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

161static u_int alk_loops = 10000;
162static SYSCTL_NODE(_debug, OID_AUTO, lockmgr, CTLFLAG_RD, NULL,
163 "lockmgr debugging");
164SYSCTL_UINT(_debug_lockmgr, OID_AUTO, retries, CTLFLAG_RW, &alk_retries, 0, "");
165SYSCTL_UINT(_debug_lockmgr, OID_AUTO, loops, CTLFLAG_RW, &alk_loops, 0, "");
166#endif
167
168static __inline struct thread *
168lockmgr_xholder(struct lock *lk)
169lockmgr_xholder(const struct lock *lk)
169{
170 uintptr_t x;
171
172 x = lk->lk_lock;
173 return ((x & LK_SHARE) ? NULL : (struct thread *)LK_HOLDER(x));
174}
175
176/*

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

330 break;
331 }
332
333 lock_profile_release_lock(&lk->lock_object);
334 return (wakeup_swapper);
335}
336
337static void
170{
171 uintptr_t x;
172
173 x = lk->lk_lock;
174 return ((x & LK_SHARE) ? NULL : (struct thread *)LK_HOLDER(x));
175}
176
177/*

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

331 break;
332 }
333
334 lock_profile_release_lock(&lk->lock_object);
335 return (wakeup_swapper);
336}
337
338static void
338assert_lockmgr(struct lock_object *lock, int what)
339assert_lockmgr(const struct lock_object *lock, int what)
339{
340
341 panic("lockmgr locks do not support assertions");
342}
343
344static void
345lock_lockmgr(struct lock_object *lock, int how)
346{

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

352unlock_lockmgr(struct lock_object *lock)
353{
354
355 panic("lockmgr locks do not support sleep interlocking");
356}
357
358#ifdef KDTRACE_HOOKS
359static int
340{
341
342 panic("lockmgr locks do not support assertions");
343}
344
345static void
346lock_lockmgr(struct lock_object *lock, int how)
347{

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

353unlock_lockmgr(struct lock_object *lock)
354{
355
356 panic("lockmgr locks do not support sleep interlocking");
357}
358
359#ifdef KDTRACE_HOOKS
360static int
360owner_lockmgr(struct lock_object *lock, struct thread **owner)
361owner_lockmgr(const struct lock_object *lock, struct thread **owner)
361{
362
363 panic("lockmgr locks do not support owner inquiring");
364}
365#endif
366
367void
368lockinit(struct lock *lk, int pri, const char *wmesg, int timo, int flags)

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

1255 if (atomic_cmpset_rel_ptr(&lk->lk_lock, tid | x,
1256 LK_KERNPROC | x))
1257 return;
1258 cpu_spinwait();
1259 }
1260}
1261
1262void
362{
363
364 panic("lockmgr locks do not support owner inquiring");
365}
366#endif
367
368void
369lockinit(struct lock *lk, int pri, const char *wmesg, int timo, int flags)

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

1256 if (atomic_cmpset_rel_ptr(&lk->lk_lock, tid | x,
1257 LK_KERNPROC | x))
1258 return;
1259 cpu_spinwait();
1260 }
1261}
1262
1263void
1263lockmgr_printinfo(struct lock *lk)
1264lockmgr_printinfo(const struct lock *lk)
1264{
1265 struct thread *td;
1266 uintptr_t x;
1267
1268 if (lk->lk_lock == LK_UNLOCKED)
1269 printf("lock type %s: UNLOCKED\n", lk->lock_object.lo_name);
1270 else if (lk->lk_lock & LK_SHARE)
1271 printf("lock type %s: SHARED (count %ju)\n",

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

1284 printf(" with shared waiters pending\n");
1285 if (x & LK_EXCLUSIVE_SPINNERS)
1286 printf(" with exclusive spinners pending\n");
1287
1288 STACK_PRINT(lk);
1289}
1290
1291int
1265{
1266 struct thread *td;
1267 uintptr_t x;
1268
1269 if (lk->lk_lock == LK_UNLOCKED)
1270 printf("lock type %s: UNLOCKED\n", lk->lock_object.lo_name);
1271 else if (lk->lk_lock & LK_SHARE)
1272 printf("lock type %s: SHARED (count %ju)\n",

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

1285 printf(" with shared waiters pending\n");
1286 if (x & LK_EXCLUSIVE_SPINNERS)
1287 printf(" with exclusive spinners pending\n");
1288
1289 STACK_PRINT(lk);
1290}
1291
1292int
1292lockstatus(struct lock *lk)
1293lockstatus(const struct lock *lk)
1293{
1294 uintptr_t v, x;
1295 int ret;
1296
1297 ret = LK_SHARED;
1298 x = lk->lk_lock;
1299 v = LK_HOLDER(x);
1300

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

1314FEATURE(invariant_support,
1315 "Support for modules compiled with INVARIANTS option");
1316
1317#ifndef INVARIANTS
1318#undef _lockmgr_assert
1319#endif
1320
1321void
1294{
1295 uintptr_t v, x;
1296 int ret;
1297
1298 ret = LK_SHARED;
1299 x = lk->lk_lock;
1300 v = LK_HOLDER(x);
1301

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

1315FEATURE(invariant_support,
1316 "Support for modules compiled with INVARIANTS option");
1317
1318#ifndef INVARIANTS
1319#undef _lockmgr_assert
1320#endif
1321
1322void
1322_lockmgr_assert(struct lock *lk, int what, const char *file, int line)
1323_lockmgr_assert(const struct lock *lk, int what, const char *file, int line)
1323{
1324 int slocked = 0;
1325
1326 if (panicstr != NULL)
1327 return;
1328 switch (what) {
1329 case KA_SLOCKED:
1330 case KA_SLOCKED | KA_NOTRECURSED:

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

1407 else
1408 db_printf("EXCL\n");
1409 *ownerp = lockmgr_xholder(lk);
1410
1411 return (1);
1412}
1413
1414static void
1324{
1325 int slocked = 0;
1326
1327 if (panicstr != NULL)
1328 return;
1329 switch (what) {
1330 case KA_SLOCKED:
1331 case KA_SLOCKED | KA_NOTRECURSED:

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

1408 else
1409 db_printf("EXCL\n");
1410 *ownerp = lockmgr_xholder(lk);
1411
1412 return (1);
1413}
1414
1415static void
1415db_show_lockmgr(struct lock_object *lock)
1416db_show_lockmgr(const struct lock_object *lock)
1416{
1417 struct thread *td;
1417{
1418 struct thread *td;
1418 struct lock *lk;
1419 const struct lock *lk;
1419
1420
1420 lk = (struct lock *)lock;
1421 lk = (const struct lock *)lock;
1421
1422 db_printf(" state: ");
1423 if (lk->lk_lock == LK_UNLOCKED)
1424 db_printf("UNLOCKED\n");
1425 else if (lk->lk_lock & LK_SHARE)
1426 db_printf("SLOCK: %ju\n", (uintmax_t)LK_SHARERS(lk->lk_lock));
1427 else {
1428 td = lockmgr_xholder(lk);

--- 30 unchanged lines hidden ---
1422
1423 db_printf(" state: ");
1424 if (lk->lk_lock == LK_UNLOCKED)
1425 db_printf("UNLOCKED\n");
1426 else if (lk->lk_lock & LK_SHARE)
1427 db_printf("SLOCK: %ju\n", (uintmax_t)LK_SHARERS(lk->lk_lock));
1428 else {
1429 td = lockmgr_xholder(lk);

--- 30 unchanged lines hidden ---