17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5e824d57fSjohnlev * Common Development and Distribution License (the "License"). 6e824d57fSjohnlev * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*fb2f18f8Sesaxe * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_CPUPART_H 277c478bd9Sstevel@tonic-gate #define _SYS_CPUPART_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/processor.h> 337c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 347c478bd9Sstevel@tonic-gate #include <sys/disp.h> 357c478bd9Sstevel@tonic-gate #include <sys/pset.h> 367c478bd9Sstevel@tonic-gate #include <sys/lgrp.h> 377c478bd9Sstevel@tonic-gate #include <sys/lgrp_user.h> 38*fb2f18f8Sesaxe #include <sys/pg.h> 39*fb2f18f8Sesaxe #include <sys/bitset.h> 407c478bd9Sstevel@tonic-gate #include <sys/time.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #ifdef __cplusplus 437c478bd9Sstevel@tonic-gate extern "C" { 447c478bd9Sstevel@tonic-gate #endif 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #ifdef _KERNEL 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate typedef int cpupartid_t; 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * Special partition id. 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate #define CP_DEFAULT 0 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * Flags for cpupart_list() 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate #define CP_ALL 0 /* return all cpu partitions */ 597c478bd9Sstevel@tonic-gate #define CP_NONEMPTY 1 /* return only non-empty ones */ 607c478bd9Sstevel@tonic-gate 61e824d57fSjohnlev #if defined(_MACHDEP) 62e824d57fSjohnlev struct mach_cpupart { 63e824d57fSjohnlev cpuset_t mc_haltset; 64e824d57fSjohnlev }; 65e824d57fSjohnlev 66e824d57fSjohnlev extern struct mach_cpupart cp_default_mach; 67e824d57fSjohnlev #else 68e824d57fSjohnlev struct mach_cpupart; 69e824d57fSjohnlev #endif 70e824d57fSjohnlev 717c478bd9Sstevel@tonic-gate typedef struct cpupart { 727c478bd9Sstevel@tonic-gate disp_t cp_kp_queue; /* partition-wide kpreempt queue */ 737c478bd9Sstevel@tonic-gate cpupartid_t cp_id; /* partition ID */ 747c478bd9Sstevel@tonic-gate int cp_ncpus; /* number of online processors */ 757c478bd9Sstevel@tonic-gate struct cpupart *cp_next; /* next partition in list */ 767c478bd9Sstevel@tonic-gate struct cpupart *cp_prev; /* previous partition in list */ 777c478bd9Sstevel@tonic-gate struct cpu *cp_cpulist; /* processor list */ 787c478bd9Sstevel@tonic-gate struct kstat *cp_kstat; /* per-partition statistics */ 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * cp_nrunnable and cp_nrunning are used to calculate load average. 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate uint_t cp_nrunnable; /* current # of runnable threads */ 847c478bd9Sstevel@tonic-gate uint_t cp_nrunning; /* current # of running threads */ 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * cp_updates, cp_nrunnable_cum, cp_nwaiting_cum, and cp_hp_avenrun 887c478bd9Sstevel@tonic-gate * are used to generate kstat information on an as-needed basis. 897c478bd9Sstevel@tonic-gate */ 907c478bd9Sstevel@tonic-gate uint64_t cp_updates; /* number of statistics updates */ 917c478bd9Sstevel@tonic-gate uint64_t cp_nrunnable_cum; /* cum. # of runnable threads */ 927c478bd9Sstevel@tonic-gate uint64_t cp_nwaiting_cum; /* cum. # of waiting threads */ 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate struct loadavg_s cp_loadavg; /* cpupart loadavg */ 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate klgrpset_t cp_lgrpset; /* set of lgroups on which this */ 977c478bd9Sstevel@tonic-gate /* partition has cpus */ 987c478bd9Sstevel@tonic-gate lpl_t *cp_lgrploads; /* table of load averages for this */ 997c478bd9Sstevel@tonic-gate /* partition, indexed by lgrp ID */ 1007c478bd9Sstevel@tonic-gate int cp_nlgrploads; /* size of cp_lgrploads table */ 1017c478bd9Sstevel@tonic-gate uint64_t cp_hp_avenrun[3]; /* high-precision load average */ 1027c478bd9Sstevel@tonic-gate uint_t cp_attr; /* bitmask of attributes */ 1037c478bd9Sstevel@tonic-gate lgrp_gen_t cp_gen; /* generation number */ 1047c478bd9Sstevel@tonic-gate lgrp_id_t cp_lgrp_hint; /* last home lgroup chosen */ 105*fb2f18f8Sesaxe bitset_t cp_cmt_pgs; /* CMT PGs represented */ 106e824d57fSjohnlev 107e824d57fSjohnlev struct mach_cpupart *cp_mach; /* mach-specific */ 1087c478bd9Sstevel@tonic-gate } cpupart_t; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate typedef struct cpupart_kstat { 1117c478bd9Sstevel@tonic-gate kstat_named_t cpk_updates; /* number of updates */ 1127c478bd9Sstevel@tonic-gate kstat_named_t cpk_runnable; /* cum # of runnable threads */ 1137c478bd9Sstevel@tonic-gate kstat_named_t cpk_waiting; /* cum # waiting for I/O */ 1147c478bd9Sstevel@tonic-gate kstat_named_t cpk_ncpus; /* current # of CPUs */ 1157c478bd9Sstevel@tonic-gate kstat_named_t cpk_avenrun_1min; /* 1-minute load average */ 1167c478bd9Sstevel@tonic-gate kstat_named_t cpk_avenrun_5min; /* 5-minute load average */ 1177c478bd9Sstevel@tonic-gate kstat_named_t cpk_avenrun_15min; /* 15-minute load average */ 1187c478bd9Sstevel@tonic-gate } cpupart_kstat_t; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* 1217c478bd9Sstevel@tonic-gate * Macro to obtain the maximum run priority for the global queue associated 1227c478bd9Sstevel@tonic-gate * with given cpu partition. 1237c478bd9Sstevel@tonic-gate */ 1247c478bd9Sstevel@tonic-gate #define CP_MAXRUNPRI(cp) ((cp)->cp_kp_queue.disp_maxrunpri) 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * This macro is used to determine if the given thread must surrender 1287c478bd9Sstevel@tonic-gate * CPU to higher priority runnable threads on one of its dispatch queues. 1297c478bd9Sstevel@tonic-gate * This should really be defined in <sys/disp.h> but it is not because 1307c478bd9Sstevel@tonic-gate * including <sys/cpupart.h> there would cause recursive includes. 1317c478bd9Sstevel@tonic-gate */ 1327c478bd9Sstevel@tonic-gate #define DISP_MUST_SURRENDER(t) \ 1337c478bd9Sstevel@tonic-gate ((DISP_MAXRUNPRI(t) > DISP_PRIO(t)) || \ 1347c478bd9Sstevel@tonic-gate (CP_MAXRUNPRI(t->t_cpupart) > DISP_PRIO(t))) 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate extern cpupart_t cp_default; 1377c478bd9Sstevel@tonic-gate extern cpupart_t *cp_list_head; 1387c478bd9Sstevel@tonic-gate extern uint_t cp_numparts; 1397c478bd9Sstevel@tonic-gate extern uint_t cp_numparts_nonempty; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate extern void cpupart_initialize_default(); 1427c478bd9Sstevel@tonic-gate extern cpupart_t *cpupart_find(psetid_t); 1437c478bd9Sstevel@tonic-gate extern int cpupart_create(psetid_t *); 1447c478bd9Sstevel@tonic-gate extern int cpupart_destroy(psetid_t); 1457c478bd9Sstevel@tonic-gate extern psetid_t cpupart_query_cpu(cpu_t *); 1467c478bd9Sstevel@tonic-gate extern int cpupart_attach_cpu(psetid_t, cpu_t *, int); 1477c478bd9Sstevel@tonic-gate extern int cpupart_get_cpus(psetid_t *, processorid_t *, uint_t *); 1487c478bd9Sstevel@tonic-gate extern int cpupart_bind_thread(kthread_id_t, psetid_t, int, void *, 1497c478bd9Sstevel@tonic-gate void *); 1507c478bd9Sstevel@tonic-gate extern void cpupart_kpqalloc(pri_t); 1517c478bd9Sstevel@tonic-gate extern int cpupart_get_loadavg(psetid_t, int *, int); 1527c478bd9Sstevel@tonic-gate extern uint_t cpupart_list(psetid_t *, uint_t, int); 1537c478bd9Sstevel@tonic-gate extern int cpupart_setattr(psetid_t, uint_t); 1547c478bd9Sstevel@tonic-gate extern int cpupart_getattr(psetid_t, uint_t *); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate #endif 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate #endif /* _SYS_CPUPART_H */ 163