1*35a5a358SJonathan Adams /* 2*35a5a358SJonathan Adams * CDDL HEADER START 3*35a5a358SJonathan Adams * 4*35a5a358SJonathan Adams * The contents of this file are subject to the terms of the 5*35a5a358SJonathan Adams * Common Development and Distribution License (the "License"). 6*35a5a358SJonathan Adams * You may not use this file except in compliance with the License. 7*35a5a358SJonathan Adams * 8*35a5a358SJonathan Adams * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*35a5a358SJonathan Adams * or http://www.opensolaris.org/os/licensing. 10*35a5a358SJonathan Adams * See the License for the specific language governing permissions 11*35a5a358SJonathan Adams * and limitations under the License. 12*35a5a358SJonathan Adams * 13*35a5a358SJonathan Adams * When distributing Covered Code, include this CDDL HEADER in each 14*35a5a358SJonathan Adams * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*35a5a358SJonathan Adams * If applicable, add the following below this CDDL HEADER, with the 16*35a5a358SJonathan Adams * fields enclosed by brackets "[]" replaced with your own identifying 17*35a5a358SJonathan Adams * information: Portions Copyright [yyyy] [name of copyright owner] 18*35a5a358SJonathan Adams * 19*35a5a358SJonathan Adams * CDDL HEADER END 20*35a5a358SJonathan Adams */ 21*35a5a358SJonathan Adams /* 22*35a5a358SJonathan Adams * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23*35a5a358SJonathan Adams * Use is subject to license terms. 24*35a5a358SJonathan Adams */ 25*35a5a358SJonathan Adams 26*35a5a358SJonathan Adams #ifndef _SYS_SYSDC_IMPL_H 27*35a5a358SJonathan Adams #define _SYS_SYSDC_IMPL_H 28*35a5a358SJonathan Adams 29*35a5a358SJonathan Adams #include <sys/types.h> 30*35a5a358SJonathan Adams #include <sys/time.h> 31*35a5a358SJonathan Adams #include <sys/list.h> 32*35a5a358SJonathan Adams 33*35a5a358SJonathan Adams #include <sys/sysdc.h> 34*35a5a358SJonathan Adams 35*35a5a358SJonathan Adams #ifdef __cplusplus 36*35a5a358SJonathan Adams extern "C" { 37*35a5a358SJonathan Adams #endif 38*35a5a358SJonathan Adams 39*35a5a358SJonathan Adams struct _kthread; 40*35a5a358SJonathan Adams struct cpupart; 41*35a5a358SJonathan Adams 42*35a5a358SJonathan Adams /* 43*35a5a358SJonathan Adams * Tracks per-processor-set information for SDC. Its main use is to 44*35a5a358SJonathan Adams * implement per-processor-set breaks. 45*35a5a358SJonathan Adams */ 46*35a5a358SJonathan Adams typedef struct sysdc_pset { 47*35a5a358SJonathan Adams list_node_t sdp_node; /* node on sysdc_psets list */ 48*35a5a358SJonathan Adams struct cpupart *sdp_cpupart; /* associated cpu partition */ 49*35a5a358SJonathan Adams size_t sdp_nthreads; /* reference count */ 50*35a5a358SJonathan Adams 51*35a5a358SJonathan Adams /* The remainder is only touched by sysdc_update() */ 52*35a5a358SJonathan Adams hrtime_t sdp_onproc_time; /* time onproc at last update */ 53*35a5a358SJonathan Adams boolean_t sdp_need_break; /* threads forced to minpri */ 54*35a5a358SJonathan Adams uint_t sdp_should_break; /* # updates need_break is set */ 55*35a5a358SJonathan Adams uint_t sdp_dont_break; /* after break, # updates until next */ 56*35a5a358SJonathan Adams 57*35a5a358SJonathan Adams /* debugging fields */ 58*35a5a358SJonathan Adams uint_t sdp_onproc_threads; 59*35a5a358SJonathan Adams hrtime_t sdp_vtime_last_interval; 60*35a5a358SJonathan Adams uint_t sdp_DC_last_interval; 61*35a5a358SJonathan Adams } sysdc_pset_t; 62*35a5a358SJonathan Adams 63*35a5a358SJonathan Adams /* 64*35a5a358SJonathan Adams * Per-thread information, pointed to by t_cldata. 65*35a5a358SJonathan Adams */ 66*35a5a358SJonathan Adams typedef struct sysdc { 67*35a5a358SJonathan Adams uint_t sdc_target_DC; /* target duty cycle */ 68*35a5a358SJonathan Adams uint_t sdc_minpri; /* our minimum priority */ 69*35a5a358SJonathan Adams uint_t sdc_maxpri; /* our maximum priority */ 70*35a5a358SJonathan Adams 71*35a5a358SJonathan Adams sysdc_pset_t *sdc_pset; /* the processor set bound to */ 72*35a5a358SJonathan Adams 73*35a5a358SJonathan Adams /* protected by sdl_lock */ 74*35a5a358SJonathan Adams struct _kthread *sdc_thread; /* back-pointer, or NULL if freeable */ 75*35a5a358SJonathan Adams 76*35a5a358SJonathan Adams /* protected by arrangement between thread and sysdc_update() */ 77*35a5a358SJonathan Adams struct sysdc *sdc_next; /* next in hash table, NULL if not in */ 78*35a5a358SJonathan Adams 79*35a5a358SJonathan Adams /* protected by thread_lock() */ 80*35a5a358SJonathan Adams uint_t sdc_nupdates; /* number of sysdc_update_times() */ 81*35a5a358SJonathan Adams 82*35a5a358SJonathan Adams hrtime_t sdc_base_O; /* on-cpu time at last reset */ 83*35a5a358SJonathan Adams hrtime_t sdc_base_R; /* runnable time at last reset */ 84*35a5a358SJonathan Adams 85*35a5a358SJonathan Adams uint_t sdc_sleep_updates; /* 0, or nupdates when we slept */ 86*35a5a358SJonathan Adams clock_t sdc_ticks; /* sdc_tick() calls */ 87*35a5a358SJonathan Adams clock_t sdc_update_ticks; /* value of ticks for forced update */ 88*35a5a358SJonathan Adams clock_t sdc_pri_check; /* lbolt when we checked our priority */ 89*35a5a358SJonathan Adams hrtime_t sdc_last_base_O; /* onproc time at sysdc_update() */ 90*35a5a358SJonathan Adams 91*35a5a358SJonathan Adams uint_t sdc_pri; /* our last computed priority */ 92*35a5a358SJonathan Adams uint_t sdc_epri; /* our actual thread priority */ 93*35a5a358SJonathan Adams 94*35a5a358SJonathan Adams /* for debugging only */ 95*35a5a358SJonathan Adams clock_t sdc_reset; /* lbolt when we reset our bases */ 96*35a5a358SJonathan Adams hrtime_t sdc_cur_O; /* on-cpu time at last prio check */ 97*35a5a358SJonathan Adams hrtime_t sdc_cur_R; /* runnable time at last prio check */ 98*35a5a358SJonathan Adams hrtime_t sdc_last_O; /* onproc time at thread update */ 99*35a5a358SJonathan Adams uint_t sdc_cur_DC; /* our actual duty cycle at last chk */ 100*35a5a358SJonathan Adams } sysdc_t; 101*35a5a358SJonathan Adams 102*35a5a358SJonathan Adams /* 103*35a5a358SJonathan Adams * Hash bucket of active SDC threads. 104*35a5a358SJonathan Adams */ 105*35a5a358SJonathan Adams typedef struct sysdc_list { 106*35a5a358SJonathan Adams kmutex_t sdl_lock; /* lock keeping threads from exiting */ 107*35a5a358SJonathan Adams sysdc_t *volatile sdl_list; /* list of active threads in bucket */ 108*35a5a358SJonathan Adams char sdl_pad[64 - sizeof (kmutex_t) - sizeof (sysdc_t *)]; 109*35a5a358SJonathan Adams } sysdc_list_t; 110*35a5a358SJonathan Adams 111*35a5a358SJonathan Adams /* 112*35a5a358SJonathan Adams * Args to CL_ENTERCLASS(). 113*35a5a358SJonathan Adams */ 114*35a5a358SJonathan Adams typedef struct sysdc_params { 115*35a5a358SJonathan Adams uint_t sdp_minpri; 116*35a5a358SJonathan Adams uint_t sdp_maxpri; 117*35a5a358SJonathan Adams uint_t sdp_DC; 118*35a5a358SJonathan Adams } sysdc_params_t; 119*35a5a358SJonathan Adams 120*35a5a358SJonathan Adams /* 121*35a5a358SJonathan Adams * Duty cycles are percentages in the range [1,100]. 122*35a5a358SJonathan Adams */ 123*35a5a358SJonathan Adams #define SYSDC_DC_MAX 100u /* 1 <= DC <= DC_MAX */ 124*35a5a358SJonathan Adams 125*35a5a358SJonathan Adams #ifdef __cplusplus 126*35a5a358SJonathan Adams } 127*35a5a358SJonathan Adams #endif 128*35a5a358SJonathan Adams 129*35a5a358SJonathan Adams #endif /* _SYS_SYSDC_IMPL_H */ 130