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*6890d023SEric Saxe * Copyright 2008 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 #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/processor.h> 317c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 327c478bd9Sstevel@tonic-gate #include <sys/disp.h> 337c478bd9Sstevel@tonic-gate #include <sys/pset.h> 347c478bd9Sstevel@tonic-gate #include <sys/lgrp.h> 357c478bd9Sstevel@tonic-gate #include <sys/lgrp_user.h> 36fb2f18f8Sesaxe #include <sys/pg.h> 37fb2f18f8Sesaxe #include <sys/bitset.h> 387c478bd9Sstevel@tonic-gate #include <sys/time.h> 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #ifdef __cplusplus 417c478bd9Sstevel@tonic-gate extern "C" { 427c478bd9Sstevel@tonic-gate #endif 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #ifdef _KERNEL 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate typedef int cpupartid_t; 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* 497c478bd9Sstevel@tonic-gate * Special partition id. 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate #define CP_DEFAULT 0 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * Flags for cpupart_list() 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate #define CP_ALL 0 /* return all cpu partitions */ 577c478bd9Sstevel@tonic-gate #define CP_NONEMPTY 1 /* return only non-empty ones */ 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate typedef struct cpupart { 607c478bd9Sstevel@tonic-gate disp_t cp_kp_queue; /* partition-wide kpreempt queue */ 617c478bd9Sstevel@tonic-gate cpupartid_t cp_id; /* partition ID */ 627c478bd9Sstevel@tonic-gate int cp_ncpus; /* number of online processors */ 637c478bd9Sstevel@tonic-gate struct cpupart *cp_next; /* next partition in list */ 647c478bd9Sstevel@tonic-gate struct cpupart *cp_prev; /* previous partition in list */ 657c478bd9Sstevel@tonic-gate struct cpu *cp_cpulist; /* processor list */ 667c478bd9Sstevel@tonic-gate struct kstat *cp_kstat; /* per-partition statistics */ 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * cp_nrunnable and cp_nrunning are used to calculate load average. 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate uint_t cp_nrunnable; /* current # of runnable threads */ 727c478bd9Sstevel@tonic-gate uint_t cp_nrunning; /* current # of running threads */ 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * cp_updates, cp_nrunnable_cum, cp_nwaiting_cum, and cp_hp_avenrun 767c478bd9Sstevel@tonic-gate * are used to generate kstat information on an as-needed basis. 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate uint64_t cp_updates; /* number of statistics updates */ 797c478bd9Sstevel@tonic-gate uint64_t cp_nrunnable_cum; /* cum. # of runnable threads */ 807c478bd9Sstevel@tonic-gate uint64_t cp_nwaiting_cum; /* cum. # of waiting threads */ 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate struct loadavg_s cp_loadavg; /* cpupart loadavg */ 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate klgrpset_t cp_lgrpset; /* set of lgroups on which this */ 857c478bd9Sstevel@tonic-gate /* partition has cpus */ 867c478bd9Sstevel@tonic-gate lpl_t *cp_lgrploads; /* table of load averages for this */ 877c478bd9Sstevel@tonic-gate /* partition, indexed by lgrp ID */ 887c478bd9Sstevel@tonic-gate int cp_nlgrploads; /* size of cp_lgrploads table */ 897c478bd9Sstevel@tonic-gate uint64_t cp_hp_avenrun[3]; /* high-precision load average */ 907c478bd9Sstevel@tonic-gate uint_t cp_attr; /* bitmask of attributes */ 917c478bd9Sstevel@tonic-gate lgrp_gen_t cp_gen; /* generation number */ 927c478bd9Sstevel@tonic-gate lgrp_id_t cp_lgrp_hint; /* last home lgroup chosen */ 93fb2f18f8Sesaxe bitset_t cp_cmt_pgs; /* CMT PGs represented */ 94*6890d023SEric Saxe bitset_t cp_haltset; /* halted CPUs */ 957c478bd9Sstevel@tonic-gate } cpupart_t; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate typedef struct cpupart_kstat { 987c478bd9Sstevel@tonic-gate kstat_named_t cpk_updates; /* number of updates */ 997c478bd9Sstevel@tonic-gate kstat_named_t cpk_runnable; /* cum # of runnable threads */ 1007c478bd9Sstevel@tonic-gate kstat_named_t cpk_waiting; /* cum # waiting for I/O */ 1017c478bd9Sstevel@tonic-gate kstat_named_t cpk_ncpus; /* current # of CPUs */ 1027c478bd9Sstevel@tonic-gate kstat_named_t cpk_avenrun_1min; /* 1-minute load average */ 1037c478bd9Sstevel@tonic-gate kstat_named_t cpk_avenrun_5min; /* 5-minute load average */ 1047c478bd9Sstevel@tonic-gate kstat_named_t cpk_avenrun_15min; /* 15-minute load average */ 1057c478bd9Sstevel@tonic-gate } cpupart_kstat_t; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * Macro to obtain the maximum run priority for the global queue associated 1097c478bd9Sstevel@tonic-gate * with given cpu partition. 1107c478bd9Sstevel@tonic-gate */ 1117c478bd9Sstevel@tonic-gate #define CP_MAXRUNPRI(cp) ((cp)->cp_kp_queue.disp_maxrunpri) 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate /* 1147c478bd9Sstevel@tonic-gate * This macro is used to determine if the given thread must surrender 1157c478bd9Sstevel@tonic-gate * CPU to higher priority runnable threads on one of its dispatch queues. 1167c478bd9Sstevel@tonic-gate * This should really be defined in <sys/disp.h> but it is not because 1177c478bd9Sstevel@tonic-gate * including <sys/cpupart.h> there would cause recursive includes. 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate #define DISP_MUST_SURRENDER(t) \ 1207c478bd9Sstevel@tonic-gate ((DISP_MAXRUNPRI(t) > DISP_PRIO(t)) || \ 1217c478bd9Sstevel@tonic-gate (CP_MAXRUNPRI(t->t_cpupart) > DISP_PRIO(t))) 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate extern cpupart_t cp_default; 1247c478bd9Sstevel@tonic-gate extern cpupart_t *cp_list_head; 1257c478bd9Sstevel@tonic-gate extern uint_t cp_numparts; 1267c478bd9Sstevel@tonic-gate extern uint_t cp_numparts_nonempty; 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate extern void cpupart_initialize_default(); 1297c478bd9Sstevel@tonic-gate extern cpupart_t *cpupart_find(psetid_t); 1307c478bd9Sstevel@tonic-gate extern int cpupart_create(psetid_t *); 1317c478bd9Sstevel@tonic-gate extern int cpupart_destroy(psetid_t); 1327c478bd9Sstevel@tonic-gate extern psetid_t cpupart_query_cpu(cpu_t *); 1337c478bd9Sstevel@tonic-gate extern int cpupart_attach_cpu(psetid_t, cpu_t *, int); 1347c478bd9Sstevel@tonic-gate extern int cpupart_get_cpus(psetid_t *, processorid_t *, uint_t *); 1357c478bd9Sstevel@tonic-gate extern int cpupart_bind_thread(kthread_id_t, psetid_t, int, void *, 1367c478bd9Sstevel@tonic-gate void *); 1377c478bd9Sstevel@tonic-gate extern void cpupart_kpqalloc(pri_t); 1387c478bd9Sstevel@tonic-gate extern int cpupart_get_loadavg(psetid_t, int *, int); 1397c478bd9Sstevel@tonic-gate extern uint_t cpupart_list(psetid_t *, uint_t, int); 1407c478bd9Sstevel@tonic-gate extern int cpupart_setattr(psetid_t, uint_t); 1417c478bd9Sstevel@tonic-gate extern int cpupart_getattr(psetid_t, uint_t *); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate #endif 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate #endif /* _SYS_CPUPART_H */ 150