xref: /illumos-gate/usr/src/lib/libc/port/sys/psetsys.c (revision 7c478bd9)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 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 "synonyms.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