kern_mutex.c (189789) | kern_mutex.c (189846) |
---|---|
1/*- 2 * Copyright (c) 1998 Berkeley Software Design, Inc. 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. --- 20 unchanged lines hidden (view full) --- 29 * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $ 30 */ 31 32/* 33 * Machine independent bits of mutex implementation. 34 */ 35 36#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1998 Berkeley Software Design, Inc. 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. --- 20 unchanged lines hidden (view full) --- 29 * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $ 30 */ 31 32/* 33 * Machine independent bits of mutex implementation. 34 */ 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/sys/kern/kern_mutex.c 189789 2009-03-14 11:43:38Z jeff $"); | 37__FBSDID("$FreeBSD: head/sys/kern/kern_mutex.c 189846 2009-03-15 08:03:54Z jeff $"); |
38 39#include "opt_adaptive_mutexes.h" 40#include "opt_ddb.h" 41#include "opt_global.h" 42#include "opt_sched.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> --- 203 unchanged lines hidden (view full) --- 249/* 250 * The important part of mtx_trylock{,_flags}() 251 * Tries to acquire lock `m.' If this function is called on a mutex that 252 * is already owned, it will recursively acquire the lock. 253 */ 254int 255_mtx_trylock(struct mtx *m, int opts, const char *file, int line) 256{ | 38 39#include "opt_adaptive_mutexes.h" 40#include "opt_ddb.h" 41#include "opt_global.h" 42#include "opt_sched.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> --- 203 unchanged lines hidden (view full) --- 249/* 250 * The important part of mtx_trylock{,_flags}() 251 * Tries to acquire lock `m.' If this function is called on a mutex that 252 * is already owned, it will recursively acquire the lock. 253 */ 254int 255_mtx_trylock(struct mtx *m, int opts, const char *file, int line) 256{ |
257 int rval, contested = 0; | 257#ifdef LOCK_PROFILING |
258 uint64_t waittime = 0; | 258 uint64_t waittime = 0; |
259 int contested = 0; 260#endif 261 int rval; |
|
259 260 MPASS(curthread != NULL); 261 KASSERT(m->mtx_lock != MTX_DESTROYED, 262 ("mtx_trylock() of destroyed mutex @ %s:%d", file, line)); 263 KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_sleep, 264 ("mtx_trylock() of spin mutex %s @ %s:%d", m->lock_object.lo_name, 265 file, line)); 266 --- 24 unchanged lines hidden (view full) --- 291 * We call this if the lock is either contested (i.e. we need to go to 292 * sleep waiting for it), or if we need to recurse on it. 293 */ 294void 295_mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts, const char *file, 296 int line) 297{ 298 struct turnstile *ts; | 262 263 MPASS(curthread != NULL); 264 KASSERT(m->mtx_lock != MTX_DESTROYED, 265 ("mtx_trylock() of destroyed mutex @ %s:%d", file, line)); 266 KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_sleep, 267 ("mtx_trylock() of spin mutex %s @ %s:%d", m->lock_object.lo_name, 268 file, line)); 269 --- 24 unchanged lines hidden (view full) --- 294 * We call this if the lock is either contested (i.e. we need to go to 295 * sleep waiting for it), or if we need to recurse on it. 296 */ 297void 298_mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts, const char *file, 299 int line) 300{ 301 struct turnstile *ts; |
302 uintptr_t v; |
|
299#ifdef ADAPTIVE_MUTEXES 300 volatile struct thread *owner; 301#endif 302#ifdef KTR 303 int cont_logged = 0; 304#endif | 303#ifdef ADAPTIVE_MUTEXES 304 volatile struct thread *owner; 305#endif 306#ifdef KTR 307 int cont_logged = 0; 308#endif |
309#ifdef LOCK_PROFILING |
|
305 int contested = 0; 306 uint64_t waittime = 0; | 310 int contested = 0; 311 uint64_t waittime = 0; |
307 uintptr_t v; | 312#endif |
308 309 if (mtx_owned(m)) { 310 KASSERT((m->lock_object.lo_flags & LO_RECURSABLE) != 0, 311 ("_mtx_lock_sleep: recursed on non-recursive mutex %s @ %s:%d\n", 312 m->lock_object.lo_name, file, line)); 313 m->mtx_recurse++; 314 atomic_set_ptr(&m->mtx_lock, MTX_RECURSED); 315 if (LOCK_LOG_TEST(&m->lock_object, opts)) --- 127 unchanged lines hidden (view full) --- 443 * 444 * This is only called if we need to actually spin for the lock. Recursion 445 * is handled inline. 446 */ 447void 448_mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts, const char *file, 449 int line) 450{ | 313 314 if (mtx_owned(m)) { 315 KASSERT((m->lock_object.lo_flags & LO_RECURSABLE) != 0, 316 ("_mtx_lock_sleep: recursed on non-recursive mutex %s @ %s:%d\n", 317 m->lock_object.lo_name, file, line)); 318 m->mtx_recurse++; 319 atomic_set_ptr(&m->mtx_lock, MTX_RECURSED); 320 if (LOCK_LOG_TEST(&m->lock_object, opts)) --- 127 unchanged lines hidden (view full) --- 448 * 449 * This is only called if we need to actually spin for the lock. Recursion 450 * is handled inline. 451 */ 452void 453_mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts, const char *file, 454 int line) 455{ |
451 int i = 0, contested = 0; | 456 int i = 0; 457#ifdef LOCK_PROFILING 458 int contested = 0; |
452 uint64_t waittime = 0; | 459 uint64_t waittime = 0; |
460#endif |
|
453 454 if (LOCK_LOG_TEST(&m->lock_object, opts)) 455 CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m); 456 457 lock_profile_obtain_lock_failed(&m->lock_object, &contested, &waittime); 458 while (!_obtain_lock(m, tid)) { 459 460 /* Give interrupts a chance while we spin. */ --- 20 unchanged lines hidden (view full) --- 481} 482#endif /* SMP */ 483 484void 485_thread_lock_flags(struct thread *td, int opts, const char *file, int line) 486{ 487 struct mtx *m; 488 uintptr_t tid; | 461 462 if (LOCK_LOG_TEST(&m->lock_object, opts)) 463 CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m); 464 465 lock_profile_obtain_lock_failed(&m->lock_object, &contested, &waittime); 466 while (!_obtain_lock(m, tid)) { 467 468 /* Give interrupts a chance while we spin. */ --- 20 unchanged lines hidden (view full) --- 489} 490#endif /* SMP */ 491 492void 493_thread_lock_flags(struct thread *td, int opts, const char *file, int line) 494{ 495 struct mtx *m; 496 uintptr_t tid; |
489 int i, contested; 490 uint64_t waittime; | 497 int i; 498#ifdef LOCK_PROFILING 499 int contested = 0; 500 uint64_t waittime = 0; 501#endif |
491 | 502 |
492 contested = i = 0; 493 waittime = 0; | 503 i = 0; |
494 tid = (uintptr_t)curthread; 495 for (;;) { 496retry: 497 spinlock_enter(); 498 m = td->td_lock; 499 KASSERT(m->mtx_lock != MTX_DESTROYED, 500 ("thread_lock() of destroyed mutex @ %s:%d", file, line)); 501 KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_spin, --- 341 unchanged lines hidden --- | 504 tid = (uintptr_t)curthread; 505 for (;;) { 506retry: 507 spinlock_enter(); 508 m = td->td_lock; 509 KASSERT(m->mtx_lock != MTX_DESTROYED, 510 ("thread_lock() of destroyed mutex @ %s:%d", file, line)); 511 KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_spin, --- 341 unchanged lines hidden --- |