17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57257d1braf * Common Development and Distribution License (the "License").
67257d1braf * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217257d1braf
227c478bdstevel@tonic-gate/*
23fb9b0aaSurya Prakki * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277257d1braf#include "lint.h"
287c478bdstevel@tonic-gate#include <sys/types.h>
297c478bdstevel@tonic-gate#include <sys/procset.h>
307c478bdstevel@tonic-gate#include <sys/processor.h>
317c478bdstevel@tonic-gate#include <sys/pset.h>
327c478bdstevel@tonic-gate#include <sys/param.h>
337c478bdstevel@tonic-gate#include <sys/loadavg.h>
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gateint _pset(int, ...);
367c478bdstevel@tonic-gate
377c478bdstevel@tonic-gate/* subcode wrappers for _pset system call */
387c478bdstevel@tonic-gate
397c478bdstevel@tonic-gateint
407c478bdstevel@tonic-gatepset_create(psetid_t *npset)
417c478bdstevel@tonic-gate{
427c478bdstevel@tonic-gate	return (_pset(PSET_CREATE, npset));
437c478bdstevel@tonic-gate}
447c478bdstevel@tonic-gate
457c478bdstevel@tonic-gateint
467c478bdstevel@tonic-gatepset_destroy(psetid_t pset)
477c478bdstevel@tonic-gate{
487c478bdstevel@tonic-gate	return (_pset(PSET_DESTROY, pset));
497c478bdstevel@tonic-gate}
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gateint
527c478bdstevel@tonic-gatepset_assign(psetid_t pset, processorid_t cpu, psetid_t *opset)
537c478bdstevel@tonic-gate{
547c478bdstevel@tonic-gate	return (_pset(PSET_ASSIGN, pset, cpu, opset));
557c478bdstevel@tonic-gate}
567c478bdstevel@tonic-gate
577c478bdstevel@tonic-gateint
587c478bdstevel@tonic-gatepset_assign_forced(psetid_t pset, processorid_t cpu, psetid_t *opset)
597c478bdstevel@tonic-gate{
607c478bdstevel@tonic-gate	return (_pset(PSET_ASSIGN_FORCED, pset, cpu, opset));
617c478bdstevel@tonic-gate}
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gateint
647c478bdstevel@tonic-gatepset_info(psetid_t pset, int *type, uint_t *numcpus, processorid_t *cpulist)
657c478bdstevel@tonic-gate{
667c478bdstevel@tonic-gate	return (_pset(PSET_INFO, pset, type, numcpus, cpulist));
677c478bdstevel@tonic-gate}
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gateint
707c478bdstevel@tonic-gatepset_bind(psetid_t pset, idtype_t idtype, id_t id, psetid_t *opset)
717c478bdstevel@tonic-gate{
727c478bdstevel@tonic-gate	return (_pset(PSET_BIND, pset, idtype, id, opset));
737c478bdstevel@tonic-gate}
747c478bdstevel@tonic-gate
75fb9b0aaSurya Prakkiint
76fb9b0aaSurya Prakkipset_bind_lwp(psetid_t pset, id_t id, pid_t pid, psetid_t *opset)
77fb9b0aaSurya Prakki{
78fb9b0aaSurya Prakki	return (_pset(PSET_BIND_LWP, pset, id, pid, opset));
79fb9b0aaSurya Prakki}
80fb9b0aaSurya Prakki
817c478bdstevel@tonic-gate/*
827c478bdstevel@tonic-gate * Get the per-processor-set load average.
837c478bdstevel@tonic-gate */
847c478bdstevel@tonic-gateint
857c478bdstevel@tonic-gatepset_getloadavg(psetid_t pset, double loadavg[], int nelem)
867c478bdstevel@tonic-gate{
877c478bdstevel@tonic-gate	int i, buf[LOADAVG_NSTATS];
887c478bdstevel@tonic-gate
897c478bdstevel@tonic-gate	if (nelem > LOADAVG_NSTATS)
907c478bdstevel@tonic-gate		nelem = LOADAVG_NSTATS;
917c478bdstevel@tonic-gate
927c478bdstevel@tonic-gate	if (_pset(PSET_GETLOADAVG, pset, buf, nelem) == -1)
937c478bdstevel@tonic-gate		return (-1);
947c478bdstevel@tonic-gate
957c478bdstevel@tonic-gate	for (i = 0; i < nelem; i++)
967c478bdstevel@tonic-gate		loadavg[i] = (double)buf[i] / FSCALE;
977c478bdstevel@tonic-gate
987c478bdstevel@tonic-gate	return (nelem);
997c478bdstevel@tonic-gate}
1007c478bdstevel@tonic-gate
1017c478bdstevel@tonic-gateint
1027c478bdstevel@tonic-gatepset_list(psetid_t *psetlist, uint_t *numpsets)
1037c478bdstevel@tonic-gate{
1047c478bdstevel@tonic-gate	return (_pset(PSET_LIST, psetlist, numpsets));
1057c478bdstevel@tonic-gate}
1067c478bdstevel@tonic-gate
1077c478bdstevel@tonic-gateint
1087c478bdstevel@tonic-gatepset_setattr(psetid_t pset, uint_t attr)
1097c478bdstevel@tonic-gate{
1107c478bdstevel@tonic-gate	return (_pset(PSET_SETATTR, pset, attr));
1117c478bdstevel@tonic-gate}
1127c478bdstevel@tonic-gate
1137c478bdstevel@tonic-gateint
1147c478bdstevel@tonic-gatepset_getattr(psetid_t pset, uint_t *attr)
1157c478bdstevel@tonic-gate{
1167c478bdstevel@tonic-gate	return (_pset(PSET_GETATTR, pset, attr));
1177c478bdstevel@tonic-gate}
118