Handle early initialization requirements - thanks martin@ and others

This commit is contained in:
pgoyette 2015-04-25 23:40:09 +00:00
parent 66a3d0a3c8
commit eb659e1350
3 changed files with 49 additions and 20 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysmon_envsys.c,v 1.136 2015/04/25 14:06:58 christos Exp $ */
/* $NetBSD: sysmon_envsys.c,v 1.137 2015/04/25 23:40:09 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.136 2015/04/25 14:06:58 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.137 2015/04/25 23:40:09 pgoyette Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -78,6 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.136 2015/04/25 14:06:58 christos
#include <sys/kmem.h>
#include <sys/rndsource.h>
#include <sys/module.h>
#include <sys/once.h>
#include <dev/sysmon/sysmonvar.h>
#include <dev/sysmon/sysmon_envsysvar.h>
@ -109,18 +110,17 @@ static struct sysmon_opvec sysmon_envsys_opvec = {
NULL, NULL, NULL
};
static void
ONCE_DECL(once_envsys);
static int
sme_preinit(void)
{
static bool passed = false;
if (passed)
return;
passed = true;
LIST_INIT(&sysmon_envsys_list);
mutex_init(&sme_global_mtx, MUTEX_DEFAULT, IPL_NONE);
sme_propd = prop_dictionary_create();
return 0;
}
/*
@ -133,7 +133,7 @@ sysmon_envsys_init(void)
{
int error;
sme_preinit();
(void)RUN_ONCE(&once_envsys, sme_preinit);
error = sysmon_attach_minor(SYSMON_MINOR_ENVSYS, &sysmon_envsys_opvec);
@ -694,7 +694,7 @@ sysmon_envsys_register(struct sysmon_envsys *sme)
KASSERT(sme != NULL);
KASSERT(sme->sme_name != NULL);
sme_preinit();
(void)RUN_ONCE(&once_envsys, sme_preinit);
/*
* Check if requested sysmon_envsys device is valid

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysmon_power.c,v 1.54 2015/04/23 23:22:03 pgoyette Exp $ */
/* $NetBSD: sysmon_power.c,v 1.55 2015/04/25 23:40:09 pgoyette Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.54 2015/04/23 23:22:03 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.55 2015/04/25 23:40:09 pgoyette Exp $");
#ifndef _LKM
#include "opt_compat_netbsd.h"
@ -88,6 +88,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.54 2015/04/23 23:22:03 pgoyette E
#include <sys/device.h>
#include <sys/rndsource.h>
#include <sys/module.h>
#include <sys/once.h>
#include <dev/sysmon/sysmonvar.h>
#include <prop/proplib.h>
@ -199,6 +200,18 @@ static struct sysmon_opvec sysmon_power_opvec = {
#define SYSMON_NEXT_EVENT(x) (((x) + 1) % SYSMON_MAX_POWER_EVENTS)
ONCE_DECL(once_power);
static int
power_preinit(void)
{
mutex_init(&sysmon_power_event_queue_mtx, MUTEX_DEFAULT, IPL_NONE);
cv_init(&sysmon_power_event_queue_cv, "smpower");
return 0;
}
/*
* sysmon_power_init:
*
@ -210,8 +223,8 @@ sysmon_power_init(void)
{
int error;
mutex_init(&sysmon_power_event_queue_mtx, MUTEX_DEFAULT, IPL_NONE);
cv_init(&sysmon_power_event_queue_cv, "smpower");
(void)RUN_ONCE(&once_power, power_preinit);
selinit(&sysmon_power_event_queue_selinfo);
rnd_attach_source(&sysmon_rndsource, "system-power",
@ -938,7 +951,8 @@ sysmon_penvsys_event(struct penvsys_state *pes, int event)
int
sysmon_pswitch_register(struct sysmon_pswitch *smpsw)
{
/* nada */
(void)RUN_ONCE(&once_power, power_preinit);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysmon_wdog.c,v 1.26 2015/04/23 23:22:03 pgoyette Exp $ */
/* $NetBSD: sysmon_wdog.c,v 1.27 2015/04/25 23:40:09 pgoyette Exp $ */
/*-
* Copyright (c) 2000 Zembu Labs, Inc.
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysmon_wdog.c,v 1.26 2015/04/23 23:22:03 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysmon_wdog.c,v 1.27 2015/04/25 23:40:09 pgoyette Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_wdog.c,v 1.26 2015/04/23 23:22:03 pgoyette Ex
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/once.h>
#include <dev/sysmon/sysmonvar.h>
@ -82,14 +83,26 @@ static struct sysmon_opvec sysmon_wdog_opvec = {
MODULE(MODULE_CLASS_MISC, sysmon_wdog, "sysmon");
ONCE_DECL(once_wdog);
static int
wdog_preinit(void)
{
mutex_init(&sysmon_wdog_list_mtx, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&sysmon_wdog_mtx, MUTEX_DEFAULT, IPL_SOFTCLOCK);
cv_init(&sysmon_wdog_cv, "wdogref");
return 0;
}
int
sysmon_wdog_init(void)
{
int error;
mutex_init(&sysmon_wdog_list_mtx, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&sysmon_wdog_mtx, MUTEX_DEFAULT, IPL_SOFTCLOCK);
cv_init(&sysmon_wdog_cv, "wdogref");
(void)RUN_ONCE(&once_wdog, wdog_preinit);
sysmon_wdog_sdhook = shutdownhook_establish(sysmon_wdog_shutdown, NULL);
if (sysmon_wdog_sdhook == NULL)
printf("WARNING: unable to register watchdog shutdown hook\n");
@ -312,6 +325,8 @@ sysmon_wdog_register(struct sysmon_wdog *smw)
struct sysmon_wdog *lsmw;
int error = 0;
(void)RUN_ONCE(&once_wdog, wdog_preinit);
mutex_enter(&sysmon_wdog_list_mtx);
LIST_FOREACH(lsmw, &sysmon_wdog_list, smw_list) {