/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h> /* sleep() */
#include <string.h>
#include <errno.h>
#include <syslog.h>
#include <thread.h>
#include <time.h>
#include <kstat.h>
#include <sys/sysmacros.h>
#include "powerd.h"
/*
* External Variables
*/
extern pwr_info_t *info;
/*
* State Variables
*/
static int ncpus;
typedef struct activity_data {
int activity_delta;
struct diskinfo {
};
CPU_STAT(&old_cpu_stats, (x)))
/*
* Local Functions
*/
static void init_all(void);
static void init_disks(void);
static void cpu_stats_init(void);
static void load_ave_init(void);
static void nfs_init(void);
static void conskbd_init(void);
static void consms_init(void);
static int diskinfo_load(void);
static int cpu_stats_load(void);
static int load_ave_load(void);
static int nfs_load(void);
static void fail(char *, ...);
static void safe_zalloc(void **, int, int);
static void *safe_kstat_data_lookup(kstat_t *, char *);
int *, int, hrtime_t);
void
{
info->pd_ttychars_sum = 0;
info->pd_loadaverage = 0;
info->pd_diskreads_sum = 0;
info->pd_nfsreqs_sum = 0;
}
init_all();
}
static void
init_all(void)
{
init_disks();
if (diskinfo_load() != 0) {
}
if (cpu_stats_load() != 0) {
}
if (load_ave_load() != 0) {
}
nfs_init();
if (nfs_load() != 0) {
}
conskbd_init();
consms_init();
}
int
{
threshold));
}
int
{
threshold));
}
int
{
}
int
{
threshold));
}
static void
init_disks(void)
{
/*
* Patch the snip in the diskinfo list (see below)
*/
if (snip) {
}
continue;
}
} else {
sizeof (struct diskinfo), 0);
}
sizeof (kstat_io_t));
/*
* Insertion sort on (ks_module, ks_instance, ks_name)
*/
}
}
}
/*
* Put a snip in the linked list of diskinfos. The idea:
* If there was a state change such that now there are fewer
* disks, we snip the list and retain the tail, rather than
* freeing it. At the next state change, we clip the tail back on.
*/
}
static int
diskinfo_load(void)
{
return (1);
}
}
return (0);
}
int
{
int delta = 0;
init_all();
}
if (time == 0) {
}
if (DISK_DELTA(reads) > 0) {
}
}
#ifdef DEBUG
#endif
threshold));
}
static void
cpu_stats_init(void)
{
ncpus = 0;
ncpus++;
}
1);
ncpus = 0;
}
if (ncpus == 0)
fail("can't find any cpu statistics");
}
static int
cpu_stats_load(void)
{
int i, j;
tty_snaptime = 0;
/*
* Sum across all cpus
*/
for (i = 0; i < ncpus; i++) {
return (1);
if (i == 0) {
continue;
} else {
/*
* Other CPUs' statistics are accumulated in
* new_cpu_stats, initialized at the first iteration of
* the loop.
*/
for (j = 0; j < cpu_stats_list[i]->ks_ndata; j++)
cpu_stats_list[i]->ks_snaptime);
}
}
return (0);
}
int
{
int delta;
init_all();
}
#ifdef DEBUG
#endif
threshold));
}
static void
load_ave_init(void)
{
NULL) {
fail("kstat_lookup('unix', 0, 'system_misc') failed");
}
}
static int
load_ave_load(void)
{
return (1);
}
return (0);
}
int
{
init_all();
}
}
#ifdef DEBUG
#endif
}
static void
nfs_init(void)
{
}
static int
nfs_load(void)
{
int index;
return (0);
}
/*
* NFS client "getattr", NFS3 client "access", and NFS server "null"
* requests are excluded from consideration.
*/
if (nfs_client2_kstat) {
return (1);
}
}
}
if (nfs_client3_kstat) {
return (1);
}
}
}
if (nfs_server2_kstat) {
return (1);
}
}
}
if (nfs_server3_kstat) {
return (1);
}
}
null_calls +=
}
return (0);
}
int
{
int delta;
init_all();
}
return (0);
}
if (nfs_client2_kstat) {
}
if (nfs_client3_kstat) {
}
if (nfs_server2_kstat) {
}
if (nfs_server3_kstat) {
}
#ifdef DEBUG
#endif
threshold));
}
static void
conskbd_init(void)
{
}
/*
* Return the number of seconds since the last keystroke on console keyboard.
* Caller responsible for error reporting.
*/
long
conskbd_idle_time(void)
{
void *p;
return ((time_t)-1);
return (((kstat_named_t *)p)->value.l);
}
static void
consms_init(void)
{
}
/*
* Return the number of seconds since the most recent action (movement or
* click) of the console mouse. Caller responsible for error reporting.
*/
long
consms_idle_time(void)
{
void *p;
return ((time_t)-1);
return (((kstat_named_t *)p)->value.l);
}
static void
{
else
thr_exit((void *) 0);
}
static void
{
}
fail("malloc failed");
}
}
static void *
{
fail("kstat_data_lookup('%s', '%s') failed",
}
return (fp);
}
static int
{
int cmp;
if (cmp != 0) {
return (cmp);
}
if (cmp != 0) {
return (cmp);
}
}
static void
{
/*
* Add new nodes to the beginning of the list.
*/
if (*act_start == NULLACTIVITY) {
} else {
}
/*
* Remove nodes that are time-stamped later than the idle time.
*/
}
}
static int
int thold)
{
int sum = 0;
/*
* No need to walk the list if the sum of the deltas are not greater
* than the threshold value.
*/
return (idle_time);
}
/*
* Walk through the list and add up the activity deltas. When the
* sum is greater than the threshold value, difference of current
* time and the snaptime of that node will give us the idle time.
*/
}
}
}
return (idle_time);
}
static void
{
if (fr)
} else {
dst->ks_data_size = 0;
}
}