10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6247Sraf * Common Development and Distribution License (the "License").
6*6247Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6247Sraf
22*6247Sraf /*
23*6247Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24*6247Sraf * Use is subject to license terms.
25*6247Sraf */
26*6247Sraf
270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.15 */
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/param.h>
340Sstevel@tonic-gate #include <sys/sysmacros.h>
350Sstevel@tonic-gate #include <sys/systm.h>
360Sstevel@tonic-gate #include <sys/errno.h>
370Sstevel@tonic-gate #include <sys/cred.h>
380Sstevel@tonic-gate #include <sys/proc.h>
390Sstevel@tonic-gate #include <sys/debug.h>
400Sstevel@tonic-gate #include <sys/class.h>
410Sstevel@tonic-gate #include <sys/mutex.h>
42*6247Sraf #include <sys/schedctl.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate * We support the nice system call for compatibility although
460Sstevel@tonic-gate * the priocntl system call supports a superset of nice's functionality.
470Sstevel@tonic-gate * We support nice only for time sharing threads. It will fail
480Sstevel@tonic-gate * if called by a thread from another class.
490Sstevel@tonic-gate */
500Sstevel@tonic-gate
510Sstevel@tonic-gate int
nice(int niceness)520Sstevel@tonic-gate nice(int niceness)
530Sstevel@tonic-gate {
540Sstevel@tonic-gate int error = 0;
550Sstevel@tonic-gate int err, retval;
56*6247Sraf kthread_t *t;
57*6247Sraf proc_t *p = curproc;
580Sstevel@tonic-gate
590Sstevel@tonic-gate mutex_enter(&p->p_lock);
600Sstevel@tonic-gate t = p->p_tlist;
610Sstevel@tonic-gate do {
620Sstevel@tonic-gate err = CL_DONICE(t, CRED(), niceness, &retval);
63*6247Sraf schedctl_set_cidpri(t);
640Sstevel@tonic-gate if (error == 0 && err)
650Sstevel@tonic-gate error = set_errno(err);
660Sstevel@tonic-gate } while ((t = t->t_forw) != p->p_tlist);
670Sstevel@tonic-gate mutex_exit(&p->p_lock);
680Sstevel@tonic-gate if (error)
690Sstevel@tonic-gate return (error);
700Sstevel@tonic-gate return (retval);
710Sstevel@tonic-gate }
72