xref: /illumos-gate/usr/src/cmd/fm/modules/common/cpumem-retire/cma_main.c (revision 1a220b56b93ff1dc80855691548503117af4cc10)
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 2006 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 #include <cma.h>
30 
31 #include <strings.h>
32 #include <errno.h>
33 #include <time.h>
34 #include <fm/fmd_api.h>
35 #include <sys/fm/protocol.h>
36 
37 cma_t cma;
38 
39 cma_stats_t cma_stats = {
40 	{ "cpu_flts", FMD_TYPE_UINT64, "cpu faults resolved" },
41 	{ "cpu_fails", FMD_TYPE_UINT64, "cpu faults unresolveable" },
42 	{ "cpu_blfails", FMD_TYPE_UINT64, "failed cpu blacklists" },
43 	{ "cpu_supp", FMD_TYPE_UINT64, "cpu offlines suppressed" },
44 	{ "cpu_blsupp", FMD_TYPE_UINT64, "cpu blacklists suppressed" },
45 	{ "page_flts", FMD_TYPE_UINT64, "page faults resolved" },
46 	{ "page_fails", FMD_TYPE_UINT64, "page faults unresolveable" },
47 	{ "page_supp", FMD_TYPE_UINT64, "page retires suppressed" },
48 	{ "page_nonent", FMD_TYPE_UINT64, "retires for non-existent fmris" },
49 	{ "page_retmax", FMD_TYPE_UINT64, "hit max retries for page retire" },
50 	{ "bad_flts", FMD_TYPE_UINT64, "invalid fault events received" },
51 	{ "nop_flts", FMD_TYPE_UINT64, "inapplicable fault events received" },
52 	{ "auto_flts", FMD_TYPE_UINT64, "auto-close faults received" }
53 };
54 
55 typedef struct cma_subscriber {
56 	const char *subr_class;
57 	const char *subr_sname;
58 	uint_t subr_svers;
59 	int (*subr_func)(fmd_hdl_t *, nvlist_t *, nvlist_t *, const char *);
60 } cma_subscriber_t;
61 
62 static const cma_subscriber_t cma_subrs[] = {
63 	{ "fault.memory.page", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
64 	    cma_page_retire },
65 	{ "fault.memory.dimm", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
66 	    NULL },
67 	{ "fault.memory.dimm_sb", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
68 	    NULL },
69 	{ "fault.memory.dimm_ck", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
70 	    NULL },
71 	{ "fault.memory.dimm_ue", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
72 	    NULL },
73 	{ "fault.memory.bank", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
74 	    NULL },
75 	{ "fault.memory.datapath", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
76 	    NULL },
77 
78 	/*
79 	 * The following ultraSPARC-T1 faults do NOT retire a cpu thread,
80 	 * and therefore must be intercepted before
81 	 * the default "fault.cpu.*" dispatch to cma_cpu_retire.
82 	 */
83 	{ "fault.cpu.ultraSPARC-T1.freg", FM_FMRI_SCHEME_CPU,
84 	    FM_CPU_SCHEME_VERSION, NULL },
85 	{ "fault.cpu.ultraSPARC-T1.l2cachedata", FM_FMRI_SCHEME_CPU,
86 	    FM_CPU_SCHEME_VERSION, NULL },
87 	{ "fault.cpu.ultraSPARC-T1.l2cachetag", FM_FMRI_SCHEME_CPU,
88 	    FM_CPU_SCHEME_VERSION, NULL },
89 	{ "fault.cpu.ultraSPARC-T1.l2cachectl", FM_FMRI_SCHEME_CPU,
90 	    FM_CPU_SCHEME_VERSION, NULL },
91 	{ "fault.cpu.ultraSPARC-T1.mau", FM_FMRI_SCHEME_CPU,
92 	    FM_CPU_SCHEME_VERSION, NULL },
93 	{ "fault.cpu.*", FM_FMRI_SCHEME_CPU, FM_CPU_SCHEME_VERSION,
94 	    cma_cpu_retire },
95 	{ NULL, NULL, 0, NULL }
96 };
97 
98 static const cma_subscriber_t *
99 nvl2subr(fmd_hdl_t *hdl, nvlist_t *nvl, nvlist_t **asrup)
100 {
101 	const cma_subscriber_t *sp;
102 	nvlist_t *asru;
103 	char *scheme;
104 	uint8_t version;
105 
106 	if (nvlist_lookup_nvlist(nvl, FM_FAULT_ASRU, &asru) != 0 ||
107 	    nvlist_lookup_string(asru, FM_FMRI_SCHEME, &scheme) != 0 ||
108 	    nvlist_lookup_uint8(asru, FM_VERSION, &version) != 0) {
109 		cma_stats.bad_flts.fmds_value.ui64++;
110 		return (NULL);
111 	}
112 
113 	for (sp = cma_subrs; sp->subr_class != NULL; sp++) {
114 		if (fmd_nvl_class_match(hdl, nvl, sp->subr_class) &&
115 		    strcmp(scheme, sp->subr_sname) == 0 &&
116 		    version <= sp->subr_svers) {
117 			*asrup = asru;
118 			return (sp);
119 		}
120 	}
121 
122 	cma_stats.nop_flts.fmds_value.ui64++;
123 	return (NULL);
124 }
125 
126 static void
127 cma_recv_list(fmd_hdl_t *hdl, nvlist_t *nvl)
128 {
129 	char *uuid = NULL;
130 	nvlist_t **nva;
131 	uint_t nvc = 0;
132 	uint_t keepopen;
133 	int err = 0;
134 
135 	err |= nvlist_lookup_string(nvl, FM_SUSPECT_UUID, &uuid);
136 	err |= nvlist_lookup_nvlist_array(nvl, FM_SUSPECT_FAULT_LIST,
137 	    &nva, &nvc);
138 	if (err != 0) {
139 		cma_stats.bad_flts.fmds_value.ui64++;
140 		return;
141 	}
142 
143 	keepopen = nvc;
144 	while (nvc-- != 0 && !fmd_case_uuclosed(hdl, uuid)) {
145 		nvlist_t *nvl = *nva++;
146 		const cma_subscriber_t *subr;
147 		nvlist_t *asru;
148 
149 		if ((subr = nvl2subr(hdl, nvl, &asru)) == NULL)
150 			continue;
151 
152 		/*
153 		 * A handler returns CMA_RA_SUCCESS to indicate that
154 		 * from this suspects  point-of-view the case may be
155 		 * closed, CMA_RA_FAILURE otherwise.
156 		 * A handler must not close the case itself.
157 		 */
158 		if (subr->subr_func != NULL) {
159 			err = subr->subr_func(hdl, nvl, asru, uuid);
160 
161 			if (err == CMA_RA_SUCCESS)
162 				keepopen--;
163 		}
164 	}
165 
166 	if (!keepopen)
167 		fmd_case_uuclose(hdl, uuid);
168 }
169 
170 static void
171 cma_recv_one(fmd_hdl_t *hdl, nvlist_t *nvl)
172 {
173 	const cma_subscriber_t *subr;
174 	nvlist_t *asru;
175 
176 	if ((subr = nvl2subr(hdl, nvl, &asru)) == NULL)
177 		return;
178 
179 	if (subr->subr_func != NULL)
180 		(void) subr->subr_func(hdl, nvl, asru, NULL);
181 
182 }
183 
184 /*ARGSUSED*/
185 static void
186 cma_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class)
187 {
188 	fmd_hdl_debug(hdl, "received %s\n", class);
189 
190 	if (strcmp(class, FM_LIST_SUSPECT_CLASS) == 0)
191 		cma_recv_list(hdl, nvl);
192 	else
193 		cma_recv_one(hdl, nvl);
194 }
195 
196 /*ARGSUSED*/
197 static void
198 cma_timeout(fmd_hdl_t *hdl, id_t id, void *arg)
199 {
200 	if (id == cma.cma_page_timerid)
201 		cma_page_retry(hdl);
202 }
203 
204 static const fmd_hdl_ops_t fmd_ops = {
205 	cma_recv,	/* fmdo_recv */
206 	cma_timeout,	/* fmdo_timeout */
207 	NULL,		/* fmdo_close */
208 	NULL,		/* fmdo_stats */
209 	NULL,		/* fmdo_gc */
210 };
211 
212 static const fmd_prop_t fmd_props[] = {
213 	{ "cpu_tries", FMD_TYPE_UINT32, "10" },
214 	{ "cpu_delay", FMD_TYPE_TIME, "1sec" },
215 	{ "cpu_offline_enable", FMD_TYPE_BOOL, "true" },
216 	{ "cpu_forced_offline", FMD_TYPE_BOOL, "true" },
217 	{ "cpu_blacklist_enable", FMD_TYPE_BOOL, "true" },
218 	{ "page_ret_mindelay", FMD_TYPE_TIME, "1sec" },
219 	{ "page_ret_maxdelay", FMD_TYPE_TIME, "5min" },
220 	{ "page_retire_enable", FMD_TYPE_BOOL, "true" },
221 #ifdef	i386
222 	/*
223 	 * On i386, leaving cases open while we retry the
224 	 * retire can cause the eft module to use large amounts
225 	 * of memory.  Until eft is fixed, we set a maximum number
226 	 * of retries on page retires, after which the case will
227 	 * be closed.
228 	 */
229 	{ "page_retire_maxretries", FMD_TYPE_UINT32, "8" },
230 #else
231 	{ "page_retire_maxretries", FMD_TYPE_UINT32, "0" },
232 #endif	/* i386 */
233 	{ NULL, 0, NULL }
234 };
235 
236 static const fmd_hdl_info_t fmd_info = {
237 	"CPU/Memory Retire Agent", CMA_VERSION, &fmd_ops, fmd_props
238 };
239 
240 void
241 _fmd_init(fmd_hdl_t *hdl)
242 {
243 	hrtime_t nsec;
244 
245 	if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0)
246 		return; /* invalid data in configuration file */
247 
248 	fmd_hdl_subscribe(hdl, "fault.cpu.*");
249 	fmd_hdl_subscribe(hdl, "fault.memory.*");
250 
251 	(void) fmd_stat_create(hdl, FMD_STAT_NOALLOC, sizeof (cma_stats) /
252 	    sizeof (fmd_stat_t), (fmd_stat_t *)&cma_stats);
253 
254 	cma.cma_cpu_tries = fmd_prop_get_int32(hdl, "cpu_tries");
255 
256 	nsec = fmd_prop_get_int64(hdl, "cpu_delay");
257 	cma.cma_cpu_delay.tv_sec = nsec / NANOSEC;
258 	cma.cma_cpu_delay.tv_nsec = nsec % NANOSEC;
259 
260 	cma.cma_page_mindelay = fmd_prop_get_int64(hdl, "page_ret_mindelay");
261 	cma.cma_page_maxdelay = fmd_prop_get_int64(hdl, "page_ret_maxdelay");
262 
263 	cma.cma_cpu_dooffline = fmd_prop_get_int32(hdl, "cpu_offline_enable");
264 	cma.cma_cpu_forcedoffline = fmd_prop_get_int32(hdl,
265 	    "cpu_forced_offline");
266 	cma.cma_cpu_doblacklist = fmd_prop_get_int32(hdl,
267 	    "cpu_blacklist_enable");
268 	cma.cma_page_doretire = fmd_prop_get_int32(hdl, "page_retire_enable");
269 	cma.cma_page_maxretries =
270 	    fmd_prop_get_int32(hdl, "page_retire_maxretries");
271 
272 	if (cma.cma_page_maxdelay < cma.cma_page_mindelay)
273 		fmd_hdl_abort(hdl, "page retirement delays conflict\n");
274 }
275 
276 void
277 _fmd_fini(fmd_hdl_t *hdl)
278 {
279 	cma_page_fini(hdl);
280 }
281