Commit Graph

143 Commits

Author SHA1 Message Date
xtraeme 38371ef4fb - Do not touch sme_nsensors when sensors with duplicate description are
found, rather maintain a global counter for all sensors that are unique,
  and use this global to get the correct index in the array.
- Use prop_array_set() rather than prop_array_add() for adding dictionaries
  into our global array. Thanks to yamt@.
- Overwrite the sensor index in the first sensor of a device, to avoid
  a problem with LKMs where the first sensor gets the index of all edata
  structures allocated in kernel.
- Add missing proto for sme_register_sensorname().

All them fix another part of yamt@'s PR.
2007-07-21 22:11:02 +00:00
xtraeme 82313816f8 Use the mutex that belongs to the specific task and do not mix them
blindly.

	- sme_list_mtx to access to the linked lists sme_list/sme_names_list.
	- sme_mtx to access to the data in the sysmon envsys device.
2007-07-21 17:18:00 +00:00
xtraeme 2ae3d17915 sme_update_dictionary: if there's a sensor with duplicate description,
there's no need to decrease 'i' again, just sme->sme_nsensors is enough.

Reported by yamt@.
2007-07-21 16:16:59 +00:00
xtraeme ed4bc532ce Simplify previous. 2007-07-21 15:45:12 +00:00
xtraeme bbb2e25d8f Skip sensor with duplicate descriptions in the COMPAT_40 case, verified
with envstat(8) from netbsd-4 and sys/lkm/misc/envsys2.

Fixes another part of kern/36673 by yamt@.
2007-07-21 15:30:04 +00:00
xtraeme 3fbf42ac66 - 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.
2007-07-21 15:16:58 +00:00
xtraeme b2537bf157 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().
2007-07-21 12:11:27 +00:00
xtraeme ad4c687095 Re-add a strlcpy() to copy the new description in edata->desc, if the
object in dictionary was updated succesfully.
2007-07-21 00:05:54 +00:00
xtraeme d78abcef3d Add another missing break if updating the drive-state object fails. 2007-07-20 14:59:58 +00:00
xtraeme 7282589dc3 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.
2007-07-20 14:10:22 +00:00
xtraeme 20fa88e24a Add a missing break if error when setting a new description. 2007-07-20 10:47:25 +00:00
xtraeme bf9c65870b Replace the macros to create/update objects in dictionary with three
inline functions, suggested by yamt@.

This also gets rid of a few gotos.
2007-07-20 10:40:07 +00:00
xtraeme 5ddbe8d764 sysmon_envsys_unregister: do not kmem_free(9) with the mutex held. 2007-07-19 17:06:25 +00:00
xtraeme 502368620a sme_register_sensorname: don't forget to kmem_free(9) before returning
EEXIST.
2007-07-19 09:29:48 +00:00
xtraeme a71b3e13ac Apply some indent to recent changes. 2007-07-19 00:28:47 +00:00
xtraeme 9b54edd947 Maintain a SLIST per device to check for unique descriptions and do not
create any dictionary if it's duplicated. Only the first sensor that has
a unique description will be added.

Remove all elements from the list at sysmon_envsys_unregister() time and
free resources associated with it.
2007-07-19 00:12:47 +00:00
xtraeme 4a393b31d2 - More changes related to locking.
- Add a condvar(9) to protect deletions on the list if there's an event
  in the worker thread.
2007-07-18 20:31:41 +00:00
xtraeme 711835b263 sme_make_dictionary: if prop_array_add() fails, don't forget to release
the dictionary. Pointed out by yamt@.
2007-07-18 20:23:10 +00:00
xtraeme fe7e9a002c - 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@.
2007-07-18 20:09:49 +00:00
xtraeme d11db10f38 Add more debugging printfs to catch sensors with duplicate description,
and some cosmetic ones.
2007-07-17 17:56:04 +00:00
xtraeme fc370c98c4 Skip sensors with the same description on the same device at attach time,
if the description of it is not unique, mark the sensor with
ENVSYS_FDUPDESC, return EEXIST and continue.

Also, when changing a description, check that the new description is not
assigned by any other sensor, otherwise return EEXIST.

Note that these restrictions are only per device. Fixes PR kern/36660.
2007-07-17 16:47:58 +00:00
xtraeme 0a6f85e0f3 Only allow to use ENVSYS_SETDICTIONARY if the user has write permission
in the /dev/sysmon device.

Use O_RDONLY for ENVSYS_GETDICTIONARY and O_RDWR for ENVSYS_SETDICTIONARY
in envstat(8).

Fixes PR kern/36661 by YAMAMOTO Takashi.
2007-07-17 15:43:08 +00:00
xtraeme 2557124ac5 There's no reason why integer sensors were disabled for monitoring,
so enable it. This will allow to set a min/max limit for the
macppc/battery.c driver, which uses an integer sensor to report the
battery capacity.

Indicator/Integer sensors will share the /etc/power/scripts/sensor_indicator
script to report the events.
2007-07-16 17:48:52 +00:00
ad 3ea425911b The power daemon is now an LWP. 2007-07-15 15:27:53 +00:00
xtraeme 91f3f6b1f8 sme_events_worker: there's no need to use an extra int that gets
the value of see->snum to get the index of sme_sensor_data, just use
see->snum directly.
2007-07-14 00:48:56 +00:00
xtraeme 8ae7221593 sme_event_add: if the event is already on the list, update the
critical value only if new value is different than the one it has.

While I'm here, improve the debugging printf for this.
2007-07-13 23:46:24 +00:00
xtraeme 8483d81318 sme_event_add: if sme_event_register() fails return the error of this
function and not EINVAL.
2007-07-13 23:21:46 +00:00
xtraeme aae1d72d54 sme_events_worker: simplify the code that sends the events. 2007-07-13 22:49:15 +00:00
xtraeme 961a1c929f sme_event_unregister: if the events list is empty, just after the
callout is stopped, use callout_destroy().
2007-07-13 11:09:09 +00:00
rmind 20bbb87e34 Implementation of per-CPU work-queues support for workqueue(9) interface.
WQ_PERCPU flag for workqueue and additional argument for workqueue_enqueue()
to assign a CPU might be used. Notes:
 - For now, the list is used for workqueue_queue, which is non-optimal,
   and will be changed with array, where index would be CPU ID.
 - The data structures should be changed to be cache-friendly.

Reviewed by: <yamt>, <tech-kern>
2007-07-12 20:39:56 +00:00
yamt f71c4c0db9 sme_events_init: create seewq with IPL_SOFTCLOCK as it's accessed by a callout. 2007-07-10 06:32:08 +00:00
ad 88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
xtraeme 4108f3ed3a SENSOR_UPTYPE: accept values of 0 for any object, so that the value is
showed in its dictionary.
2007-07-05 23:48:22 +00:00
xtraeme a7874cd432 Remove the max limit in the refresh value for the refresh_value sysctl,
use whatever you want within the limits of an integer.

Suggested by garbled@ and freza@.
2007-07-04 17:48:16 +00:00
xtraeme 68bb919d1f Fix the old ENVSYS_GTREDATA ioctl if there are sensors with invalid
state. Enable all sensors by default as valid and current valid data and
if there is one that is in invalid state, mark current data as not valid.

This matches the behaviour with the old API. Also, this fixes the problem
with ipmi(4) reporting bogus values with sensors in invalid state using
the old envstat(8).

Note that this only happened when using the old envstat(8).
2007-07-04 16:30:18 +00:00
xtraeme ccae4b9276 Erm, fix previous: 6min != 5min... 2007-07-03 22:38:20 +00:00
xtraeme be7048ebd1 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
$
2007-07-03 22:33:36 +00:00
xtraeme 6a9b572563 Add PENVSYS_TYPE_INDICATOR to handle events on Indicator sensors.
ipmi(4) uses this for the Intrussion and Power Supply sensors.
2007-07-02 15:18:30 +00:00
xtraeme 9f49f1431d sme_event_drvadd:
- Check the error returned by sme_event_add() and print details if
  returned value is not EEXIST.
- If sme_event_add() returned an error, don't add the monitoring-* object
  into the dictionary.
2007-07-02 11:05:52 +00:00
xtraeme bf4558f8cf 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).
2007-07-01 07:36:39 +00:00
xtraeme e31adb2d42 Use aprint_debug rather than printf for the annoying message
"WARNING: Callback scheduled before sysmon task queue thread present.".
2007-06-27 13:04:15 +00:00
xtraeme b6336505dc Remove duplicate sysmonioctl_envsys() prototype. 2007-05-08 20:04:42 +00:00
christos 53524e44ef Kill caddr_t; there will be some MI fallout, but it will be fixed shortly. 2007-03-04 05:59:00 +00:00
ad 3a91cc8a3b Back out previous for now. There isn't currently an easy way to set up
shared state before these get attached or used.

From xtraeme@.
2007-02-19 06:08:37 +00:00
xtraeme 0bb6833f55 Replace SYSMON_ENVSYS_{LOCK,UNLOCK} with mutex_{enter,exit}. 2007-02-19 00:36:12 +00:00
xtraeme bf63a83084 * sysmon_wdog_mtx needs to run at IPL_SOFTCLOCK.
* replace SYSMON_WDOG_{LOCK,UNLOCK} macros with mutex_{enter,exit}

reminded by ad@.
2007-02-19 00:25:30 +00:00
xtraeme 406b5ff314 * Replace simple_locks and exclusive locks with adaptive mutexes.
* Replace ltsleep/wakeup pairs with condition variables
  (cv_init/cv_wait/cv_broadcast).

Reviewed by ad@.
2007-02-18 23:38:11 +00:00
xtraeme 840604a1a8 Replace simple_locks with mutexes, reviewed by ad@. 2007-02-18 23:34:55 +00:00
hubertf eda05c6413 Remove more duplicate headers.
Patch by Slava Semushin <slava.semushin@gmail.com>

Again, this was tested by comparing obj files from a pristine and a patched
source tree against an i386/ALL kernel, and also for src/sbin/fsck_ffs,
src/sbin/fsdb and src/usr.sbin/makefs. Only changes in assert() line numbers
were detected in 'objdump -d' output.
2007-01-29 01:52:43 +00:00
smb 4612e5b3e5 Handle new gcc properly 2006-12-19 21:17:17 +00:00
christos 168cd830d2 __unused removal on arguments; approved by core. 2006-11-16 01:32:37 +00:00
christos 4d595fd7b1 - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
2006-10-12 01:30:41 +00:00
christos 05bd5641dd add missing initializers 2006-09-03 06:41:38 +00:00
christos 3c00d4c7e1 expose the ioctl internal function now used by the acpi_apm code. 2006-07-08 20:26:06 +00:00
freza a88dd66a11 Advance queue indices properly instead of silently rewriting
sysmon_power_event_queue[0] all the time.

OK by thorpej@
2006-06-08 04:23:34 +00:00
lukem 35f57c3fc9 Don't attempt to call (*sme->sme_gtredata)() or (*sme->sme_streinfo)()
if those members are NULL.
As discussed on tech-kern in October/November 2005.
2006-03-20 03:23:35 +00:00
christos 95e1ffb156 merge ktrace-lwp. 2005-12-11 12:16:03 +00:00
simonb 94e3e9f7f5 Spinkle some KNF. 2005-10-17 03:08:24 +00:00
christos 2c91ca8bd0 - add const
- avoid variable shadowing.
2005-05-29 22:18:25 +00:00
perry f31bd063e9 nuke trailing whitespace 2005-02-27 00:26:58 +00:00
drochner 3ad43282d2 apply an "& WDOG_MODE_MASK" so that user mode watchdogs started with "-A"
are terminated properly
2005-01-12 16:14:35 +00:00
smb ddd2ade252 Add a software watchdog timer facility. Because this slightly
changes the "tickle" model of wdogctl(8), it was modified as well;
while I was in there, I cleaned up the argument parsing.

The code was reviewed by simonb@.
2005-01-09 22:51:32 +00:00
cube c271a0dea6 According to acpi_acad.c and powerd(8), PRESSED event for AC adapter device
means it gets connected.  It feels odd to be told the AC adapter went
offline right after plugging it in.
2004-05-22 11:32:50 +00:00
kochi 1bc204dbcc Add AC adapter event type. 2004-05-03 07:43:37 +00:00
simonb b6abb6ab1d Remove some assigned-to but otherwise unused variables. 2003-10-30 01:58:17 +00:00
christos 5d43dc85d6 Rename the thread command name so that it fits on top's display. 2003-09-06 23:28:30 +00:00
yamt 44d0d57217 do wakeup() only when someone is waiting for us. 2003-08-11 15:07:14 +00:00
yamt 104f2a80df introduce SME_FLAG_BUSY and set it during operations
instead of keeping sysmon_envsys_list_slock spinlock held
because some drivers might sleep in sysmon_envsys ops,

XXX sysmon_envsys_lock is now redundant
2003-08-11 14:24:41 +00:00
lukem 365cbd9428 add missing __KERNEL_RCSID() 2003-07-14 15:47:00 +00:00
fvdl d5aece61d6 Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
2003-06-29 22:28:00 +00:00
darrenr 960df3c8d1 Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records.  The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
2003-06-28 14:20:43 +00:00
kochi 620bc11015 Fix a locking problem, which closes kern/21607.
ok'd by Jason Thorpe.
2003-05-19 23:24:55 +00:00
fvdl beed0b1c91 Fix format / number of argument mismatch for a printf. 2003-05-11 18:52:39 +00:00
thorpej 4bbda47b54 Add a "reset button" type. 2003-04-20 20:48:27 +00:00
thorpej d14efd22d1 Generic "task queue" for sysmon back-ends. This provides a thread
context for callbacks that require it in order to handle sysmon-related
events.

Adapted from the "OsdSchedule" bits of the ACPI code.
2003-04-20 20:20:35 +00:00
thorpej 5a20f4be3c * Add a generic power management event API, defined in <sys/power.h>.
Right now, only power switch state change events are supported.  This
  is a work-in-progress.
* Add support to sysmon for delivering power mangement events to userland.
  Add poll, kqueue, and read entry points to sysmon.
* Adapt ACPI to use the new generic <sys/power.h> event types.

This provides the kernel support for a forthcoming powerd(8) which can
do nice things like gracefully shut the system down when an ACPI power
button is pressed.
2003-04-18 01:31:34 +00:00
thorpej b0f79c65ce Start at a power management framework for sysmon. Right now we just
provide some VERY basic support for power/sleep buttons and lid switches;
if someone presses the power button, shut down the system semi-gracefully.

Eventually, we will send events for all types of button/lid events down
to a userland power management daemon, which will be able to define a
separate policy for each button/switch.
2003-04-17 01:02:21 +00:00
thorpej a5bb7e6494 Group things in this file a bit more logically. 2003-04-10 18:04:20 +00:00
thorpej 89ef67a28c Nothing cares about NSYSMON anymore; delete it. 2002-12-31 22:47:48 +00:00
explorer 59e0238f99 add envsys support to acpi A/C adapter and batteries. This is still a work
in progress, much like the rest of ACPI.
2002-12-31 05:26:56 +00:00
explorer 89f72704d1 remove redundant defines 2002-12-30 06:16:10 +00:00
jdolecek e0cc03a09b merge kqueue branch into -current
kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
2002-10-23 09:10:23 +00:00
kristerw d509ae30db Correct possible return of uninitialized error variable. 2002-10-06 09:48:29 +00:00
gehenna 77a6b82b27 Merge the gehenna-devsw branch into the trunk.
This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

	device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
  by using this grammer.

- Added the new naming convention.
  The name of the device switch must be <prefix>_[bc]devsw for auto-generation
  of device switch tables.

- The backward compatibility of loading block/character device
  switch by LKM framework is broken. This is necessary to convert
  from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
  We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
  the LKM framework will refer it to assign device major number dynamically.
2002-09-06 13:18:43 +00:00
simonb 10f735a013 Fix WDOGIOC_GTICKLER for userland ticklers. 2002-07-31 06:48:58 +00:00
thorpej 20ddfbf4c1 Move sysmon configuration definitions to dev/sysmon/files.sysmon. 2002-04-16 21:00:27 +00:00
jdolecek 57b53bc9a8 The device close routine is called when _last_ descriptor to the
device file is closed, rather on every descriptor close. Instead of
getting the exclusive lock on open and releasing on close, get
the lock only when needed in sysmonioctl_envsys().
Fixes kern/14368 by Anthony Mallet. Okayed by Jason Thorpe.

While here, also inline sysmon_envsys_init() to sysmonopen_envsys(),
and g/c sysmonioctl_wdog() prototype.
2002-01-03 22:35:53 +00:00
lukem 640249d1e9 add RCSIDs 2001-11-13 06:28:55 +00:00
thorpej 4e7ff09e27 Make sure to clear sysmon_armed_wdog once the watchdog timer
is disarmed.
2001-01-30 22:24:31 +00:00
thorpej e67f5e66bc Split the envsys and watchdog parts of sysmon into their own
files.
2000-11-05 04:06:13 +00:00
thorpej c48d521bdb Add a watchog timer framework to the system monitor. 2000-11-04 18:37:19 +00:00
thorpej e24d6ebc19 Fix a couple of brain-o's in error cases, and use PCATCH for
the sysmon mutex wait.
2000-06-28 06:51:17 +00:00
thorpej f82e306928 Add a clearing-house pseudo-device for system monitoring devices
such as the LM78 and VT82C686A (and eventually ACPI).  Multiple
sensor devices can be hooked registered with `sysmon', and eventually
sysmon will also handle hardware (and software) watchdog timers.

Convert the `lm' and `viaenv' drivers to the new interface.
2000-06-24 00:37:19 +00:00