1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/*
28 * Generic x86 CPU MCA poller - support functions for native and xpv pollers.
29 */
30
31#include <sys/types.h>
32#include <sys/sysmacros.h>
33#include <sys/sdt.h>
34#include <sys/cmn_err.h>
35
36#include "gcpu.h"
37
38uint_t gcpu_poll_trace_nent = 100;
39
40#ifdef DEBUG
41int gcpu_poll_trace_always = 1;
42#else
43int gcpu_poll_trace_always = 0;
44#endif
45
46void
47gcpu_poll_trace(gcpu_poll_trace_ctl_t *ptc, uint8_t what, uint8_t nerr)
48{
49	gcpu_poll_trace_t *pt;
50	uint_t next;
51
52	DTRACE_PROBE2(gcpu__mca__poll__trace, uint32_t, what, uint32_t, nerr);
53
54	if (ptc->mptc_tbufs == NULL)
55		return; /* poll trace buffer is disabled */
56
57	next = (ptc->mptc_curtrace + 1) % gcpu_poll_trace_nent;
58	pt = &ptc->mptc_tbufs[next];
59
60	pt->mpt_when = 0;
61	pt->mpt_what = what;
62
63	pt->mpt_nerr = MIN(nerr, UINT8_MAX);
64
65	pt->mpt_when = gethrtime_waitfree();
66	ptc->mptc_curtrace = next;
67}
68
69void
70gcpu_poll_trace_init(gcpu_poll_trace_ctl_t *ptc)
71{
72	gcpu_poll_trace_t *tbufs = NULL;
73
74	if (gcpu_poll_trace_always) {
75		tbufs = kmem_zalloc(sizeof (gcpu_poll_trace_t) *
76		    gcpu_poll_trace_nent, KM_SLEEP);
77	}
78
79	ptc->mptc_tbufs = tbufs;
80	ptc->mptc_curtrace = 0;
81}
82