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