Commit Graph

185 Commits

Author SHA1 Message Date
jmcneill 0b59054580 Use aprint when reporting AC adapter status. 2008-05-10 14:01:32 +00:00
xtraeme c32766fd4f Pass KTHREAD_MPSAFE to kthread_create(). I've been testing this for
some weeks in both UP and SMP without any issue so far.
2008-04-06 09:42:04 +00:00
hannken ad882177bc Update includes. Builds again on sparc64.
Ok: Juan Romero Pardines <xtraeme@netbsd.org>
2008-04-04 10:10:20 +00:00
xtraeme 6dcb9dd40c 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().
2008-04-02 11:19:22 +00:00
xtraeme 18b1d12d0e Also fix a memleak when the event is already in dictionary
and has been updated.
2008-04-01 17:01:34 +00:00
rmind 4b02b68c59 sme_event_register: fix a memory leaks in two error paths. 2008-04-01 16:48:18 +00:00
xtraeme 5ee4eba88d 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
2008-04-01 12:25:30 +00:00
xtraeme a826e85aba 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.
2008-03-23 16:09:41 +00:00
xtraeme b1700faaf8 Pass D_MPSAFE to d_flag in the cdevsw struct, so that the kernel_lock
is not taken in the driver methods.

I've been running with this for some days without any effect.
2008-03-03 09:38:49 +00:00
rmind c6186face4 Welcome to 4.99.55:
- Add a lot of missing selinit() and seldestroy() calls.

- Merge selwakeup() and selnotify() calls into a single selnotify().

- Add an additional 'events' argument to selnotify() call.  It will
  indicate which event (POLL_IN, POLL_OUT, etc) happen.  If unknown,
  zero may be used.

Note: please pass appropriate value of 'events' where possible.
Proposed on: <tech-kern>
2008-03-01 14:16:49 +00:00
xtraeme 4089d9068a Added a missing break that was bothering me. 2008-02-29 18:07:11 +00:00
xtraeme 9f5371f02a Only check sysmon_low_power if the event comes from
ENVSYS_BATTERY_CAPACITY sensors.
2008-02-29 14:34:49 +00:00
xtraeme 51e43163c8 Add three new values for ENVSYS_DRIVE units:
* ENVSYS_DRIVE_OFFLINE, ENVSYS_DRIVE_CHECK and ENVSYS_DRIVE_BUILD
2008-02-28 16:21:34 +00:00
xtraeme b5abdb42f6 Destroy the callout via sysmon_envsys_destroy() now that it's
initialized in sysmon_envsys_create().
2008-02-02 02:02:37 +00:00
ad 0664a0459b Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
2008-01-04 21:17:40 +00:00
xtraeme b88ea32e70 - 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).
2008-01-02 12:20:26 +00:00
dyoung 09767a906c In sysmon_envsys_create(), initialize the callout structure. Stops
panics with a DIAGNOSTIC kernel.

In sysmon_envsys_find_40(), wait until an envsys is not busy before
settings its busy flag, in the pattern of sysmon_envsys_find().
2008-01-02 10:15:53 +00:00
dyoung 5493a07f14 Use LIST_FOREACH(). 2008-01-02 03:06:02 +00:00
dyoung 5b4182ee05 Use TAILQ_FOREACH(). 2008-01-02 02:29:14 +00:00
jmcneill ebad57771c Handle hotkey events using /etc/powerd/scripts/hotkey_button, ok xtraeme 2007-12-22 18:35:13 +00:00
dyoung 10bb018ab2 In sysmon_wdog_unregister(), do not return until all of the watchdog
timer's users are gone.  A signal cancels the unregister:
sysmon_wdog_unregister() leaves the watchdog registered.

The only user of sysmon_wdog_unregister() that I can find is in
elansc(4), so this looks like a safe change to make.
2007-12-16 21:07:45 +00:00
dyoung 19b79f5c39 Use LIST_FOREACH(). 2007-12-15 04:58:39 +00:00
martin 14587719e2 Add missing <sys/device.h> include. 2007-12-09 20:57:19 +00:00
jmcneill 4c1d81b2b5 Merge jmcneill-pm branch. 2007-12-09 20:27:42 +00:00
xtraeme 820f120b52 Add ENVSYS_DRIVE_MIGRATING for ENVSYS_DRIVE sensors, this is for RAID
volumes that are migrating such as when you change the stripe size.

While I'm here use the same string than we had in the old framework to
report status "online" vs "drive is online", because the sensor might be
a RAID volume and not just a drive.
2007-12-07 11:47:49 +00:00
pooka 4e38160d4d Do not "return 1" from kqfilter for errors. That value is passed
directly to the userland caller and results in a mysterious EPERM.
Instead, return EINVAL or something else sensible depending on the
case.
2007-12-05 17:19:46 +00:00
ad 598ab03ad0 Match the docs: MUTEX_DRIVER/SPIN are now only for porting code written
for Solaris.
2007-12-05 07:06:50 +00:00
ad ba369f0439 MUTEX_SPIN -> MUTEX_DEFAULT. 2007-12-05 06:52:27 +00:00
xtraeme 58406f0ac9 Update a comment. 2007-11-20 17:27:35 +00:00
xtraeme 714201def5 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.
2007-11-20 17:24:32 +00:00
xtraeme 752ee73cf1 Remove duplicate sme_events_list. 2007-11-16 08:18:33 +00:00
xtraeme 31962fc6e5 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.
2007-11-16 08:00:11 +00:00
xtraeme 91551751e7 Add another flag that is set only when the event was enqueued
(and its dictionary created) successfully and use it in the
POWER_EVENT_RECVDICT ioctl to check if the dictionary is ready before
calling prop_dictionary_copyout_ioctl().

This fixes a rare condition when too many events are enqueued and
there wasn't time to create the dictionary, so prop_dictionary_copyout_ioctl()
fails with a NULL pointer dereference.
2007-11-10 09:32:24 +00:00
xtraeme 4fbcc4c832 Remove sysmon_envsys_find() proto, it's defined on sysmon_envsysvar.h. 2007-11-03 23:25:20 +00:00
xtraeme 4e10a84855 - 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@.
2007-11-03 23:05:21 +00:00
plunky 812fa1c5a1 do not embed acpi device names in the sensor names
fake it in the compat code for the old envsys API
2007-11-02 19:21:29 +00:00
xtraeme 03ececeaba Use a flag for see_flags to know when the sensor has been refreshed
rather than using a boolean. Suggested by rmind.
2007-10-23 21:36:03 +00:00
xtraeme eccf5885ea 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.
2007-10-20 00:12:35 +00:00
xtraeme ed29af22c3 sme_event_drvadd: there's no need to acquire the mutex only when
setting the object on its dictionary.
2007-10-13 16:00:46 +00:00
xtraeme 7703f72284 Use PRI_NONE for the priority argument in workqueue_create(9). 2007-10-13 02:44:19 +00:00
xtraeme 752d116414 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.
2007-10-11 16:51:48 +00:00
xtraeme 7ade6d03ad 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.
2007-10-10 23:25:39 +00:00
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