11414Scindi /* 21414Scindi * CDDL HEADER START 31414Scindi * 41414Scindi * The contents of this file are subject to the terms of the 51538Sgavinm * Common Development and Distribution License (the "License"). 61538Sgavinm * You may not use this file except in compliance with the License. 71414Scindi * 81414Scindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91414Scindi * or http://www.opensolaris.org/os/licensing. 101414Scindi * See the License for the specific language governing permissions 111414Scindi * and limitations under the License. 121414Scindi * 131414Scindi * When distributing Covered Code, include this CDDL HEADER in each 141414Scindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151414Scindi * If applicable, add the following below this CDDL HEADER, with the 161414Scindi * fields enclosed by brackets "[]" replaced with your own identifying 171414Scindi * information: Portions Copyright [yyyy] [name of copyright owner] 181414Scindi * 191414Scindi * CDDL HEADER END 201414Scindi */ 211414Scindi 221414Scindi /* 23*5254Sgavinm * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 241414Scindi * Use is subject to license terms. 251414Scindi */ 261414Scindi 271414Scindi #pragma ident "%Z%%M% %I% %E% SMI" 281414Scindi 291414Scindi /* 30*5254Sgavinm * AMD Athlon64/Opteron Model-Specific Poller Implementation 311414Scindi */ 321414Scindi 331414Scindi #include <sys/types.h> 341414Scindi 351414Scindi #include "ao.h" 361414Scindi 372869Sgavinm /* 382869Sgavinm * Decide whether the caller should poll the NB. The decision is made 39*5254Sgavinm * and any poll is performed under protection of the chip-wide mutex 40*5254Sgavinm * enforced at the caller's level. That mutex already ensures that all 41*5254Sgavinm * pollers on a chip are serialized - the following is simply to 42*5254Sgavinm * avoid the NB poll ping-ponging between different detectors. 432869Sgavinm */ 44*5254Sgavinm uint64_t ao_ms_poll_ownermask(cmi_hdl_t hdl,hrtime_t pintvl)45*5254Sgavinmao_ms_poll_ownermask(cmi_hdl_t hdl, hrtime_t pintvl) 462869Sgavinm { 47*5254Sgavinm ao_ms_data_t *ao = cms_hdl_getcmsdata(hdl); 48*5254Sgavinm hrtime_t now = gethrtime_waitfree(); 49*5254Sgavinm hrtime_t last = ao->ao_ms_shared->aos_nb_poll_timestamp; 50*5254Sgavinm int dopoll = 0; 512869Sgavinm 52*5254Sgavinm if (now - last > 2 * pintvl || last == 0) { 53*5254Sgavinm /* 54*5254Sgavinm * If no last value has been recorded assume ownership. 55*5254Sgavinm * Otherwise only take over if the current "owner" seems 56*5254Sgavinm * to be making little progress. 57*5254Sgavinm */ 58*5254Sgavinm ao->ao_ms_shared->aos_nb_poll_owner = hdl; 59*5254Sgavinm dopoll = 1; 60*5254Sgavinm } else if (ao->ao_ms_shared->aos_nb_poll_owner == hdl) { 61*5254Sgavinm /* 62*5254Sgavinm * This is the current owner and it is making progress. 63*5254Sgavinm */ 64*5254Sgavinm dopoll = 1; 652869Sgavinm } 662869Sgavinm 67*5254Sgavinm if (dopoll) 68*5254Sgavinm ao->ao_ms_shared->aos_nb_poll_timestamp = now; 691414Scindi 70*5254Sgavinm return (dopoll ? -1ULL : ~(1 << AMD_MCA_BANK_NB)); 711414Scindi } 72