10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51996Sml93401 * Common Development and Distribution License (the "License").
61996Sml93401 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
2212273SCasper.Dik@Sun.COM * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate #include <sys/project.h>
260Sstevel@tonic-gate #include <sys/modhash.h>
270Sstevel@tonic-gate #include <sys/modctl.h>
280Sstevel@tonic-gate #include <sys/kmem.h>
293247Sgjelinek #include <sys/kstat.h>
300Sstevel@tonic-gate #include <sys/atomic.h>
310Sstevel@tonic-gate #include <sys/cmn_err.h>
320Sstevel@tonic-gate #include <sys/proc.h>
330Sstevel@tonic-gate #include <sys/rctl.h>
340Sstevel@tonic-gate #include <sys/sunddi.h>
350Sstevel@tonic-gate #include <sys/fss.h>
360Sstevel@tonic-gate #include <sys/systm.h>
370Sstevel@tonic-gate #include <sys/ipc_impl.h>
380Sstevel@tonic-gate #include <sys/port_kernel.h>
390Sstevel@tonic-gate #include <sys/task.h>
400Sstevel@tonic-gate #include <sys/zone.h>
413792Sakolb #include <sys/cpucaps.h>
426134Scasper #include <sys/klpd.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate int project_hash_size = 64;
450Sstevel@tonic-gate static kmutex_t project_hash_lock;
460Sstevel@tonic-gate static kmutex_t projects_list_lock;
470Sstevel@tonic-gate static mod_hash_t *projects_hash;
480Sstevel@tonic-gate static kproject_t *projects_list;
490Sstevel@tonic-gate
500Sstevel@tonic-gate rctl_hndl_t rc_project_cpu_shares;
513792Sakolb rctl_hndl_t rc_project_cpu_cap;
520Sstevel@tonic-gate rctl_hndl_t rc_project_nlwps;
53*12725SMenno.Lageman@Sun.COM rctl_hndl_t rc_project_nprocs;
540Sstevel@tonic-gate rctl_hndl_t rc_project_ntasks;
550Sstevel@tonic-gate rctl_hndl_t rc_project_msgmni;
560Sstevel@tonic-gate rctl_hndl_t rc_project_semmni;
570Sstevel@tonic-gate rctl_hndl_t rc_project_shmmax;
580Sstevel@tonic-gate rctl_hndl_t rc_project_shmmni;
590Sstevel@tonic-gate rctl_hndl_t rc_project_portids;
602768Ssl108498 rctl_hndl_t rc_project_locked_mem;
610Sstevel@tonic-gate rctl_hndl_t rc_project_contract;
620Sstevel@tonic-gate rctl_hndl_t rc_project_crypto_mem;
630Sstevel@tonic-gate
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate * Dummy structure used when comparing projects. This structure must be kept
660Sstevel@tonic-gate * identical to the first two fields of kproject_t.
670Sstevel@tonic-gate */
680Sstevel@tonic-gate struct project_zone {
690Sstevel@tonic-gate projid_t kpj_id;
700Sstevel@tonic-gate zoneid_t kpj_zoneid;
710Sstevel@tonic-gate };
720Sstevel@tonic-gate
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate * Projects
750Sstevel@tonic-gate *
760Sstevel@tonic-gate * A dictionary of all active projects is maintained by the kernel so that we
770Sstevel@tonic-gate * may track project usage and limits. (By an active project, we mean a
780Sstevel@tonic-gate * project associated with one or more task, and therefore with one or more
790Sstevel@tonic-gate * processes.) We build the dictionary on top of the mod_hash facility, since
800Sstevel@tonic-gate * project additions and deletions are relatively rare events. An
810Sstevel@tonic-gate * integer-to-pointer mapping is maintained within the hash, representing the
820Sstevel@tonic-gate * map from project id to project structure. All projects, including the
830Sstevel@tonic-gate * primordial "project 0", are allocated via the project_hold_by_id()
840Sstevel@tonic-gate * interface.
850Sstevel@tonic-gate *
860Sstevel@tonic-gate * Currently, the project contains a reference count; the project ID, which is
870Sstevel@tonic-gate * examined by the extended accounting subsystem as well as /proc; a resource
880Sstevel@tonic-gate * control set, which contains the allowable values (and actions on exceeding
890Sstevel@tonic-gate * those values) for controlled project-level resources on the system; and a
900Sstevel@tonic-gate * number of CPU shares, which is used by the fair share scheduling class
910Sstevel@tonic-gate * (FSS) to support its proportion-based scheduling algorithm.
920Sstevel@tonic-gate *
930Sstevel@tonic-gate * Reference counting convention
940Sstevel@tonic-gate * The dictionary entry does not itself count as a reference--only references
950Sstevel@tonic-gate * outside of the subsystem are tallied. At the drop of the final external
960Sstevel@tonic-gate * reference, the project entry is removed. The reference counter keeps
970Sstevel@tonic-gate * track of the number of threads *and* tasks within a project.
980Sstevel@tonic-gate *
990Sstevel@tonic-gate * Locking
1000Sstevel@tonic-gate * Walking the doubly-linked project list must be done while holding
1010Sstevel@tonic-gate * projects_list_lock. Thus, any dereference of kpj_next or kpj_prev must be
1020Sstevel@tonic-gate * under projects_list_lock.
1030Sstevel@tonic-gate *
1040Sstevel@tonic-gate * If both the hash lock, project_hash_lock, and the list lock are to be
1050Sstevel@tonic-gate * acquired, the hash lock is to be acquired first.
1060Sstevel@tonic-gate */
1070Sstevel@tonic-gate
108*12725SMenno.Lageman@Sun.COM static void project_kstat_create(kproject_t *pj, zone_t *zone);
1093247Sgjelinek static void project_kstat_delete(kproject_t *pj);
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate static void
project_data_init(kproject_data_t * data)1120Sstevel@tonic-gate project_data_init(kproject_data_t *data)
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate /*
1150Sstevel@tonic-gate * Initialize subsystem-specific data
1160Sstevel@tonic-gate */
1170Sstevel@tonic-gate data->kpd_shmmax = 0;
1182677Sml93401 data->kpd_ipc.ipcq_shmmni = 0;
1192677Sml93401 data->kpd_ipc.ipcq_semmni = 0;
1202677Sml93401 data->kpd_ipc.ipcq_msgmni = 0;
1212768Ssl108498 data->kpd_locked_mem = 0;
1222768Ssl108498 data->kpd_locked_mem_ctl = UINT64_MAX;
1230Sstevel@tonic-gate data->kpd_contract = 0;
1240Sstevel@tonic-gate data->kpd_crypto_mem = 0;
1253620Skrishna data->kpd_crypto_mem_ctl = UINT64_MAX;
1263247Sgjelinek data->kpd_lockedmem_kstat = NULL;
127*12725SMenno.Lageman@Sun.COM data->kpd_nprocs_kstat = NULL;
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /*ARGSUSED*/
1310Sstevel@tonic-gate static uint_t
project_hash_by_id(void * hash_data,mod_hash_key_t key)1320Sstevel@tonic-gate project_hash_by_id(void *hash_data, mod_hash_key_t key)
1330Sstevel@tonic-gate {
1340Sstevel@tonic-gate struct project_zone *pz = key;
1350Sstevel@tonic-gate uint_t mykey;
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate /*
1380Sstevel@tonic-gate * Merge the zoneid and projectid together to a 32-bit quantity, and
1390Sstevel@tonic-gate * then pass that in to the existing idhash.
1400Sstevel@tonic-gate */
1410Sstevel@tonic-gate mykey = (pz->kpj_zoneid << 16) | pz->kpj_id;
1420Sstevel@tonic-gate return (mod_hash_byid(hash_data, (mod_hash_key_t)(uintptr_t)mykey));
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate static int
project_hash_key_cmp(mod_hash_key_t key1,mod_hash_key_t key2)1460Sstevel@tonic-gate project_hash_key_cmp(mod_hash_key_t key1, mod_hash_key_t key2)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate struct project_zone *pz1 = key1, *pz2 = key2;
1490Sstevel@tonic-gate int retval;
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate return ((int)((retval = pz1->kpj_id - pz2->kpj_id) != 0 ? retval :
1520Sstevel@tonic-gate pz1->kpj_zoneid - pz2->kpj_zoneid));
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate static void
project_hash_val_dtor(mod_hash_val_t val)1560Sstevel@tonic-gate project_hash_val_dtor(mod_hash_val_t val)
1570Sstevel@tonic-gate {
1580Sstevel@tonic-gate kproject_t *kp = (kproject_t *)val;
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate ASSERT(kp->kpj_count == 0);
1613792Sakolb ASSERT(kp->kpj_cpucap == NULL);
1620Sstevel@tonic-gate kmem_free(kp, sizeof (kproject_t));
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate /*
1660Sstevel@tonic-gate * kproject_t *project_hold(kproject_t *)
1670Sstevel@tonic-gate *
1680Sstevel@tonic-gate * Overview
1690Sstevel@tonic-gate * Record that an additional reference on the indicated project has been
1700Sstevel@tonic-gate * taken.
1710Sstevel@tonic-gate *
1720Sstevel@tonic-gate * Return values
1730Sstevel@tonic-gate * A pointer to the indicated project.
1740Sstevel@tonic-gate *
1750Sstevel@tonic-gate * Caller's context
1760Sstevel@tonic-gate * project_hash_lock must not be held across the project_hold() call.
1770Sstevel@tonic-gate */
1780Sstevel@tonic-gate kproject_t *
project_hold(kproject_t * p)1790Sstevel@tonic-gate project_hold(kproject_t *p)
1800Sstevel@tonic-gate {
1810Sstevel@tonic-gate mutex_enter(&project_hash_lock);
1820Sstevel@tonic-gate ASSERT(p != NULL);
1830Sstevel@tonic-gate p->kpj_count++;
1840Sstevel@tonic-gate ASSERT(p->kpj_count != 0);
1850Sstevel@tonic-gate mutex_exit(&project_hash_lock);
1860Sstevel@tonic-gate return (p);
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate /*
1903247Sgjelinek * kproject_t *project_hold_by_id(projid_t, zone_t *, int)
1910Sstevel@tonic-gate *
1920Sstevel@tonic-gate * Overview
1930Sstevel@tonic-gate * project_hold_by_id() performs a look-up in the dictionary of projects
1943247Sgjelinek * active on the system by specified project ID + zone and puts a hold on
1950Sstevel@tonic-gate * it. The third argument defines the desired behavior in the case when
1960Sstevel@tonic-gate * project with given project ID cannot be found:
1970Sstevel@tonic-gate *
1980Sstevel@tonic-gate * PROJECT_HOLD_INSERT New entry is made in dictionary and the project
1990Sstevel@tonic-gate * is added to the global list.
2000Sstevel@tonic-gate *
2010Sstevel@tonic-gate * PROJECT_HOLD_FIND Return NULL.
2020Sstevel@tonic-gate *
2030Sstevel@tonic-gate * The project is returned with its reference count incremented by one.
2040Sstevel@tonic-gate * A new project derives its resource controls from those of project 0.
2050Sstevel@tonic-gate *
2060Sstevel@tonic-gate * Return values
2070Sstevel@tonic-gate * A pointer to the held project.
2080Sstevel@tonic-gate *
2090Sstevel@tonic-gate * Caller's context
2100Sstevel@tonic-gate * Caller must be in a context suitable for KM_SLEEP allocations.
2110Sstevel@tonic-gate */
2120Sstevel@tonic-gate kproject_t *
project_hold_by_id(projid_t id,zone_t * zone,int flag)2133247Sgjelinek project_hold_by_id(projid_t id, zone_t *zone, int flag)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate kproject_t *spare_p;
2160Sstevel@tonic-gate kproject_t *p;
2170Sstevel@tonic-gate mod_hash_hndl_t hndl;
2180Sstevel@tonic-gate rctl_set_t *set;
2190Sstevel@tonic-gate rctl_alloc_gp_t *gp;
2200Sstevel@tonic-gate rctl_entity_p_t e;
2210Sstevel@tonic-gate struct project_zone pz;
2223247Sgjelinek boolean_t create = B_FALSE;
2230Sstevel@tonic-gate
2240Sstevel@tonic-gate pz.kpj_id = id;
2253247Sgjelinek pz.kpj_zoneid = zone->zone_id;
2260Sstevel@tonic-gate
2270Sstevel@tonic-gate if (flag == PROJECT_HOLD_FIND) {
2280Sstevel@tonic-gate mutex_enter(&project_hash_lock);
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate if (mod_hash_find(projects_hash, (mod_hash_key_t)&pz,
2310Sstevel@tonic-gate (mod_hash_val_t)&p) == MH_ERR_NOTFOUND)
2320Sstevel@tonic-gate p = NULL;
2330Sstevel@tonic-gate else
2340Sstevel@tonic-gate p->kpj_count++;
2350Sstevel@tonic-gate
2360Sstevel@tonic-gate mutex_exit(&project_hash_lock);
2370Sstevel@tonic-gate return (p);
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate ASSERT(flag == PROJECT_HOLD_INSERT);
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate spare_p = kmem_zalloc(sizeof (kproject_t), KM_SLEEP);
2430Sstevel@tonic-gate set = rctl_set_create();
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate gp = rctl_set_init_prealloc(RCENTITY_PROJECT);
2460Sstevel@tonic-gate
2470Sstevel@tonic-gate (void) mod_hash_reserve(projects_hash, &hndl);
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate mutex_enter(&curproc->p_lock);
2500Sstevel@tonic-gate mutex_enter(&project_hash_lock);
2510Sstevel@tonic-gate if (mod_hash_find(projects_hash, (mod_hash_key_t)&pz,
2520Sstevel@tonic-gate (mod_hash_val_t *)&p) == MH_ERR_NOTFOUND) {
2533247Sgjelinek
2540Sstevel@tonic-gate p = spare_p;
2550Sstevel@tonic-gate p->kpj_id = id;
2563792Sakolb p->kpj_zone = zone;
2573247Sgjelinek p->kpj_zoneid = zone->zone_id;
2580Sstevel@tonic-gate p->kpj_count = 0;
2590Sstevel@tonic-gate p->kpj_shares = 1;
2600Sstevel@tonic-gate p->kpj_nlwps = 0;
261*12725SMenno.Lageman@Sun.COM p->kpj_nprocs = 0;
2620Sstevel@tonic-gate p->kpj_ntasks = 0;
2630Sstevel@tonic-gate p->kpj_nlwps_ctl = INT_MAX;
264*12725SMenno.Lageman@Sun.COM p->kpj_nprocs_ctl = INT_MAX;
2650Sstevel@tonic-gate p->kpj_ntasks_ctl = INT_MAX;
2660Sstevel@tonic-gate project_data_init(&p->kpj_data);
2670Sstevel@tonic-gate e.rcep_p.proj = p;
2680Sstevel@tonic-gate e.rcep_t = RCENTITY_PROJECT;
2690Sstevel@tonic-gate p->kpj_rctls = rctl_set_init(RCENTITY_PROJECT, curproc, &e,
2700Sstevel@tonic-gate set, gp);
2710Sstevel@tonic-gate mutex_exit(&curproc->p_lock);
2720Sstevel@tonic-gate
2730Sstevel@tonic-gate if (mod_hash_insert_reserve(projects_hash, (mod_hash_key_t)p,
2740Sstevel@tonic-gate (mod_hash_val_t)p, hndl))
2750Sstevel@tonic-gate panic("unable to insert project %d(%p)", id, (void *)p);
2760Sstevel@tonic-gate
2770Sstevel@tonic-gate /*
2780Sstevel@tonic-gate * Insert project into global project list.
2790Sstevel@tonic-gate */
2800Sstevel@tonic-gate mutex_enter(&projects_list_lock);
2813247Sgjelinek if (id != 0 || zone != &zone0) {
2820Sstevel@tonic-gate p->kpj_next = projects_list;
2830Sstevel@tonic-gate p->kpj_prev = projects_list->kpj_prev;
2840Sstevel@tonic-gate p->kpj_prev->kpj_next = p;
2850Sstevel@tonic-gate projects_list->kpj_prev = p;
2860Sstevel@tonic-gate } else {
2870Sstevel@tonic-gate /*
2880Sstevel@tonic-gate * Special case: primordial hold on project 0.
2890Sstevel@tonic-gate */
2900Sstevel@tonic-gate p->kpj_next = p;
2910Sstevel@tonic-gate p->kpj_prev = p;
2920Sstevel@tonic-gate projects_list = p;
2930Sstevel@tonic-gate }
2940Sstevel@tonic-gate mutex_exit(&projects_list_lock);
2953247Sgjelinek create = B_TRUE;
2960Sstevel@tonic-gate } else {
2970Sstevel@tonic-gate mutex_exit(&curproc->p_lock);
2980Sstevel@tonic-gate mod_hash_cancel(projects_hash, &hndl);
2990Sstevel@tonic-gate kmem_free(spare_p, sizeof (kproject_t));
3000Sstevel@tonic-gate rctl_set_free(set);
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate rctl_prealloc_destroy(gp);
3040Sstevel@tonic-gate p->kpj_count++;
3050Sstevel@tonic-gate mutex_exit(&project_hash_lock);
3060Sstevel@tonic-gate
3073247Sgjelinek /*
3083247Sgjelinek * The kstat stores the project's zone name, as zoneid's may change
3093247Sgjelinek * across reboots.
3103247Sgjelinek */
3113247Sgjelinek if (create == B_TRUE) {
3123792Sakolb /*
3133792Sakolb * Inform CPU caps framework of the new project
3143792Sakolb */
3153792Sakolb cpucaps_project_add(p);
3163792Sakolb /*
3173792Sakolb * Set up project kstats
3183792Sakolb */
319*12725SMenno.Lageman@Sun.COM project_kstat_create(p, zone);
3203247Sgjelinek }
3210Sstevel@tonic-gate return (p);
3220Sstevel@tonic-gate }
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate /*
3250Sstevel@tonic-gate * void project_rele(kproject_t *)
3260Sstevel@tonic-gate *
3270Sstevel@tonic-gate * Overview
3280Sstevel@tonic-gate * Advertise that one external reference to this project is no longer needed.
3290Sstevel@tonic-gate *
3300Sstevel@tonic-gate * Return values
3310Sstevel@tonic-gate * None.
3320Sstevel@tonic-gate *
3330Sstevel@tonic-gate * Caller's context
3340Sstevel@tonic-gate * No restriction on context.
3350Sstevel@tonic-gate */
3360Sstevel@tonic-gate void
project_rele(kproject_t * p)3370Sstevel@tonic-gate project_rele(kproject_t *p)
3380Sstevel@tonic-gate {
3390Sstevel@tonic-gate mutex_enter(&project_hash_lock);
3400Sstevel@tonic-gate ASSERT(p->kpj_count != 0);
3410Sstevel@tonic-gate p->kpj_count--;
3420Sstevel@tonic-gate if (p->kpj_count == 0) {
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate /*
3450Sstevel@tonic-gate * Remove project from global list.
3460Sstevel@tonic-gate */
347*12725SMenno.Lageman@Sun.COM ASSERT(p->kpj_nprocs == 0);
348*12725SMenno.Lageman@Sun.COM
3490Sstevel@tonic-gate mutex_enter(&projects_list_lock);
3500Sstevel@tonic-gate p->kpj_next->kpj_prev = p->kpj_prev;
3510Sstevel@tonic-gate p->kpj_prev->kpj_next = p->kpj_next;
3520Sstevel@tonic-gate if (projects_list == p)
3530Sstevel@tonic-gate projects_list = p->kpj_next;
3540Sstevel@tonic-gate mutex_exit(&projects_list_lock);
3550Sstevel@tonic-gate
3563792Sakolb cpucaps_project_remove(p);
3573792Sakolb
3580Sstevel@tonic-gate rctl_set_free(p->kpj_rctls);
3593247Sgjelinek project_kstat_delete(p);
3600Sstevel@tonic-gate
3616134Scasper if (p->kpj_klpd != NULL)
36212273SCasper.Dik@Sun.COM klpd_freelist(&p->kpj_klpd);
3636134Scasper
3640Sstevel@tonic-gate if (mod_hash_destroy(projects_hash, (mod_hash_key_t)p))
3650Sstevel@tonic-gate panic("unable to delete project %d zone %d", p->kpj_id,
3660Sstevel@tonic-gate p->kpj_zoneid);
3670Sstevel@tonic-gate
3686134Scasper }
3690Sstevel@tonic-gate mutex_exit(&project_hash_lock);
3700Sstevel@tonic-gate }
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate /*
3730Sstevel@tonic-gate * int project_walk_all(zoneid_t, int (*)(kproject_t *, void *), void *)
3740Sstevel@tonic-gate *
3750Sstevel@tonic-gate * Overview
3760Sstevel@tonic-gate * Walk the project list for the given zoneid with a callback.
3770Sstevel@tonic-gate *
3780Sstevel@tonic-gate * Return values
3790Sstevel@tonic-gate * -1 for an invalid walk, number of projects visited otherwise.
3800Sstevel@tonic-gate *
3810Sstevel@tonic-gate * Caller's context
3820Sstevel@tonic-gate * projects_list_lock must not be held, as it is acquired by
3830Sstevel@tonic-gate * project_walk_all(). Accordingly, callbacks may not perform KM_SLEEP
3840Sstevel@tonic-gate * allocations.
3850Sstevel@tonic-gate */
3860Sstevel@tonic-gate int
project_walk_all(zoneid_t zoneid,int (* cb)(kproject_t *,void *),void * walk_data)3870Sstevel@tonic-gate project_walk_all(zoneid_t zoneid, int (*cb)(kproject_t *, void *),
3880Sstevel@tonic-gate void *walk_data)
3890Sstevel@tonic-gate {
3900Sstevel@tonic-gate int cnt = 0;
3910Sstevel@tonic-gate kproject_t *kp = proj0p;
3920Sstevel@tonic-gate
3930Sstevel@tonic-gate mutex_enter(&projects_list_lock);
3940Sstevel@tonic-gate do {
3950Sstevel@tonic-gate if (zoneid != ALL_ZONES && kp->kpj_zoneid != zoneid)
3960Sstevel@tonic-gate continue;
3970Sstevel@tonic-gate if (cb(kp, walk_data) == -1) {
3980Sstevel@tonic-gate cnt = -1;
3990Sstevel@tonic-gate break;
4000Sstevel@tonic-gate } else {
4010Sstevel@tonic-gate cnt++;
4020Sstevel@tonic-gate }
4030Sstevel@tonic-gate } while ((kp = kp->kpj_next) != proj0p);
4040Sstevel@tonic-gate mutex_exit(&projects_list_lock);
4050Sstevel@tonic-gate return (cnt);
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate
4080Sstevel@tonic-gate /*
4090Sstevel@tonic-gate * projid_t curprojid(void)
4100Sstevel@tonic-gate *
4110Sstevel@tonic-gate * Overview
4120Sstevel@tonic-gate * Return project ID of the current thread
4130Sstevel@tonic-gate *
4140Sstevel@tonic-gate * Caller's context
4150Sstevel@tonic-gate * No restrictions.
4160Sstevel@tonic-gate */
4170Sstevel@tonic-gate projid_t
curprojid()4180Sstevel@tonic-gate curprojid()
4190Sstevel@tonic-gate {
4200Sstevel@tonic-gate return (ttoproj(curthread)->kpj_id);
4210Sstevel@tonic-gate }
4220Sstevel@tonic-gate
4230Sstevel@tonic-gate /*
4240Sstevel@tonic-gate * project.cpu-shares resource control support.
4250Sstevel@tonic-gate */
4260Sstevel@tonic-gate /*ARGSUSED*/
4270Sstevel@tonic-gate static rctl_qty_t
project_cpu_shares_usage(rctl_t * rctl,struct proc * p)4280Sstevel@tonic-gate project_cpu_shares_usage(rctl_t *rctl, struct proc *p)
4290Sstevel@tonic-gate {
4300Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
4310Sstevel@tonic-gate return (p->p_task->tk_proj->kpj_shares);
4320Sstevel@tonic-gate }
4330Sstevel@tonic-gate
4340Sstevel@tonic-gate /*ARGSUSED*/
4350Sstevel@tonic-gate static int
project_cpu_shares_set(rctl_t * rctl,struct proc * p,rctl_entity_p_t * e,rctl_qty_t nv)4360Sstevel@tonic-gate project_cpu_shares_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e,
4370Sstevel@tonic-gate rctl_qty_t nv)
4380Sstevel@tonic-gate {
4390Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
4400Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
4410Sstevel@tonic-gate if (e->rcep_p.proj == NULL)
4420Sstevel@tonic-gate return (0);
4430Sstevel@tonic-gate
4440Sstevel@tonic-gate e->rcep_p.proj->kpj_shares = nv;
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate return (0);
4470Sstevel@tonic-gate }
4480Sstevel@tonic-gate
4490Sstevel@tonic-gate static rctl_ops_t project_cpu_shares_ops = {
4500Sstevel@tonic-gate rcop_no_action,
4510Sstevel@tonic-gate project_cpu_shares_usage,
4520Sstevel@tonic-gate project_cpu_shares_set,
4530Sstevel@tonic-gate rcop_no_test
4540Sstevel@tonic-gate };
4550Sstevel@tonic-gate
4563792Sakolb
4573792Sakolb /*
4583792Sakolb * project.cpu-cap resource control support.
4593792Sakolb */
4603792Sakolb /*ARGSUSED*/
4613792Sakolb static rctl_qty_t
project_cpu_cap_get(rctl_t * rctl,struct proc * p)4623792Sakolb project_cpu_cap_get(rctl_t *rctl, struct proc *p)
4633792Sakolb {
4643792Sakolb ASSERT(MUTEX_HELD(&p->p_lock));
4653792Sakolb return (cpucaps_project_get(p->p_task->tk_proj));
4663792Sakolb }
4673792Sakolb
4683792Sakolb /*ARGSUSED*/
4693792Sakolb static int
project_cpu_cap_set(rctl_t * rctl,struct proc * p,rctl_entity_p_t * e,rctl_qty_t nv)4703792Sakolb project_cpu_cap_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e,
4713792Sakolb rctl_qty_t nv)
4723792Sakolb {
4733792Sakolb kproject_t *kpj = e->rcep_p.proj;
4743792Sakolb
4753792Sakolb ASSERT(MUTEX_HELD(&p->p_lock));
4763792Sakolb ASSERT(e->rcep_t == RCENTITY_PROJECT);
4773792Sakolb if (kpj == NULL)
4783792Sakolb return (0);
4793792Sakolb
4803792Sakolb /*
4813792Sakolb * set cap to the new value.
4823792Sakolb */
4833792Sakolb return (cpucaps_project_set(kpj, nv));
4843792Sakolb }
4853792Sakolb
4863792Sakolb static rctl_ops_t project_cpu_cap_ops = {
4873792Sakolb rcop_no_action,
4883792Sakolb project_cpu_cap_get,
4893792Sakolb project_cpu_cap_set,
4903792Sakolb rcop_no_test
4913792Sakolb };
4923792Sakolb
4930Sstevel@tonic-gate /*ARGSUSED*/
4940Sstevel@tonic-gate static rctl_qty_t
project_lwps_usage(rctl_t * r,proc_t * p)4950Sstevel@tonic-gate project_lwps_usage(rctl_t *r, proc_t *p)
4960Sstevel@tonic-gate {
4970Sstevel@tonic-gate kproject_t *pj;
4980Sstevel@tonic-gate rctl_qty_t nlwps;
4990Sstevel@tonic-gate
5000Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
5010Sstevel@tonic-gate pj = p->p_task->tk_proj;
5020Sstevel@tonic-gate mutex_enter(&p->p_zone->zone_nlwps_lock);
5030Sstevel@tonic-gate nlwps = pj->kpj_nlwps;
5040Sstevel@tonic-gate mutex_exit(&p->p_zone->zone_nlwps_lock);
5050Sstevel@tonic-gate
5060Sstevel@tonic-gate return (nlwps);
5070Sstevel@tonic-gate }
5080Sstevel@tonic-gate
5090Sstevel@tonic-gate /*ARGSUSED*/
5100Sstevel@tonic-gate static int
project_lwps_test(rctl_t * r,proc_t * p,rctl_entity_p_t * e,rctl_val_t * rcntl,rctl_qty_t incr,uint_t flags)5110Sstevel@tonic-gate project_lwps_test(rctl_t *r, proc_t *p, rctl_entity_p_t *e, rctl_val_t *rcntl,
5120Sstevel@tonic-gate rctl_qty_t incr, uint_t flags)
5130Sstevel@tonic-gate {
5140Sstevel@tonic-gate rctl_qty_t nlwps;
5150Sstevel@tonic-gate
5160Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
5172768Ssl108498 ASSERT(MUTEX_HELD(&p->p_zone->zone_nlwps_lock));
5180Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
5190Sstevel@tonic-gate if (e->rcep_p.proj == NULL)
5200Sstevel@tonic-gate return (0);
5210Sstevel@tonic-gate
5220Sstevel@tonic-gate nlwps = e->rcep_p.proj->kpj_nlwps;
5230Sstevel@tonic-gate if (nlwps + incr > rcntl->rcv_value)
5240Sstevel@tonic-gate return (1);
5250Sstevel@tonic-gate
5260Sstevel@tonic-gate return (0);
5270Sstevel@tonic-gate }
5280Sstevel@tonic-gate
5290Sstevel@tonic-gate /*ARGSUSED*/
5300Sstevel@tonic-gate static int
project_lwps_set(rctl_t * rctl,struct proc * p,rctl_entity_p_t * e,rctl_qty_t nv)5310Sstevel@tonic-gate project_lwps_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e,
5320Sstevel@tonic-gate rctl_qty_t nv) {
5330Sstevel@tonic-gate
5340Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
5350Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
5360Sstevel@tonic-gate if (e->rcep_p.proj == NULL)
5370Sstevel@tonic-gate return (0);
5380Sstevel@tonic-gate
5390Sstevel@tonic-gate e->rcep_p.proj->kpj_nlwps_ctl = nv;
5400Sstevel@tonic-gate return (0);
5410Sstevel@tonic-gate }
5420Sstevel@tonic-gate
5430Sstevel@tonic-gate static rctl_ops_t project_lwps_ops = {
5440Sstevel@tonic-gate rcop_no_action,
5450Sstevel@tonic-gate project_lwps_usage,
5460Sstevel@tonic-gate project_lwps_set,
5470Sstevel@tonic-gate project_lwps_test,
5480Sstevel@tonic-gate };
5490Sstevel@tonic-gate
5500Sstevel@tonic-gate /*ARGSUSED*/
5510Sstevel@tonic-gate static rctl_qty_t
project_procs_usage(rctl_t * r,proc_t * p)552*12725SMenno.Lageman@Sun.COM project_procs_usage(rctl_t *r, proc_t *p)
553*12725SMenno.Lageman@Sun.COM {
554*12725SMenno.Lageman@Sun.COM kproject_t *pj;
555*12725SMenno.Lageman@Sun.COM rctl_qty_t nprocs;
556*12725SMenno.Lageman@Sun.COM
557*12725SMenno.Lageman@Sun.COM ASSERT(MUTEX_HELD(&p->p_lock));
558*12725SMenno.Lageman@Sun.COM pj = p->p_task->tk_proj;
559*12725SMenno.Lageman@Sun.COM mutex_enter(&p->p_zone->zone_nlwps_lock);
560*12725SMenno.Lageman@Sun.COM nprocs = pj->kpj_nprocs;
561*12725SMenno.Lageman@Sun.COM mutex_exit(&p->p_zone->zone_nlwps_lock);
562*12725SMenno.Lageman@Sun.COM
563*12725SMenno.Lageman@Sun.COM return (nprocs);
564*12725SMenno.Lageman@Sun.COM }
565*12725SMenno.Lageman@Sun.COM
566*12725SMenno.Lageman@Sun.COM /*ARGSUSED*/
567*12725SMenno.Lageman@Sun.COM static int
project_procs_test(rctl_t * r,proc_t * p,rctl_entity_p_t * e,rctl_val_t * rcntl,rctl_qty_t incr,uint_t flags)568*12725SMenno.Lageman@Sun.COM project_procs_test(rctl_t *r, proc_t *p, rctl_entity_p_t *e, rctl_val_t *rcntl,
569*12725SMenno.Lageman@Sun.COM rctl_qty_t incr, uint_t flags)
570*12725SMenno.Lageman@Sun.COM {
571*12725SMenno.Lageman@Sun.COM rctl_qty_t nprocs;
572*12725SMenno.Lageman@Sun.COM
573*12725SMenno.Lageman@Sun.COM ASSERT(MUTEX_HELD(&p->p_lock));
574*12725SMenno.Lageman@Sun.COM ASSERT(MUTEX_HELD(&p->p_zone->zone_nlwps_lock));
575*12725SMenno.Lageman@Sun.COM ASSERT(e->rcep_t == RCENTITY_PROJECT);
576*12725SMenno.Lageman@Sun.COM if (e->rcep_p.proj == NULL)
577*12725SMenno.Lageman@Sun.COM return (0);
578*12725SMenno.Lageman@Sun.COM
579*12725SMenno.Lageman@Sun.COM nprocs = e->rcep_p.proj->kpj_nprocs;
580*12725SMenno.Lageman@Sun.COM if (nprocs + incr > rcntl->rcv_value)
581*12725SMenno.Lageman@Sun.COM return (1);
582*12725SMenno.Lageman@Sun.COM
583*12725SMenno.Lageman@Sun.COM return (0);
584*12725SMenno.Lageman@Sun.COM }
585*12725SMenno.Lageman@Sun.COM
586*12725SMenno.Lageman@Sun.COM /*ARGSUSED*/
587*12725SMenno.Lageman@Sun.COM static int
project_procs_set(rctl_t * rctl,struct proc * p,rctl_entity_p_t * e,rctl_qty_t nv)588*12725SMenno.Lageman@Sun.COM project_procs_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e,
589*12725SMenno.Lageman@Sun.COM rctl_qty_t nv) {
590*12725SMenno.Lageman@Sun.COM
591*12725SMenno.Lageman@Sun.COM ASSERT(MUTEX_HELD(&p->p_lock));
592*12725SMenno.Lageman@Sun.COM ASSERT(e->rcep_t == RCENTITY_PROJECT);
593*12725SMenno.Lageman@Sun.COM if (e->rcep_p.proj == NULL)
594*12725SMenno.Lageman@Sun.COM return (0);
595*12725SMenno.Lageman@Sun.COM
596*12725SMenno.Lageman@Sun.COM e->rcep_p.proj->kpj_nprocs_ctl = nv;
597*12725SMenno.Lageman@Sun.COM return (0);
598*12725SMenno.Lageman@Sun.COM }
599*12725SMenno.Lageman@Sun.COM
600*12725SMenno.Lageman@Sun.COM static rctl_ops_t project_procs_ops = {
601*12725SMenno.Lageman@Sun.COM rcop_no_action,
602*12725SMenno.Lageman@Sun.COM project_procs_usage,
603*12725SMenno.Lageman@Sun.COM project_procs_set,
604*12725SMenno.Lageman@Sun.COM project_procs_test,
605*12725SMenno.Lageman@Sun.COM };
606*12725SMenno.Lageman@Sun.COM
607*12725SMenno.Lageman@Sun.COM /*ARGSUSED*/
608*12725SMenno.Lageman@Sun.COM static rctl_qty_t
project_ntasks_usage(rctl_t * r,proc_t * p)6090Sstevel@tonic-gate project_ntasks_usage(rctl_t *r, proc_t *p)
6100Sstevel@tonic-gate {
6110Sstevel@tonic-gate kproject_t *pj;
6120Sstevel@tonic-gate rctl_qty_t ntasks;
6130Sstevel@tonic-gate
6140Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
6150Sstevel@tonic-gate pj = p->p_task->tk_proj;
6160Sstevel@tonic-gate mutex_enter(&p->p_zone->zone_nlwps_lock);
6170Sstevel@tonic-gate ntasks = pj->kpj_ntasks;
6180Sstevel@tonic-gate mutex_exit(&p->p_zone->zone_nlwps_lock);
6190Sstevel@tonic-gate
6200Sstevel@tonic-gate return (ntasks);
6210Sstevel@tonic-gate }
6220Sstevel@tonic-gate
6230Sstevel@tonic-gate /*ARGSUSED*/
6240Sstevel@tonic-gate static int
project_ntasks_test(rctl_t * r,proc_t * p,rctl_entity_p_t * e,rctl_val_t * rcntl,rctl_qty_t incr,uint_t flags)6250Sstevel@tonic-gate project_ntasks_test(rctl_t *r, proc_t *p, rctl_entity_p_t *e, rctl_val_t *rcntl,
6260Sstevel@tonic-gate rctl_qty_t incr, uint_t flags)
6270Sstevel@tonic-gate {
6280Sstevel@tonic-gate rctl_qty_t ntasks;
6290Sstevel@tonic-gate
6300Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
6310Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
6320Sstevel@tonic-gate ntasks = e->rcep_p.proj->kpj_ntasks;
6330Sstevel@tonic-gate if (ntasks + incr > rcntl->rcv_value)
6340Sstevel@tonic-gate return (1);
6350Sstevel@tonic-gate
6360Sstevel@tonic-gate return (0);
6370Sstevel@tonic-gate }
6380Sstevel@tonic-gate
6390Sstevel@tonic-gate /*ARGSUSED*/
6400Sstevel@tonic-gate static int
project_ntasks_set(rctl_t * rctl,struct proc * p,rctl_entity_p_t * e,rctl_qty_t nv)6410Sstevel@tonic-gate project_ntasks_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e,
6420Sstevel@tonic-gate rctl_qty_t nv) {
6430Sstevel@tonic-gate
6440Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
6450Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
6460Sstevel@tonic-gate e->rcep_p.proj->kpj_ntasks_ctl = nv;
6470Sstevel@tonic-gate return (0);
6480Sstevel@tonic-gate }
6490Sstevel@tonic-gate
6500Sstevel@tonic-gate static rctl_ops_t project_tasks_ops = {
6510Sstevel@tonic-gate rcop_no_action,
6520Sstevel@tonic-gate project_ntasks_usage,
6530Sstevel@tonic-gate project_ntasks_set,
6540Sstevel@tonic-gate project_ntasks_test,
6550Sstevel@tonic-gate };
6560Sstevel@tonic-gate
6570Sstevel@tonic-gate /*
6580Sstevel@tonic-gate * project.max-shm-memory resource control support.
6590Sstevel@tonic-gate */
6600Sstevel@tonic-gate
6610Sstevel@tonic-gate /*ARGSUSED*/
6620Sstevel@tonic-gate static int
project_shmmax_test(struct rctl * rctl,struct proc * p,rctl_entity_p_t * e,rctl_val_t * rval,rctl_qty_t inc,uint_t flags)6630Sstevel@tonic-gate project_shmmax_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e,
6640Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags)
6650Sstevel@tonic-gate {
6660Sstevel@tonic-gate rctl_qty_t v;
6670Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
6680Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
6690Sstevel@tonic-gate v = e->rcep_p.proj->kpj_data.kpd_shmmax + inc;
6700Sstevel@tonic-gate if (v > rval->rcv_value)
6710Sstevel@tonic-gate return (1);
6720Sstevel@tonic-gate
6730Sstevel@tonic-gate return (0);
6740Sstevel@tonic-gate }
6750Sstevel@tonic-gate
6760Sstevel@tonic-gate static rctl_ops_t project_shmmax_ops = {
6770Sstevel@tonic-gate rcop_no_action,
6780Sstevel@tonic-gate rcop_no_usage,
6790Sstevel@tonic-gate rcop_no_set,
6800Sstevel@tonic-gate project_shmmax_test
6810Sstevel@tonic-gate };
6820Sstevel@tonic-gate
6830Sstevel@tonic-gate /*
6840Sstevel@tonic-gate * project.max-shm-ids resource control support.
6850Sstevel@tonic-gate */
6860Sstevel@tonic-gate
6870Sstevel@tonic-gate /*ARGSUSED*/
6880Sstevel@tonic-gate static int
project_shmmni_test(struct rctl * rctl,struct proc * p,rctl_entity_p_t * e,rctl_val_t * rval,rctl_qty_t inc,uint_t flags)6890Sstevel@tonic-gate project_shmmni_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e,
6900Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags)
6910Sstevel@tonic-gate {
6920Sstevel@tonic-gate rctl_qty_t v;
6930Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
6940Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
6952677Sml93401 v = e->rcep_p.proj->kpj_data.kpd_ipc.ipcq_shmmni + inc;
6960Sstevel@tonic-gate if (v > rval->rcv_value)
6970Sstevel@tonic-gate return (1);
6980Sstevel@tonic-gate
6990Sstevel@tonic-gate return (0);
7000Sstevel@tonic-gate }
7010Sstevel@tonic-gate
7020Sstevel@tonic-gate static rctl_ops_t project_shmmni_ops = {
7030Sstevel@tonic-gate rcop_no_action,
7040Sstevel@tonic-gate rcop_no_usage,
7050Sstevel@tonic-gate rcop_no_set,
7060Sstevel@tonic-gate project_shmmni_test
7070Sstevel@tonic-gate };
7080Sstevel@tonic-gate
7090Sstevel@tonic-gate /*
7100Sstevel@tonic-gate * project.max-sem-ids resource control support.
7110Sstevel@tonic-gate */
7120Sstevel@tonic-gate
7130Sstevel@tonic-gate /*ARGSUSED*/
7140Sstevel@tonic-gate static int
project_semmni_test(struct rctl * rctl,struct proc * p,rctl_entity_p_t * e,rctl_val_t * rval,rctl_qty_t inc,uint_t flags)7150Sstevel@tonic-gate project_semmni_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e,
7160Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags)
7170Sstevel@tonic-gate {
7180Sstevel@tonic-gate rctl_qty_t v;
7190Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
7200Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
7212677Sml93401 v = e->rcep_p.proj->kpj_data.kpd_ipc.ipcq_semmni + inc;
7220Sstevel@tonic-gate if (v > rval->rcv_value)
7230Sstevel@tonic-gate return (1);
7240Sstevel@tonic-gate
7250Sstevel@tonic-gate return (0);
7260Sstevel@tonic-gate }
7270Sstevel@tonic-gate
7280Sstevel@tonic-gate static rctl_ops_t project_semmni_ops = {
7290Sstevel@tonic-gate rcop_no_action,
7300Sstevel@tonic-gate rcop_no_usage,
7310Sstevel@tonic-gate rcop_no_set,
7320Sstevel@tonic-gate project_semmni_test
7330Sstevel@tonic-gate };
7340Sstevel@tonic-gate
7350Sstevel@tonic-gate /*
7360Sstevel@tonic-gate * project.max-msg-ids resource control support.
7370Sstevel@tonic-gate */
7380Sstevel@tonic-gate
7390Sstevel@tonic-gate /*ARGSUSED*/
7400Sstevel@tonic-gate static int
project_msgmni_test(struct rctl * rctl,struct proc * p,rctl_entity_p_t * e,rctl_val_t * rval,rctl_qty_t inc,uint_t flags)7410Sstevel@tonic-gate project_msgmni_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e,
7420Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags)
7430Sstevel@tonic-gate {
7440Sstevel@tonic-gate rctl_qty_t v;
7450Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
7460Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
7472677Sml93401 v = e->rcep_p.proj->kpj_data.kpd_ipc.ipcq_msgmni + inc;
7480Sstevel@tonic-gate if (v > rval->rcv_value)
7490Sstevel@tonic-gate return (1);
7500Sstevel@tonic-gate
7510Sstevel@tonic-gate return (0);
7520Sstevel@tonic-gate }
7530Sstevel@tonic-gate
7540Sstevel@tonic-gate static rctl_ops_t project_msgmni_ops = {
7550Sstevel@tonic-gate rcop_no_action,
7560Sstevel@tonic-gate rcop_no_usage,
7570Sstevel@tonic-gate rcop_no_set,
7580Sstevel@tonic-gate project_msgmni_test
7590Sstevel@tonic-gate };
7600Sstevel@tonic-gate
7612768Ssl108498 /*ARGSUSED*/
7622768Ssl108498 static rctl_qty_t
project_locked_mem_usage(rctl_t * rctl,struct proc * p)7632768Ssl108498 project_locked_mem_usage(rctl_t *rctl, struct proc *p)
7642768Ssl108498 {
7652768Ssl108498 rctl_qty_t q;
7662768Ssl108498 ASSERT(MUTEX_HELD(&p->p_lock));
7673247Sgjelinek mutex_enter(&p->p_zone->zone_mem_lock);
7682768Ssl108498 q = p->p_task->tk_proj->kpj_data.kpd_locked_mem;
7693247Sgjelinek mutex_exit(&p->p_zone->zone_mem_lock);
7702768Ssl108498 return (q);
7712768Ssl108498 }
7720Sstevel@tonic-gate
7730Sstevel@tonic-gate /*ARGSUSED*/
7740Sstevel@tonic-gate static int
project_locked_mem_test(struct rctl * rctl,struct proc * p,rctl_entity_p_t * e,rctl_val_t * rval,rctl_qty_t inc,uint_t flags)7752768Ssl108498 project_locked_mem_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e,
7760Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags)
7770Sstevel@tonic-gate {
7782768Ssl108498 rctl_qty_t q;
7790Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
7803247Sgjelinek ASSERT(MUTEX_HELD(&p->p_zone->zone_mem_lock));
7812768Ssl108498 q = p->p_task->tk_proj->kpj_data.kpd_locked_mem;
7822768Ssl108498 if (q + inc > rval->rcv_value)
7830Sstevel@tonic-gate return (1);
7840Sstevel@tonic-gate return (0);
7850Sstevel@tonic-gate }
7860Sstevel@tonic-gate
7872768Ssl108498 /*ARGSUSED*/
7882768Ssl108498 static int
project_locked_mem_set(rctl_t * rctl,struct proc * p,rctl_entity_p_t * e,rctl_qty_t nv)7892768Ssl108498 project_locked_mem_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e,
7902768Ssl108498 rctl_qty_t nv) {
7912768Ssl108498
7922768Ssl108498 ASSERT(MUTEX_HELD(&p->p_lock));
7932768Ssl108498 ASSERT(e->rcep_t == RCENTITY_PROJECT);
7942768Ssl108498 if (e->rcep_p.proj == NULL)
7952768Ssl108498 return (0);
7962768Ssl108498
7972768Ssl108498 e->rcep_p.proj->kpj_data.kpd_locked_mem_ctl = nv;
7982768Ssl108498 return (0);
7992768Ssl108498 }
8002768Ssl108498
8012768Ssl108498 static rctl_ops_t project_locked_mem_ops = {
8020Sstevel@tonic-gate rcop_no_action,
8032768Ssl108498 project_locked_mem_usage,
8042768Ssl108498 project_locked_mem_set,
8052768Ssl108498 project_locked_mem_test
8060Sstevel@tonic-gate };
8070Sstevel@tonic-gate
8080Sstevel@tonic-gate /*
8090Sstevel@tonic-gate * project.max-contracts resource control support.
8100Sstevel@tonic-gate */
8110Sstevel@tonic-gate
8120Sstevel@tonic-gate /*ARGSUSED*/
8130Sstevel@tonic-gate static int
project_contract_test(struct rctl * rctl,struct proc * p,rctl_entity_p_t * e,rctl_val_t * rval,rctl_qty_t inc,uint_t flags)8140Sstevel@tonic-gate project_contract_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e,
8150Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags)
8160Sstevel@tonic-gate {
8170Sstevel@tonic-gate rctl_qty_t v;
8180Sstevel@tonic-gate
8190Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
8200Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
8210Sstevel@tonic-gate
8220Sstevel@tonic-gate v = e->rcep_p.proj->kpj_data.kpd_contract + inc;
8230Sstevel@tonic-gate
8240Sstevel@tonic-gate if ((p->p_task != NULL) && (p->p_task->tk_proj) != NULL &&
8250Sstevel@tonic-gate (v > rval->rcv_value))
8260Sstevel@tonic-gate return (1);
8270Sstevel@tonic-gate
8280Sstevel@tonic-gate return (0);
8290Sstevel@tonic-gate }
8300Sstevel@tonic-gate
8310Sstevel@tonic-gate static rctl_ops_t project_contract_ops = {
8320Sstevel@tonic-gate rcop_no_action,
8330Sstevel@tonic-gate rcop_no_usage,
8340Sstevel@tonic-gate rcop_no_set,
8350Sstevel@tonic-gate project_contract_test
8360Sstevel@tonic-gate };
8370Sstevel@tonic-gate
8380Sstevel@tonic-gate /*ARGSUSED*/
8393620Skrishna static rctl_qty_t
project_crypto_usage(rctl_t * r,proc_t * p)8403620Skrishna project_crypto_usage(rctl_t *r, proc_t *p)
8413620Skrishna {
8423620Skrishna ASSERT(MUTEX_HELD(&p->p_lock));
8433620Skrishna return (p->p_task->tk_proj->kpj_data.kpd_crypto_mem);
8443620Skrishna }
8453620Skrishna
8463620Skrishna /*ARGSUSED*/
8473620Skrishna static int
project_crypto_set(rctl_t * r,proc_t * p,rctl_entity_p_t * e,rctl_qty_t nv)8483620Skrishna project_crypto_set(rctl_t *r, proc_t *p, rctl_entity_p_t *e,
8493620Skrishna rctl_qty_t nv)
8503620Skrishna {
8513620Skrishna ASSERT(MUTEX_HELD(&p->p_lock));
8523620Skrishna ASSERT(e->rcep_t == RCENTITY_PROJECT);
8533620Skrishna if (e->rcep_p.proj == NULL)
8543620Skrishna return (0);
8553620Skrishna
8563620Skrishna e->rcep_p.proj->kpj_data.kpd_crypto_mem_ctl = nv;
8573620Skrishna return (0);
8583620Skrishna }
8593620Skrishna
8603620Skrishna /*ARGSUSED*/
8610Sstevel@tonic-gate static int
project_crypto_test(rctl_t * r,proc_t * p,rctl_entity_p_t * e,rctl_val_t * rval,rctl_qty_t incr,uint_t flags)8620Sstevel@tonic-gate project_crypto_test(rctl_t *r, proc_t *p, rctl_entity_p_t *e,
8630Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t incr, uint_t flags)
8640Sstevel@tonic-gate {
8650Sstevel@tonic-gate rctl_qty_t v;
8660Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock));
8670Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT);
8680Sstevel@tonic-gate v = e->rcep_p.proj->kpj_data.kpd_crypto_mem + incr;
8690Sstevel@tonic-gate if (v > rval->rcv_value)
8700Sstevel@tonic-gate return (1);
8710Sstevel@tonic-gate return (0);
8720Sstevel@tonic-gate }
8730Sstevel@tonic-gate
8740Sstevel@tonic-gate static rctl_ops_t project_crypto_mem_ops = {
8750Sstevel@tonic-gate rcop_no_action,
8763620Skrishna project_crypto_usage,
8773620Skrishna project_crypto_set,
8780Sstevel@tonic-gate project_crypto_test
8790Sstevel@tonic-gate };
8800Sstevel@tonic-gate
8810Sstevel@tonic-gate /*
8820Sstevel@tonic-gate * void project_init(void)
8830Sstevel@tonic-gate *
8840Sstevel@tonic-gate * Overview
8850Sstevel@tonic-gate * Initialize the project subsystem, including the primordial project 0 entry.
8860Sstevel@tonic-gate * Register generic project resource controls, if any.
8870Sstevel@tonic-gate *
8880Sstevel@tonic-gate * Return values
8890Sstevel@tonic-gate * None.
8900Sstevel@tonic-gate *
8910Sstevel@tonic-gate * Caller's context
8920Sstevel@tonic-gate * Safe for KM_SLEEP allocations.
8930Sstevel@tonic-gate */
8940Sstevel@tonic-gate void
project_init(void)8950Sstevel@tonic-gate project_init(void)
8960Sstevel@tonic-gate {
8970Sstevel@tonic-gate rctl_qty_t shmmni, shmmax, qty;
8980Sstevel@tonic-gate boolean_t check;
8990Sstevel@tonic-gate
9000Sstevel@tonic-gate projects_hash = mod_hash_create_extended("projects_hash",
9010Sstevel@tonic-gate project_hash_size, mod_hash_null_keydtor, project_hash_val_dtor,
9020Sstevel@tonic-gate project_hash_by_id,
9030Sstevel@tonic-gate (void *)(uintptr_t)mod_hash_iddata_gen(project_hash_size),
9040Sstevel@tonic-gate project_hash_key_cmp, KM_SLEEP);
9050Sstevel@tonic-gate
9060Sstevel@tonic-gate rc_project_cpu_shares = rctl_register("project.cpu-shares",
9070Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_SIGNAL_NEVER |
9080Sstevel@tonic-gate RCTL_GLOBAL_DENY_NEVER | RCTL_GLOBAL_NOBASIC |
9091996Sml93401 RCTL_GLOBAL_COUNT | RCTL_GLOBAL_SYSLOG_NEVER,
9101996Sml93401 FSS_MAXSHARES, FSS_MAXSHARES,
9110Sstevel@tonic-gate &project_cpu_shares_ops);
9120Sstevel@tonic-gate rctl_add_default_limit("project.cpu-shares", 1, RCPRIV_PRIVILEGED,
9130Sstevel@tonic-gate RCTL_LOCAL_NOACTION);
9140Sstevel@tonic-gate
9153792Sakolb rc_project_cpu_cap = rctl_register("project.cpu-cap",
9163792Sakolb RCENTITY_PROJECT, RCTL_GLOBAL_SIGNAL_NEVER |
9173792Sakolb RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC |
9183792Sakolb RCTL_GLOBAL_COUNT | RCTL_GLOBAL_SYSLOG_NEVER |
9193792Sakolb RCTL_GLOBAL_INFINITE,
9203792Sakolb MAXCAP, MAXCAP, &project_cpu_cap_ops);
9213792Sakolb
9220Sstevel@tonic-gate rc_project_nlwps = rctl_register("project.max-lwps", RCENTITY_PROJECT,
9230Sstevel@tonic-gate RCTL_GLOBAL_NOACTION | RCTL_GLOBAL_NOBASIC | RCTL_GLOBAL_COUNT,
9240Sstevel@tonic-gate INT_MAX, INT_MAX, &project_lwps_ops);
9250Sstevel@tonic-gate
926*12725SMenno.Lageman@Sun.COM rc_project_nprocs = rctl_register("project.max-processes",
927*12725SMenno.Lageman@Sun.COM RCENTITY_PROJECT, RCTL_GLOBAL_NOACTION | RCTL_GLOBAL_NOBASIC |
928*12725SMenno.Lageman@Sun.COM RCTL_GLOBAL_COUNT, INT_MAX, INT_MAX, &project_procs_ops);
929*12725SMenno.Lageman@Sun.COM
9300Sstevel@tonic-gate rc_project_ntasks = rctl_register("project.max-tasks", RCENTITY_PROJECT,
9310Sstevel@tonic-gate RCTL_GLOBAL_NOACTION | RCTL_GLOBAL_NOBASIC | RCTL_GLOBAL_COUNT,
9320Sstevel@tonic-gate INT_MAX, INT_MAX, &project_tasks_ops);
9330Sstevel@tonic-gate
9340Sstevel@tonic-gate /*
9350Sstevel@tonic-gate * This rctl handle is used by /dev/crypto. It is here rather than
9360Sstevel@tonic-gate * in misc/kcf or the drv/crypto module because resource controls
9370Sstevel@tonic-gate * currently don't allow modules to be unloaded, and the control
9380Sstevel@tonic-gate * must be registered before init starts.
9390Sstevel@tonic-gate */
9400Sstevel@tonic-gate rc_project_crypto_mem = rctl_register("project.max-crypto-memory",
9410Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC |
9420Sstevel@tonic-gate RCTL_GLOBAL_BYTES, UINT64_MAX, UINT64_MAX,
9430Sstevel@tonic-gate &project_crypto_mem_ops);
9440Sstevel@tonic-gate
9450Sstevel@tonic-gate /*
9460Sstevel@tonic-gate * Default to a quarter of the machine's memory
9470Sstevel@tonic-gate */
9480Sstevel@tonic-gate qty = availrmem_initial << (PAGESHIFT - 2);
9490Sstevel@tonic-gate rctl_add_default_limit("project.max-crypto-memory", qty,
9500Sstevel@tonic-gate RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY);
9510Sstevel@tonic-gate
9520Sstevel@tonic-gate /*
9530Sstevel@tonic-gate * System V IPC resource controls
9540Sstevel@tonic-gate */
9550Sstevel@tonic-gate rc_project_semmni = rctl_register("project.max-sem-ids",
9560Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC |
9570Sstevel@tonic-gate RCTL_GLOBAL_COUNT, IPC_IDS_MAX, IPC_IDS_MAX, &project_semmni_ops);
9580Sstevel@tonic-gate rctl_add_legacy_limit("project.max-sem-ids", "semsys",
9590Sstevel@tonic-gate "seminfo_semmni", 128, IPC_IDS_MAX);
9600Sstevel@tonic-gate
9610Sstevel@tonic-gate rc_project_msgmni = rctl_register("project.max-msg-ids",
9620Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC |
9630Sstevel@tonic-gate RCTL_GLOBAL_COUNT, IPC_IDS_MAX, IPC_IDS_MAX, &project_msgmni_ops);
9640Sstevel@tonic-gate rctl_add_legacy_limit("project.max-msg-ids", "msgsys",
9650Sstevel@tonic-gate "msginfo_msgmni", 128, IPC_IDS_MAX);
9660Sstevel@tonic-gate
9670Sstevel@tonic-gate rc_project_shmmni = rctl_register("project.max-shm-ids",
9680Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC |
9690Sstevel@tonic-gate RCTL_GLOBAL_COUNT, IPC_IDS_MAX, IPC_IDS_MAX, &project_shmmni_ops);
9700Sstevel@tonic-gate rctl_add_legacy_limit("project.max-shm-ids", "shmsys",
9710Sstevel@tonic-gate "shminfo_shmmni", 128, IPC_IDS_MAX);
9720Sstevel@tonic-gate
9730Sstevel@tonic-gate rc_project_shmmax = rctl_register("project.max-shm-memory",
9740Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC |
9750Sstevel@tonic-gate RCTL_GLOBAL_BYTES, UINT64_MAX, UINT64_MAX, &project_shmmax_ops);
9760Sstevel@tonic-gate
9770Sstevel@tonic-gate check = B_FALSE;
9780Sstevel@tonic-gate if (!mod_sysvar("shmsys", "shminfo_shmmni", &shmmni))
9790Sstevel@tonic-gate shmmni = 100;
9800Sstevel@tonic-gate else
9810Sstevel@tonic-gate check = B_TRUE;
9820Sstevel@tonic-gate if (!mod_sysvar("shmsys", "shminfo_shmmax", &shmmax))
9830Sstevel@tonic-gate shmmax = 0x800000;
9840Sstevel@tonic-gate else
9850Sstevel@tonic-gate check = B_TRUE;
9860Sstevel@tonic-gate
9870Sstevel@tonic-gate /*
9880Sstevel@tonic-gate * Default to a quarter of the machine's memory
9890Sstevel@tonic-gate */
9900Sstevel@tonic-gate qty = availrmem_initial << (PAGESHIFT - 2);
9910Sstevel@tonic-gate if (check) {
9920Sstevel@tonic-gate if ((shmmax > 0) && (UINT64_MAX / shmmax <= shmmni))
9930Sstevel@tonic-gate qty = UINT64_MAX;
9940Sstevel@tonic-gate else if (shmmni * shmmax > qty)
9950Sstevel@tonic-gate qty = shmmni * shmmax;
9960Sstevel@tonic-gate }
9970Sstevel@tonic-gate rctl_add_default_limit("project.max-shm-memory", qty,
9980Sstevel@tonic-gate RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY);
9990Sstevel@tonic-gate
10000Sstevel@tonic-gate /*
10010Sstevel@tonic-gate * Event Ports resource controls
10020Sstevel@tonic-gate */
10030Sstevel@tonic-gate
10040Sstevel@tonic-gate rc_project_portids = rctl_register("project.max-port-ids",
10050Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC |
10060Sstevel@tonic-gate RCTL_GLOBAL_COUNT, PORT_MAX_PORTS, PORT_MAX_PORTS,
10070Sstevel@tonic-gate &rctl_absolute_ops);
10080Sstevel@tonic-gate rctl_add_default_limit("project.max-port-ids", PORT_DEFAULT_PORTS,
10090Sstevel@tonic-gate RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY);
10100Sstevel@tonic-gate
10110Sstevel@tonic-gate /*
10120Sstevel@tonic-gate * Resource control for locked memory
10130Sstevel@tonic-gate */
10142768Ssl108498 rc_project_locked_mem = rctl_register(
10152768Ssl108498 "project.max-locked-memory", RCENTITY_PROJECT,
10160Sstevel@tonic-gate RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC | RCTL_GLOBAL_BYTES,
10172768Ssl108498 UINT64_MAX, UINT64_MAX, &project_locked_mem_ops);
10180Sstevel@tonic-gate
10190Sstevel@tonic-gate /*
10200Sstevel@tonic-gate * Per project limit on contracts.
10210Sstevel@tonic-gate */
10220Sstevel@tonic-gate rc_project_contract = rctl_register("project.max-contracts",
10233684Srd117015 RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC |
10243684Srd117015 RCTL_GLOBAL_COUNT, INT_MAX, INT_MAX, &project_contract_ops);
10250Sstevel@tonic-gate rctl_add_default_limit("project.max-contracts", 10000,
10260Sstevel@tonic-gate RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY);
10270Sstevel@tonic-gate
10283247Sgjelinek t0.t_proj = proj0p = project_hold_by_id(0, &zone0,
10290Sstevel@tonic-gate PROJECT_HOLD_INSERT);
10300Sstevel@tonic-gate
10310Sstevel@tonic-gate mutex_enter(&p0.p_lock);
10320Sstevel@tonic-gate proj0p->kpj_nlwps = p0.p_lwpcnt;
10330Sstevel@tonic-gate mutex_exit(&p0.p_lock);
1034*12725SMenno.Lageman@Sun.COM proj0p->kpj_nprocs = 1;
10350Sstevel@tonic-gate proj0p->kpj_ntasks = 1;
10360Sstevel@tonic-gate }
10373247Sgjelinek
10383247Sgjelinek static int
project_lockedmem_kstat_update(kstat_t * ksp,int rw)10393247Sgjelinek project_lockedmem_kstat_update(kstat_t *ksp, int rw)
10403247Sgjelinek {
10413247Sgjelinek kproject_t *pj = ksp->ks_private;
10423247Sgjelinek kproject_kstat_t *kpk = ksp->ks_data;
10433247Sgjelinek
10443247Sgjelinek if (rw == KSTAT_WRITE)
10453247Sgjelinek return (EACCES);
10463247Sgjelinek
10473247Sgjelinek kpk->kpk_usage.value.ui64 = pj->kpj_data.kpd_locked_mem;
10483247Sgjelinek kpk->kpk_value.value.ui64 = pj->kpj_data.kpd_locked_mem_ctl;
10493247Sgjelinek return (0);
10503247Sgjelinek }
10513247Sgjelinek
1052*12725SMenno.Lageman@Sun.COM static int
project_nprocs_kstat_update(kstat_t * ksp,int rw)1053*12725SMenno.Lageman@Sun.COM project_nprocs_kstat_update(kstat_t *ksp, int rw)
1054*12725SMenno.Lageman@Sun.COM {
1055*12725SMenno.Lageman@Sun.COM kproject_t *pj = ksp->ks_private;
1056*12725SMenno.Lageman@Sun.COM kproject_kstat_t *kpk = ksp->ks_data;
1057*12725SMenno.Lageman@Sun.COM
1058*12725SMenno.Lageman@Sun.COM if (rw == KSTAT_WRITE)
1059*12725SMenno.Lageman@Sun.COM return (EACCES);
1060*12725SMenno.Lageman@Sun.COM
1061*12725SMenno.Lageman@Sun.COM kpk->kpk_usage.value.ui64 = pj->kpj_nprocs;
1062*12725SMenno.Lageman@Sun.COM kpk->kpk_value.value.ui64 = pj->kpj_nprocs_ctl;
1063*12725SMenno.Lageman@Sun.COM return (0);
1064*12725SMenno.Lageman@Sun.COM }
1065*12725SMenno.Lageman@Sun.COM
10663247Sgjelinek static kstat_t *
project_kstat_create_common(kproject_t * pj,char * name,char * zonename,int (* updatefunc)(kstat_t *,int))1067*12725SMenno.Lageman@Sun.COM project_kstat_create_common(kproject_t *pj, char *name, char *zonename,
1068*12725SMenno.Lageman@Sun.COM int (*updatefunc) (kstat_t *, int))
10693247Sgjelinek {
10703247Sgjelinek kstat_t *ksp;
10713247Sgjelinek kproject_kstat_t *kpk;
10723247Sgjelinek
1073*12725SMenno.Lageman@Sun.COM ksp = rctl_kstat_create_project(pj, name, KSTAT_TYPE_NAMED,
10743247Sgjelinek sizeof (kproject_kstat_t) / sizeof (kstat_named_t),
10753247Sgjelinek KSTAT_FLAG_VIRTUAL);
10763247Sgjelinek
10773247Sgjelinek if (ksp == NULL)
10783247Sgjelinek return (NULL);
10793247Sgjelinek
10803247Sgjelinek kpk = ksp->ks_data = kmem_alloc(sizeof (kproject_kstat_t), KM_SLEEP);
10813247Sgjelinek ksp->ks_data_size += strlen(zonename) + 1;
10823247Sgjelinek kstat_named_init(&kpk->kpk_zonename, "zonename", KSTAT_DATA_STRING);
10833247Sgjelinek kstat_named_setstr(&kpk->kpk_zonename, zonename);
10843247Sgjelinek kstat_named_init(&kpk->kpk_usage, "usage", KSTAT_DATA_UINT64);
10853247Sgjelinek kstat_named_init(&kpk->kpk_value, "value", KSTAT_DATA_UINT64);
1086*12725SMenno.Lageman@Sun.COM ksp->ks_update = updatefunc;
10873247Sgjelinek ksp->ks_private = pj;
10883247Sgjelinek kstat_install(ksp);
1089*12725SMenno.Lageman@Sun.COM return (ksp);
1090*12725SMenno.Lageman@Sun.COM }
10913247Sgjelinek
1092*12725SMenno.Lageman@Sun.COM static void
project_kstat_create(kproject_t * pj,zone_t * zone)1093*12725SMenno.Lageman@Sun.COM project_kstat_create(kproject_t *pj, zone_t *zone)
1094*12725SMenno.Lageman@Sun.COM {
1095*12725SMenno.Lageman@Sun.COM kstat_t *ksp_lockedmem;
1096*12725SMenno.Lageman@Sun.COM kstat_t *ksp_nprocs;
1097*12725SMenno.Lageman@Sun.COM
1098*12725SMenno.Lageman@Sun.COM ksp_lockedmem = project_kstat_create_common(pj, "lockedmem",
1099*12725SMenno.Lageman@Sun.COM zone->zone_name, project_lockedmem_kstat_update);
1100*12725SMenno.Lageman@Sun.COM ksp_nprocs = project_kstat_create_common(pj, "nprocs",
1101*12725SMenno.Lageman@Sun.COM zone->zone_name, project_nprocs_kstat_update);
1102*12725SMenno.Lageman@Sun.COM
1103*12725SMenno.Lageman@Sun.COM mutex_enter(&project_hash_lock);
1104*12725SMenno.Lageman@Sun.COM ASSERT(pj->kpj_data.kpd_lockedmem_kstat == NULL);
1105*12725SMenno.Lageman@Sun.COM pj->kpj_data.kpd_lockedmem_kstat = ksp_lockedmem;
1106*12725SMenno.Lageman@Sun.COM ASSERT(pj->kpj_data.kpd_nprocs_kstat == NULL);
1107*12725SMenno.Lageman@Sun.COM pj->kpj_data.kpd_nprocs_kstat = ksp_nprocs;
1108*12725SMenno.Lageman@Sun.COM mutex_exit(&project_hash_lock);
1109*12725SMenno.Lageman@Sun.COM }
1110*12725SMenno.Lageman@Sun.COM
1111*12725SMenno.Lageman@Sun.COM static void
project_kstat_delete_common(kstat_t ** kstat)1112*12725SMenno.Lageman@Sun.COM project_kstat_delete_common(kstat_t **kstat)
1113*12725SMenno.Lageman@Sun.COM {
1114*12725SMenno.Lageman@Sun.COM void *data;
1115*12725SMenno.Lageman@Sun.COM
1116*12725SMenno.Lageman@Sun.COM if (*kstat != NULL) {
1117*12725SMenno.Lageman@Sun.COM data = (*kstat)->ks_data;
1118*12725SMenno.Lageman@Sun.COM kstat_delete(*kstat);
1119*12725SMenno.Lageman@Sun.COM kmem_free(data, sizeof (kproject_kstat_t));
1120*12725SMenno.Lageman@Sun.COM *kstat = NULL;
1121*12725SMenno.Lageman@Sun.COM }
11223247Sgjelinek }
11233247Sgjelinek
11243247Sgjelinek static void
project_kstat_delete(kproject_t * pj)11253247Sgjelinek project_kstat_delete(kproject_t *pj)
11263247Sgjelinek {
1127*12725SMenno.Lageman@Sun.COM project_kstat_delete_common(&pj->kpj_data.kpd_lockedmem_kstat);
1128*12725SMenno.Lageman@Sun.COM project_kstat_delete_common(&pj->kpj_data.kpd_nprocs_kstat);
11293247Sgjelinek }
1130