Home | History | Annotate | Download | only in sys
      1  3792  akolb /*
      2  3792  akolb  * CDDL HEADER START
      3  3792  akolb  *
      4  3792  akolb  * The contents of this file are subject to the terms of the
      5  3792  akolb  * Common Development and Distribution License (the "License").
      6  3792  akolb  * You may not use this file except in compliance with the License.
      7  3792  akolb  *
      8  3792  akolb  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  3792  akolb  * or http://www.opensolaris.org/os/licensing.
     10  3792  akolb  * See the License for the specific language governing permissions
     11  3792  akolb  * and limitations under the License.
     12  3792  akolb  *
     13  3792  akolb  * When distributing Covered Code, include this CDDL HEADER in each
     14  3792  akolb  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  3792  akolb  * If applicable, add the following below this CDDL HEADER, with the
     16  3792  akolb  * fields enclosed by brackets "[]" replaced with your own identifying
     17  3792  akolb  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  3792  akolb  *
     19  3792  akolb  * CDDL HEADER END
     20  3792  akolb  */
     21  3792  akolb 
     22  3792  akolb /*
     23  3792  akolb  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     24  3792  akolb  * Use is subject to license terms.
     25  3792  akolb  */
     26  3792  akolb 
     27  3792  akolb #ifndef	_SYS_CPUCAPS_H
     28  3792  akolb #define	_SYS_CPUCAPS_H
     29  3792  akolb 
     30  3792  akolb #pragma ident	"%Z%%M%	%I%	%E% SMI"
     31  3792  akolb 
     32  3792  akolb #ifdef	__cplusplus
     33  3792  akolb extern "C" {
     34  3792  akolb #endif
     35  3792  akolb 
     36  3792  akolb #include <sys/types.h>
     37  3792  akolb #include <sys/zone.h>
     38  3792  akolb #include <sys/project.h>
     39  3792  akolb #include <sys/time.h>
     40  3792  akolb #include <sys/rctl.h>
     41  3792  akolb 
     42  3792  akolb /*
     43  3792  akolb  * CPU caps provide an absolute hard CPU usage limit which is enforced even if
     44  3792  akolb  * some CPUs are idle. It can be enforced at project or zone level.
     45  3792  akolb  */
     46  3792  akolb 
     47  3792  akolb #ifdef _KERNEL
     48  3792  akolb 
     49  3792  akolb /*
     50  3792  akolb  * Valid caps values go from 1 to MAXCAP - 1. Specifying the MAXCAP as the cap
     51  3792  akolb  * value is equivalent to disabling the cap.
     52  3792  akolb  */
     53  3792  akolb #define	MAXCAP		UINT_MAX
     54  3792  akolb 
     55  3792  akolb /*
     56  3792  akolb  * cpucaps_enabled is used to quickly check whether any CPU caps specific code
     57  3792  akolb  * should be invoked. Users outside CPU Caps framework should use CPUCAPS_ON()
     58  3792  akolb  * and CPUCAPS_OFF() macros.
     59  3792  akolb  */
     60  3792  akolb extern boolean_t cpucaps_enabled;
     61  3792  akolb 
     62  3792  akolb #define	CPUCAPS_ON()	cpucaps_enabled
     63  3792  akolb #define	CPUCAPS_OFF()	(!cpucaps_enabled)
     64  3792  akolb 
     65  3792  akolb /*
     66  3792  akolb  * Initialize the CPU caps framework.
     67  3792  akolb  */
     68  3792  akolb extern void cpucaps_init(void);
     69  3792  akolb 
     70  3792  akolb /*
     71  3792  akolb  * Notify caps framework of a new project coming in or existing project
     72  3792  akolb  * going away
     73  3792  akolb  */
     74  3792  akolb extern void cpucaps_project_add(kproject_t *);
     75  3792  akolb extern void cpucaps_project_remove(kproject_t *);
     76  3792  akolb 
     77  3792  akolb /*
     78  3792  akolb  * Notify caps framework when a zone is going away.
     79  3792  akolb  */
     80  3792  akolb extern void cpucaps_zone_remove(zone_t *);
     81  3792  akolb 
     82  3792  akolb /*
     83  3792  akolb  * Set project/zone cap to specified value. Value of MAXCAP should disable caps.
     84  3792  akolb  */
     85  3792  akolb extern int cpucaps_project_set(kproject_t *, rctl_qty_t);
     86  3792  akolb extern int cpucaps_zone_set(zone_t *, rctl_qty_t);
     87  3792  akolb 
     88  3792  akolb /*
     89  3792  akolb  * Get current CPU usage for a project/zone.
     90  3792  akolb  */
     91  3792  akolb extern rctl_qty_t cpucaps_project_get(kproject_t *);
     92  3792  akolb extern rctl_qty_t cpucaps_zone_get(zone_t *);
     93  3792  akolb 
     94  3792  akolb /*
     95  3792  akolb  * Scheduling class hooks into CPU caps framework.
     96  3792  akolb  */
     97  3792  akolb 
     98  3792  akolb /*
     99  3792  akolb  * CPU caps specific data for each scheduling class.
    100  3792  akolb  *
    101  3792  akolb  * There is a small amount of accounting data that should be kept by each
    102  3792  akolb  * scheduling class for each thread which is only used by CPU caps code. This
    103  3792  akolb  * data is kept in the caps_sc structure which is transparent for all scheduling
    104  3792  akolb  * classes. The fields in the structure are:
    105  3792  akolb  *
    106  3792  akolb  *     csc_cputime -  Total time spent on CPU during thread lifetime, obtained
    107  3792  akolb  *                    as the sum of user, system and trap time, reported by
    108  3792  akolb  *                    microstate accounting.
    109  3792  akolb  */
    110  3792  akolb typedef struct caps_sc {
    111  3792  akolb 	hrtime_t	csc_cputime;
    112  3792  akolb } caps_sc_t;
    113  3792  akolb 
    114  3792  akolb /*
    115  3792  akolb  * Initialize per-thread cpu-caps specific data.
    116  3792  akolb  */
    117  3792  akolb extern void cpucaps_sc_init(caps_sc_t *);
    118  3792  akolb 
    119  3792  akolb /*
    120  3792  akolb  * Modus operandi for cpucaps_charge() function.
    121  3792  akolb  *
    122  3792  akolb  *   CPUCAPS_CHARGE_ENFORCE - charge a thread for its CPU time and
    123  3792  akolb  *				flag it to be placed on wait queue.
    124  3792  akolb  *
    125  3792  akolb  *   CPUCAPS_CHARGE_ONLY    - charge a thread for its CPU time.
    126  3792  akolb  */
    127  3792  akolb typedef enum {
    128  3792  akolb 	CPUCAPS_CHARGE_ENFORCE,
    129  3792  akolb 	CPUCAPS_CHARGE_ONLY
    130  3792  akolb } cpucaps_charge_t;
    131  3792  akolb 
    132  3792  akolb /*
    133  3792  akolb  * Add accumulated CPU usage of a thread to its cap.
    134  3792  akolb  * Return True if thread should be placed on waitq.
    135  3792  akolb  */
    136  3792  akolb extern boolean_t cpucaps_charge(kthread_t *, caps_sc_t *, cpucaps_charge_t);
    137  3792  akolb #define	CPUCAPS_CHARGE(t, scp, flag) \
    138  3792  akolb 	(CPUCAPS_ON() && cpucaps_charge(t, scp, flag))
    139  3792  akolb 
    140  3792  akolb /*
    141  3792  akolb  * Request a thread to be placed on a wait queue because the cap is exceeded
    142  3792  akolb  */
    143  3792  akolb extern boolean_t cpucaps_enforce(kthread_t *);
    144  3792  akolb #define	CPUCAPS_ENFORCE(t) (CPUCAPS_ON() && cpucaps_enforce(t))
    145  3792  akolb 
    146  3792  akolb /*
    147  3792  akolb  * CPU Caps hook into clock().
    148  3792  akolb  */
    149  3792  akolb extern void (*cpucaps_clock_callout)(void);
    150  3792  akolb 
    151  3792  akolb #endif	/* _KERNEL */
    152  3792  akolb 
    153  3792  akolb #ifdef	__cplusplus
    154  3792  akolb }
    155  3792  akolb #endif
    156  3792  akolb 
    157  3792  akolb #endif	/* _SYS_CPUCAPS_H */
    158