Deleted Added
full compact
kern_mutex.c (167787) kern_mutex.c (167801)
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 167787 2007-03-21 21:20:51Z jhb $");
37__FBSDID("$FreeBSD: head/sys/kern/kern_mutex.c 167801 2007-03-22 16:09:23Z jhb $");
38
39#include "opt_adaptive_mutexes.h"
40#include "opt_ddb.h"
41#include "opt_global.h"
42#include "opt_mutex_wake_all.h"
43#include "opt_sched.h"
44
45#include <sys/param.h>

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

76 * Force MUTEX_WAKE_ALL for now.
77 * single thread wakeup needs fixes to avoid race conditions with
78 * priority inheritance.
79 */
80#ifndef MUTEX_WAKE_ALL
81#define MUTEX_WAKE_ALL
82#endif
83
38
39#include "opt_adaptive_mutexes.h"
40#include "opt_ddb.h"
41#include "opt_global.h"
42#include "opt_mutex_wake_all.h"
43#include "opt_sched.h"
44
45#include <sys/param.h>

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

76 * Force MUTEX_WAKE_ALL for now.
77 * single thread wakeup needs fixes to avoid race conditions with
78 * priority inheritance.
79 */
80#ifndef MUTEX_WAKE_ALL
81#define MUTEX_WAKE_ALL
82#endif
83
84#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
85#define ADAPTIVE_MUTEXES
86#endif
87
84/*
85 * Internal utility macros.
86 */
87#define mtx_unowned(m) ((m)->mtx_lock == MTX_UNOWNED)
88
89#define mtx_owner(m) ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK))
90
91#ifdef DDB

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

294 *
295 * We call this if the lock is either contested (i.e. we need to go to
296 * sleep waiting for it), or if we need to recurse on it.
297 */
298void
299_mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts, const char *file,
300 int line)
301{
88/*
89 * Internal utility macros.
90 */
91#define mtx_unowned(m) ((m)->mtx_lock == MTX_UNOWNED)
92
93#define mtx_owner(m) ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK))
94
95#ifdef DDB

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

298 *
299 * We call this if the lock is either contested (i.e. we need to go to
300 * sleep waiting for it), or if we need to recurse on it.
301 */
302void
303_mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts, const char *file,
304 int line)
305{
302#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
306#ifdef ADAPTIVE_MUTEXES
303 volatile struct thread *owner;
304#endif
305#ifdef KTR
306 int cont_logged = 0;
307#endif
308 uintptr_t v;
309
310 if (mtx_owned(m)) {

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

360 */
361 if ((v & MTX_CONTESTED) == 0 &&
362 !atomic_cmpset_ptr(&m->mtx_lock, v, v | MTX_CONTESTED)) {
363 turnstile_release(&m->lock_object);
364 cpu_spinwait();
365 continue;
366 }
367
307 volatile struct thread *owner;
308#endif
309#ifdef KTR
310 int cont_logged = 0;
311#endif
312 uintptr_t v;
313
314 if (mtx_owned(m)) {

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

364 */
365 if ((v & MTX_CONTESTED) == 0 &&
366 !atomic_cmpset_ptr(&m->mtx_lock, v, v | MTX_CONTESTED)) {
367 turnstile_release(&m->lock_object);
368 cpu_spinwait();
369 continue;
370 }
371
368#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
372#ifdef ADAPTIVE_MUTEXES
369 /*
370 * If the current owner of the lock is executing on another
371 * CPU, spin instead of blocking.
372 */
373 owner = (struct thread *)(v & ~MTX_FLAGMASK);
374#ifdef ADAPTIVE_GIANT
375 if (TD_IS_RUNNING(owner))
376#else
377 if (m != &Giant && TD_IS_RUNNING(owner))
378#endif
379 {
380 turnstile_release(&m->lock_object);
381 while (mtx_owner(m) == owner && TD_IS_RUNNING(owner)) {
382 cpu_spinwait();
383 }
384 continue;
385 }
373 /*
374 * If the current owner of the lock is executing on another
375 * CPU, spin instead of blocking.
376 */
377 owner = (struct thread *)(v & ~MTX_FLAGMASK);
378#ifdef ADAPTIVE_GIANT
379 if (TD_IS_RUNNING(owner))
380#else
381 if (m != &Giant && TD_IS_RUNNING(owner))
382#endif
383 {
384 turnstile_release(&m->lock_object);
385 while (mtx_owner(m) == owner && TD_IS_RUNNING(owner)) {
386 cpu_spinwait();
387 }
388 continue;
389 }
386#endif /* SMP && !NO_ADAPTIVE_MUTEXES */
390#endif /* ADAPTIVE_MUTEXES */
387
388 /*
389 * We definitely must sleep for this lock.
390 */
391 mtx_assert(m, MA_NOTOWNED);
392
393#ifdef KTR
394 if (!cont_logged) {

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

493 return;
494 }
495
496 turnstile_lock(&m->lock_object);
497 ts = turnstile_lookup(&m->lock_object);
498 if (LOCK_LOG_TEST(&m->lock_object, opts))
499 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m);
500
391
392 /*
393 * We definitely must sleep for this lock.
394 */
395 mtx_assert(m, MA_NOTOWNED);
396
397#ifdef KTR
398 if (!cont_logged) {

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

497 return;
498 }
499
500 turnstile_lock(&m->lock_object);
501 ts = turnstile_lookup(&m->lock_object);
502 if (LOCK_LOG_TEST(&m->lock_object, opts))
503 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m);
504
501#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
505#ifdef ADAPTIVE_MUTEXES
502 if (ts == NULL) {
503 _release_lock_quick(m);
504 if (LOCK_LOG_TEST(&m->lock_object, opts))
505 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p no sleepers", m);
506 turnstile_release(&m->lock_object);
507 return;
508 }
509#else

--- 288 unchanged lines hidden ---
506 if (ts == NULL) {
507 _release_lock_quick(m);
508 if (LOCK_LOG_TEST(&m->lock_object, opts))
509 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p no sleepers", m);
510 turnstile_release(&m->lock_object);
511 return;
512 }
513#else

--- 288 unchanged lines hidden ---