diff options
| author | xtraeme <xtraeme@NetBSD.org> | 2008-03-23 16:09:41 +0000 |
|---|---|---|
| committer | xtraeme <xtraeme@NetBSD.org> | 2008-03-23 16:09:41 +0000 |
| commit | a826e85aba4f268ce74a4c6222e4e32c5c30ca79 (patch) | |
| tree | c17275905ce453d30a50daa89cb5009b4e04ecc0 /sys/dev/sysmon | |
| parent | a27f79f69e578bd2df636a8713d538eb2647d767 (diff) | |
Fix some problems reported by <drochner> a while ago on tech-kern:
sme_events_worker: skip sensors with invalid state.
sme_acadapter_check:
* use a boolean to check if an SME_CLASS_ACADAPTER was found.
* Always refresh sensor data before checking value_cur.
Introduce the SME_INIT_REFRESH flag. If a device sets this it will mean
that after interrupts are enabled in the autoconf(9) process, sensor
data will be refreshed once.
Diffstat (limited to 'sys/dev/sysmon')
| -rw-r--r-- | sys/dev/sysmon/sysmon_envsys.c | 38 | ||||
| -rw-r--r-- | sys/dev/sysmon/sysmon_envsys_events.c | 30 | ||||
| -rw-r--r-- | sys/dev/sysmon/sysmonvar.h | 5 |
3 files changed, 53 insertions, 20 deletions
diff --git a/sys/dev/sysmon/sysmon_envsys.c b/sys/dev/sysmon/sysmon_envsys.c index a7e6c0dd986..583ce8f180c 100644 --- a/sys/dev/sysmon/sysmon_envsys.c +++ b/sys/dev/sysmon/sysmon_envsys.c @@ -1,7 +1,7 @@ -/* $NetBSD: sysmon_envsys.c,v 1.80 2008/02/02 02:02:37 xtraeme Exp $ */ +/* $NetBSD: sysmon_envsys.c,v 1.81 2008/03/23 16:09:41 xtraeme Exp $ */ /*- - * Copyright (c) 2007 Juan Romero Pardines. + * Copyright (c) 2007, 2008 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,7 +64,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.80 2008/02/02 02:02:37 xtraeme Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.81 2008/03/23 16:09:41 xtraeme Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -120,6 +120,7 @@ static void sysmon_envsys_destroy_plist(prop_array_t); static void sme_remove_userprops(void); static int sme_add_property_dictionary(struct sysmon_envsys *, prop_array_t, prop_dictionary_t); +static void sme_initial_refresh(void *); /* * sysmon_envsys_init: @@ -660,7 +661,7 @@ sysmon_envsys_register(struct sysmon_envsys *sme) prop_dictionary_t dict, dict2; prop_array_t array; envsys_data_t *edata = NULL; - int i, error = 0; + int error = 0; KASSERT(sme != NULL); KASSERT(sme->sme_name != NULL); @@ -778,18 +779,20 @@ out: mutex_exit(&sme_mtx); /* - * No errors? register the events that were set in the driver. + * No errors? register the events that were set in the driver + * and make an initial data refresh if was requested. */ if (error == 0) { - i = 0; + sysmon_task_queue_init(); SLIST_FOREACH(sme_evdrv, &sme_evdrv_list, evdrv_head) { - if (i == 0) - sysmon_task_queue_init(); sysmon_task_queue_sched(0, sme_event_drvadd, sme_evdrv->evdrv); } DPRINTF(("%s: driver '%s' registered (nsens=%d)\n", __func__, sme->sme_name, sme->sme_nsensors)); + + if (sme->sme_flags & SME_INIT_REFRESH) + sysmon_task_queue_sched(0, sme_initial_refresh, sme); } out2: @@ -993,6 +996,25 @@ again: } /* + * sme_initial_refresh: + * + * + Do an initial refresh of the sensors in a device just after + * interrupts are enabled in the autoconf(9) process. + * + */ +static void +sme_initial_refresh(void *arg) +{ + struct sysmon_envsys *sme = arg; + envsys_data_t *edata; + + mutex_enter(&sme_mtx); + TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) + (*sme->sme_refresh)(sme, edata); + mutex_exit(&sme_mtx); +} + +/* * sme_sensor_dictionary_get: * * + Returns a dictionary of a device specified by its index diff --git a/sys/dev/sysmon/sysmon_envsys_events.c b/sys/dev/sysmon/sysmon_envsys_events.c index 8467f925f32..d8f301dcd79 100644 --- a/sys/dev/sysmon/sysmon_envsys_events.c +++ b/sys/dev/sysmon/sysmon_envsys_events.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysmon_envsys_events.c,v 1.49 2008/02/29 14:34:49 xtraeme Exp $ */ +/* $NetBSD: sysmon_envsys_events.c,v 1.50 2008/03/23 16:09:41 xtraeme Exp $ */ /*- * Copyright (c) 2007 Juan Romero Pardines. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.49 2008/02/29 14:34:49 xtraeme Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.50 2008/03/23 16:09:41 xtraeme Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -62,8 +62,6 @@ static const struct sme_sensor_event sme_sensor_event[] = { { -1, -1 } }; -kmutex_t sme_mtx, sme_events_mtx, sme_callout_mtx; -kcondvar_t sme_cv; static bool sysmon_low_power = false; #define SME_EVTIMO (SME_EVENTS_DEFTIMEOUT * hz) @@ -471,11 +469,15 @@ sme_events_worker(struct work *wk, void *arg) } } - DPRINTFOBJ(("%s: (%s) desc=%s sensor=%d units=%d value_cur=%d\n", - __func__, sme->sme_name, see->see_edata->desc, - see->see_edata->sensor, + DPRINTFOBJ(("%s: (%s) desc=%s sensor=%d state=%d units=%d " + "value_cur=%d\n", __func__, sme->sme_name, see->see_edata->desc, + see->see_edata->sensor, see->see_edata->state, see->see_edata->units, see->see_edata->value_cur)); + /* skip the event if current sensor is in invalid state */ + if (see->see_edata->state == ENVSYS_SINVALID) + goto out; + #define SME_SEND_NORMALEVENT() \ do { \ see->see_evsent = false; \ @@ -615,6 +617,7 @@ do { \ break; } +out: see->see_flags &= ~SME_EVENT_WORKING; cv_broadcast(&sme_cv); mutex_exit(&sme_mtx); @@ -640,17 +643,20 @@ sme_acadapter_check(void) { struct sysmon_envsys *sme; envsys_data_t *edata; - bool sensor = false; + bool dev = false, sensor = false; KASSERT(mutex_owned(&sme_mtx)); - LIST_FOREACH(sme, &sysmon_envsys_list, sme_list) - if (sme->sme_class == SME_CLASS_ACADAPTER) + LIST_FOREACH(sme, &sysmon_envsys_list, sme_list) { + if (sme->sme_class == SME_CLASS_ACADAPTER) { + dev = true; break; + } + } /* * No AC Adapter devices were found. */ - if (!sme) + if (!dev) return false; /* * Check if there's an AC adapter device connected. @@ -658,6 +664,8 @@ sme_acadapter_check(void) TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) { if (edata->units == ENVSYS_INDICATOR) { sensor = true; + /* refresh current sensor */ + (*sme->sme_refresh)(sme, edata); if (edata->value_cur) return false; } diff --git a/sys/dev/sysmon/sysmonvar.h b/sys/dev/sysmon/sysmonvar.h index 231f777b649..5d769309f65 100644 --- a/sys/dev/sysmon/sysmonvar.h +++ b/sys/dev/sysmon/sysmonvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: sysmonvar.h,v 1.23 2007/12/16 21:07:46 dyoung Exp $ */ +/* $NetBSD: sysmonvar.h,v 1.24 2008/03/23 16:09:41 xtraeme Exp $ */ /*- * Copyright (c) 2000 Zembu Labs, Inc. @@ -71,6 +71,9 @@ struct sysmon_envsys { #define SME_FLAG_BUSY 0x00000001 /* device busy */ #define SME_DISABLE_REFRESH 0x00000002 /* disable sme_refresh */ #define SME_CALLOUT_INITIALIZED 0x00000004 /* callout was initialized */ +#define SME_INIT_REFRESH 0x00000008 /* call sme_refresh() after + interrupts are enabled in + the autoconf(9) process. */ void *sme_cookie; /* for ENVSYS back-end */ |
