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 58d4e547dSae112802 * Common Development and Distribution License (the "License"). 68d4e547dSae112802 * 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*b9e93c10SJonathan Haslam * Copyright 2009 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_KCPC_H 277c478bd9Sstevel@tonic-gate #define _SYS_KCPC_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/cpc_impl.h> 304568bee7Strevtom #include <sys/ksynch.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 337c478bd9Sstevel@tonic-gate extern "C" { 347c478bd9Sstevel@tonic-gate #endif 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * Kernel clients need this file in order to know what a request is and how to 387c478bd9Sstevel@tonic-gate * program one. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate typedef struct _kcpc_set kcpc_set_t; 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #ifdef _KERNEL 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * Forward declarations. 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate struct _kthread; 497c478bd9Sstevel@tonic-gate struct cpu; 507c478bd9Sstevel@tonic-gate typedef struct _kcpc_request kcpc_request_t; 517c478bd9Sstevel@tonic-gate struct __pcbe_ops; 527c478bd9Sstevel@tonic-gate 534568bee7Strevtom #define KCPC_SET_BOUND 0x0001 /* Used in ks_state */ 544568bee7Strevtom 557c478bd9Sstevel@tonic-gate struct _kcpc_set { 567c478bd9Sstevel@tonic-gate int ks_flags; 577c478bd9Sstevel@tonic-gate int ks_nreqs; /* Number of reqs */ 587c478bd9Sstevel@tonic-gate kcpc_request_t *ks_req; /* Pointer to reqs */ 597c478bd9Sstevel@tonic-gate uint64_t *ks_data; /* Data store for this set */ 607c478bd9Sstevel@tonic-gate kcpc_ctx_t *ks_ctx; /* ctx this set belongs to */ 614568bee7Strevtom ushort_t ks_state; /* Set is bound or unbound */ 624568bee7Strevtom kmutex_t ks_lock; /* Protects ks_state */ 634568bee7Strevtom kcondvar_t ks_condv; /* Wait for bind to complete */ 647c478bd9Sstevel@tonic-gate }; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate struct _kcpc_request { 677c478bd9Sstevel@tonic-gate void *kr_config; 687c478bd9Sstevel@tonic-gate int kr_index; /* indx of data for this req */ 697c478bd9Sstevel@tonic-gate int kr_picnum; /* Number of phys pic */ 707c478bd9Sstevel@tonic-gate kcpc_pic_t *kr_picp; /* Ptr to PIC in context */ 717c478bd9Sstevel@tonic-gate uint64_t *kr_data; /* Ptr to virtual 64-bit pic */ 727c478bd9Sstevel@tonic-gate char kr_event[CPC_MAX_EVENT_LEN]; 737c478bd9Sstevel@tonic-gate uint64_t kr_preset; 747c478bd9Sstevel@tonic-gate uint_t kr_flags; 757c478bd9Sstevel@tonic-gate uint_t kr_nattrs; 767c478bd9Sstevel@tonic-gate kcpc_attr_t *kr_attr; 777c478bd9Sstevel@tonic-gate }; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* 807c478bd9Sstevel@tonic-gate * Bind the set to the indicated thread. 817c478bd9Sstevel@tonic-gate * Returns 0 on success, or an errno in case of error. If EINVAL is returned, 827c478bd9Sstevel@tonic-gate * a specific error code will be returned in the subcode parameter. 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate extern int kcpc_bind_thread(kcpc_set_t *set, struct _kthread *t, int *subcode); 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * Bind the set to the indicated CPU. 887c478bd9Sstevel@tonic-gate * Same return convention as kcpc_bind_thread(). 897c478bd9Sstevel@tonic-gate */ 907c478bd9Sstevel@tonic-gate extern int kcpc_bind_cpu(kcpc_set_t *set, int cpuid, int *subcode); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate /* 937c478bd9Sstevel@tonic-gate * Request the system to sample the current state of the set into users buf. 947c478bd9Sstevel@tonic-gate */ 957c478bd9Sstevel@tonic-gate extern int kcpc_sample(kcpc_set_t *set, uint64_t *buf, hrtime_t *hrtime, 967c478bd9Sstevel@tonic-gate uint64_t *tick); 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /* 997c478bd9Sstevel@tonic-gate * Unbind a request and release the associated resources. 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate extern int kcpc_unbind(kcpc_set_t *set); 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * Preset the indicated request's counter and underlying PCBE config to the 1057c478bd9Sstevel@tonic-gate * given value. 1067c478bd9Sstevel@tonic-gate */ 1077c478bd9Sstevel@tonic-gate extern int kcpc_preset(kcpc_set_t *set, int index, uint64_t preset); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* 1107c478bd9Sstevel@tonic-gate * Unfreeze the set and get it counting again. 1117c478bd9Sstevel@tonic-gate */ 1127c478bd9Sstevel@tonic-gate extern int kcpc_restart(kcpc_set_t *set); 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate extern int kcpc_enable(struct _kthread *t, int cmd, int enable); 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* 1177c478bd9Sstevel@tonic-gate * Mark a thread's CPC context, if it exists, INVALID. 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate extern void kcpc_invalidate(struct _kthread *t); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate extern int kcpc_overflow_ast(void); 1227c478bd9Sstevel@tonic-gate extern uint_t kcpc_hw_overflow_intr(caddr_t, caddr_t); 1237c478bd9Sstevel@tonic-gate extern int kcpc_hw_cpu_hook(int cpuid, ulong_t *kcpc_cpumap); 1247c478bd9Sstevel@tonic-gate extern int kcpc_hw_lwp_hook(void); 1257c478bd9Sstevel@tonic-gate extern void kcpc_idle_save(struct cpu *cp); 1267c478bd9Sstevel@tonic-gate extern void kcpc_idle_restore(struct cpu *cp); 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate extern krwlock_t kcpc_cpuctx_lock; /* lock for 'kcpc_cpuctx' below */ 1297c478bd9Sstevel@tonic-gate extern int kcpc_cpuctx; /* number of cpu-specific contexts */ 1307c478bd9Sstevel@tonic-gate 131*b9e93c10SJonathan Haslam /* 132*b9e93c10SJonathan Haslam * 'dtrace_cpc_in_use' contains the number of currently active cpc provider 133*b9e93c10SJonathan Haslam * based enablings. See the block comment in uts/common/os/dtrace_subr.c for 134*b9e93c10SJonathan Haslam * details of its actual usage. 135*b9e93c10SJonathan Haslam */ 136*b9e93c10SJonathan Haslam extern uint32_t dtrace_cpc_in_use; 137*b9e93c10SJonathan Haslam extern void (*dtrace_cpc_fire)(uint64_t); 138*b9e93c10SJonathan Haslam 1397c478bd9Sstevel@tonic-gate extern void kcpc_free_set(kcpc_set_t *set); 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate extern void *kcpc_next_config(void *token, void *current, 1427c478bd9Sstevel@tonic-gate uint64_t **data); 1438d4e547dSae112802 extern void kcpc_invalidate_config(void *token); 144*b9e93c10SJonathan Haslam extern char *kcpc_list_attrs(void); 145*b9e93c10SJonathan Haslam extern char *kcpc_list_events(uint_t pic); 146*b9e93c10SJonathan Haslam extern void kcpc_free_configs(kcpc_set_t *set); 147*b9e93c10SJonathan Haslam extern uint_t kcpc_pcbe_capabilities(void); 148*b9e93c10SJonathan Haslam extern int kcpc_pcbe_loaded(void); 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* 1517c478bd9Sstevel@tonic-gate * Called by a PCBE to determine if nonprivileged access to counters should be 1527c478bd9Sstevel@tonic-gate * allowed. Returns non-zero if non-privileged access is allowed, 0 if not. 1537c478bd9Sstevel@tonic-gate */ 1547c478bd9Sstevel@tonic-gate extern int kcpc_allow_nonpriv(void *token); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate extern void kcpc_register_pcbe(struct __pcbe_ops *); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate #endif 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate #endif /* _SYS_KCPC_H */ 165