subr_turnstile.c (136150) | subr_turnstile.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. --- 45 unchanged lines hidden (view full) --- 54 * if there are any other waiters. If it is the only thread blocked on the 55 * lock, then it reclaims the turnstile associated with the lock and removes 56 * it from the hash table. 57 */ 58 59#include "opt_turnstile_profiling.h" 60 61#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. --- 45 unchanged lines hidden (view full) --- 54 * if there are any other waiters. If it is the only thread blocked on the 55 * lock, then it reclaims the turnstile associated with the lock and removes 56 * it from the hash table. 57 */ 58 59#include "opt_turnstile_profiling.h" 60 61#include <sys/cdefs.h> |
62__FBSDID("$FreeBSD: head/sys/kern/subr_turnstile.c 136150 2004-10-05 18:00:30Z jhb $"); | 62__FBSDID("$FreeBSD: head/sys/kern/subr_turnstile.c 136445 2004-10-12 18:36:20Z jhb $"); |
63 64#include <sys/param.h> 65#include <sys/systm.h> 66#include <sys/kernel.h> 67#include <sys/ktr.h> 68#include <sys/lock.h> 69#include <sys/malloc.h> 70#include <sys/mutex.h> --- 321 unchanged lines hidden (view full) --- 392 393 MPASS(ts != NULL); 394 MPASS(TAILQ_EMPTY(&ts->ts_blocked)); 395 MPASS(TAILQ_EMPTY(&ts->ts_pending)); 396 free(ts, M_TURNSTILE); 397} 398 399/* | 63 64#include <sys/param.h> 65#include <sys/systm.h> 66#include <sys/kernel.h> 67#include <sys/ktr.h> 68#include <sys/lock.h> 69#include <sys/malloc.h> 70#include <sys/mutex.h> --- 321 unchanged lines hidden (view full) --- 392 393 MPASS(ts != NULL); 394 MPASS(TAILQ_EMPTY(&ts->ts_blocked)); 395 MPASS(TAILQ_EMPTY(&ts->ts_pending)); 396 free(ts, M_TURNSTILE); 397} 398 399/* |
400 * Lock the turnstile chain associated with the specified lock. 401 */ 402void 403turnstile_lock(struct lock_object *lock) 404{ 405 struct turnstile_chain *tc; 406 407 tc = TC_LOOKUP(lock); 408 mtx_lock_spin(&tc->tc_lock); 409} 410 411/* |
|
400 * Look up the turnstile for a lock in the hash table locking the associated | 412 * Look up the turnstile for a lock in the hash table locking the associated |
401 * turnstile chain along the way. Return with the turnstile chain locked. 402 * If no turnstile is found in the hash table, NULL is returned. | 413 * turnstile chain along the way. If no turnstile is found in the hash 414 * table, NULL is returned. |
403 */ 404struct turnstile * 405turnstile_lookup(struct lock_object *lock) 406{ 407 struct turnstile_chain *tc; 408 struct turnstile *ts; 409 410 tc = TC_LOOKUP(lock); | 415 */ 416struct turnstile * 417turnstile_lookup(struct lock_object *lock) 418{ 419 struct turnstile_chain *tc; 420 struct turnstile *ts; 421 422 tc = TC_LOOKUP(lock); |
411 mtx_lock_spin(&tc->tc_lock); | 423 mtx_assert(&tc->tc_lock, MA_OWNED); |
412 LIST_FOREACH(ts, &tc->tc_turnstiles, ts_hash) 413 if (ts->ts_lockobj == lock) 414 return (ts); 415 return (NULL); 416} 417 418/* 419 * Unlock the turnstile chain associated with a given lock. --- 7 unchanged lines hidden (view full) --- 427 mtx_unlock_spin(&tc->tc_lock); 428} 429 430/* 431 * Take ownership of a turnstile and adjust the priority of the new 432 * owner appropriately. 433 */ 434void | 424 LIST_FOREACH(ts, &tc->tc_turnstiles, ts_hash) 425 if (ts->ts_lockobj == lock) 426 return (ts); 427 return (NULL); 428} 429 430/* 431 * Unlock the turnstile chain associated with a given lock. --- 7 unchanged lines hidden (view full) --- 439 mtx_unlock_spin(&tc->tc_lock); 440} 441 442/* 443 * Take ownership of a turnstile and adjust the priority of the new 444 * owner appropriately. 445 */ 446void |
435turnstile_claim(struct turnstile *ts) | 447turnstile_claim(struct lock_object *lock) |
436{ 437 struct turnstile_chain *tc; | 448{ 449 struct turnstile_chain *tc; |
450 struct turnstile *ts; |
|
438 struct thread *td, *owner; 439 | 451 struct thread *td, *owner; 452 |
440 tc = TC_LOOKUP(ts->ts_lockobj); | 453 tc = TC_LOOKUP(lock); |
441 mtx_assert(&tc->tc_lock, MA_OWNED); | 454 mtx_assert(&tc->tc_lock, MA_OWNED); |
455 ts = turnstile_lookup(lock); 456 MPASS(ts != NULL); |
|
442 443 owner = curthread; 444 mtx_lock_spin(&td_contested_lock); 445 turnstile_setowner(ts, owner); 446 mtx_unlock_spin(&td_contested_lock); 447 448 td = TAILQ_FIRST(&ts->ts_blocked); 449 MPASS(td != NULL); --- 5 unchanged lines hidden (view full) --- 455 */ 456 mtx_lock_spin(&sched_lock); 457 if (td->td_priority < owner->td_priority) 458 owner->td_priority = td->td_priority; 459 mtx_unlock_spin(&sched_lock); 460} 461 462/* | 457 458 owner = curthread; 459 mtx_lock_spin(&td_contested_lock); 460 turnstile_setowner(ts, owner); 461 mtx_unlock_spin(&td_contested_lock); 462 463 td = TAILQ_FIRST(&ts->ts_blocked); 464 MPASS(td != NULL); --- 5 unchanged lines hidden (view full) --- 470 */ 471 mtx_lock_spin(&sched_lock); 472 if (td->td_priority < owner->td_priority) 473 owner->td_priority = td->td_priority; 474 mtx_unlock_spin(&sched_lock); 475} 476 477/* |
463 * Block the current thread on the turnstile ts. This function will context 464 * switch and not return until this thread has been woken back up. This 465 * function must be called with the appropriate turnstile chain locked and 466 * will return with it unlocked. | 478 * Block the current thread on the turnstile assicated with 'lock'. This 479 * function will context switch and not return until this thread has been 480 * woken back up. This function must be called with the appropriate 481 * turnstile chain locked and will return with it unlocked. |
467 */ 468void | 482 */ 483void |
469turnstile_wait(struct turnstile *ts, struct lock_object *lock, 470 struct thread *owner) | 484turnstile_wait(struct lock_object *lock, struct thread *owner) |
471{ 472 struct turnstile_chain *tc; | 485{ 486 struct turnstile_chain *tc; |
487 struct turnstile *ts; |
|
473 struct thread *td, *td1; 474 475 td = curthread; 476 tc = TC_LOOKUP(lock); 477 mtx_assert(&tc->tc_lock, MA_OWNED); 478 MPASS(td->td_turnstile != NULL); 479 MPASS(owner != NULL); 480 MPASS(owner->td_proc->p_magic == P_MAGIC); 481 | 488 struct thread *td, *td1; 489 490 td = curthread; 491 tc = TC_LOOKUP(lock); 492 mtx_assert(&tc->tc_lock, MA_OWNED); 493 MPASS(td->td_turnstile != NULL); 494 MPASS(owner != NULL); 495 MPASS(owner->td_proc->p_magic == P_MAGIC); 496 |
482 /* If the passed in turnstile is NULL, use this thread's turnstile. */ | 497 /* Look up the turnstile associated with the lock 'lock'. */ 498 ts = turnstile_lookup(lock); 499 500 /* 501 * If the lock does not already have a turnstile, use this thread's 502 * turnstile. Otherwise insert the current thread into the 503 * turnstile already in use by this lock. 504 */ |
483 if (ts == NULL) { 484#ifdef TURNSTILE_PROFILING 485 tc->tc_depth++; 486 if (tc->tc_depth > tc->tc_max_depth) { 487 tc->tc_max_depth = tc->tc_depth; 488 if (tc->tc_max_depth > turnstile_max_depth) 489 turnstile_max_depth = tc->tc_max_depth; 490 } --- 290 unchanged lines hidden --- | 505 if (ts == NULL) { 506#ifdef TURNSTILE_PROFILING 507 tc->tc_depth++; 508 if (tc->tc_depth > tc->tc_max_depth) { 509 tc->tc_max_depth = tc->tc_depth; 510 if (tc->tc_max_depth > turnstile_max_depth) 511 turnstile_max_depth = tc->tc_max_depth; 512 } --- 290 unchanged lines hidden --- |