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 #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/param.h>
327c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
337c478bd9Sstevel@tonic-gate #include <sys/systm.h>
347c478bd9Sstevel@tonic-gate #include <sys/errno.h>
357c478bd9Sstevel@tonic-gate #include <sys/cred.h>
367c478bd9Sstevel@tonic-gate #include <sys/proc.h>
377c478bd9Sstevel@tonic-gate #include <sys/debug.h>
387c478bd9Sstevel@tonic-gate #include <sys/class.h>
397c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
40*d4204c85Sraf #include <sys/schedctl.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * We support the nice system call for compatibility although
447c478bd9Sstevel@tonic-gate * the priocntl system call supports a superset of nice's functionality.
457c478bd9Sstevel@tonic-gate * We support nice only for time sharing threads. It will fail
467c478bd9Sstevel@tonic-gate * if called by a thread from another class.
477c478bd9Sstevel@tonic-gate */
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate int
nice(int niceness)507c478bd9Sstevel@tonic-gate nice(int niceness)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate int error = 0;
537c478bd9Sstevel@tonic-gate int err, retval;
54*d4204c85Sraf kthread_t *t;
55*d4204c85Sraf proc_t *p = curproc;
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock);
587c478bd9Sstevel@tonic-gate t = p->p_tlist;
597c478bd9Sstevel@tonic-gate do {
607c478bd9Sstevel@tonic-gate err = CL_DONICE(t, CRED(), niceness, &retval);
61*d4204c85Sraf schedctl_set_cidpri(t);
627c478bd9Sstevel@tonic-gate if (error == 0 && err)
637c478bd9Sstevel@tonic-gate error = set_errno(err);
647c478bd9Sstevel@tonic-gate } while ((t = t->t_forw) != p->p_tlist);
657c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock);
667c478bd9Sstevel@tonic-gate if (error)
677c478bd9Sstevel@tonic-gate return (error);
687c478bd9Sstevel@tonic-gate return (retval);
697c478bd9Sstevel@tonic-gate }
70