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