xref: /onnv-gate/usr/src/uts/common/sys/kcpc.h (revision 6275:c0f4f775d1fa)
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*6275Strevtom  * Copyright 2008 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/cpc_impl.h>
32*6275Strevtom #include <sys/ksynch.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifdef	__cplusplus
350Sstevel@tonic-gate extern "C" {
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate  * Kernel clients need this file in order to know what a request is and how to
400Sstevel@tonic-gate  * program one.
410Sstevel@tonic-gate  */
420Sstevel@tonic-gate 
430Sstevel@tonic-gate typedef struct _kcpc_set kcpc_set_t;
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #ifdef _KERNEL
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate  * Forward declarations.
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate struct _kthread;
510Sstevel@tonic-gate struct cpu;
520Sstevel@tonic-gate typedef struct _kcpc_request kcpc_request_t;
530Sstevel@tonic-gate struct __pcbe_ops;
540Sstevel@tonic-gate 
55*6275Strevtom #define	KCPC_SET_BOUND		0x0001		/* Used in ks_state */
56*6275Strevtom 
570Sstevel@tonic-gate struct _kcpc_set {
580Sstevel@tonic-gate 	int			ks_flags;
590Sstevel@tonic-gate 	int			ks_nreqs;	/* Number of reqs */
600Sstevel@tonic-gate 	kcpc_request_t		*ks_req;	/* Pointer to reqs */
610Sstevel@tonic-gate 	uint64_t		*ks_data;	/* Data store for this set */
620Sstevel@tonic-gate 	kcpc_ctx_t		*ks_ctx;	/* ctx this set belongs to */
63*6275Strevtom 	ushort_t		ks_state;	/* Set is bound or unbound */
64*6275Strevtom 	kmutex_t		ks_lock;	/* Protects ks_state */
65*6275Strevtom 	kcondvar_t		ks_condv;	/* Wait for bind to complete */
660Sstevel@tonic-gate };
670Sstevel@tonic-gate 
680Sstevel@tonic-gate struct _kcpc_request {
690Sstevel@tonic-gate 	void			*kr_config;
700Sstevel@tonic-gate 	int			kr_index;	/* indx of data for this req */
710Sstevel@tonic-gate 	int			kr_picnum;	/* Number of phys pic */
720Sstevel@tonic-gate 	kcpc_pic_t		*kr_picp;	/* Ptr to PIC in context */
730Sstevel@tonic-gate 	uint64_t		*kr_data;	/* Ptr to virtual 64-bit pic */
740Sstevel@tonic-gate 	char			kr_event[CPC_MAX_EVENT_LEN];
750Sstevel@tonic-gate 	uint64_t		kr_preset;
760Sstevel@tonic-gate 	uint_t			kr_flags;
770Sstevel@tonic-gate 	uint_t			kr_nattrs;
780Sstevel@tonic-gate 	kcpc_attr_t		*kr_attr;
790Sstevel@tonic-gate };
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /*
820Sstevel@tonic-gate  * Bind the set to the indicated thread.
830Sstevel@tonic-gate  * Returns 0 on success, or an errno in case of error. If EINVAL is returned,
840Sstevel@tonic-gate  * a specific error code will be returned in the subcode parameter.
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate extern int kcpc_bind_thread(kcpc_set_t *set, struct _kthread *t, int *subcode);
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /*
890Sstevel@tonic-gate  * Bind the set to the indicated CPU.
900Sstevel@tonic-gate  * Same return convention as kcpc_bind_thread().
910Sstevel@tonic-gate  */
920Sstevel@tonic-gate extern int kcpc_bind_cpu(kcpc_set_t *set, int cpuid, int *subcode);
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /*
950Sstevel@tonic-gate  * Request the system to sample the current state of the set into users buf.
960Sstevel@tonic-gate  */
970Sstevel@tonic-gate extern int kcpc_sample(kcpc_set_t *set, uint64_t *buf, hrtime_t *hrtime,
980Sstevel@tonic-gate     uint64_t *tick);
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate /*
1010Sstevel@tonic-gate  * Unbind a request and release the associated resources.
1020Sstevel@tonic-gate  */
1030Sstevel@tonic-gate extern int kcpc_unbind(kcpc_set_t *set);
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate  * Preset the indicated request's counter and underlying PCBE config to the
1070Sstevel@tonic-gate  * given value.
1080Sstevel@tonic-gate  */
1090Sstevel@tonic-gate extern int kcpc_preset(kcpc_set_t *set, int index, uint64_t preset);
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate /*
1120Sstevel@tonic-gate  * Unfreeze the set and get it counting again.
1130Sstevel@tonic-gate  */
1140Sstevel@tonic-gate extern int kcpc_restart(kcpc_set_t *set);
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate extern int kcpc_enable(struct _kthread *t, int cmd, int enable);
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate /*
1190Sstevel@tonic-gate  * Mark a thread's CPC context, if it exists, INVALID.
1200Sstevel@tonic-gate  */
1210Sstevel@tonic-gate extern void kcpc_invalidate(struct _kthread *t);
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate extern int kcpc_overflow_ast(void);
1240Sstevel@tonic-gate extern uint_t kcpc_hw_overflow_intr(caddr_t, caddr_t);
1250Sstevel@tonic-gate extern int kcpc_hw_cpu_hook(int cpuid, ulong_t *kcpc_cpumap);
1260Sstevel@tonic-gate extern int kcpc_hw_lwp_hook(void);
1270Sstevel@tonic-gate extern void kcpc_idle_save(struct cpu *cp);
1280Sstevel@tonic-gate extern void kcpc_idle_restore(struct cpu *cp);
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate extern krwlock_t	kcpc_cpuctx_lock;  /* lock for 'kcpc_cpuctx' below */
1310Sstevel@tonic-gate extern int		kcpc_cpuctx;	   /* number of cpu-specific contexts */
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate extern void kcpc_free_set(kcpc_set_t *set);
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate extern void *kcpc_next_config(void *token, void *current,
1360Sstevel@tonic-gate     uint64_t **data);
1373732Sae112802 extern void kcpc_invalidate_config(void *token);
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * Called by a PCBE to determine if nonprivileged access to counters should be
1410Sstevel@tonic-gate  * allowed. Returns non-zero if non-privileged access is allowed, 0 if not.
1420Sstevel@tonic-gate  */
1430Sstevel@tonic-gate extern int kcpc_allow_nonpriv(void *token);
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate extern void kcpc_register_pcbe(struct __pcbe_ops *);
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate #endif /* _KERNEL */
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate #ifdef	__cplusplus
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate #endif
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate #endif /* _SYS_KCPC_H */
154