summaryrefslogtreecommitdiff
path: root/sys/dev/sysmon/sysmon_envsys_events.c
AgeCommit message (Collapse)Author
2021-12-31sysmon(9): Fix callout/thread synchronization.riastradh
Callout may ONLY take sme_work_mtx, at IPL_SOFTCLOCK; MUST NOT touch sme_mtx at IPL_NONE. All state the callout needs is serialized by sme_work_mtx now: - calls to sme_schedule_callout - calls to sme_schedule_halt - struct sysmon_envsys::sme_events_timeout - struct sysmon_envsys::sme_events_list - struct sysmon_envsys::sme_callout_state - struct envsys_data::flags => yes, this is a little silly -- used for ENVSYS_FNEED_REFRESH => should maybe separate the static driver-defined features from the state flags needed by sysmon_envsys but not important now Sleeping under sme_work_mtx (except on other adaptive locks at IPL_SOFTCLOCK) is forbidden. Calling out to the driver under sme_work_mtx is forbidden. This should properly fix: https://mail-index.netbsd.org/tech-kern/2015/10/14/msg019511.html PR kern/56592
2021-12-31sysmon: Delete trailing whitespace. No functional change intended.riastradh
2017-09-11Improve tracking of the state of an event's callout, and protect allpgoyette
queries or modifications of the state with the sme_mtx mutex. Detach the rndsrc before re-attaching it (with potentially new values). Clean up some lock-ordering issues. And a couple of KNF issues for good measure! Should address PR kern/52533 XXX Pullup-8 along with the previous fixes from msaitoh@ XXX http://mail-index.netbsd.org/source-changes/2017/09/06/msg088028.html ~ ~
2017-09-06 Fixes a problem that some driver(e.g. acpitz(4) or coretemp(5)) whichmsaitoh
use sysmon_envsys sleep waiting at "rndsrc" when "drvctl -d". Don't call rnd_detach_source() in sme_remove_event() which is called from sme_event_unregister_all(). Instead, call rnd_detach_source() in sysmon_envsys_sensor_detach() and call sysmon_envsys_sensor_detach() before sme_event_unregister_sensor(). Each sensor(envsys_data) has each rnd_src, but some sme_events point to the same rnd_src in a sensor. Calling rnd_detach_souce() twice with the same rnd_src brokes a reference count in rnd_src. OK'd by pgoyette@.
2017-06-01remove checks for failure after memory allocation calls that cannot fail:chs
kmem_alloc() with KM_SLEEP kmem_zalloc() with KM_SLEEP percpu_alloc() pserialize_create() psref_class_create() all of these paths include an assertion that the allocation has not failed, so callers should not assert that again.
2015-10-15As proposed inbouyer
https://mail-index.netbsd.org/tech-kern/2015/10/14/msg019511.html don't sleep on sme->sme_mtx in the callout but use mutex_tryenter() and just reschedule the callout if we can't get the mutex now. This fixes a deadlock which can happen if the backed wants to sleep with timeout (e.g. cv_timedwait()) as the backed is called with sme->sme_mtx held. This is a stopgap measure for netbsd-7; sysmon should be changed to not sleep (or call a backend which will sleep) with mutexes held.
2015-06-23Separate the two conditions for the KASSERT, so we can tell whichpgoyette
one occurred.
2015-06-23Fix the KASSERT - we want to make sure that _both_ pointers are non-NULL,pgoyette
n ot just that one or the other is non-NULL!
2015-04-18use unsigned type for flag bits.mlelstv
2015-03-14Add a counter of busy events and stop enqueueing more work if a device is busy.hannken
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.
2014-11-23Pull workqueue_destroy out of sme->sme_mtxozaki-r
workqueue_destroy may sleep so we shouldn't run it with holding a mutex. Requested by riastradh@.
2014-11-22Replace callout_stop with callout_haltozaki-r
In order to call callout_destroy for a callout safely, we have to ensure the function of the callout is not running and pending. To do so, we should use callout_halt, not callout_stop. In this case, we need to pass an interlock to callout_halt to wait for the callout complete. And also we make sure that SME_CALLOUT_INITIALIZED is unset before calling callout_halt to prevent the callout from calling callout_schedule. This is the same as what we did in sys/netinet6/mld6.c@1.61. Reviewed by riastradh@.
2014-11-22Kill sme_callout_mtx and use sme_mtx insteadozaki-r
We can use sme_mtx for the callout as well. Actually we should do so because sme_events_list and some other data that are touched in the callout should be protected by sme_mtx, not sme_callout_mtx. Discussed with riastradh@ in http://mail-index.netbsd.org/tech-kern/2014/11/11/msg017956.html
2013-09-15Remove unused variablemartin
2013-01-23Fix spelling, grammar, typos.mbalmer
2012-12-14Constifypgoyette
2012-12-11Replace a couple of many-line #define with equivalent code loops.pgoyette
No functional change intended, and atf tests (using swsensor(4)) still pass 100%
2012-10-31in sme_battery_check():macallan
- don't assume that all batteries have exactly one ENVSYS_INDICATOR - check capacity and charge sensors for ENVSYS_SVALID before using them now this works on macppc
2012-09-06Remove (commented-out) definitions for debugging - thanks to macallan@pgoyette
for defflagging these.
2012-08-271. Enable use of FMONSTCHANGED events for INDICATOR sensorspgoyette
2. Update handling of FMONCRITICAL event reporting. The state transition does not require a corresponding change in value. With these changes, you can now have an INDICATOR sensor that reports the presence or absence of a device, and (if the device is present) separately monitor it for proper functioning. Should address the concerns expressed recently with the commit of changes to wmi(4) BBU handling.
2012-07-19If previously there was only a dummy event entry (to force refresh forpgoyette
entropy gathering), allow it to be updated for the current request to add a real entry.
2012-07-18Release the mutex before taking a quick exit.pgoyette
2012-07-16Extend previous changes so that even sensors which don't use a refresh()pgoyette
callback to update the value can be polled to provide rnd(4) entropy.
2012-07-15If a sensor is flagged as capable of providing rnd(4) with entropy,pgoyette
hook the sensor into rnd subsystem, and make sure we periodically refresh the sensor whether or not it is being actively monitored.
2012-07-15When unregistering a sensor device, make sure we unregister and deletepgoyette
all the associated events.
2011-06-08Restrict limit monitoring for Indicator sensors as well as forpgoyette
Battery-charge sensors.
2010-12-30When the user updates the sensor device's refresh timer, reset thepgoyette
callout immediately rather than waiting for the previous timer to expire.
2010-12-15Extract searching of description tables into a single function, ratherpgoyette
than duplicating the code every time. Minor reduction in code size (about 1200 bytes on amd64), no change in functionality.
2010-12-08When removing properties (as in envstat -S), clear the flags that trackpgoyette
whether the properties actually exist. When setting new limit values, don't complain/ignore about duplicate values if the associated flag bits (indicating that the limit is valid) are not set. These two fixes together should fix a problem reported in private Email by njoly@ a couple months ago. Issue replicated and solution tested using my recent swsensor pseudo-device running inside qemu world!
2010-12-06Make this compile when "options ENVSYS_OBJECTS_DEBUG" is defined.pgoyette
2010-09-221. Don't try to call the driver's get_limits routine if it doesn't havepgoyette
one. Fixes a panic reported by njoly@ in private Email 2. Acquire the device before checking whether or not the get_limits routine exists. XXX There's still a bug in here somewhere that prevents setting of XXX limit values after using 'envstat -S'
2010-04-10When removing sensor properties with envstat -S, ensure that driverspgoyette
which could have modified hardware state are informed so that original state can be restored. Welcome to 5.99.27
2010-04-01Permit creation of an event-monitor for alarm limits even if the limitspgoyette
are not currently set (and, in case of battery capacity sensors, if there is no value_max). Ensure that such an event-monitor does not trigger the delivery of any actual events. Provide a mechanism for sensors to set their limits at time other than system startup (for example, when a battery is inserted). This allows us to boot a system with a battery missing, install the battery some time later, and automatically monitor it without requiring any user intervention to create the event-monitor. (The actual changes for battery sensors to use this new capability will come later.)
2010-03-24Fix ENVSYS_DEBUG build.njoly
2010-03-24In sysmon_envsys_sensor_event(), permit delivery of all events for thepgoyette
sensor if no event type is specified.
2010-03-23Additional info in DPRINTF to help debugging effortspgoyette
2010-03-19Modify previous commit. The routine to deliver events is intended to bepgoyette
exported to device drivers, so rename it and move the declaration to <dev/sysmon/sysmonvar.h>
2010-03-19Separate event delivery from polling and limit evaluation inpgoyette
sme_events_worker(). Provide a wrapper that can be called from sensor drivers' interrupt routines to find and deliver a specific event. XXX Actually updating sensor drivers (and their parent devices) to XXX have interrupts is a future enhancement. This is simply an XXX enabler.
2010-02-18If we're going to valdate things, at least do it correctly.pgoyette
2010-02-15For symmetry, allow warning and critical upper-limits for capacitypgoyette
sensors.
2010-02-14Replace large amount of replicated code with a macro to improve readability.pgoyette
2010-02-14Remove the flags member of the limits structure. Its value was onlypgoyette
meaningful for a few limited function calls; all persitent storage of limit-present flags is maintained in the edata->upropset member.
2010-02-14Correct one more instance of checking flags in the wrong place.pgoyette
2010-02-13When checking current sensor value vs limits, check the correct set ofpgoyette
flags to determine which limits are present.
2010-02-05Fix a typo in one DPRINTF (s/edata->des/edata->desc/).jruoho
2010-02-04If the AC adapter is flagged with SME_DISABLE_REFRESH, don't try to callpgoyette
its refresh() callback. Just assume that its value has been properly updated by other means.
2010-01-30Validate limit-based monitoring in one place, so we can apply thepgoyette
constraints to both driver-requested and user-requested monitoring. While here, clean up some of the debugging DPRINTFs.
2010-01-26Move the limits out of the event structure and into the main sensor.pgoyette
Use the limits_flags only for calls to the {get,set}_limits() callbacks and merge the results into upropset, rather than trying to maintain both values (error prone).
2010-01-18If no limits are exceeded, make sure we set state to SVALIDpgoyette
2010-01-02Flags for existence of limit values need to be propagated to thepgoyette
event data. Otherwise, they're not processed. XXX This needs to be rethought. While fixing it this way makes things XXX "work", we really shouldn't need to replicate these flags. The XXX limits and their flags should be kept as part of the sensor data, XXX and not part of the event-monitor data. I'll work on this in the XXX near future.