0002-kernel-Replace-LW-P-HOLD-RELE-to-use-refcount-APIs.patch

y0n3t4n1, 04/25/2011 12:15 PM

Download (5.79 KB)

View differences:

sys/kern/kern_exit.c
619 619
	 * Nobody actually wakes us when the lock
620 620
	 * count reaches zero, so just wait one tick.
621 621
	 */
622
	while (lp->lwp_lock > 0)
623
		tsleep(lp, 0, "lwpexit", 1);
622
	LWPLOCKWAIT(lp, "lwpexit", 1);
624 623

  
625 624
	/* Hand down resource usage to our proc */
626 625
	ruadd(&p->p_ru, &lp->lwp_ru);
......
690 689

  
691 690
	KKASSERT(lwkt_preempted_proc() != lp);
692 691

  
693
	while (lp->lwp_lock > 0)
694
		tsleep(lp, 0, "lwpwait1", 1);
692
	LWPLOCKWAIT(lp, "lwpwait1", 1);
695 693

  
696 694
	lwkt_wait_free(td);
697 695

  
......
867 865
			 * put a hold on the process for short periods of
868 866
			 * time.
869 867
			 */
870
			while (p->p_lock)
871
				tsleep(p, 0, "reap3", hz);
868
			PLOCKWAIT(p, "reap3", hz);
872 869

  
873 870
			/* Take care of our return values. */
874 871
			*res = p->p_pid;
......
898 895
			 * inconsistent state for processes running down
899 896
			 * the zombie list.
900 897
			 */
901
			KKASSERT(p->p_lock == 0);
898
			if (p->p_lock) {
899
				kprintf("%s: pid %d is still held (%x)\n",
900
					__func__, p->p_pid, p->p_lock);
901
			}
902 902
			proc_remove_zombie(p);
903 903
			leavepgrp(p);
904 904

  
sys/kern/kern_proc.c
638 638
proc_move_allproc_zombie(struct proc *p)
639 639
{
640 640
	lwkt_gettoken(&proc_token);
641
	while (p->p_lock) {
642
		tsleep(p, 0, "reap1", hz / 10);
643
	}
641
	PLOCKWAIT(p, "reap1", hz / 10);
644 642
	LIST_REMOVE(p, p_list);
645 643
	LIST_INSERT_HEAD(&zombproc, p, p_list);
646 644
	LIST_REMOVE(p, p_hash);
......
660 658
proc_remove_zombie(struct proc *p)
661 659
{
662 660
	lwkt_gettoken(&proc_token);
663
	while (p->p_lock) {
664
		tsleep(p, 0, "reap1", hz / 10);
665
	}
661
	PLOCKWAIT(p, "reap1", hz / 10);
666 662
	LIST_REMOVE(p, p_list); /* off zombproc */
667 663
	LIST_REMOVE(p, p_sibling);
668 664
	lwkt_reltoken(&proc_token);
sys/platform/pc32/i386/pmap.c
1020 1020
void
1021 1021
pmap_dispose_proc(struct proc *p)
1022 1022
{
1023
	KASSERT(p->p_lock == 0, ("attempt to dispose referenced proc! %p", p));
1023
	KASSERT(p->p_lock == 0,
1024
		("attempt to dispose referenced or waited for proc! %p", p));
1024 1025
}
1025 1026

  
1026 1027
/***************************************************
sys/platform/pc64/x86_64/pmap.c
1151 1151
void
1152 1152
pmap_dispose_proc(struct proc *p)
1153 1153
{
1154
	KASSERT(p->p_lock == 0, ("attempt to dispose referenced proc! %p", p));
1154
	KASSERT(p->p_lock == 0,
1155
		("attempt to dispose referenced or waited for proc! %p", p));
1155 1156
}
1156 1157

  
1157 1158
/***************************************************
sys/platform/vkernel/platform/pmap.c
888 888
void
889 889
pmap_dispose_proc(struct proc *p)
890 890
{
891
	KASSERT(p->p_lock == 0, ("attempt to dispose referenced proc! %p", p));
891
	KASSERT(p->p_lock == 0,
892
		("attempt to dispose referenced or waited for proc! %p", p));
892 893
}
893 894

  
894 895
/*
sys/platform/vkernel64/platform/pmap.c
905 905
void
906 906
pmap_dispose_proc(struct proc *p)
907 907
{
908
	KASSERT(p->p_lock == 0, ("attempt to dispose referenced proc! %p", p));
908
	KASSERT(p->p_lock == 0,
909
		("attempt to dispose referenced or waited for proc! %p", p));
909 910
}
910 911

  
911 912
/***************************************************
sys/sys/proc.h
56 56
#include <sys/rtprio.h>			/* For struct rtprio. */
57 57
#include <sys/signal.h>
58 58
#include <sys/lock.h>
59
#include <sys/refcount.h>
59 60
#ifndef _KERNEL
60 61
#include <sys/time.h>			/* For structs itimerval, timeval. */
61 62
#endif
......
444 445
 *
445 446
 * MPSAFE
446 447
 */
447
#define PHOLD(p)	atomic_add_int(&(p)->p_lock, 1)
448
#define PRELE(p)	atomic_add_int(&(p)->p_lock, -1)
448
#define PHOLD(p)	refcount_acquire(&(p)->p_lock)
449
#define PRELE(p)	refcount_release_wakeup(&(p)->p_lock)
450
#define PLOCKWAIT(p, wmesg, timo)	refcount_wait(&(p)->p_lock, wmesg)
449 451

  
450 452
/*
451 453
 * Hold lwp in memory, don't destruct, normally for ptrace/procfs work
452 454
 * atomic ops because they can occur from an IPI.
453 455
 * MPSAFE
454 456
 */
455
#define LWPHOLD(lp)	atomic_add_int(&(lp)->lwp_lock, 1)
456
#define LWPRELE(lp)	atomic_add_int(&(lp)->lwp_lock, -1)
457
#define LWPHOLD(lp)	refcount_acquire(&(lp)->lwp_lock)
458
#define LWPRELE(lp)	refcount_release_wakeup(&(lp)->lwp_lock)
459
#define LWPLOCKWAIT(lp, wmesg, timo)	refcount_wait(&(lp)->lwp_lock, wmesg)
457 460

  
458 461
#define	PIDHASH(pid)	(&pidhashtbl[(pid) & pidhash])
459 462
extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
460
-