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.
at the same time and the code accessed to an unexistent dictionary:
- Rather than using a global dictionary, use a singly linked list to
access to the dictionaries, one per event.
- When the dictionary has been sent to userland, destroy it and remove
it from the list.
With that change it is possible to receive multiple events at the
same time without panics; again thanks to rmind@ for comments and help
with locking.
Reviewed and ok by rmind.
of another object that will be released shortly.
- Fix a memleak: add sysmon_power_destroy_dictionary() and remove
all objects that are currently in the dictionary and finally release
the dictionary.
sysmon_envsys_unregister(): in sysmon_envsys_destroy_plist() I wasn't
removing the _objects_ from the dictionary, instead I was calling
prop_object_release() with the keysym returned by
prop_object_iterator_next()... obviously this wasn't correct.
- 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.
disabled, because some drivers depend in the old code yet.
- Use a new mutex for sysmon_envsys_next_sensor_index (used in
compatibility code), otherwise bad things happen with LKMs. Thanks
to this, the hack for LKMs has been removed.
- Check in advance if the driver doesn't exist already on the list
before adding the sensors in the dictionary.
- Don't forget to call sme_event_unregister_all() if
sysmon_envsys_unregister() fails after adding the array into the global
dictionary or when creating sensors.
- Modify and add some DPRINTFs.
The lm(4) lkm works without known problems registering and unregistering
it multiple times.
(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.
ENVSYS_GSTRING (aka Generic String) uses the genstr member in
the envsys_data_t struct to add a generic string that envstat(8)
will show as value or state.
It's like the ENVSYS_DRIVER, but doesn't use value_cur. Below
is the dictionary created on these sensors:
<dict>
<key>description</key>
<string>acpibat0 charge state</string>
<key>generic-state-string</key>
<string>NORMAL</string>
<key>monitoring-supported</key>
<false/>
<key>state</key>
<string>valid</string>
<key>type</key>
<string>Generic string</string>
</dict>
Note that it's limited to 32 chars, but we can grow it if needed.
envstat(8) will print ENVSYS_GSTRING sensors as:
$ envstat -dacpibat0 -s"acpibat0 charge state"
acpibat0 charge state: NORMAL
$
(thanks god for KMEMSTATS).
- sysmon_envsys_register: add all objects in the dictionary without any
lock, at this point the sme device hasn't been added into the list
and it's safe.
- Add sysmon_envsys_destroy_plist(prop_array_t) that destroys all objects
associated with a device and use it on sysmon_envsys_unregister() and
sysmon_envsys_register() if there's any error.
Thanks to Mindaugas Rasiukevicius (rmind@) for the great comments/ideas.
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.
- 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).
(forgot in previous)
- 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).
- 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.
systems the interrupts are not configured and causes unexpected behaviour
in acpi_bat and other drivers, reported by cube@.
- Update the 'type' object in sme_update_dictionary(), so that it can
report the correct units type in acpibat(4).
- 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.
in all cases to the caller, just continue and show a debug printf if it
fails, because it's not a critical error.
- Improve some debugging printfs.
Fixes another part of yamt@'s PR kern/36673, that I forgot to commit
yesterday.
- 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.