Commit Graph

143 Commits

Author SHA1 Message Date
xtraeme ab21cdda12 sme_event_unregister: remove a goto that is not needed anymore. 2007-10-07 14:07:21 +00:00
xtraeme 6c4da82b5e 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.
2007-10-07 04:11:15 +00:00
xtraeme 50509ea822 Forgot to change the kmem_zalloc(9) calls to use KM_NOSLEEP in previous,
as was suggested by rmind.
2007-10-06 22:07:42 +00:00
xtraeme 4814127d51 Fix a bug that happened when two or more events were received almost
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.
2007-10-06 21:58:40 +00:00
xtraeme 07f9bca5af - sysmon_power_daemon_task: check if pev is valid before use.
- Add two more KASSERTS in strategic places.
2007-10-06 02:49:46 +00:00
xtraeme 2e97fc9309 - Don't use _nocopy in prop_dictionary_set_cstring, the string is part
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.
2007-09-25 19:27:08 +00:00
xtraeme 636631cccc sme_add_sensor_dictionary: don't forget to release the dictionary when
an error ocurrs. This is the last memleak in the code, let me know if
you find more and I'll pay you a beer.
2007-09-24 19:46:38 +00:00
plunky 43ed9716b7 do not use _nocopy, this string is part of another object that
will be released shortly..
2007-09-24 18:09:17 +00:00
xtraeme 25fa55f16f Change the DPRINTFs in sysmon_envsys_destroy_plist() to DPRINTFOBJs
(second level of verbosity).
2007-09-09 12:28:08 +00:00
xtraeme 66ad9e7acd sysmon_envsys_register: don't forget to clear SME_FLAG_BUSY when
registration succeeds.
2007-09-08 23:59:38 +00:00
xtraeme 1e91f1628f Use DPRINTF for a debugging printf. 2007-09-08 23:21:02 +00:00
xtraeme 2473f3e4f5 Use panic(9) for previous. To make pooka and rmind happy. 2007-09-08 23:16:08 +00:00
xtraeme 4258a2b5f4 Remove an unused variable. 2007-09-08 23:14:13 +00:00
xtraeme f854251f66 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.
2007-09-08 22:58:56 +00:00
xtraeme aeb9b8e3fb Fix another memleak that only happened when using
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.
2007-09-08 22:42:37 +00:00
xtraeme 6f2d66f364 Don't forget to free sme_evdrv in non error case too. Noticed and
reviewed by rmind.
2007-09-08 15:47:37 +00:00
xtraeme 70a37300e4 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.
2007-09-08 15:25:18 +00:00
xtraeme c1594607bd Disable debug, committed accidentally in previous. 2007-09-08 03:41:28 +00:00
xtraeme 83b57478ed sysmon_envsys_register: only call sme_event_unregister_all when any
other error than EEXIST is returned.
2007-09-08 03:37:51 +00:00
xtraeme 10fa1cb836 - 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.
2007-09-08 03:17:38 +00:00
xtraeme 8c48c47af5 Remove another COMPAT_40 block, found by rmind@. 2007-09-08 00:58:32 +00:00
xtraeme 515802b6b0 Fix previous. 2007-09-08 00:30:54 +00:00
xtraeme a880528756 - Build unconditionally compatibility code, there's no point to have it
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.
2007-09-08 00:21:43 +00:00
xtraeme 93aefe8737 - 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.
2007-09-07 23:28:33 +00:00
xtraeme 5b53183e98 - 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.
2007-09-04 16:54:02 +00:00
xtraeme dee3b63c54 Add some KASSERT(mutex_owned(&foo_lock)). 2007-09-03 01:29:51 +00:00
xtraeme 1b3709ecde Add a new sensor type to sysmon_envsys(9): ENVSYS_GSTRING.
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
$
2007-09-02 19:36:59 +00:00
xtraeme 03b7809379 Add <sys/mutex.h> rather than <sys/lock.h>. 2007-09-02 00:44:07 +00:00
xtraeme c371d1d093 Convert the sysmon watchdog framework to use mutex(9) rather than
simple_locks and initialize them on init_main via sysmon_wdog_init().

All the sysmon code now is cleaned up and doesn't use old style locking.
2007-09-02 00:41:24 +00:00
xtraeme fda9e03ae4 Remove unused (and inexistent) flag. 2007-09-02 00:28:28 +00:00
xtraeme e83dd2301e - Fix a memleak in ENVSYS_SETDICTIONARY if there wasn't any error
(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.
2007-09-01 13:43:10 +00:00
xtraeme 9da1b0ba86 sme_event_register: don't forget to add the object in dictionary when
a critical value is added via ENVSYS_SETDICTIONARY.
2007-09-01 12:46:04 +00:00
xtraeme 822a96ea64 sme_event_register: sme_sensor_upint32() was being called even when
adding events via sme_event_drvadd(), fix it.
2007-09-01 00:12:07 +00:00
xtraeme 63f1decdb2 - 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.
2007-08-31 22:44:39 +00:00
xtraeme e71bfccc23 Merge sme_event_add() into sme_event_register()... there's no need
to have two different functions for this.
2007-08-31 10:13:27 +00:00
xtraeme ab98913282 Simplify sme_event_add() and fix a problem when updating critical
values.
2007-08-31 09:12:55 +00:00
xtraeme d67fa603fc Add a few KASSERT(mutex_owned(&foo_lock)) as suggested by Andrew Doran. 2007-08-31 00:35:08 +00:00
xtraeme 885829cb69 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).

(forgot in previous)
2007-08-30 23:46:29 +00:00
xtraeme d7029deed2 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).
2007-08-30 23:44:32 +00:00
xtraeme 9df6f42177 Simplify sysmon_envsys_register() and fix an obvious error in
previous.
2007-08-30 21:31:28 +00:00
xtraeme cac66f76dd 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.
2007-08-30 18:01:26 +00:00
pavel c514daad8f Add missing #include <prop/proplib.h>, should fix build failure reported
by Juergen Hannken-Illjes. The code apparently relied on proplib.h being
included indirectly through proc.h -> event.h -> ioctl.h -> dkio.h.
2007-08-17 16:52:52 +00:00
xtraeme 555fcb5606 The acpilid(4) powerd script is "lid_switch" not "lid_button"... found
by jmcneill@.
2007-08-07 14:03:00 +00:00
xtraeme 059f68a935 In ENVSYS_SETDICTIONARY if sysmon_envsys_find() returns NULL, do not
call sysmon_envsys_release with a NULL argument.
2007-08-05 23:16:25 +00:00
xtraeme e802e6b656 - Do not call sme_gtredata in sysmon_envsys_createplist, as in some
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).
2007-07-29 14:02:29 +00:00
xtraeme 294ea334f7 Change locking stuff in sysmon_envsys_register() and
sysmon_envsys_createplist().
2007-07-27 11:59:09 +00:00
xtraeme ac5a2b6161 - 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.
2007-07-23 17:51:16 +00:00
xtraeme 079deb4a40 - sysmon_envsys_createplist: do not return the error of sme->sme_gtredata
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.
2007-07-23 08:45:51 +00:00
xtraeme 666d15456c 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.
2007-07-22 18:17:02 +00:00
xtraeme 5623c9a1de Convert sysmon_taskqueue to use mutex(9) and condvar(9) and initialize
them in init_main.c via sysmon_task_queue_preinit().

Reviewed and ok by ad@.
2007-07-21 23:15:16 +00:00