Print this page
OS-7753 THREAD_KPRI_RELEASE does nothing of the sort
Reviewed by: Bryan Cantrill <bryan@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.

  24  */
  25 
  26 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  27 /*        All Rights Reserved   */
  28 
  29 #include <sys/types.h>
  30 #include <sys/param.h>
  31 #include <sys/sysmacros.h>
  32 #include <sys/proc.h>
  33 #include <sys/kmem.h>
  34 #include <sys/tuneable.h>
  35 #include <sys/var.h>
  36 #include <sys/cred.h>
  37 #include <sys/systm.h>
  38 #include <sys/prsystm.h>
  39 #include <sys/vnode.h>
  40 #include <sys/session.h>
  41 #include <sys/cpuvar.h>
  42 #include <sys/cmn_err.h>
  43 #include <sys/bitmap.h>


 400  *
 401  * Returns 0 on success.
 402  * Returns 1 if P_PR_LOCK is set.
 403  * Returns -1 if proc is in invalid state.
 404  */
 405 int
 406 sprtrylock_proc(proc_t *p)
 407 {
 408         ASSERT(MUTEX_HELD(&p->p_lock));
 409 
 410         /* skip system and incomplete processes */
 411         if (p->p_stat == SIDL || p->p_stat == SZOMB ||
 412             (p->p_flag & (SSYS | SEXITING | SEXITLWPS))) {
 413                 return (-1);
 414         }
 415 
 416         if (p->p_proc_flag & P_PR_LOCK)
 417                 return (1);
 418 
 419         p->p_proc_flag |= P_PR_LOCK;
 420         THREAD_KPRI_REQUEST();
 421 
 422         return (0);
 423 }
 424 
 425 /*
 426  * Wait for P_PR_LOCK to become clear.  Returns with p_lock dropped,
 427  * and the proc pointer no longer valid, as the proc may have exited.
 428  */
 429 void
 430 sprwaitlock_proc(proc_t *p)
 431 {
 432         kmutex_t *mp;
 433 
 434         ASSERT(MUTEX_HELD(&p->p_lock));
 435         ASSERT(p->p_proc_flag & P_PR_LOCK);
 436 
 437         /*
 438          * p_lock is persistent, but p itself is not -- it could
 439          * vanish during cv_wait().  Load p->p_lock now so we can
 440          * drop it after cv_wait() without referencing p.


 485 {
 486         zoneid_t zoneid;
 487 
 488         if (INGLOBALZONE(curproc))
 489                 zoneid = ALL_ZONES;
 490         else
 491                 zoneid = getzoneid();
 492         return (sprlock_zone(pid, zoneid));
 493 }
 494 
 495 void
 496 sprlock_proc(proc_t *p)
 497 {
 498         ASSERT(MUTEX_HELD(&p->p_lock));
 499 
 500         while (p->p_proc_flag & P_PR_LOCK) {
 501                 cv_wait(&pr_pid_cv[p->p_slot], &p->p_lock);
 502         }
 503 
 504         p->p_proc_flag |= P_PR_LOCK;
 505         THREAD_KPRI_REQUEST();
 506 }
 507 
 508 void
 509 sprunlock(proc_t *p)
 510 {
 511         if (panicstr) {
 512                 mutex_exit(&p->p_lock);
 513                 return;
 514         }
 515 
 516         ASSERT(p->p_proc_flag & P_PR_LOCK);
 517         ASSERT(MUTEX_HELD(&p->p_lock));
 518 
 519         cv_signal(&pr_pid_cv[p->p_slot]);
 520         p->p_proc_flag &= ~P_PR_LOCK;
 521         mutex_exit(&p->p_lock);
 522         THREAD_KPRI_RELEASE();
 523 }
 524 
 525 void
 526 pid_init(void)
 527 {
 528         int i;
 529 
 530         pid_hashsz = 1 << highbit(v.v_proc / pid_hashlen);
 531 
 532         pidhash = kmem_zalloc(sizeof (struct pid *) * pid_hashsz, KM_SLEEP);
 533         procdir = kmem_alloc(sizeof (union procent) * v.v_proc, KM_SLEEP);
 534         pr_pid_cv = kmem_zalloc(sizeof (kcondvar_t) * v.v_proc, KM_SLEEP);
 535         proc_lock = kmem_zalloc(sizeof (struct plock) * v.v_proc, KM_SLEEP);
 536 
 537         nproc = 1;
 538         practive = proc_sched;
 539         proc_sched->p_next = NULL;
 540         procdir[0].pe_proc = proc_sched;
 541 
 542         procentfree = &procdir[1];




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2019 Joyent, Inc.
  25  */
  26 
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  28 /*        All Rights Reserved   */
  29 
  30 #include <sys/types.h>
  31 #include <sys/param.h>
  32 #include <sys/sysmacros.h>
  33 #include <sys/proc.h>
  34 #include <sys/kmem.h>
  35 #include <sys/tuneable.h>
  36 #include <sys/var.h>
  37 #include <sys/cred.h>
  38 #include <sys/systm.h>
  39 #include <sys/prsystm.h>
  40 #include <sys/vnode.h>
  41 #include <sys/session.h>
  42 #include <sys/cpuvar.h>
  43 #include <sys/cmn_err.h>
  44 #include <sys/bitmap.h>


 401  *
 402  * Returns 0 on success.
 403  * Returns 1 if P_PR_LOCK is set.
 404  * Returns -1 if proc is in invalid state.
 405  */
 406 int
 407 sprtrylock_proc(proc_t *p)
 408 {
 409         ASSERT(MUTEX_HELD(&p->p_lock));
 410 
 411         /* skip system and incomplete processes */
 412         if (p->p_stat == SIDL || p->p_stat == SZOMB ||
 413             (p->p_flag & (SSYS | SEXITING | SEXITLWPS))) {
 414                 return (-1);
 415         }
 416 
 417         if (p->p_proc_flag & P_PR_LOCK)
 418                 return (1);
 419 
 420         p->p_proc_flag |= P_PR_LOCK;

 421 
 422         return (0);
 423 }
 424 
 425 /*
 426  * Wait for P_PR_LOCK to become clear.  Returns with p_lock dropped,
 427  * and the proc pointer no longer valid, as the proc may have exited.
 428  */
 429 void
 430 sprwaitlock_proc(proc_t *p)
 431 {
 432         kmutex_t *mp;
 433 
 434         ASSERT(MUTEX_HELD(&p->p_lock));
 435         ASSERT(p->p_proc_flag & P_PR_LOCK);
 436 
 437         /*
 438          * p_lock is persistent, but p itself is not -- it could
 439          * vanish during cv_wait().  Load p->p_lock now so we can
 440          * drop it after cv_wait() without referencing p.


 485 {
 486         zoneid_t zoneid;
 487 
 488         if (INGLOBALZONE(curproc))
 489                 zoneid = ALL_ZONES;
 490         else
 491                 zoneid = getzoneid();
 492         return (sprlock_zone(pid, zoneid));
 493 }
 494 
 495 void
 496 sprlock_proc(proc_t *p)
 497 {
 498         ASSERT(MUTEX_HELD(&p->p_lock));
 499 
 500         while (p->p_proc_flag & P_PR_LOCK) {
 501                 cv_wait(&pr_pid_cv[p->p_slot], &p->p_lock);
 502         }
 503 
 504         p->p_proc_flag |= P_PR_LOCK;

 505 }
 506 
 507 void
 508 sprunlock(proc_t *p)
 509 {
 510         if (panicstr) {
 511                 mutex_exit(&p->p_lock);
 512                 return;
 513         }
 514 
 515         ASSERT(p->p_proc_flag & P_PR_LOCK);
 516         ASSERT(MUTEX_HELD(&p->p_lock));
 517 
 518         cv_signal(&pr_pid_cv[p->p_slot]);
 519         p->p_proc_flag &= ~P_PR_LOCK;
 520         mutex_exit(&p->p_lock);

 521 }
 522 
 523 void
 524 pid_init(void)
 525 {
 526         int i;
 527 
 528         pid_hashsz = 1 << highbit(v.v_proc / pid_hashlen);
 529 
 530         pidhash = kmem_zalloc(sizeof (struct pid *) * pid_hashsz, KM_SLEEP);
 531         procdir = kmem_alloc(sizeof (union procent) * v.v_proc, KM_SLEEP);
 532         pr_pid_cv = kmem_zalloc(sizeof (kcondvar_t) * v.v_proc, KM_SLEEP);
 533         proc_lock = kmem_zalloc(sizeof (struct plock) * v.v_proc, KM_SLEEP);
 534 
 535         nproc = 1;
 536         practive = proc_sched;
 537         proc_sched->p_next = NULL;
 538         procdir[0].pe_proc = proc_sched;
 539 
 540         procentfree = &procdir[1];