Deleted Added
full compact
kern_rmlock.c (227588) kern_rmlock.c (228424)
1/*-
2 * Copyright (c) 2007 Stephan Uphoff <ups@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

27 * SUCH DAMAGE.
28 */
29
30/*
31 * Machine independent bits of reader/writer lock implementation.
32 */
33
34#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2007 Stephan Uphoff <ups@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

27 * SUCH DAMAGE.
28 */
29
30/*
31 * Machine independent bits of reader/writer lock implementation.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/kern/kern_rmlock.c 227588 2011-11-16 21:51:17Z pjd $");
35__FBSDID("$FreeBSD: head/sys/kern/kern_rmlock.c 228424 2011-12-11 21:02:01Z avg $");
36
37#include "opt_ddb.h"
38#include "opt_kdtrace.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42
43#include <sys/kernel.h>

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

339}
340
341int
342_rm_rlock(struct rmlock *rm, struct rm_priotracker *tracker, int trylock)
343{
344 struct thread *td = curthread;
345 struct pcpu *pc;
346
36
37#include "opt_ddb.h"
38#include "opt_kdtrace.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42
43#include <sys/kernel.h>

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

339}
340
341int
342_rm_rlock(struct rmlock *rm, struct rm_priotracker *tracker, int trylock)
343{
344 struct thread *td = curthread;
345 struct pcpu *pc;
346
347 if (SCHEDULER_STOPPED())
348 return (1);
349
347 tracker->rmp_flags = 0;
348 tracker->rmp_thread = td;
349 tracker->rmp_rmlock = rm;
350
351 td->td_critnest++; /* critical_enter(); */
352
353 compiler_memory_barrier();
354

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

408}
409
410void
411_rm_runlock(struct rmlock *rm, struct rm_priotracker *tracker)
412{
413 struct pcpu *pc;
414 struct thread *td = tracker->rmp_thread;
415
350 tracker->rmp_flags = 0;
351 tracker->rmp_thread = td;
352 tracker->rmp_rmlock = rm;
353
354 td->td_critnest++; /* critical_enter(); */
355
356 compiler_memory_barrier();
357

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

411}
412
413void
414_rm_runlock(struct rmlock *rm, struct rm_priotracker *tracker)
415{
416 struct pcpu *pc;
417 struct thread *td = tracker->rmp_thread;
418
419 if (SCHEDULER_STOPPED())
420 return;
421
416 td->td_critnest++; /* critical_enter(); */
417 pc = cpuid_to_pcpu[td->td_oncpu]; /* pcpu_find(td->td_oncpu); */
418 rm_tracker_remove(pc, tracker);
419 td->td_critnest--;
420 sched_unpin();
421
422 if (0 == (td->td_owepreempt | tracker->rmp_flags))
423 return;
424
425 _rm_unlock_hard(td, tracker);
426}
427
428void
429_rm_wlock(struct rmlock *rm)
430{
431 struct rm_priotracker *prio;
432 struct turnstile *ts;
433 cpuset_t readcpus;
434
422 td->td_critnest++; /* critical_enter(); */
423 pc = cpuid_to_pcpu[td->td_oncpu]; /* pcpu_find(td->td_oncpu); */
424 rm_tracker_remove(pc, tracker);
425 td->td_critnest--;
426 sched_unpin();
427
428 if (0 == (td->td_owepreempt | tracker->rmp_flags))
429 return;
430
431 _rm_unlock_hard(td, tracker);
432}
433
434void
435_rm_wlock(struct rmlock *rm)
436{
437 struct rm_priotracker *prio;
438 struct turnstile *ts;
439 cpuset_t readcpus;
440
441 if (SCHEDULER_STOPPED())
442 return;
443
435 if (rm->lock_object.lo_flags & RM_SLEEPABLE)
436 sx_xlock(&rm->rm_lock_sx);
437 else
438 mtx_lock(&rm->rm_lock_mtx);
439
440 if (CPU_CMP(&rm->rm_writecpus, &all_cpus)) {
441 /* Get all read tokens back */
442 readcpus = all_cpus;

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

481 mtx_unlock(&rm->rm_lock_mtx);
482}
483
484#ifdef LOCK_DEBUG
485
486void _rm_wlock_debug(struct rmlock *rm, const char *file, int line)
487{
488
444 if (rm->lock_object.lo_flags & RM_SLEEPABLE)
445 sx_xlock(&rm->rm_lock_sx);
446 else
447 mtx_lock(&rm->rm_lock_mtx);
448
449 if (CPU_CMP(&rm->rm_writecpus, &all_cpus)) {
450 /* Get all read tokens back */
451 readcpus = all_cpus;

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

490 mtx_unlock(&rm->rm_lock_mtx);
491}
492
493#ifdef LOCK_DEBUG
494
495void _rm_wlock_debug(struct rmlock *rm, const char *file, int line)
496{
497
498 if (SCHEDULER_STOPPED())
499 return;
500
489 WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE,
490 file, line, NULL);
491
492 _rm_wlock(rm);
493
494 LOCK_LOG_LOCK("RMWLOCK", &rm->lock_object, 0, 0, file, line);
495
496 if (rm->lock_object.lo_flags & RM_SLEEPABLE)

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

502 curthread->td_locks++;
503
504}
505
506void
507_rm_wunlock_debug(struct rmlock *rm, const char *file, int line)
508{
509
501 WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE,
502 file, line, NULL);
503
504 _rm_wlock(rm);
505
506 LOCK_LOG_LOCK("RMWLOCK", &rm->lock_object, 0, 0, file, line);
507
508 if (rm->lock_object.lo_flags & RM_SLEEPABLE)

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

514 curthread->td_locks++;
515
516}
517
518void
519_rm_wunlock_debug(struct rmlock *rm, const char *file, int line)
520{
521
522 if (SCHEDULER_STOPPED())
523 return;
524
510 curthread->td_locks--;
511 if (rm->lock_object.lo_flags & RM_SLEEPABLE)
512 WITNESS_UNLOCK(&rm->rm_lock_sx.lock_object, LOP_EXCLUSIVE,
513 file, line);
514 else
515 WITNESS_UNLOCK(&rm->lock_object, LOP_EXCLUSIVE, file, line);
516 LOCK_LOG_LOCK("RMWUNLOCK", &rm->lock_object, 0, 0, file, line);
517 _rm_wunlock(rm);
518}
519
520int
521_rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
522 int trylock, const char *file, int line)
523{
525 curthread->td_locks--;
526 if (rm->lock_object.lo_flags & RM_SLEEPABLE)
527 WITNESS_UNLOCK(&rm->rm_lock_sx.lock_object, LOP_EXCLUSIVE,
528 file, line);
529 else
530 WITNESS_UNLOCK(&rm->lock_object, LOP_EXCLUSIVE, file, line);
531 LOCK_LOG_LOCK("RMWUNLOCK", &rm->lock_object, 0, 0, file, line);
532 _rm_wunlock(rm);
533}
534
535int
536_rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
537 int trylock, const char *file, int line)
538{
539
540 if (SCHEDULER_STOPPED())
541 return (1);
542
524 if (!trylock && (rm->lock_object.lo_flags & RM_SLEEPABLE))
525 WITNESS_CHECKORDER(&rm->rm_lock_sx.lock_object, LOP_NEWORDER,
526 file, line, NULL);
527 WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER, file, line, NULL);
528
529 if (_rm_rlock(rm, tracker, trylock)) {
530 LOCK_LOG_LOCK("RMRLOCK", &rm->lock_object, 0, 0, file, line);
531

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

539 return (0);
540}
541
542void
543_rm_runlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
544 const char *file, int line)
545{
546
543 if (!trylock && (rm->lock_object.lo_flags & RM_SLEEPABLE))
544 WITNESS_CHECKORDER(&rm->rm_lock_sx.lock_object, LOP_NEWORDER,
545 file, line, NULL);
546 WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER, file, line, NULL);
547
548 if (_rm_rlock(rm, tracker, trylock)) {
549 LOCK_LOG_LOCK("RMRLOCK", &rm->lock_object, 0, 0, file, line);
550

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

558 return (0);
559}
560
561void
562_rm_runlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
563 const char *file, int line)
564{
565
566 if (SCHEDULER_STOPPED())
567 return;
568
547 curthread->td_locks--;
548 WITNESS_UNLOCK(&rm->lock_object, 0, file, line);
549 LOCK_LOG_LOCK("RMRUNLOCK", &rm->lock_object, 0, 0, file, line);
550 _rm_runlock(rm, tracker);
551}
552
553#else
554

--- 35 unchanged lines hidden ---
569 curthread->td_locks--;
570 WITNESS_UNLOCK(&rm->lock_object, 0, file, line);
571 LOCK_LOG_LOCK("RMRUNLOCK", &rm->lock_object, 0, 0, file, line);
572 _rm_runlock(rm, tracker);
573}
574
575#else
576

--- 35 unchanged lines hidden ---