Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/sysmon Handle early initialization requirements - th...
details: https://anonhg.NetBSD.org/src/rev/bf4bc116cf36
branches: trunk
changeset: 337744:bf4bc116cf36
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Sat Apr 25 23:40:09 2015 +0000
description:
Handle early initialization requirements - thanks martin@ and others
diffstat:
sys/dev/sysmon/sysmon_envsys.c | 20 ++++++++++----------
sys/dev/sysmon/sysmon_power.c | 24 +++++++++++++++++++-----
sys/dev/sysmon/sysmon_wdog.c | 25 ++++++++++++++++++++-----
3 files changed, 49 insertions(+), 20 deletions(-)
diffs (199 lines):
diff -r 62dc7af40abb -r bf4bc116cf36 sys/dev/sysmon/sysmon_envsys.c
--- a/sys/dev/sysmon/sysmon_envsys.c Sat Apr 25 23:40:08 2015 +0000
+++ b/sys/dev/sysmon/sysmon_envsys.c Sat Apr 25 23:40:09 2015 +0000
@@ -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 @@
#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 @@
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 @@
{
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 @@
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
diff -r 62dc7af40abb -r bf4bc116cf36 sys/dev/sysmon/sysmon_power.c
--- a/sys/dev/sysmon/sysmon_power.c Sat Apr 25 23:40:08 2015 +0000
+++ b/sys/dev/sysmon/sysmon_power.c Sat Apr 25 23:40:09 2015 +0000
@@ -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 @@
#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 @@
#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 @@
{
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 @@
int
sysmon_pswitch_register(struct sysmon_pswitch *smpsw)
{
- /* nada */
+ (void)RUN_ONCE(&once_power, power_preinit);
+
return 0;
}
diff -r 62dc7af40abb -r bf4bc116cf36 sys/dev/sysmon/sysmon_wdog.c
--- a/sys/dev/sysmon/sysmon_wdog.c Sat Apr 25 23:40:08 2015 +0000
+++ b/sys/dev/sysmon/sysmon_wdog.c Sat Apr 25 23:40:09 2015 +0000
@@ -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 @@
#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 @@
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 @@
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) {
Home |
Main Index |
Thread Index |
Old Index