Deleted Added
full compact
kern_mutex.c (136437) kern_mutex.c (136445)
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 136437 2004-10-12 16:28:18Z ups $");
37__FBSDID("$FreeBSD: head/sys/kern/kern_mutex.c 136445 2004-10-12 18:36:20Z jhb $");
38
39#include "opt_adaptive_mutexes.h"
40#include "opt_ddb.h"
41#include "opt_mprof.h"
42#include "opt_mutex_wake_all.h"
43#include "opt_sched.h"
44
45#include <sys/param.h>

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

435 *
436 * We call this if the lock is either contested (i.e. we need to go to
437 * sleep waiting for it), or if we need to recurse on it.
438 */
439void
440_mtx_lock_sleep(struct mtx *m, struct thread *td, int opts, const char *file,
441 int line)
442{
38
39#include "opt_adaptive_mutexes.h"
40#include "opt_ddb.h"
41#include "opt_mprof.h"
42#include "opt_mutex_wake_all.h"
43#include "opt_sched.h"
44
45#include <sys/param.h>

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

435 *
436 * We call this if the lock is either contested (i.e. we need to go to
437 * sleep waiting for it), or if we need to recurse on it.
438 */
439void
440_mtx_lock_sleep(struct mtx *m, struct thread *td, int opts, const char *file,
441 int line)
442{
443 struct turnstile *ts;
444#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
445 struct thread *owner;
446#endif
447 uintptr_t v;
448#ifdef KTR
449 int cont_logged = 0;
450#endif
451#ifdef MUTEX_PROFILING

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

471#ifdef MUTEX_PROFILING
472 contested = 0;
473#endif
474 while (!_obtain_lock(m, td)) {
475#ifdef MUTEX_PROFILING
476 contested = 1;
477 atomic_add_int(&m->mtx_contest_holding, 1);
478#endif
443#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
444 struct thread *owner;
445#endif
446 uintptr_t v;
447#ifdef KTR
448 int cont_logged = 0;
449#endif
450#ifdef MUTEX_PROFILING

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

470#ifdef MUTEX_PROFILING
471 contested = 0;
472#endif
473 while (!_obtain_lock(m, td)) {
474#ifdef MUTEX_PROFILING
475 contested = 1;
476 atomic_add_int(&m->mtx_contest_holding, 1);
477#endif
479 ts = turnstile_lookup(&m->mtx_object);
478 turnstile_lock(&m->mtx_object);
480 v = m->mtx_lock;
481
482 /*
483 * Check if the lock has been released while spinning for
484 * the turnstile chain lock.
485 */
486 if (v == MTX_UNOWNED) {
487 turnstile_release(&m->mtx_object);

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

494#else
495 /*
496 * The mutex was marked contested on release. This means that
497 * there are other threads blocked on it. Grab ownership of
498 * it and propagate its priority to the current thread if
499 * necessary.
500 */
501 if (v == MTX_CONTESTED) {
479 v = m->mtx_lock;
480
481 /*
482 * Check if the lock has been released while spinning for
483 * the turnstile chain lock.
484 */
485 if (v == MTX_UNOWNED) {
486 turnstile_release(&m->mtx_object);

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

493#else
494 /*
495 * The mutex was marked contested on release. This means that
496 * there are other threads blocked on it. Grab ownership of
497 * it and propagate its priority to the current thread if
498 * necessary.
499 */
500 if (v == MTX_CONTESTED) {
502 MPASS(ts != NULL);
503 m->mtx_lock = (uintptr_t)td | MTX_CONTESTED;
501 m->mtx_lock = (uintptr_t)td | MTX_CONTESTED;
504 turnstile_claim(ts);
502 turnstile_claim(&m->mtx_object);
505 break;
506 }
507#endif
508
509 /*
510 * If the mutex isn't already contested and a failure occurs
511 * setting the contested bit, the mutex was either released
512 * or the state of the MTX_RECURSED bit changed.

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

552 WITNESS_LINE(&m->mtx_object));
553 cont_logged = 1;
554 }
555#endif
556
557 /*
558 * Block on the turnstile.
559 */
503 break;
504 }
505#endif
506
507 /*
508 * If the mutex isn't already contested and a failure occurs
509 * setting the contested bit, the mutex was either released
510 * or the state of the MTX_RECURSED bit changed.

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

550 WITNESS_LINE(&m->mtx_object));
551 cont_logged = 1;
552 }
553#endif
554
555 /*
556 * Block on the turnstile.
557 */
560 turnstile_wait(ts, &m->mtx_object, mtx_owner(m));
558 turnstile_wait(&m->mtx_object, mtx_owner(m));
561 }
562
563#ifdef KTR
564 if (cont_logged) {
565 CTR4(KTR_CONTENTION,
566 "contention end: %s acquired by %p at %s:%d",
567 m->mtx_object.lo_name, td, file, line);
568 }

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

640 if (mtx_recursed(m)) {
641 if (--(m->mtx_recurse) == 0)
642 atomic_clear_ptr(&m->mtx_lock, MTX_RECURSED);
643 if (LOCK_LOG_TEST(&m->mtx_object, opts))
644 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p unrecurse", m);
645 return;
646 }
647
559 }
560
561#ifdef KTR
562 if (cont_logged) {
563 CTR4(KTR_CONTENTION,
564 "contention end: %s acquired by %p at %s:%d",
565 m->mtx_object.lo_name, td, file, line);
566 }

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

638 if (mtx_recursed(m)) {
639 if (--(m->mtx_recurse) == 0)
640 atomic_clear_ptr(&m->mtx_lock, MTX_RECURSED);
641 if (LOCK_LOG_TEST(&m->mtx_object, opts))
642 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p unrecurse", m);
643 return;
644 }
645
646 turnstile_lock(&m->mtx_object);
648 ts = turnstile_lookup(&m->mtx_object);
649 if (LOCK_LOG_TEST(&m->mtx_object, opts))
650 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m);
651
652#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
653 if (ts == NULL) {
654 _release_lock_quick(m);
655 if (LOCK_LOG_TEST(&m->mtx_object, opts))

--- 253 unchanged lines hidden ---
647 ts = turnstile_lookup(&m->mtx_object);
648 if (LOCK_LOG_TEST(&m->mtx_object, opts))
649 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m);
650
651#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
652 if (ts == NULL) {
653 _release_lock_quick(m);
654 if (LOCK_LOG_TEST(&m->mtx_object, opts))

--- 253 unchanged lines hidden ---