xref: /onnv-gate/usr/src/cmd/fm/modules/sun4v/generic-mem/gmem_main.c (revision 12467:1f2119e1bc03)
18346SScott.Davenport@Sun.COM /*
28346SScott.Davenport@Sun.COM  * CDDL HEADER START
38346SScott.Davenport@Sun.COM  *
48346SScott.Davenport@Sun.COM  * The contents of this file are subject to the terms of the
58346SScott.Davenport@Sun.COM  * Common Development and Distribution License (the "License").
68346SScott.Davenport@Sun.COM  * You may not use this file except in compliance with the License.
78346SScott.Davenport@Sun.COM  *
88346SScott.Davenport@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98346SScott.Davenport@Sun.COM  * or http://www.opensolaris.org/os/licensing.
108346SScott.Davenport@Sun.COM  * See the License for the specific language governing permissions
118346SScott.Davenport@Sun.COM  * and limitations under the License.
128346SScott.Davenport@Sun.COM  *
138346SScott.Davenport@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
148346SScott.Davenport@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158346SScott.Davenport@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
168346SScott.Davenport@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
178346SScott.Davenport@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
188346SScott.Davenport@Sun.COM  *
198346SScott.Davenport@Sun.COM  * CDDL HEADER END
208346SScott.Davenport@Sun.COM  */
218346SScott.Davenport@Sun.COM /*
22*12467STrang.Do@Sun.COM  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
238346SScott.Davenport@Sun.COM  */
248346SScott.Davenport@Sun.COM 
258346SScott.Davenport@Sun.COM #include <gmem_state.h>
268346SScott.Davenport@Sun.COM #include <gmem_mem.h>
278346SScott.Davenport@Sun.COM #include <gmem_page.h>
288346SScott.Davenport@Sun.COM #include <gmem_dimm.h>
298346SScott.Davenport@Sun.COM #include <gmem.h>
308346SScott.Davenport@Sun.COM 
318346SScott.Davenport@Sun.COM #include <errno.h>
328346SScott.Davenport@Sun.COM #include <string.h>
338346SScott.Davenport@Sun.COM #include <unistd.h>
348346SScott.Davenport@Sun.COM #include <strings.h>
358346SScott.Davenport@Sun.COM #include <fm/fmd_api.h>
368346SScott.Davenport@Sun.COM #include <fm/libtopo.h>
378346SScott.Davenport@Sun.COM #include <sys/fm/protocol.h>
388346SScott.Davenport@Sun.COM #include <sys/async.h>
398346SScott.Davenport@Sun.COM 
408346SScott.Davenport@Sun.COM gmem_t gmem;
418346SScott.Davenport@Sun.COM 
428346SScott.Davenport@Sun.COM typedef struct gmem_subscriber {
438346SScott.Davenport@Sun.COM 	const char *subr_class;
448346SScott.Davenport@Sun.COM 	gmem_evdisp_t (*subr_func)(fmd_hdl_t *, fmd_event_t *, nvlist_t *,
458346SScott.Davenport@Sun.COM 	    const char *);
468346SScott.Davenport@Sun.COM 	gmem_evdisp_stat_t subr_stat;
478346SScott.Davenport@Sun.COM } gmem_subscriber_t;
488346SScott.Davenport@Sun.COM 
498346SScott.Davenport@Sun.COM static gmem_subscriber_t gmem_subscribers[] = {
508346SScott.Davenport@Sun.COM 	{ "ereport.cpu.generic-sparc.mem-is",	gmem_ce },
518346SScott.Davenport@Sun.COM 	{ "ereport.cpu.generic-sparc.mem-unk",	gmem_ce },
528346SScott.Davenport@Sun.COM 	{ "ereport.cpu.generic-sparc.mem-cs",	gmem_ce },
538346SScott.Davenport@Sun.COM 	{ "ereport.cpu.generic-sparc.mem-ss",	gmem_ce },
548346SScott.Davenport@Sun.COM 	{ NULL, NULL }
558346SScott.Davenport@Sun.COM };
568346SScott.Davenport@Sun.COM 
578346SScott.Davenport@Sun.COM static void
gmem_recv(fmd_hdl_t * hdl,fmd_event_t * ep,nvlist_t * nvl,const char * class)588346SScott.Davenport@Sun.COM gmem_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class)
598346SScott.Davenport@Sun.COM {
608346SScott.Davenport@Sun.COM 	gmem_subscriber_t *sp;
618346SScott.Davenport@Sun.COM 	int disp;
628346SScott.Davenport@Sun.COM 
638346SScott.Davenport@Sun.COM 	fmd_hdl_debug(hdl, "gmem_recv: begin: %s\n", strrchr(class, '.') + 1);
648346SScott.Davenport@Sun.COM 
658346SScott.Davenport@Sun.COM 	for (sp = gmem_subscribers; sp->subr_class != NULL; sp++) {
668346SScott.Davenport@Sun.COM 		if (fmd_nvl_class_match(hdl, nvl, sp->subr_class)) {
678346SScott.Davenport@Sun.COM 			disp = sp->subr_func(hdl, ep, nvl, class);
688346SScott.Davenport@Sun.COM 			((fmd_stat_t *)&sp->subr_stat)[disp].fmds_value.ui64++;
698346SScott.Davenport@Sun.COM 			fmd_hdl_debug(hdl, "gmem_recv: done: %s (disp %d)\n",
708346SScott.Davenport@Sun.COM 			    strrchr(class, '.') + 1, disp);
718346SScott.Davenport@Sun.COM 			return;
728346SScott.Davenport@Sun.COM 		}
738346SScott.Davenport@Sun.COM 	}
748346SScott.Davenport@Sun.COM 
758346SScott.Davenport@Sun.COM 	fmd_hdl_debug(hdl, "gmem_recv: dropping %s - unable to handle\n",
768346SScott.Davenport@Sun.COM 	    class);
778346SScott.Davenport@Sun.COM }
788346SScott.Davenport@Sun.COM 
798346SScott.Davenport@Sun.COM static void
gmem_close(fmd_hdl_t * hdl,fmd_case_t * cp)808346SScott.Davenport@Sun.COM gmem_close(fmd_hdl_t *hdl, fmd_case_t *cp)
818346SScott.Davenport@Sun.COM {
828346SScott.Davenport@Sun.COM 	gmem_case_closer_t *cl = fmd_case_getspecific(hdl, cp);
838346SScott.Davenport@Sun.COM 	const char *uuid = fmd_case_uuid(hdl, cp);
848346SScott.Davenport@Sun.COM 
858346SScott.Davenport@Sun.COM 	/*
868346SScott.Davenport@Sun.COM 	 * Our active cases all have closers registered in case-specific data.
878346SScott.Davenport@Sun.COM 	 * Cases in the process of closing (for which we've freed all associated
888346SScott.Davenport@Sun.COM 	 * data, but which haven't had an fmd-initiated fmdo_close callback)
898346SScott.Davenport@Sun.COM 	 * have had their case-specific data nulled out.
908346SScott.Davenport@Sun.COM 	 */
918346SScott.Davenport@Sun.COM 	fmd_hdl_debug(hdl, "close case %s%s\n", uuid,
928346SScott.Davenport@Sun.COM 	    (cl == NULL ? " (no cl)" : ""));
938346SScott.Davenport@Sun.COM 
948346SScott.Davenport@Sun.COM 	if (cl != NULL)
958346SScott.Davenport@Sun.COM 		cl->cl_func(hdl, cl->cl_arg);
968346SScott.Davenport@Sun.COM }
978346SScott.Davenport@Sun.COM 
988346SScott.Davenport@Sun.COM static void
gmem_gc(fmd_hdl_t * hdl)998346SScott.Davenport@Sun.COM gmem_gc(fmd_hdl_t *hdl)
1008346SScott.Davenport@Sun.COM {
1018346SScott.Davenport@Sun.COM 	gmem_mem_gc(hdl);
1028346SScott.Davenport@Sun.COM }
1038346SScott.Davenport@Sun.COM 
1048346SScott.Davenport@Sun.COM static gmem_stat_t gm_stats = {
1058346SScott.Davenport@Sun.COM 	{ "bad_mem_resource", FMD_TYPE_UINT64,
1068346SScott.Davenport@Sun.COM 	    "memory resource missing or malformed" },
1078346SScott.Davenport@Sun.COM 	{ "bad_close", FMD_TYPE_UINT64, "case close for nonexistent case" },
1088346SScott.Davenport@Sun.COM 	{ "old_erpt", FMD_TYPE_UINT64, "ereport out of date wrt hardware" },
1098346SScott.Davenport@Sun.COM 	{ "dimm_creat", FMD_TYPE_UINT64, "created new mem module structure" },
1108346SScott.Davenport@Sun.COM 	{ "page_creat", FMD_TYPE_UINT64, "created new page structure" },
1118346SScott.Davenport@Sun.COM 	{ "ce_unknown", FMD_TYPE_UINT64, "unknown CEs" },
1128346SScott.Davenport@Sun.COM 	{ "ce_interm", FMD_TYPE_UINT64, "intermittent CEs" },
1138346SScott.Davenport@Sun.COM 	{ "ce_clearable_persis", FMD_TYPE_UINT64, "clearable persistent CEs" },
1148346SScott.Davenport@Sun.COM 	{ "ce_sticky", FMD_TYPE_UINT64, "sticky CEs" },
115*12467STrang.Do@Sun.COM 	{ "dimm_migrat", FMD_TYPE_UINT64, "DIMMs migrated to new version" }
1168346SScott.Davenport@Sun.COM };
1178346SScott.Davenport@Sun.COM 
1188346SScott.Davenport@Sun.COM static const fmd_prop_t fmd_props[] = {
1198346SScott.Davenport@Sun.COM 	{ "ce_n", FMD_TYPE_UINT32, "3" },
1208346SScott.Davenport@Sun.COM 	{ "ce_t", FMD_TYPE_TIME, "72h" },
1218346SScott.Davenport@Sun.COM 	{ "filter_ratio", FMD_TYPE_UINT32, "0" },
1228346SScott.Davenport@Sun.COM 	{ "max_retired_pages", FMD_TYPE_UINT32, "512" },
123*12467STrang.Do@Sun.COM 	{ "low_ce_thresh", FMD_TYPE_UINT32, "128"},
124*12467STrang.Do@Sun.COM 	{ "nupos", FMD_TYPE_UINT32, "4"},
125*12467STrang.Do@Sun.COM 	{ "dupce", FMD_TYPE_UINT32, "120"},
1268346SScott.Davenport@Sun.COM 	{ NULL, 0, NULL }
1278346SScott.Davenport@Sun.COM };
1288346SScott.Davenport@Sun.COM 
1298346SScott.Davenport@Sun.COM static const fmd_hdl_ops_t fmd_ops = {
1308346SScott.Davenport@Sun.COM 	gmem_recv,	/* fmdo_recv */
1318346SScott.Davenport@Sun.COM 	NULL,
1328346SScott.Davenport@Sun.COM 	gmem_close,	/* fmdo_close */
1338346SScott.Davenport@Sun.COM 	NULL,		/* fmdo_stats */
1348346SScott.Davenport@Sun.COM 	gmem_gc		/* fmdo_gc */
1358346SScott.Davenport@Sun.COM };
1368346SScott.Davenport@Sun.COM 
1378346SScott.Davenport@Sun.COM static const fmd_hdl_info_t fmd_info = {
1388346SScott.Davenport@Sun.COM 	"SPARC-Generic-Memory Diagnosis", GMEM_VERSION, &fmd_ops, fmd_props
1398346SScott.Davenport@Sun.COM };
1408346SScott.Davenport@Sun.COM 
1418346SScott.Davenport@Sun.COM static const struct gmem_evdisp_name {
1428346SScott.Davenport@Sun.COM 	const char *evn_name;
1438346SScott.Davenport@Sun.COM 	const char *evn_desc;
1448346SScott.Davenport@Sun.COM } gmem_evdisp_names[] = {
1458346SScott.Davenport@Sun.COM 	{ "%s", "ok %s ereports" },			/* GMEM_EVD_OK */
1468346SScott.Davenport@Sun.COM 	{ "bad_%s", "bad %s ereports" },		/* GMEM_EVD_BAD */
1478346SScott.Davenport@Sun.COM 	{ "unused_%s", "unused %s ereports" },		/* GMEM_EVD_UNUSED */
1488346SScott.Davenport@Sun.COM 	{ "redun_%s", "redundant %s ereports" },	/* GMEM_EVD_REDUN */
1498346SScott.Davenport@Sun.COM };
1508346SScott.Davenport@Sun.COM 
1518346SScott.Davenport@Sun.COM void
_fmd_fini(fmd_hdl_t * hdl)1528346SScott.Davenport@Sun.COM _fmd_fini(fmd_hdl_t *hdl)
1538346SScott.Davenport@Sun.COM {
1548346SScott.Davenport@Sun.COM 	gmem_mem_fini(hdl);
1558346SScott.Davenport@Sun.COM 	gmem_page_fini(hdl);
1568346SScott.Davenport@Sun.COM }
1578346SScott.Davenport@Sun.COM 
1588346SScott.Davenport@Sun.COM void
_fmd_init(fmd_hdl_t * hdl)1598346SScott.Davenport@Sun.COM _fmd_init(fmd_hdl_t *hdl)
1608346SScott.Davenport@Sun.COM {
1618346SScott.Davenport@Sun.COM 	gmem_subscriber_t *sp;
1628346SScott.Davenport@Sun.COM 
1638346SScott.Davenport@Sun.COM 	if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0)
1648346SScott.Davenport@Sun.COM 		return; /* error in configuration file or fmd_info */
1658346SScott.Davenport@Sun.COM 
1668346SScott.Davenport@Sun.COM 	for (sp = gmem_subscribers; sp->subr_class != NULL; sp++)
1678346SScott.Davenport@Sun.COM 		fmd_hdl_subscribe(hdl, sp->subr_class);
1688346SScott.Davenport@Sun.COM 
1698346SScott.Davenport@Sun.COM 	bzero(&gmem, sizeof (gmem_t));
1708346SScott.Davenport@Sun.COM 
1718346SScott.Davenport@Sun.COM 	gmem.gm_stats = (gmem_stat_t *)fmd_stat_create(hdl, FMD_STAT_NOALLOC,
1728346SScott.Davenport@Sun.COM 	    sizeof (gm_stats) / sizeof (fmd_stat_t),
1738346SScott.Davenport@Sun.COM 	    (fmd_stat_t *)&gm_stats);
1748346SScott.Davenport@Sun.COM 
1758346SScott.Davenport@Sun.COM 	for (sp = gmem_subscribers; sp->subr_class != NULL; sp++) {
1768346SScott.Davenport@Sun.COM 		const char *type = strrchr(sp->subr_class, '.') + 1;
1778346SScott.Davenport@Sun.COM 		int i;
1788346SScott.Davenport@Sun.COM 
1798346SScott.Davenport@Sun.COM 		for (i = 0; i < sizeof (gmem_evdisp_names) /
1808346SScott.Davenport@Sun.COM 		    sizeof (struct gmem_evdisp_name); i++) {
1818346SScott.Davenport@Sun.COM 			fmd_stat_t *stat = ((fmd_stat_t *)&sp->subr_stat) + i;
1828346SScott.Davenport@Sun.COM 
1838346SScott.Davenport@Sun.COM 			(void) snprintf(stat->fmds_name,
1848346SScott.Davenport@Sun.COM 			    sizeof (stat->fmds_name),
1858346SScott.Davenport@Sun.COM 			    gmem_evdisp_names[i].evn_name, type);
1868346SScott.Davenport@Sun.COM 
1878346SScott.Davenport@Sun.COM 			stat->fmds_type = FMD_TYPE_UINT64;
1888346SScott.Davenport@Sun.COM 			(void) snprintf(stat->fmds_desc,
1898346SScott.Davenport@Sun.COM 			    sizeof (stat->fmds_desc),
1908346SScott.Davenport@Sun.COM 			    gmem_evdisp_names[i].evn_desc, type);
1918346SScott.Davenport@Sun.COM 
1928346SScott.Davenport@Sun.COM 			(void) fmd_stat_create(hdl, FMD_STAT_NOALLOC, 1, stat);
1938346SScott.Davenport@Sun.COM 		}
1948346SScott.Davenport@Sun.COM 	}
1958346SScott.Davenport@Sun.COM 
1968346SScott.Davenport@Sun.COM 	gmem.gm_pagesize = sysconf(_SC_PAGESIZE);
1978346SScott.Davenport@Sun.COM 	gmem.gm_pagemask = ~((uint64_t)gmem.gm_pagesize - 1);
1988346SScott.Davenport@Sun.COM 
1998346SScott.Davenport@Sun.COM 	gmem.gm_max_retired_pages = fmd_prop_get_int32(hdl,
2008346SScott.Davenport@Sun.COM 	    "max_retired_pages");
2018346SScott.Davenport@Sun.COM 
2028346SScott.Davenport@Sun.COM 	gmem.gm_ce_n = fmd_prop_get_int32(hdl, "ce_n");
2038346SScott.Davenport@Sun.COM 	gmem.gm_ce_t = fmd_prop_get_int64(hdl, "ce_t");
2048346SScott.Davenport@Sun.COM 	gmem.gm_filter_ratio = fmd_prop_get_int32(hdl, "filter_ratio");
205*12467STrang.Do@Sun.COM 	gmem.gm_low_ce_thresh = fmd_prop_get_int32(hdl, "low_ce_thresh");
206*12467STrang.Do@Sun.COM 	gmem.gm_nupos = fmd_prop_get_int32(hdl, "nupos");
207*12467STrang.Do@Sun.COM 	gmem.gm_dupce = fmd_prop_get_int32(hdl, "dupce");
208*12467STrang.Do@Sun.COM 
2098346SScott.Davenport@Sun.COM 
2108346SScott.Davenport@Sun.COM 	if (gmem_state_restore(hdl) < 0) {
2118346SScott.Davenport@Sun.COM 		_fmd_fini(hdl);
2128346SScott.Davenport@Sun.COM 		fmd_hdl_abort(hdl, "failed to restore saved state\n");
2138346SScott.Davenport@Sun.COM 	}
2148346SScott.Davenport@Sun.COM }
215