xref: /titanic_50/usr/src/lib/libc/port/sys/psetsys.c (revision 694c35faa87b858ecdadfe4fc592615f4eefbb07)
1 /*
2  * CDDL HEADER START
3  *
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include "lint.h"
28 #include <sys/types.h>
29 #include <sys/procset.h>
30 #include <sys/processor.h>
31 #include <sys/pset.h>
32 #include <sys/param.h>
33 #include <sys/loadavg.h>
34 
35 int _pset(int, ...);
36 
37 /* subcode wrappers for _pset system call */
38 
39 int
40 pset_create(psetid_t *npset)
41 {
42 	return (_pset(PSET_CREATE, npset));
43 }
44 
45 int
46 pset_destroy(psetid_t pset)
47 {
48 	return (_pset(PSET_DESTROY, pset));
49 }
50 
51 int
52 pset_assign(psetid_t pset, processorid_t cpu, psetid_t *opset)
53 {
54 	return (_pset(PSET_ASSIGN, pset, cpu, opset));
55 }
56 
57 int
58 pset_assign_forced(psetid_t pset, processorid_t cpu, psetid_t *opset)
59 {
60 	return (_pset(PSET_ASSIGN_FORCED, pset, cpu, opset));
61 }
62 
63 int
64 pset_info(psetid_t pset, int *type, uint_t *numcpus, processorid_t *cpulist)
65 {
66 	return (_pset(PSET_INFO, pset, type, numcpus, cpulist));
67 }
68 
69 int
70 pset_bind(psetid_t pset, idtype_t idtype, id_t id, psetid_t *opset)
71 {
72 	return (_pset(PSET_BIND, pset, idtype, id, opset));
73 }
74 
75 int
76 pset_bind_lwp(psetid_t pset, id_t id, pid_t pid, psetid_t *opset)
77 {
78 	return (_pset(PSET_BIND_LWP, pset, id, pid, opset));
79 }
80 
81 /*
82  * Get the per-processor-set load average.
83  */
84 int
85 pset_getloadavg(psetid_t pset, double loadavg[], int nelem)
86 {
87 	int i, buf[LOADAVG_NSTATS];
88 
89 	if (nelem > LOADAVG_NSTATS)
90 		nelem = LOADAVG_NSTATS;
91 
92 	if (_pset(PSET_GETLOADAVG, pset, buf, nelem) == -1)
93 		return (-1);
94 
95 	for (i = 0; i < nelem; i++)
96 		loadavg[i] = (double)buf[i] / FSCALE;
97 
98 	return (nelem);
99 }
100 
101 int
102 pset_list(psetid_t *psetlist, uint_t *numpsets)
103 {
104 	return (_pset(PSET_LIST, psetlist, numpsets));
105 }
106 
107 int
108 pset_setattr(psetid_t pset, uint_t attr)
109 {
110 	return (_pset(PSET_SETATTR, pset, attr));
111 }
112 
113 int
114 pset_getattr(psetid_t pset, uint_t *attr)
115 {
116 	return (_pset(PSET_GETATTR, pset, attr));
117 }
118