Home | History | Annotate | Download | only in sysmon
History log of /src/sys/dev/sysmon/sysmon_envsysvar.h
RevisionDateAuthorComments
 1.48  31-Dec-2021  riastradh sysmon: Delete trailing whitespace. No functional change intended.
 1.47  23-Nov-2014  ozaki-r 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.46  14-Dec-2012  pgoyette The sensor limit values were moved out of the event structure and into the
per-sensor structure a long time ago. Garbage collect the old structure
member which is now unused.
 1.45  06-Sep-2012  macallan branches: 1.45.2;
opt_envsys.h needs #ifdef _KERNEL_OPT
( thanks martin@ )
 1.44  06-Sep-2012  macallan defflag debug #defines
 1.43  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.42  15-Jul-2012  pgoyette When unregistering a sensor device, make sure we unregister and delete
all the associated events.
 1.41  18-Feb-2012  matt Don't export sysmon_envsys_list as a common.
 1.40  19-Jun-2011  pgoyette branches: 1.40.2; 1.40.6; 1.40.8;
Add routine to lookup description tables by description instead of by
type.
 1.39  08-Jun-2011  pgoyette Factor out some duplicated code to simplify maintenance. Reduces
the source file by ~100 lines, and amd64 object file shrinks by
~650 bytes.

No functional change intended.
 1.38  30-Dec-2010  pgoyette branches: 1.38.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.37  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.36  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.35  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.34  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.33  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.32  14-Mar-2010  pgoyette branches: 1.32.2;
Retire the 'monitor' member of the envsys_data_t. It was only used in
one place, and functioned as a logical OR of the ENVSYS_FMON* flag bits.
 1.31  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.30  13-Jun-2009  pgoyette branches: 1.30.2;
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.29  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.28  22-Aug-2008  pgoyette branches: 1.28.8;
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.27  01-Apr-2008  xtraeme branches: 1.27.4; 1.27.6; 1.27.10;
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.26  20-Nov-2007  xtraeme branches: 1.26.14;
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.25  16-Nov-2007  xtraeme Remove duplicate sme_events_list.
 1.24  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.23  03-Nov-2007  xtraeme branches: 1.23.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.22  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.21  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.20  07-Oct-2007  xtraeme branches: 1.20.2;
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.19  08-Sep-2007  xtraeme branches: 1.19.2;
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.18  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.17  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.16  31-Aug-2007  xtraeme branches: 1.16.2;
- 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.15  31-Aug-2007  xtraeme Merge sme_event_add() into sme_event_register()... there's no need
to have two different functions for this.
 1.14  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.13  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.12  23-Jul-2007  xtraeme branches: 1.12.4; 1.12.6; 1.12.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.11  22-Jul-2007  xtraeme Fix the last point reported by yamt in PR kern/36673:

- There must be three mandatory objects in a sensor to be valid and be
enabled on its dictionary: units, state and desc. If any of these
objects fails for some reason, its dictionary won't created in the
array and sensor will be marked with ENVSYS_FNOTVALID in edata->flags.

That means there won't never be a partial dictionary.

- Mark all invalid sensors and sensors with duplicate description with
ENVSYS_FNOTVALID and remove ENVSYS_FDUPDESC. The former is the generic
way to say that a sensor does not obey the rules and must be not
created.

- sysmon_envsys_createplist: if the array does not contain any object,
release the array and return the error.

And with all that stuff I can go to holidays and be happy.
 1.10  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.9  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.8  20-Jul-2007  xtraeme Move the functions to create/update objects in a dictionary into its
own file, and DO NOT MAKE THEM inline AS IT IS WRONG.

Looks like I'm very stupid and I didn't know what inline meant.
Thank you very much YAMAMOTO Takashi.
 1.7  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.6  19-Jul-2007  xtraeme Apply some indent to recent changes.
 1.5  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.4  18-Jul-2007  xtraeme - Cleanup sme_event_t: just use the struct work without any union and
remove the TAILQ.
- If prop_dictionary_set_* fails, do not release the object. The function
calling it will release the object. Pointed out by yamt@.
 1.3  05-Jul-2007  xtraeme branches: 1.3.2; 1.3.4; 1.3.6;
SENSOR_UPTYPE: accept values of 0 for any object, so that the value is
showed in its dictionary.
 1.2  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.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.3.6.3  10-Sep-2007  skrll Sync with HEAD.
 1.3.6.2  03-Sep-2007  skrll Sync with HEAD.
 1.3.6.1  15-Aug-2007  skrll Sync with HEAD.
 1.3.4.4  09-Oct-2007  ad Sync with head.
 1.3.4.3  20-Aug-2007  ad Sync with HEAD.
 1.3.4.2  15-Jul-2007  ad Sync with head.
 1.3.4.1  05-Jul-2007  ad file sysmon_envsysvar.h was added on branch vmlocking on 2007-07-15 13:21:45 +0000
 1.3.2.2  11-Jul-2007  mjf Sync with head.
 1.3.2.1  05-Jul-2007  mjf file sysmon_envsysvar.h was added on branch mjf-ufs-trans on 2007-07-11 20:08:25 +0000
 1.12.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.12.8.1  23-Jul-2007  xtraeme file sysmon_envsysvar.h was added on branch matt-mips64 on 2007-07-23 17:51:18 +0000
 1.12.6.2  09-Jan-2008  matt sync with HEAD
 1.12.6.1  06-Nov-2007  matt sync with HEAD
 1.12.4.6  21-Nov-2007  joerg Sync with HEAD.
 1.12.4.5  04-Nov-2007  jmcneill Sync with HEAD.
 1.12.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.12.4.3  07-Oct-2007  joerg Sync with HEAD.
 1.12.4.2  02-Oct-2007  joerg Sync with HEAD.
 1.12.4.1  03-Sep-2007  jmcneill Sync with HEAD.
 1.16.2.5  07-Dec-2007  yamt sync with head
 1.16.2.4  15-Nov-2007  yamt sync with head.
 1.16.2.3  27-Oct-2007  yamt sync with head.
 1.16.2.2  03-Sep-2007  yamt sync with head.
 1.16.2.1  31-Aug-2007  yamt file sysmon_envsysvar.h was added on branch yamt-lazymbuf on 2007-09-03 14:38:51 +0000
 1.19.2.1  14-Oct-2007  yamt sync with head.
 1.20.2.4  21-Nov-2007  bouyer Sync with HEAD
 1.20.2.3  18-Nov-2007  bouyer Sync with HEAD
 1.20.2.2  13-Nov-2007  bouyer Sync with HEAD
 1.20.2.1  25-Oct-2007  bouyer Sync with HEAD.
 1.23.2.2  08-Dec-2007  mjf Sync with HEAD.
 1.23.2.1  19-Nov-2007  mjf Sync with HEAD.
 1.26.14.2  28-Sep-2008  mjf Sync with HEAD.
 1.26.14.1  03-Apr-2008  mjf Sync with HEAD.
 1.27.10.1  19-Oct-2008  haad Sync with HEAD.
 1.27.6.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.27.4.4  11-Aug-2010  yamt sync with head.
 1.27.4.3  11-Mar-2010  yamt sync with head
 1.27.4.2  20-Jun-2009  yamt sync with head
 1.27.4.1  04-May-2009  yamt sync with head.
 1.28.8.1  23-Jul-2009  jym Sync with HEAD.
 1.30.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.32.2.3  12-Jun-2011  rmind sync with head
 1.32.2.2  05-Mar-2011  rmind sync with head
 1.32.2.1  30-May-2010  rmind sync with head
 1.38.6.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.40.8.3  19-Oct-2012  riz Remove stray CR characters introduced in ticket #544. From pgoyette.
 1.40.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.40.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.40.6.1  18-Feb-2012  mrg merge to -current.
 1.40.2.3  23-Jan-2013  yamt sync with head
 1.40.2.2  30-Oct-2012  yamt sync with head
 1.40.2.1  17-Apr-2012  yamt sync with head
 1.45.2.2  03-Dec-2017  jdolecek update from HEAD
 1.45.2.1  25-Feb-2013  tls resync with head

RSS XML Feed