17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*d4204c85Sraf * Common Development and Distribution License (the "License").
6*d4204c85Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*d4204c85Sraf
22*d4204c85Sraf /*
23*d4204c85Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24*d4204c85Sraf * Use is subject to license terms.
25*d4204c85Sraf */
26*d4204c85Sraf
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.15 */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/param.h>
347c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
357c478bd9Sstevel@tonic-gate #include <sys/systm.h>
367c478bd9Sstevel@tonic-gate #include <sys/errno.h>
377c478bd9Sstevel@tonic-gate #include <sys/cred.h>
387c478bd9Sstevel@tonic-gate #include <sys/proc.h>
397c478bd9Sstevel@tonic-gate #include <sys/debug.h>
407c478bd9Sstevel@tonic-gate #include <sys/class.h>
417c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
42*d4204c85Sraf #include <sys/schedctl.h>
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate * We support the nice system call for compatibility although
467c478bd9Sstevel@tonic-gate * the priocntl system call supports a superset of nice's functionality.
477c478bd9Sstevel@tonic-gate * We support nice only for time sharing threads. It will fail
487c478bd9Sstevel@tonic-gate * if called by a thread from another class.
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate int
nice(int niceness)527c478bd9Sstevel@tonic-gate nice(int niceness)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate int error = 0;
557c478bd9Sstevel@tonic-gate int err, retval;
56*d4204c85Sraf kthread_t *t;
577c478bd9Sstevel@tonic-gate proc_t *p = curproc;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock);
607c478bd9Sstevel@tonic-gate t = p->p_tlist;
617c478bd9Sstevel@tonic-gate do {
627c478bd9Sstevel@tonic-gate err = CL_DONICE(t, CRED(), niceness, &retval);
63*d4204c85Sraf schedctl_set_cidpri(t);
647c478bd9Sstevel@tonic-gate if (error == 0 && err)
657c478bd9Sstevel@tonic-gate error = set_errno(err);
667c478bd9Sstevel@tonic-gate } while ((t = t->t_forw) != p->p_tlist);
677c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock);
687c478bd9Sstevel@tonic-gate if (error)
697c478bd9Sstevel@tonic-gate return (error);
707c478bd9Sstevel@tonic-gate return (retval);
717c478bd9Sstevel@tonic-gate }
72