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 53732Sae112802 * Common Development and Distribution License (the "License"). 63732Sae112802 * 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 /* 22*8803SJonathan.Haslam@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_KCPC_H 270Sstevel@tonic-gate #define _SYS_KCPC_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/cpc_impl.h> 306275Strevtom #include <sys/ksynch.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate /* 370Sstevel@tonic-gate * Kernel clients need this file in order to know what a request is and how to 380Sstevel@tonic-gate * program one. 390Sstevel@tonic-gate */ 400Sstevel@tonic-gate 410Sstevel@tonic-gate typedef struct _kcpc_set kcpc_set_t; 420Sstevel@tonic-gate 430Sstevel@tonic-gate #ifdef _KERNEL 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * Forward declarations. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate struct _kthread; 490Sstevel@tonic-gate struct cpu; 500Sstevel@tonic-gate typedef struct _kcpc_request kcpc_request_t; 510Sstevel@tonic-gate struct __pcbe_ops; 520Sstevel@tonic-gate 536275Strevtom #define KCPC_SET_BOUND 0x0001 /* Used in ks_state */ 546275Strevtom 550Sstevel@tonic-gate struct _kcpc_set { 560Sstevel@tonic-gate int ks_flags; 570Sstevel@tonic-gate int ks_nreqs; /* Number of reqs */ 580Sstevel@tonic-gate kcpc_request_t *ks_req; /* Pointer to reqs */ 590Sstevel@tonic-gate uint64_t *ks_data; /* Data store for this set */ 600Sstevel@tonic-gate kcpc_ctx_t *ks_ctx; /* ctx this set belongs to */ 616275Strevtom ushort_t ks_state; /* Set is bound or unbound */ 626275Strevtom kmutex_t ks_lock; /* Protects ks_state */ 636275Strevtom kcondvar_t ks_condv; /* Wait for bind to complete */ 640Sstevel@tonic-gate }; 650Sstevel@tonic-gate 660Sstevel@tonic-gate struct _kcpc_request { 670Sstevel@tonic-gate void *kr_config; 680Sstevel@tonic-gate int kr_index; /* indx of data for this req */ 690Sstevel@tonic-gate int kr_picnum; /* Number of phys pic */ 700Sstevel@tonic-gate kcpc_pic_t *kr_picp; /* Ptr to PIC in context */ 710Sstevel@tonic-gate uint64_t *kr_data; /* Ptr to virtual 64-bit pic */ 720Sstevel@tonic-gate char kr_event[CPC_MAX_EVENT_LEN]; 730Sstevel@tonic-gate uint64_t kr_preset; 740Sstevel@tonic-gate uint_t kr_flags; 750Sstevel@tonic-gate uint_t kr_nattrs; 760Sstevel@tonic-gate kcpc_attr_t *kr_attr; 770Sstevel@tonic-gate }; 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* 800Sstevel@tonic-gate * Bind the set to the indicated thread. 810Sstevel@tonic-gate * Returns 0 on success, or an errno in case of error. If EINVAL is returned, 820Sstevel@tonic-gate * a specific error code will be returned in the subcode parameter. 830Sstevel@tonic-gate */ 840Sstevel@tonic-gate extern int kcpc_bind_thread(kcpc_set_t *set, struct _kthread *t, int *subcode); 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* 870Sstevel@tonic-gate * Bind the set to the indicated CPU. 880Sstevel@tonic-gate * Same return convention as kcpc_bind_thread(). 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate extern int kcpc_bind_cpu(kcpc_set_t *set, int cpuid, int *subcode); 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* 930Sstevel@tonic-gate * Request the system to sample the current state of the set into users buf. 940Sstevel@tonic-gate */ 950Sstevel@tonic-gate extern int kcpc_sample(kcpc_set_t *set, uint64_t *buf, hrtime_t *hrtime, 960Sstevel@tonic-gate uint64_t *tick); 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* 990Sstevel@tonic-gate * Unbind a request and release the associated resources. 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate extern int kcpc_unbind(kcpc_set_t *set); 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* 1040Sstevel@tonic-gate * Preset the indicated request's counter and underlying PCBE config to the 1050Sstevel@tonic-gate * given value. 1060Sstevel@tonic-gate */ 1070Sstevel@tonic-gate extern int kcpc_preset(kcpc_set_t *set, int index, uint64_t preset); 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * Unfreeze the set and get it counting again. 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate extern int kcpc_restart(kcpc_set_t *set); 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate extern int kcpc_enable(struct _kthread *t, int cmd, int enable); 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * Mark a thread's CPC context, if it exists, INVALID. 1180Sstevel@tonic-gate */ 1190Sstevel@tonic-gate extern void kcpc_invalidate(struct _kthread *t); 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate extern int kcpc_overflow_ast(void); 1220Sstevel@tonic-gate extern uint_t kcpc_hw_overflow_intr(caddr_t, caddr_t); 1230Sstevel@tonic-gate extern int kcpc_hw_cpu_hook(int cpuid, ulong_t *kcpc_cpumap); 1240Sstevel@tonic-gate extern int kcpc_hw_lwp_hook(void); 1250Sstevel@tonic-gate extern void kcpc_idle_save(struct cpu *cp); 1260Sstevel@tonic-gate extern void kcpc_idle_restore(struct cpu *cp); 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate extern krwlock_t kcpc_cpuctx_lock; /* lock for 'kcpc_cpuctx' below */ 1290Sstevel@tonic-gate extern int kcpc_cpuctx; /* number of cpu-specific contexts */ 1300Sstevel@tonic-gate 131*8803SJonathan.Haslam@Sun.COM /* 132*8803SJonathan.Haslam@Sun.COM * 'dtrace_cpc_in_use' contains the number of currently active cpc provider 133*8803SJonathan.Haslam@Sun.COM * based enablings. See the block comment in uts/common/os/dtrace_subr.c for 134*8803SJonathan.Haslam@Sun.COM * details of its actual usage. 135*8803SJonathan.Haslam@Sun.COM */ 136*8803SJonathan.Haslam@Sun.COM extern uint32_t dtrace_cpc_in_use; 137*8803SJonathan.Haslam@Sun.COM extern void (*dtrace_cpc_fire)(uint64_t); 138*8803SJonathan.Haslam@Sun.COM 1390Sstevel@tonic-gate extern void kcpc_free_set(kcpc_set_t *set); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate extern void *kcpc_next_config(void *token, void *current, 1420Sstevel@tonic-gate uint64_t **data); 1433732Sae112802 extern void kcpc_invalidate_config(void *token); 144*8803SJonathan.Haslam@Sun.COM extern char *kcpc_list_attrs(void); 145*8803SJonathan.Haslam@Sun.COM extern char *kcpc_list_events(uint_t pic); 146*8803SJonathan.Haslam@Sun.COM extern void kcpc_free_configs(kcpc_set_t *set); 147*8803SJonathan.Haslam@Sun.COM extern uint_t kcpc_pcbe_capabilities(void); 148*8803SJonathan.Haslam@Sun.COM extern int kcpc_pcbe_loaded(void); 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* 1510Sstevel@tonic-gate * Called by a PCBE to determine if nonprivileged access to counters should be 1520Sstevel@tonic-gate * allowed. Returns non-zero if non-privileged access is allowed, 0 if not. 1530Sstevel@tonic-gate */ 1540Sstevel@tonic-gate extern int kcpc_allow_nonpriv(void *token); 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate extern void kcpc_register_pcbe(struct __pcbe_ops *); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate #endif /* _KERNEL */ 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate #ifdef __cplusplus 1610Sstevel@tonic-gate } 1620Sstevel@tonic-gate #endif 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate #endif /* _SYS_KCPC_H */ 165