Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/sysmon Add a counter of busy events and stop enqueue...
details: https://anonhg.NetBSD.org/src/rev/a91795dec174
branches: trunk
changeset: 336726:a91795dec174
user: hannken <hannken%NetBSD.org@localhost>
date: Sat Mar 14 09:52:49 2015 +0000
description:
Add a counter of busy events and stop enqueueing more work if a device is busy.
Protect this counter with a new short time lock "sme_work_mtx" and
keep "sme_mtx" as long time lock.
Removes a deadlock where an active event holds "sme_mtx", the callout
"sme_events_check" blocks on "sme_mtx" and callout processing stops.
diffstat:
sys/dev/sysmon/sysmon_envsys.c | 6 ++++--
sys/dev/sysmon/sysmon_envsys_events.c | 21 +++++++++++++++++++--
sys/dev/sysmon/sysmonvar.h | 6 +++++-
3 files changed, 28 insertions(+), 5 deletions(-)
diffs (116 lines):
diff -r 543b443b9bd9 -r a91795dec174 sys/dev/sysmon/sysmon_envsys.c
--- a/sys/dev/sysmon/sysmon_envsys.c Sat Mar 14 08:32:07 2015 +0000
+++ b/sys/dev/sysmon/sysmon_envsys.c Sat Mar 14 09:52:49 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys.c,v 1.128 2014/11/23 10:00:20 ozaki-r Exp $ */
+/* $NetBSD: sysmon_envsys.c,v 1.129 2015/03/14 09:52:49 hannken 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.128 2014/11/23 10:00:20 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.129 2015/03/14 09:52:49 hannken Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -485,6 +485,7 @@
TAILQ_INIT(&sme->sme_sensors_list);
LIST_INIT(&sme->sme_events_list);
mutex_init(&sme->sme_mtx, MUTEX_DEFAULT, IPL_NONE);
+ mutex_init(&sme->sme_work_mtx, MUTEX_DEFAULT, IPL_NONE);
cv_init(&sme->sme_condvar, "sme_wait");
return sme;
@@ -508,6 +509,7 @@
TAILQ_REMOVE(&sme->sme_sensors_list, edata, sensors_head);
}
mutex_destroy(&sme->sme_mtx);
+ mutex_destroy(&sme->sme_work_mtx);
cv_destroy(&sme->sme_condvar);
kmem_free(sme, sizeof(*sme));
}
diff -r 543b443b9bd9 -r a91795dec174 sys/dev/sysmon/sysmon_envsys_events.c
--- a/sys/dev/sysmon/sysmon_envsys_events.c Sat Mar 14 08:32:07 2015 +0000
+++ b/sys/dev/sysmon/sysmon_envsys_events.c Sat Mar 14 09:52:49 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.113 2014/11/23 10:00:20 ozaki-r Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.114 2015/03/14 09:52:49 hannken Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.113 2014/11/23 10:00:20 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.114 2015/03/14 09:52:49 hannken Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -42,6 +42,7 @@
#include <sys/mutex.h>
#include <sys/kmem.h>
#include <sys/callout.h>
+#include <sys/syslog.h>
#include <dev/sysmon/sysmonvar.h>
#include <dev/sysmon/sysmon_envsysvar.h>
@@ -731,11 +732,23 @@
KASSERT(sme != NULL);
+ mutex_enter(&sme->sme_work_mtx);
+ if (sme->sme_busy > 0) {
+ log(LOG_WARNING, "%s: workqueue busy: updates stopped\n",
+ sme->sme_name);
+ mutex_exit(&sme->sme_work_mtx);
+ return;
+ }
+ mutex_exit(&sme->sme_work_mtx);
+
mutex_enter(&sme->sme_mtx);
+ mutex_enter(&sme->sme_work_mtx);
LIST_FOREACH(see, &sme->sme_events_list, see_list) {
workqueue_enqueue(sme->sme_wq, &see->see_wk, NULL);
see->see_edata->flags |= ENVSYS_FNEED_REFRESH;
+ sme->sme_busy++;
}
+ mutex_exit(&sme->sme_work_mtx);
if (!sysmon_low_power)
sme_schedule_callout(sme);
mutex_exit(&sme->sme_mtx);
@@ -815,6 +828,10 @@
out:
see->see_flags &= ~SEE_EVENT_WORKING;
cv_broadcast(&sme->sme_condvar);
+ mutex_enter(&sme->sme_work_mtx);
+ KASSERT(sme->sme_busy > 0);
+ sme->sme_busy--;
+ mutex_exit(&sme->sme_work_mtx);
mutex_exit(&sme->sme_mtx);
}
diff -r 543b443b9bd9 -r a91795dec174 sys/dev/sysmon/sysmonvar.h
--- a/sys/dev/sysmon/sysmonvar.h Sat Mar 14 08:32:07 2015 +0000
+++ b/sys/dev/sysmon/sysmonvar.h Sat Mar 14 09:52:49 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmonvar.h,v 1.45 2014/11/22 15:00:05 ozaki-r Exp $ */
+/* $NetBSD: sysmonvar.h,v 1.46 2015/03/14 09:52:49 hannken Exp $ */
/*-
* Copyright (c) 2000 Zembu Labs, Inc.
@@ -207,7 +207,11 @@
/*
* Locking/synchronization.
*/
+ int sme_busy; /* number of items on workqueue,
+ sme_mtx or sme_work_mtx to read,
+ both to write */
kmutex_t sme_mtx;
+ kmutex_t sme_work_mtx;
kcondvar_t sme_condvar;
};
Home |
Main Index |
Thread Index |
Old Index