Home | History | Annotate | Download | only in sysmon
History log of /src/sys/dev/sysmon/sysmon_envsys_events.c
RevisionDateAuthorComments
 1.123  31-Dec-2021  riastradh sysmon(9): Fix callout/thread synchronization.

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
 1.122  31-Dec-2021  riastradh sysmon: Delete trailing whitespace. No functional change intended.
 1.121  11-Sep-2017  pgoyette Improve tracking of the state of an event's callout, and protect all
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
~
~
 1.120  06-Sep-2017  msaitoh Fixes a problem that some driver(e.g. acpitz(4) or coretemp(5)) which
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@.
 1.119  01-Jun-2017  chs branches: 1.119.2;
remove checks for failure after memory allocation calls that cannot fail:

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.
 1.118  15-Oct-2015  bouyer As proposed in
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.
 1.117  23-Jun-2015  pgoyette Separate the two conditions for the KASSERT, so we can tell which
one occurred.
 1.116  23-Jun-2015  pgoyette Fix the KASSERT - we want to make sure that _both_ pointers are non-NULL,
n ot just that one or the other is non-NULL!
 1.115  18-Apr-2015  mlelstv use unsigned type for flag bits.
 1.114  14-Mar-2015  hannken 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.
 1.113  23-Nov-2014  ozaki-r branches: 1.113.2;
Pull workqueue_destroy out of sme->sme_mtx

workqueue_destroy may sleep so we shouldn't run it with holding a mutex.

Requested by riastradh@.
 1.112  22-Nov-2014  ozaki-r Replace callout_stop with callout_halt

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@.
 1.111  22-Nov-2014  ozaki-r Kill sme_callout_mtx and use sme_mtx instead

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
 1.110  15-Sep-2013  martin branches: 1.110.4;
Remove unused variable
 1.109  23-Jan-2013  mbalmer branches: 1.109.2;
Fix spelling, grammar, typos.
 1.108  14-Dec-2012  pgoyette Constify
 1.107  11-Dec-2012  pgoyette Replace a couple of many-line #define with equivalent code loops.

No functional change intended, and atf tests (using swsensor(4)) still
pass 100%
 1.106  31-Oct-2012  macallan in sme_battery_check():
- 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
 1.105  06-Sep-2012  pgoyette branches: 1.105.2;
Remove (commented-out) definitions for debugging - thanks to macallan@
for defflagging these.
 1.104  27-Aug-2012  pgoyette 1. Enable use of FMONSTCHANGED events for INDICATOR sensors
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.
 1.103  19-Jul-2012  pgoyette If previously there was only a dummy event entry (to force refresh for
entropy gathering), allow it to be updated for the current request to
add a real entry.
 1.102  18-Jul-2012  pgoyette Release the mutex before taking a quick exit.
 1.101  16-Jul-2012  pgoyette Extend previous changes so that even sensors which don't use a refresh()
callback to update the value can be polled to provide rnd(4) entropy.
 1.100  15-Jul-2012  pgoyette If a sensor is flagged as capable of providing rnd(4) with entropy,
hook the sensor into rnd subsystem, and make sure we periodically
refresh the sensor whether or not it is being actively monitored.
 1.99  15-Jul-2012  pgoyette When unregistering a sensor device, make sure we unregister and delete
all the associated events.
 1.98  08-Jun-2011  pgoyette branches: 1.98.2; 1.98.8;
Restrict limit monitoring for Indicator sensors as well as for
Battery-charge sensors.
 1.97  30-Dec-2010  pgoyette branches: 1.97.6;
When the user updates the sensor device's refresh timer, reset the
callout immediately rather than waiting for the previous timer to
expire.
 1.96  15-Dec-2010  pgoyette Extract searching of description tables into a single function, rather
than duplicating the code every time. Minor reduction in code size
(about 1200 bytes on amd64), no change in functionality.
 1.95  08-Dec-2010  pgoyette When removing properties (as in envstat -S), clear the flags that track
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!
 1.94  06-Dec-2010  pgoyette Make this compile when "options ENVSYS_OBJECTS_DEBUG" is defined.
 1.93  22-Sep-2010  pgoyette 1. Don't try to call the driver's get_limits routine if it doesn't have
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'
 1.92  10-Apr-2010  pgoyette When removing sensor properties with envstat -S, ensure that drivers
which could have modified hardware state are informed so that original
state can be restored.

Welcome to 5.99.27
 1.91  01-Apr-2010  pgoyette Permit creation of an event-monitor for alarm limits even if the limits
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.)
 1.90  24-Mar-2010  njoly Fix ENVSYS_DEBUG build.
 1.89  24-Mar-2010  pgoyette In sysmon_envsys_sensor_event(), permit delivery of all events for the
sensor if no event type is specified.
 1.88  23-Mar-2010  pgoyette Additional info in DPRINTF to help debugging efforts
 1.87  19-Mar-2010  pgoyette Modify previous commit. The routine to deliver events is intended to be
exported to device drivers, so rename it and move the declaration to
<dev/sysmon/sysmonvar.h>
 1.86  19-Mar-2010  pgoyette Separate event delivery from polling and limit evaluation in
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.
 1.85  18-Feb-2010  pgoyette branches: 1.85.2;
If we're going to valdate things, at least do it correctly.
 1.84  15-Feb-2010  pgoyette For symmetry, allow warning and critical upper-limits for capacity
sensors.
 1.83  14-Feb-2010  pgoyette Replace large amount of replicated code with a macro to improve readability.
 1.82  14-Feb-2010  pgoyette Remove the flags member of the limits structure. Its value was only
meaningful for a few limited function calls; all persitent storage
of limit-present flags is maintained in the edata->upropset member.
 1.81  14-Feb-2010  pgoyette Correct one more instance of checking flags in the wrong place.
 1.80  13-Feb-2010  pgoyette When checking current sensor value vs limits, check the correct set of
flags to determine which limits are present.
 1.79  05-Feb-2010  jruoho branches: 1.79.2;
Fix a typo in one DPRINTF (s/edata->des/edata->desc/).
 1.78  04-Feb-2010  pgoyette If the AC adapter is flagged with SME_DISABLE_REFRESH, don't try to call
its refresh() callback. Just assume that its value has been properly
updated by other means.
 1.77  30-Jan-2010  pgoyette Validate limit-based monitoring in one place, so we can apply the
constraints to both driver-requested and user-requested monitoring.

While here, clean up some of the debugging DPRINTFs.
 1.76  26-Jan-2010  pgoyette Move the limits out of the event structure and into the main sensor.

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).
 1.75  18-Jan-2010  pgoyette If no limits are exceeded, make sure we set state to SVALID
 1.74  02-Jan-2010  pgoyette Flags for existence of limit values need to be propagated to the
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.
 1.73  01-Jan-2010  pgoyette Don't infer a sensor driver's ability to handle limit checking itself.
 1.72  23-Dec-2009  pgoyette Check for value exceeding crit-max limit before checking against warn-max
limit. Otherwise we'll never notice if we exceed crit-max (assuming that
crit-max is at least as large as warn-max).
 1.71  10-Jul-2009  pgoyette Document usage of PROP_DRIVER_LIMITS flag and set it correctly.

Use flag bits to determine validity of limit values, rather than
assuming that invalid/not-present values are set to zero.
 1.70  08-Jul-2009  pgoyette Initialize lims.sel_flags before using it. Prevents spurious limit
events being created for devices that don't provide internal limits.

Thanks to Mattias for finding this.
 1.69  08-Jul-2009  pgoyette Clean up a couple of debug statements that got missed previously.
 1.68  14-Jun-2009  pgoyette Ooops - {get,set}_limits() need to be sensor-specific. Pass an extra
argument to them to identify the individual sensor being processed.
 1.67  13-Jun-2009  pgoyette Add capability to send sensor limit values to the driver so they can
be programmed into device registers. This way we can let the hardware
help us out instead of having to always compare the value against each
limit. (Driver updates for some sensors to take advantage of this
capability will be forthcoming.)
 1.66  08-Jun-2009  pgoyette Correct typo in last so we can #undef the correct macro.
 1.65  08-Jun-2009  pgoyette General clean-up and some restructuring of event handling. This is a
precursor to letting sensor drivers actually exchange limits/thresholds
with user-land.
 1.64  01-Jun-2009  pgoyette Since we no longer have individual events for each sensor value limit,
we don't need individual flag bits. Clean up extra bit definitions.
Bump kernel version - welcome to 5.99.13
 1.63  07-Apr-2009  dyoung Fix spelling: mak -> make.
 1.62  11-Nov-2008  pgoyette branches: 1.62.4;
Fix typo in previous, and wrap a panic with #ifdef DIAGNOSTIC
 1.61  11-Nov-2008  pgoyette Initialize event's "previous sent state" based on the event monitor type,
regardless of sensor type. Fixes spurious "device: normal state on
'sensor-name' messages (reported by ad@) which interfere with sysinst.
 1.60  04-Nov-2008  pgoyette Fix cut&paste error in prev
 1.59  04-Nov-2008  pgoyette Restore previous behavior concerning CRITICAL events. Send an event
whenever state enters or exits CRITICAL, or whenever value of sensor
changes while the state is CRITICAL.
 1.58  07-Sep-2008  pgoyette branches: 1.58.2; 1.58.4;
Only report new sensor state values if the new value is valid for the
particular event being monitored. This avoids duplicate reporting for
sensors that monitor both a normal/critical state and value-within-limits
state as reported by Simon Burge on current-users.

While we're here, clean-up some stair-stepping if's.

OK garbled@
 1.57  04-Sep-2008  pgoyette Initialize event's sent-state appropriately to avoid unnecessary start-up
time messages that report a "transition" to the Normal state.
 1.56  22-Aug-2008  pgoyette 1. provide for warning-min and warning-max alarm levels in addition to
critical-min and critical-max; also, a battery warning-capacity is
added in addition to a critical-capacity.

2. usr.sbin/envstat is modified to introduce a -W command line switch to
display the warning-* values instead of the critical-* values, and
envstat(8) and envsys.conf(5) man pages are updated appropriately.

3. Treat user-defined limits as a single continuum and generate a single
event regardless of how many boundaries a change in sensor value
crosses; ditto for driver-defined limits.

Fixes my PR/39021
Fixes my PR/39022

OK'd by christos@ bouyer@ cube@
 1.55  11-Jun-2008  drochner branches: 1.55.2;
in sme_battery_check(), explicitely check whether the battery is
present before using the values read, and clean up the logics
a bit to make it more understandable
 1.54  02-Apr-2008  xtraeme branches: 1.54.2; 1.54.4; 1.54.6; 1.54.8;
Initialize and destroy the callout in sme_events_init() and
sme_events_destroy() respectively. And don't stop twice the callout
when calling sysmon_envsys_unregister().
 1.53  01-Apr-2008  xtraeme Also fix a memleak when the event is already in dictionary
and has been updated.
 1.52  01-Apr-2008  rmind sme_event_register: fix a memory leaks in two error paths.
 1.51  01-Apr-2008  xtraeme Introduce per-device locking/synchronization and maintain only a
global mutex for the linked list of devices and the global proplib
dictionary.

This has improved locking contention a lot when multiple devices with
multiple monitoring events are running:

New:

0.30 35 0.33 sme_global_mtx sysmonioctl_envsys+28b
0.10 10 0.11 00000000cd97feac sysmon_envsys_acquire+4c
0.08 6 0.09 00000000cd97feac sme_update_dictionary+24f
0.01 4 0.01 00000000cd97feac sme_events_worker+2f
0.01 10 0.01 00000000cd97fe2c sysmon_envsys_acquire+4c
0.00 1 0.00 00000000cd97fe2c sysmon_envsys_release+3b
28.38 94 9.16 sme_global_mtx sysmonioctl_envsys+28b
4.54 74 1.47 00000000cd97fe2c sysmon_envsys_acquire+4c
0.06 3 0.02 00000000cd97fe2c sysmon_envsys_release+3b
0.03 1 0.01 00000000cd97fe2c sme_events_worker+2f
1.40 19 0.45 00000000cd97bee4 sysmon_envsys_acquire+4c

Old:

4.25 313 4.74 sme_mtx <all>
3.12 185 3.49 sme_mtx sme_events_worker+21
1.12 128 1.25 sme_mtx sysmonioctl_envsys+29b
34.75 1423 59.52 sme_mtx <all>
22.08 477 37.82 sme_mtx sysmonioctl_envsys+29b
12.67 946 21.70 sme_mtx sme_events_worker+21
 1.50  23-Mar-2008  xtraeme 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.
 1.49  29-Feb-2008  xtraeme Only check sysmon_low_power if the event comes from
ENVSYS_BATTERY_CAPACITY sensors.
 1.48  02-Feb-2008  xtraeme branches: 1.48.2; 1.48.6;
Destroy the callout via sysmon_envsys_destroy() now that it's
initialized in sysmon_envsys_create().
 1.47  02-Jan-2008  xtraeme - Initialize the callout with CALLOUT_MPSAFE, like it was done before
in sysmon_envsys_events.c.
- Separate sme_event_check_low_power() into sme_battery_check(),
sme_acadapter_check() and sme_battery_critical() (no functional changes).
 1.46  20-Nov-2007  xtraeme branches: 1.46.6;
After comments from Andrew Doran:

- The mutex for the callout handler must run at IPL_SOFTCLOCK.
- Just stop the callout in sysmon_envsys_unregister() and don't wait
for the callout to finish.
 1.45  16-Nov-2007  xtraeme Extend the envsys2 API (one more time, sorry) as defined in:

http://mail-index.netbsd.org/tech-kern/2007/11/09/0001.html

sysmon_envsys_create() and sysmon_envsys_destroy() were added to
create/destroy sysmon_envsys objects (and its TAILQ/LIST for sensors/events).

sysmon_envsys_sensor_attach() and sysmon_envsys_sensor_detach() were
added to attach/detach sensors to a specified sysmon_envsys device.

The events framework is now per device and configurable via the
ENVSYS_SETDICTIONARY ioctl or /etc/envsys.conf and envstat(8).

Update all users and documentation to reflect these changes.
 1.44  03-Nov-2007  xtraeme branches: 1.44.2;
- Rename ENVSYS_BATTERY_STATE units to ENVSYS_BATTERY_CAPACITY and
introduce ENVSYS_BATTERY_CHARGE, which is the same than an Indicator and
it's used to know if the battery is currently charging or discharging.

- Require two sensors at least for SME_CLASS_BATTERY to make the low-power
condition work: a ENVSYS_BATTERY_CAPACITY plus ENVSYS_BATTERY_CHARGE.

- Simplify sme_event_check_lowpower() and make it check the required
sensors in the SME_CLASS_ACADAPTER and SME_CLASS_BATTERY classes.
If the acadapter is not ready, trust the state returned by the battery
device.

Based on suggestion from joerg@.
 1.43  23-Oct-2007  xtraeme Use a flag for see_flags to know when the sensor has been refreshed
rather than using a boolean. Suggested by rmind.
 1.42  20-Oct-2007  xtraeme performance fix: in the workqueue handler only refresh the sensor once,
not multiple times for the same sensor and clear its state after all
events were processed.
 1.41  13-Oct-2007  xtraeme branches: 1.41.2;
sme_event_drvadd: there's no need to acquire the mutex only when
setting the object on its dictionary.
 1.40  13-Oct-2007  xtraeme Use PRI_NONE for the priority argument in workqueue_create(9).
 1.39  11-Oct-2007  xtraeme Check for the low power condition only when a new battery state sensor
changed its state, there's no need to check this in all cases.
 1.38  10-Oct-2007  xtraeme Fix the problems described in:
http://mail-index.netbsd.org/current-users/2007/07/16/0012.html

- Introduce sme_class into the sysmon_envsys struct to specify a
class; currently there are two classes: SME_CLASS_ACADAPTER and
SME_CLASS_BATTERY.

- Add a new envsys event: PENVSYS_EVENT_LOW_POWER that is reached when
all SME_CLASS_BATTERY devices are in CRITICAL/LOW state and there's not
any SME_CLASS_ACADAPTER connected.

- Add the 'low-power' event into the sensor_battery script that will
shutdown the system gracefully via 'shutdown -p'. If powerd(8) is
not running, cpu_reboot(9) with RB_POWERDOWN is used.

- Make acpiacad(4) a SME_CLASS_ACADAPTER device and acpibat(4) a
SME_CLASS_BATTERY device.

Update the documentation accordingly to these changes.
 1.37  07-Oct-2007  xtraeme sme_event_unregister: remove a goto that is not needed anymore.
 1.36  07-Oct-2007  xtraeme New changes to support the new configuration file format for
envstat(8) and the envsys framework:

- Modify the ENVSYS_SETDICTIONARY ioctl to support the following
plist structure:

<dict>
<key>foo0</key>
<array>
<dict>
<key>index</key>
<string>sensor0</string>
<key>description</key>
<string>cpu temp</string>
...
Another property for this sensor
...
</dict>
...
Another dictionary for other sensor
...
</array>
...
Another device as above
...
</dict>

Multiple devices with multiple sensors can now be specified, that means
that to set the properties only one copyin(9) is needed now.

- Added the ENVSYS_REMOVEPROPS ioctl, that accepts a boolean object
"envsys-remove-props" and when set to true, all properties that were
set previously by ENVSYS_SETDICTIONARY will be removed. That means that
you can now set multiple critical limits, descriptions and all they
will be removed or changed to its default value (for rfact and
description objects).

- Added the 'index' and 'allow-rfact' objects into the sensor dictionaries,
for better interactivity with userland. To know the position of the
sensor and to know if sensor allows to change the rfact.

- Misc cosmetic changes for consistency.

- Use a two clause license for all my code.
 1.35  08-Sep-2007  xtraeme branches: 1.35.2;
Use panic(9) for previous. To make pooka and rmind happy.
 1.34  08-Sep-2007  xtraeme sme_event_worker: in PENVSYS_EVENT_STATE_CHANGED, only
ENVSYS_DRIVE or ENVSYS_BATTERY_STATE sensors are allowed for now.

Other type of sensors will be ignored. Added this to make
Coverity Prevent happy.
 1.33  08-Sep-2007  xtraeme Use only one single condvar(9) for devices and events, they are protected
by the same mutex (sme_mtx) and there's no point in using two of them.

Also add a comment mentioning some locking notes.

Reviewed and ok by rmind.
 1.32  08-Sep-2007  xtraeme Disable debug, committed accidentally in previous.
 1.31  08-Sep-2007  xtraeme - Use only one global mutex for all tasks with devices & events.
- sysmon_envsys_register: use a SLIST to maintain allocated sme_event_drv_t
structs for later use in sysmon_task_queue_sched(). This avoids a
locking error acquiring/dropping the mutex multiple times.

Suggested by rmind.
 1.30  08-Sep-2007  xtraeme Fix previous.
 1.29  07-Sep-2007  xtraeme - sme_event_unregister_all: check if sme_events_initialized is set
before calling sme_events_destroy().
- sme_event_worker: remove a KASSERT and always check if returned sme
is NULL and do not continue the task.
 1.28  04-Sep-2007  xtraeme - Remove ENVSYS_GSTRING and the genstr member from envsys_data_t.
(at least three or four persons were against it).
- Add a new sensor type: ENVSYS_BATTERY_STATE, this uses value_cur
and some predefined values in a static table, like ENVSYS_DRIVE.
- Move all static tables to sysmon_envsys_tables.c and use a function
on it to retrieve a pointer to the struct of the specified type.
- Rename the ENVSYS_FMONDRVSTCHANGED to ENVSYS_FMONSTCHANGED and make
it generic for Battery state and drive sensors (this flag enables
monitoring on these sensors when state has been changed).
- Update sysmon_penvsys_event() to report state changes on
ENVSYS_BATTERY_STATE sensors and remove other type of events, with
PENVSYS_EVENT_STATE_CHANGED they are not necessary anymore.
 1.27  01-Sep-2007  xtraeme branches: 1.27.2;
sme_event_register: don't forget to add the object in dictionary when
a critical value is added via ENVSYS_SETDICTIONARY.
 1.26  01-Sep-2007  xtraeme sme_event_register: sme_sensor_upint32() was being called even when
adding events via sme_event_drvadd(), fix it.
 1.25  31-Aug-2007  xtraeme - sme_unregister_all: there's no need to use a struct sysmon_envsys as
argument, just pass sme->sme_name to it.
- sysmon_envsys_register: drop the array in all cases, not just when
there's an error. The reference is stored in the dictionary anyway...
- Update some comments.
 1.24  31-Aug-2007  xtraeme Merge sme_event_add() into sme_event_register()... there's no need
to have two different functions for this.
 1.23  31-Aug-2007  xtraeme Simplify sme_event_add() and fix a problem when updating critical
values.
 1.22  31-Aug-2007  xtraeme Add a few KASSERT(mutex_owned(&foo_lock)) as suggested by Andrew Doran.
 1.21  30-Aug-2007  xtraeme More misc changes for sysmon_envsys(9):

- Add the SLIST for sensor descriptions and sme_uniqsensors into the
struct sysmon_envsys (it's per device now).
- Use only one common struct with three members for the static tables
(there's no need to have different structs just for them).
- While initializing/destroying the events framework, use the
strategy specified by Andrew Doran in:
http://mail-index.netbsd.org/tech-kern/2007/06/21/0025.html).
 1.20  30-Aug-2007  xtraeme Some changes to improve locking on sysmon_envsys(9):

- Remove sme_mtx, a global lock (sme_list_mtx) is used to access to
the sysmon envsys device.
- Allocate memory with KM_NOSLEEP rather than KM_SLEEP if there's a
mutex held, to avoid sleeping.
- Remove sysmon_envsys_createplist() and add the logic into
sysmon_envsys_register().
- sysmon_envsys_register: allocate the array and dictionaries required
in advance for a device before the locking and adding the objects
into the array happens.
- Rename sme_make_dictionary() to sme_add_sensor_dictionary() and pass
to it the dictionary on which the objects will be stored for a sensor.
- Improve locking here and there.

Thanks to Mindaugas Rasiukevicius and Andrew Doran for comments.
 1.19  23-Jul-2007  xtraeme branches: 1.19.4; 1.19.6; 1.19.8;
- ENVSYS_SETDICTIONARY: use sysmon_envsys_release() if there's an error.
- sme_events_worker: use sme_list_mtx when accessing to the sysmon_envsys
linked list.
- Improve the comments in sysmon_envsysvar.h about the mutexes and condvar.
 1.18  21-Jul-2007  xtraeme - Add sme_events_destroy() to stop/destroy the callout and workqueue if
there are no more events.
- Add sme_event_unregister_all() to remove all events associated with
a device and use it in sysmon_envsys_unregister() to fix a "use-after-free".
- Check return error of sme_sensor_upfoo() in sme_make_dictionary() and
return it rather than 0 all the time.
- Add more KASSERTS.
 1.17  21-Jul-2007  xtraeme Some fixes for kern/36673 by yamt@:

- sme_register_sensorname: there's no need to handle empty list case.
- 'obj' argument in sme_sensor_upstring and similar functions is useless:
removed the obj argument from the functions, it's handled in the function
itself now.
- check for more errors in sme_make_dictionary() and
sysmon_envsys_createplist().
 1.16  20-Jul-2007  xtraeme Replace the macros to create/update objects in dictionary with three
inline functions, suggested by yamt@.

This also gets rid of a few gotos.
 1.15  18-Jul-2007  xtraeme - More changes related to locking.
- Add a condvar(9) to protect deletions on the list if there's an event
in the worker thread.
 1.14  17-Jul-2007  xtraeme branches: 1.14.2;
Add more debugging printfs to catch sensors with duplicate description,
and some cosmetic ones.
 1.13  14-Jul-2007  xtraeme branches: 1.13.2;
sme_events_worker: there's no need to use an extra int that gets
the value of see->snum to get the index of sme_sensor_data, just use
see->snum directly.
 1.12  13-Jul-2007  xtraeme sme_event_add: if the event is already on the list, update the
critical value only if new value is different than the one it has.

While I'm here, improve the debugging printf for this.
 1.11  13-Jul-2007  xtraeme sme_event_add: if sme_event_register() fails return the error of this
function and not EINVAL.
 1.10  13-Jul-2007  xtraeme sme_events_worker: simplify the code that sends the events.
 1.9  13-Jul-2007  xtraeme sme_event_unregister: if the events list is empty, just after the
callout is stopped, use callout_destroy().
 1.8  12-Jul-2007  rmind Implementation of per-CPU work-queues support for workqueue(9) interface.
WQ_PERCPU flag for workqueue and additional argument for workqueue_enqueue()
to assign a CPU might be used. Notes:
- For now, the list is used for workqueue_queue, which is non-optimal,
and will be changed with array, where index would be CPU ID.
- The data structures should be changed to be cache-friendly.

Reviewed by: <yamt>, <tech-kern>
 1.7  10-Jul-2007  yamt branches: 1.7.2;
sme_events_init: create seewq with IPL_SOFTCLOCK as it's accessed by a callout.
 1.6  09-Jul-2007  ad Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.5  04-Jul-2007  xtraeme Remove the max limit in the refresh value for the refresh_value sysctl,
use whatever you want within the limits of an integer.

Suggested by garbled@ and freza@.
 1.4  03-Jul-2007  xtraeme Erm, fix previous: 6min != 5min...
 1.3  03-Jul-2007  xtraeme Make the refresh value of the callout function (that monitors the sensors)
configurable via sysctl. By default it uses 10 seconds, but it can be changed
between 1 second and 5 minutes.

$ sysctl -d kern.envsys
kern.envsys.refresh_value: wait time in seconds to refresh sensors being monitored
$
 1.2  02-Jul-2007  xtraeme sme_event_drvadd:

- Check the error returned by sme_event_add() and print details if
returned value is not EEXIST.
- If sme_event_add() returned an error, don't add the monitoring-* object
into the dictionary.
 1.1  01-Jul-2007  xtraeme Imported envsys 2, a brief description of the new features:
(Part 1: API)

* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.

Tested by:

blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
 1.7.2.2  11-Jul-2007  mjf Sync with head.
 1.7.2.1  10-Jul-2007  mjf file sysmon_envsys_events.c was added on branch mjf-ufs-trans on 2007-07-11 20:08:24 +0000
 1.13.2.6  23-Oct-2007  ad Sync with head.
 1.13.2.5  12-Oct-2007  ad Sync with head.
 1.13.2.4  09-Oct-2007  ad Sync with head.
 1.13.2.3  20-Aug-2007  ad Sync with HEAD.
 1.13.2.2  15-Jul-2007  ad Sync with head.
 1.13.2.1  14-Jul-2007  ad file sysmon_envsys_events.c was added on branch vmlocking on 2007-07-15 13:21:45 +0000
 1.14.2.3  10-Sep-2007  skrll Sync with HEAD.
 1.14.2.2  03-Sep-2007  skrll Sync with HEAD.
 1.14.2.1  15-Aug-2007  skrll Sync with HEAD.
 1.19.8.2  23-Jul-2007  xtraeme - ENVSYS_SETDICTIONARY: use sysmon_envsys_release() if there's an error.
- sme_events_worker: use sme_list_mtx when accessing to the sysmon_envsys
linked list.
- Improve the comments in sysmon_envsysvar.h about the mutexes and condvar.
 1.19.8.1  23-Jul-2007  xtraeme file sysmon_envsys_events.c was added on branch matt-mips64 on 2007-07-23 17:51:18 +0000
 1.19.6.3  23-Mar-2008  matt sync with HEAD
 1.19.6.2  09-Jan-2008  matt sync with HEAD
 1.19.6.1  06-Nov-2007  matt sync with HEAD
 1.19.4.6  21-Nov-2007  joerg Sync with HEAD.
 1.19.4.5  04-Nov-2007  jmcneill Sync with HEAD.
 1.19.4.4  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.19.4.3  07-Oct-2007  joerg Sync with HEAD.
 1.19.4.2  02-Oct-2007  joerg Sync with HEAD.
 1.19.4.1  03-Sep-2007  jmcneill Sync with HEAD.
 1.27.2.9  24-Mar-2008  yamt sync with head.
 1.27.2.8  17-Mar-2008  yamt sync with head.
 1.27.2.7  04-Feb-2008  yamt sync with head.
 1.27.2.6  21-Jan-2008  yamt sync with head
 1.27.2.5  07-Dec-2007  yamt sync with head
 1.27.2.4  15-Nov-2007  yamt sync with head.
 1.27.2.3  27-Oct-2007  yamt sync with head.
 1.27.2.2  03-Sep-2007  yamt sync with head.
 1.27.2.1  01-Sep-2007  yamt file sysmon_envsys_events.c was added on branch yamt-lazymbuf on 2007-09-03 14:38:50 +0000
 1.35.2.1  14-Oct-2007  yamt sync with head.
 1.41.2.4  21-Nov-2007  bouyer Sync with HEAD
 1.41.2.3  18-Nov-2007  bouyer Sync with HEAD
 1.41.2.2  13-Nov-2007  bouyer Sync with HEAD
 1.41.2.1  25-Oct-2007  bouyer Sync with HEAD.
 1.44.2.3  18-Feb-2008  mjf Sync with HEAD.
 1.44.2.2  08-Dec-2007  mjf Sync with HEAD.
 1.44.2.1  19-Nov-2007  mjf Sync with HEAD.
 1.46.6.1  02-Jan-2008  bouyer Sync with HEAD
 1.48.6.4  17-Jan-2009  mjf Sync with HEAD.
 1.48.6.3  28-Sep-2008  mjf Sync with HEAD.
 1.48.6.2  29-Jun-2008  mjf Sync with HEAD.
 1.48.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.48.2.1  24-Mar-2008  keiichi sync with head.
 1.54.8.1  18-Jun-2008  simonb Sync with head.
 1.54.6.2  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.54.6.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.54.4.6  09-Oct-2010  yamt sync with head
 1.54.4.5  11-Aug-2010  yamt sync with head.
 1.54.4.4  11-Mar-2010  yamt sync with head
 1.54.4.3  18-Jul-2009  yamt sync with head.
 1.54.4.2  20-Jun-2009  yamt sync with head
 1.54.4.1  04-May-2009  yamt sync with head.
 1.54.2.1  17-Jun-2008  yamt sync with head.
 1.55.2.2  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.55.2.1  19-Oct-2008  haad Sync with HEAD.
 1.58.4.5  07-Jan-2011  riz Pull up following revision(s) (requested by pgoyette in ticket #1505):
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.94
Make this compile when "options ENVSYS_OBJECTS_DEBUG" is defined.
 1.58.4.4  13-Nov-2008  snj Pull up following revision(s) (requested by tls in ticket #49):
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.62
Fix typo in previous, and wrap a panic with #ifdef DIAGNOSTIC
 1.58.4.3  13-Nov-2008  snj Pull up following revision(s) (requested by tls in ticket #49):
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.61
Initialize event's "previous sent state" based on the event monitor type,
regardless of sensor type. Fixes spurious "device: normal state on
'sensor-name' messages (reported by ad@) which interfere with sysinst.
 1.58.4.2  06-Nov-2008  snj Pull up following revision(s) (requested by pgoyette in ticket #15):
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.60
Fix cut&paste error in prev
 1.58.4.1  06-Nov-2008  snj Pull up following revision(s) (requested by pgoyette in ticket #15):
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.59
Restore previous behavior concerning CRITICAL events. Send an event
whenever state enters or exits CRITICAL, or whenever value of sensor
changes while the state is CRITICAL.
 1.58.2.2  28-Apr-2009  skrll Sync with HEAD.
 1.58.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.62.4.2  23-Jul-2009  jym Sync with HEAD.
 1.62.4.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.79.2.2  22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.79.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.85.2.3  12-Jun-2011  rmind sync with head
 1.85.2.2  05-Mar-2011  rmind sync with head
 1.85.2.1  30-May-2010  rmind sync with head
 1.97.6.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.98.8.4  07-Dec-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #1201):
sys/kern/kern_ktrace.c: revision 1.166
sys/dev/isa/aps.c: revision 1.16
sys/dev/sysmon/sysmonvar.h: revision 1.45
sys/dev/ir/irframe_tty.c: revision 1.60
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.111-1.112 (patch)
sys/dev/pci/pccbb.c: revision 1.207
sys/dev/wscons/wskbd.c: revision 1.135
sys/dev/usb/ohci.c: revision 1.254
sys/net/if_ecosubr.c: revision 1.41
sys/dev/pcmcia/btbc.c: revision 1.17
sys/arch/x86/x86/via_padlock.c: revision 1.23
sys/dev/sdmmc/sdmmc.c: revision 1.23 (patch)
sys/dev/bluetooth/btkbd.c: revision 1.17
sys/dev/bluetooth/bcsp.c: revision 1.25
sys/arch/x86/pci/fwhrng.c: revision 1.8
sys/dev/ic/nslm7x.c: revision 1.61
share/man/man9/callout.9: revision 1.28 (patch)

Replace callout_stop with callout_halt and ensure the callout
is not running before destroying it.
 1.98.8.3  19-Oct-2012  riz Remove stray CR characters introduced in ticket #544. From pgoyette.
 1.98.8.2  17-Oct-2012  riz Pull up following revision(s) (requested by pgoyette in ticket #545):
etc/powerd/scripts/sensor_indicator: revision 1.5
sys/dev/sysmon/sysmon_envsys_tables.c: revision 1.11
sys/sys/envsys.h: revision 1.32
sys/dev/sysmon/sysmon_envsysvar.h: revision 1.43
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.104
Provide names for the values associated with INDICATOR sensors.
1. Enable use of FMONSTCHANGED events for INDICATOR sensors
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.
Handle any reports of state changes for INDICATORs
 1.98.8.1  17-Oct-2012  riz Pull up following revision(s) (requested by pgoyette in ticket #544):
sys/dev/sysmon/sysmon_envsysvar.h: revision 1.42
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.99
sys/dev/sysmon/sysmon_envsys.c: revision 1.119
When unregistering a sensor device, make sure we unregister and delete
all the associated events.
 1.98.2.4  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.98.2.3  23-Jan-2013  yamt sync with head
 1.98.2.2  16-Jan-2013  yamt sync with (a bit old) head
 1.98.2.1  30-Oct-2012  yamt sync with head
 1.105.2.4  03-Dec-2017  jdolecek update from HEAD
 1.105.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.105.2.2  25-Feb-2013  tls resync with head
 1.105.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.109.2.1  18-May-2014  rmind sync with head
 1.110.4.2  06-Apr-2015  snj Pull up following revision(s) (requested by hannken in ticket #666):
sys/dev/sysmon/sysmon_envsys.c: revision 1.129
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.114
sys/dev/sysmon/sysmonvar.h: revision 1.46
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.
 1.110.4.1  01-Dec-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #279):
sys/kern/kern_ktrace.c: revision 1.166
sys/dev/isa/aps.c: revision 1.16
sys/dev/sysmon/sysmonvar.h: revision 1.45
sys/dev/ir/irframe_tty.c: revision 1.60
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.111
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.112
sys/dev/pci/pccbb.c: revision 1.207
sys/dev/wscons/wskbd.c: revision 1.135
sys/dev/usb/ohci.c: revision 1.254
sys/net/if_ecosubr.c: revision 1.41
sys/dev/pcmcia/btbc.c: revision 1.17
sys/arch/x86/x86/via_padlock.c: revision 1.23
sys/dev/sdmmc/sdmmc.c: revision 1.23
sys/dev/bluetooth/btkbd.c: revision 1.17
sys/dev/bluetooth/bcsp.c: revision 1.25
sys/arch/x86/pci/fwhrng.c: revision 1.8
sys/dev/ic/nslm7x.c: revision 1.61
share/man/man9/callout.9: revision 1.28
Replace callout_stop with callout_halt
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.
Discussed with martin@ and riastradh@.
Make it clear that we should use not callout_stop but callout_halt
before callout_destroy
Replace callout_stop with callout_halt
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.
Reviewed by riastradh@.
Kill sme_callout_mtx and use sme_mtx instead
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
Replace callout_stop with callout_halt
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@.
 1.113.2.5  28-Aug-2017  skrll Sync with HEAD
 1.113.2.4  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.113.2.3  22-Sep-2015  skrll Sync with HEAD
 1.113.2.2  06-Jun-2015  skrll Sync with HEAD
 1.113.2.1  06-Apr-2015  skrll Sync with HEAD
 1.119.2.1  23-Sep-2017  snj Pull up following revision(s) (requested by pgoyette in ticket #281):
sys/dev/sysmon/sysmon_envsys.c: 1.140-1.141
sys/dev/sysmon/sysmon_envsys_events.c: 1.120-1.121
sys/dev/sysmon/sysmonvar.h: 1.50
Fixes a problem that some driver(e.g. acpitz(4) or coretemp(5)) which
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@.
--
Improve tracking of the state of an event's callout, and protect all
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

RSS XML Feed