xref: /illumos-gate/usr/src/uts/i86pc/cpu/amd_opteron/ao_poll.c (revision 0250c53ad267726f2438e3c6556199a0bbf588a2)
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 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * AMD Athlon64/Opteron Model-Specific Poller Implementation
29  */
30 
31 #include <sys/types.h>
32 
33 #include "ao.h"
34 
35 /*
36  * Decide whether the caller should poll the NB.  The decision is made
37  * and any poll is performed under protection of the chip-wide mutex
38  * enforced at the caller's level.  That mutex already ensures that all
39  * pollers on a chip are serialized - the following is simply to
40  * avoid the NB poll ping-ponging between different detectors.
41  */
42 uint64_t
43 ao_ms_poll_ownermask(cmi_hdl_t hdl, hrtime_t pintvl)
44 {
45 	ao_ms_data_t *ao = cms_hdl_getcmsdata(hdl);
46 	hrtime_t now = gethrtime_waitfree();
47 	hrtime_t last = ao->ao_ms_shared->aos_nb_poll_timestamp;
48 	int dopoll = 0;
49 
50 	if (now - last > 2 * pintvl || last == 0) {
51 		/*
52 		 * If no last value has been recorded assume ownership.
53 		 * Otherwise only take over if the current "owner" seems
54 		 * to be making little progress.
55 		 */
56 		ao->ao_ms_shared->aos_nb_poll_owner = hdl;
57 		dopoll = 1;
58 	} else if (ao->ao_ms_shared->aos_nb_poll_owner == hdl) {
59 		/*
60 		 * This is the current owner and it is making progress.
61 		 */
62 		dopoll = 1;
63 	}
64 
65 	if (dopoll)
66 		ao->ao_ms_shared->aos_nb_poll_timestamp = now;
67 
68 	return (dopoll ? -1ULL : ~(1 << AMD_MCA_BANK_NB));
69 }
70