Commit Graph

90 Commits

Author SHA1 Message Date
njoly
3e46e29198 Fix ENVSYS_DEBUG build. 2010-03-24 19:15:00 +00:00
pgoyette
7e351badfc In sysmon_envsys_sensor_event(), permit delivery of all events for the
sensor if no event type is specified.
2010-03-24 13:11:41 +00:00
pgoyette
bc480daf7a Additional info in DPRINTF to help debugging efforts 2010-03-23 16:52:02 +00:00
pgoyette
3a92a7609d 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>
2010-03-19 02:19:13 +00:00
pgoyette
4e3cadf247 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.
2010-03-19 01:16:44 +00:00
pgoyette
f2b6b76565 If we're going to valdate things, at least do it correctly. 2010-02-18 12:30:53 +00:00
pgoyette
8844275b30 For symmetry, allow warning and critical upper-limits for capacity
sensors.
2010-02-15 22:32:04 +00:00
pgoyette
de08bb89f2 Replace large amount of replicated code with a macro to improve readability. 2010-02-14 23:30:52 +00:00
pgoyette
9150436462 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.
2010-02-14 23:06:01 +00:00
pgoyette
f84d320712 Correct one more instance of checking flags in the wrong place. 2010-02-14 16:22:09 +00:00
pgoyette
7bd93168ee When checking current sensor value vs limits, check the correct set of
flags to determine which limits are present.
2010-02-13 19:34:14 +00:00
jruoho
7ed7fa0c2a Fix a typo in one DPRINTF (s/edata->des/edata->desc/). 2010-02-05 19:22:25 +00:00
pgoyette
4c60416219 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.
2010-02-04 18:06:53 +00:00
pgoyette
aaabf34dde 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.
2010-01-30 02:46:52 +00:00
pgoyette
af4bab2a6f 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).
2010-01-26 14:22:00 +00:00
pgoyette
299ee01345 If no limits are exceeded, make sure we set state to SVALID 2010-01-18 21:48:15 +00:00
pgoyette
4e1c0f753c 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.
2010-01-02 19:02:39 +00:00
pgoyette
801c007d68 Don't infer a sensor driver's ability to handle limit checking itself. 2010-01-01 15:41:25 +00:00
pgoyette
160a805c1d 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).
2009-12-23 18:31:00 +00:00
pgoyette
d36ea2afc5 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.
2009-07-10 15:27:33 +00:00
pgoyette
c7ba8d5428 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.
2009-07-08 17:28:53 +00:00
pgoyette
e65558aef1 Clean up a couple of debug statements that got missed previously. 2009-07-08 13:34:11 +00:00
pgoyette
45f4717820 Ooops - {get,set}_limits() need to be sensor-specific. Pass an extra
argument to them to identify the individual sensor being processed.
2009-06-14 19:43:12 +00:00
pgoyette
c235777756 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.)
2009-06-13 16:08:25 +00:00
pgoyette
260b6fd907 Correct typo in last so we can #undef the correct macro. 2009-06-08 13:06:33 +00:00
pgoyette
f7ad703892 General clean-up and some restructuring of event handling. This is a
precursor to letting sensor drivers actually exchange limits/thresholds
with user-land.
2009-06-08 00:55:35 +00:00
pgoyette
5a84f3060e 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
2009-06-01 20:08:44 +00:00
dyoung
3afac3e189 Fix spelling: mak -> make. 2009-04-07 21:49:36 +00:00
pgoyette
438c6057be Fix typo in previous, and wrap a panic with #ifdef DIAGNOSTIC 2008-11-11 19:03:06 +00:00
pgoyette
0ba7ea9569 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.
2008-11-11 16:55:01 +00:00
pgoyette
287fe7d56d Fix cut&paste error in prev 2008-11-04 22:16:15 +00:00
pgoyette
3880525312 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.
2008-11-04 22:06:10 +00:00
pgoyette
494623b269 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@
2008-09-07 12:13:00 +00:00
pgoyette
0d1ae4cbb2 Initialize event's sent-state appropriately to avoid unnecessary start-up
time messages that report a "transition" to the Normal state.
2008-09-04 21:54:51 +00:00
pgoyette
6d65ba8398 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@
2008-08-22 11:27:50 +00:00
drochner
96a9f67868 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
2008-06-11 17:40:06 +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
9f5371f02a Only check sysmon_low_power if the event comes from
ENVSYS_BATTERY_CAPACITY sensors.
2008-02-29 14:34:49 +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
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
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
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
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
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