Deleted Added
full compact
kern_mutex.c (174005) kern_mutex.c (174629)
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 174005 2007-11-28 05:50:45Z attilio $");
37__FBSDID("$FreeBSD: head/sys/kern/kern_mutex.c 174629 2007-12-15 23:13:31Z 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>

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

118};
119
120/*
121 * System-wide mutexes
122 */
123struct mtx blocked_lock;
124struct mtx Giant;
125
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>

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

118};
119
120/*
121 * System-wide mutexes
122 */
123struct mtx blocked_lock;
124struct mtx Giant;
125
126#ifdef LOCK_PROFILING
127static inline void lock_profile_init(void)
128{
129 int i;
130 /* Initialize the mutex profiling locks */
131 for (i = 0; i < LPROF_LOCK_SIZE; i++) {
132 mtx_init(&lprof_locks[i], "mprof lock",
133 NULL, MTX_SPIN|MTX_QUIET|MTX_NOPROFILE);
134 }
135}
136#else
137static inline void lock_profile_init(void) {;}
138#endif
139
140void
141assert_mtx(struct lock_object *lock, int what)
142{
143
144 mtx_assert((struct mtx *)lock, what);
145}
146
147void

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

420#ifdef KTR
421 if (cont_logged) {
422 CTR4(KTR_CONTENTION,
423 "contention end: %s acquired by %p at %s:%d",
424 m->lock_object.lo_name, (void *)tid, file, line);
425 }
426#endif
427 lock_profile_obtain_lock_success(&m->lock_object, contested,
126void
127assert_mtx(struct lock_object *lock, int what)
128{
129
130 mtx_assert((struct mtx *)lock, what);
131}
132
133void

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

406#ifdef KTR
407 if (cont_logged) {
408 CTR4(KTR_CONTENTION,
409 "contention end: %s acquired by %p at %s:%d",
410 m->lock_object.lo_name, (void *)tid, file, line);
411 }
412#endif
413 lock_profile_obtain_lock_success(&m->lock_object, contested,
428 waittime, (file), (line));
414 waittime, file, line);
429}
430
431static void
432_mtx_lock_spin_failed(struct mtx *m)
433{
434 struct thread *td;
435
436 td = mtx_owner(m);

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

509 m = td->td_lock;
510 WITNESS_CHECKORDER(&m->lock_object,
511 opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line);
512 while (!_obtain_lock(m, tid)) {
513 if (m->mtx_lock == tid) {
514 m->mtx_recurse++;
515 break;
516 }
415}
416
417static void
418_mtx_lock_spin_failed(struct mtx *m)
419{
420 struct thread *td;
421
422 td = mtx_owner(m);

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

495 m = td->td_lock;
496 WITNESS_CHECKORDER(&m->lock_object,
497 opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line);
498 while (!_obtain_lock(m, tid)) {
499 if (m->mtx_lock == tid) {
500 m->mtx_recurse++;
501 break;
502 }
517 lock_profile_obtain_lock_failed(&m->lock_object, &contested, &waittime);
503 lock_profile_obtain_lock_failed(&m->lock_object,
504 &contested, &waittime);
518 /* Give interrupts a chance while we spin. */
519 spinlock_exit();
520 while (m->mtx_lock != MTX_UNOWNED) {
521 if (i++ < 10000000)
522 cpu_spinwait();
523 else if (i < 60000000 ||
524 kdb_active || panicstr != NULL)
525 DELAY(1);

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

530 goto retry;
531 }
532 spinlock_enter();
533 }
534 if (m == td->td_lock)
535 break;
536 _rel_spin_lock(m); /* does spinlock_exit() */
537 }
505 /* Give interrupts a chance while we spin. */
506 spinlock_exit();
507 while (m->mtx_lock != MTX_UNOWNED) {
508 if (i++ < 10000000)
509 cpu_spinwait();
510 else if (i < 60000000 ||
511 kdb_active || panicstr != NULL)
512 DELAY(1);

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

517 goto retry;
518 }
519 spinlock_enter();
520 }
521 if (m == td->td_lock)
522 break;
523 _rel_spin_lock(m); /* does spinlock_exit() */
524 }
538 lock_profile_obtain_lock_success(&m->lock_object, contested,
539 waittime, (file), (line));
525 if (m->mtx_recurse == 0)
526 lock_profile_obtain_lock_success(&m->lock_object, contested,
527 waittime, (file), (line));
540 WITNESS_LOCK(&m->lock_object, opts | LOP_EXCLUSIVE, file, line);
541}
542
543struct mtx *
544thread_lock_block(struct thread *td)
545{
546 struct mtx *lock;
547

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

789 */
790 mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE);
791 mtx_init(&blocked_lock, "blocked lock", NULL, MTX_SPIN);
792 blocked_lock.mtx_lock = 0xdeadc0de; /* Always blocked. */
793 mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
794 mtx_init(&proc0.p_slock, "process slock", NULL, MTX_SPIN | MTX_RECURSE);
795 mtx_init(&devmtx, "cdev", NULL, MTX_DEF);
796 mtx_lock(&Giant);
528 WITNESS_LOCK(&m->lock_object, opts | LOP_EXCLUSIVE, file, line);
529}
530
531struct mtx *
532thread_lock_block(struct thread *td)
533{
534 struct mtx *lock;
535

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

777 */
778 mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE);
779 mtx_init(&blocked_lock, "blocked lock", NULL, MTX_SPIN);
780 blocked_lock.mtx_lock = 0xdeadc0de; /* Always blocked. */
781 mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
782 mtx_init(&proc0.p_slock, "process slock", NULL, MTX_SPIN | MTX_RECURSE);
783 mtx_init(&devmtx, "cdev", NULL, MTX_DEF);
784 mtx_lock(&Giant);
797
798 lock_profile_init();
799}
800
801#ifdef DDB
802void
803db_show_mtx(struct lock_object *lock)
804{
805 struct thread *td;
806 struct mtx *m;

--- 35 unchanged lines hidden ---
785}
786
787#ifdef DDB
788void
789db_show_mtx(struct lock_object *lock)
790{
791 struct thread *td;
792 struct mtx *m;

--- 35 unchanged lines hidden ---