For symmetry, allow warning and critical upper-limits for capacity

sensors.
This commit is contained in:
pgoyette 2010-02-15 22:32:04 +00:00
parent ff79c75809
commit 8844275b30
5 changed files with 80 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysmon_envsys.c,v 1.95 2010/02/14 23:06:01 pgoyette Exp $ */
/* $NetBSD: sysmon_envsys.c,v 1.96 2010/02/15 22:32:04 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.95 2010/02/14 23:06:01 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.96 2010/02/15 22:32:04 pgoyette Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -1061,6 +1061,18 @@ sme_remove_userprops(void)
"warning-capacity");
ptype = PENVSYS_EVENT_CAPACITY;
}
if (edata->upropset & PROP_BATTHIGH) {
prop_dictionary_remove(sdict,
"high-capacity");
ptype = PENVSYS_EVENT_CAPACITY;
}
if (edata->upropset & PROP_BATTMAX) {
prop_dictionary_remove(sdict,
"maximum-capacity");
ptype = PENVSYS_EVENT_CAPACITY;
}
if (ptype != 0)
sme_event_unregister(sme, edata->desc, ptype);
@ -1874,6 +1886,26 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
props |= PROP_BATTWARN;
}
/*
* did the user want to set a high capacity event?
*/
obj2 = prop_dictionary_get(udict, "high-capacity");
if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
targetfound = true;
lims.sel_warnmin = prop_number_integer_value(obj2);
props |= PROP_BATTHIGH;
}
/*
* did the user want to set a maximum capacity event?
*/
obj2 = prop_dictionary_get(udict, "maximum-capacity");
if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
targetfound = true;
lims.sel_warnmin = prop_number_integer_value(obj2);
props |= PROP_BATTMAX;
}
/*
* did the user want to set a critical max event?
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysmon_envsys_events.c,v 1.83 2010/02/14 23:30:52 pgoyette Exp $ */
/* $NetBSD: sysmon_envsys_events.c,v 1.84 2010/02/15 22:32:04 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.83 2010/02/14 23:30:52 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.84 2010/02/15 22:32:04 pgoyette Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -63,6 +63,8 @@ static const struct sme_sensor_event sme_sensor_event[] = {
{ ENVSYS_BATTERY_CAPACITY_NORMAL, PENVSYS_EVENT_NORMAL },
{ ENVSYS_BATTERY_CAPACITY_WARNING, PENVSYS_EVENT_BATT_WARN },
{ ENVSYS_BATTERY_CAPACITY_CRITICAL, PENVSYS_EVENT_BATT_CRIT },
{ ENVSYS_BATTERY_CAPACITY_HIGH, PENVSYS_EVENT_BATT_HIGH },
{ ENVSYS_BATTERY_CAPACITY_MAX, PENVSYS_EVENT_BATT_MAX },
{ -1, -1 }
};
@ -137,19 +139,19 @@ sme_event_register(prop_dictionary_t sdict, envsys_data_t *edata,
__func__, sme->sme_name, edata->desc, crittype));
see = osee;
if (props & PROP_CRITMAX) {
if (props & (PROP_CRITMAX | PROP_BATTMAX)) {
if (lims->sel_critmax == edata->limits.sel_critmax) {
DPRINTF(("%s: type=%d (critmax exists)\n",
__func__, crittype));
error = EEXIST;
props &= ~PROP_CRITMAX;
props &= ~(PROP_CRITMAX | PROP_BATTMAX);
}
}
if (props & PROP_WARNMAX) {
if (props & (PROP_WARNMAX | PROP_BATTHIGH)) {
if (lims->sel_warnmax == edata->limits.sel_warnmax) {
DPRINTF(("%s: warnmax exists\n", __func__));
error = EEXIST;
props &= ~PROP_WARNMAX;
props &= ~(PROP_WARNMAX | PROP_BATTHIGH);
}
}
if (props & (PROP_WARNMIN | PROP_BATTWARN)) {
@ -246,6 +248,8 @@ sme_event_register(prop_dictionary_t sdict, envsys_data_t *edata,
LIMIT_OP("critical-min", sel_critmin, PROP_CRITMIN);
/* %Capacity-based limits */
LIMIT_OP("maximum-capacity", sel_critmax, PROP_BATTMAX);
LIMIT_OP("high-capacity", sel_warnmax, PROP_BATTHIGH);
LIMIT_OP("warning-capacity", sel_warnmin, PROP_BATTWARN);
LIMIT_OP("critical-capacity", sel_critmin, PROP_BATTCAP);
@ -618,9 +622,11 @@ sme_events_worker(struct work *wk, void *arg)
else if __EXCEED_LIM(PROP_WARNMIN | PROP_BATTWARN,
sel_warnmin, <)
edata->state = ENVSYS_SWARNUNDER;
else if __EXCEED_LIM(PROP_CRITMAX, sel_critmax, >)
else if __EXCEED_LIM(PROP_CRITMAX | PROP_BATTMAX,
sel_critmax, >)
edata->state = ENVSYS_SCRITOVER;
else if __EXCEED_LIM(PROP_WARNMAX, sel_warnmax, >)
else if __EXCEED_LIM(PROP_WARNMAX | PROP_BATTHIGH,
sel_warnmax, >)
edata->state = ENVSYS_SWARNOVER;
else
edata->state = ENVSYS_SVALID;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysmon_power.c,v 1.42 2009/11/06 18:28:10 jakllsch Exp $ */
/* $NetBSD: sysmon_power.c,v 1.43 2010/02/15 22:32:04 pgoyette Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.42 2009/11/06 18:28:10 jakllsch Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.43 2010/02/15 22:32:04 pgoyette Exp $");
#include "opt_compat_netbsd.h"
#include <sys/param.h>
@ -135,6 +135,8 @@ static const struct power_event_description penvsys_event_desc[] = {
{ PENVSYS_EVENT_WARNUNDER, "warning-under" },
{ PENVSYS_EVENT_BATT_CRIT, "critical-capacity" },
{ PENVSYS_EVENT_BATT_WARN, "warning-capacity" },
{ PENVSYS_EVENT_BATT_HIGH, "high-capacity" },
{ PENVSYS_EVENT_BATT_MAX, "maximum-capacity" },
{ PENVSYS_EVENT_STATE_CHANGED, "state-changed" },
{ PENVSYS_EVENT_LOW_POWER, "low-power" },
{ -1, NULL }
@ -318,6 +320,8 @@ sysmon_power_daemon_task(struct power_event_dictionary *ped,
case PENVSYS_EVENT_WARNOVER:
case PENVSYS_EVENT_BATT_CRIT:
case PENVSYS_EVENT_BATT_WARN:
case PENVSYS_EVENT_BATT_HIGH:
case PENVSYS_EVENT_BATT_MAX:
case PENVSYS_EVENT_STATE_CHANGED:
case PENVSYS_EVENT_LOW_POWER:
{
@ -808,6 +812,14 @@ sysmon_penvsys_event(struct penvsys_state *pes, int event)
mystr = "warning capacity";
PENVSYS_SHOWSTATE(mystr);
break;
case PENVSYS_EVENT_BATT_HIGH:
mystr = "high capacity";
PENVSYS_SHOWSTATE(mystr);
break;
case PENVSYS_EVENT_BATT_MAX:
mystr = "maximum capacity";
PENVSYS_SHOWSTATE(mystr);
break;
case PENVSYS_EVENT_NORMAL:
printf("%s: normal capacity on '%s'\n",
pes->pes_dvname, pes->pes_sensname);

View File

@ -1,4 +1,4 @@
/* $NetBSD: envsys.h,v 1.29 2010/02/14 23:06:01 pgoyette Exp $ */
/* $NetBSD: envsys.h,v 1.30 2010/02/15 22:32:04 pgoyette Exp $ */
/*-
* Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@ -133,6 +133,8 @@ enum envsys_battery_capacity_states {
ENVSYS_BATTERY_CAPACITY_NORMAL = 1, /* normal cap in battery */
ENVSYS_BATTERY_CAPACITY_WARNING, /* warning cap in battery */
ENVSYS_BATTERY_CAPACITY_CRITICAL, /* critical cap in battery */
ENVSYS_BATTERY_CAPACITY_HIGH, /* high cap in battery */
ENVSYS_BATTERY_CAPACITY_MAX, /* maximum cap in battery */
ENVSYS_BATTERY_CAPACITY_LOW /* low cap in battery */
};
@ -167,13 +169,16 @@ enum envsys_battery_capacity_states {
#define PROP_WARNMIN 0x0008
#define PROP_BATTCAP 0x0010
#define PROP_BATTWARN 0x0020
#define PROP_DESC 0x0040
#define PROP_RFACT 0x0080
#define PROP_BATTHIGH 0x0040
#define PROP_BATTMAX 0x0080
#define PROP_DESC 0x0100
#define PROP_RFACT 0x0200
#define PROP_DRIVER_LIMITS 0x8000
#define PROP_CAP_LIMITS (PROP_BATTCAP | PROP_BATTWARN)
#define PROP_VAL_LIMITS (PROP_CRITMAX | PROP_CRITMIN | \
PROP_WARNMAX | PROP_WARNMIN)
#define PROP_CAP_LIMITS (PROP_BATTCAP | PROP_BATTWARN | \
PROP_BATTHIGH | PROP_BATTMAX)
#define PROP_VAL_LIMITS (PROP_CRITMAX | PROP_CRITMIN | \
PROP_WARNMAX | PROP_WARNMIN)
#define PROP_LIMITS (PROP_CAP_LIMITS | PROP_VAL_LIMITS)
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: power.h,v 1.14 2009/11/06 18:28:10 jakllsch Exp $ */
/* $NetBSD: power.h,v 1.15 2010/02/15 22:32:04 pgoyette Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@ -174,12 +174,18 @@ struct pswitch_state {
*
* PENVSYS_EVENT_BATT_WARN User warning capacity.
*
* PENVSYS_EVENT_BATT_HIGH User high capacity.
*
* PENVSYS_EVENT_BATT_MAX User maximum capacity.
*
* PENVSYS_EVENT_LOW_POWER AC Adapter is OFF and all batteries
* are discharged.
*/
#define PENVSYS_EVENT_BATT_CRIT 170
#define PENVSYS_EVENT_BATT_WARN 175
#define PENVSYS_EVENT_BATT_HIGH 177
#define PENVSYS_EVENT_BATT_MAX 178
#define PENVSYS_EVENT_LOW_POWER 180
/*