intrd.c
author Albert Lee <trisk@forkgnu.org>
Tue, 01 Feb 2011 16:10:01 -0500
changeset 4 a42e422f55c0
parent 3 380ada8fd621
permissions -rw-r--r--
More WIP, need to convert to uu_list.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
     1
/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
     2
 * CDDL HEADER START
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
     3
 *
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
     7
 *
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    11
 * and limitations under the License.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    12
 *
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    18
 *
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    19
 * CDDL HEADER END
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    20
 */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    21
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    22
/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    23
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates.  All rights reserved.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    24
 */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    25
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    26
#include <stdio.h>
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    27
#include <errno.h>
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    28
#include <unistd.h>
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    29
#include <stdlib.h>
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    30
#include <limits.h>
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    31
#include <string.h>
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    32
#include <getopt.h>
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    33
#include <libgen.h>
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    34
#include <syslog.h>
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    35
#include <kstat.h>
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    36
#include <sys/processor.h>
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    37
#include <sys/modhash.h>
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    38
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    39
#include "intrs.h"
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    40
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    41
/* Interrupt vector info */
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    42
typedef struct ivec {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    43
	int cookie;
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    44
	uint64_t time;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    45
	hrtime_t crtime;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    46
	int pil;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    47
	int ino;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    48
	int ihs;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    49
	int num_ino;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    50
	int origcpu;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    51
	int nowcpu;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    52
	int inum;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    53
} ivec_t;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    54
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    55
uu_list_pool_t *ivec_pool;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    56
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    57
/* MSI device info */
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    58
typedef struct msi_dev {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    59
	msi_dev_t *next;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    60
	char *devpath[MAXPATHLEN];
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    61
	int num_intr;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    62
	*ivec_t ivecs;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    63
} msi_dev_t;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    64
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    65
uu_list_pool_t *msi_dev_pool;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    66
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    67
/* Bus info */
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    68
typedef struct bus_dev {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    69
	bus_dev_t *next;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    70
	char *buspath[MAXPATHLEN];
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    71
	int num_intr;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    72
	ivec_t *ivecs;
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    73
	int is_pcplusmp;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    74
	msi_dev_t *msi_head;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    75
} bus_dev_t;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    76
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    77
uu_list_pool_t *bus_dev_pool;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    78
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    79
/* Per-CPU statistics */
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    80
typedef struct cpu_stat {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    81
	int state;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    82
	uint64_t tot;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    83
	hrtime_t crtime;
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    84
	bus_dev_t *bus_head;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    85
} cpu_stat_t;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    86
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    87
uu_list_pool_t *cpu_stat_pool;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    88
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    89
/* Interrupt statistics */
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    90
type def struct intr_stat {
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    91
	hrtime_t snaptime;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    92
	*cpu_stat_t *cpus;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    93
} intr_stat_t;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    94
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    95
uu_list_pool_t *intr_stat_pool;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    96
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
    97
typedef enum sleeptime {
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    98
	NORMAL_SLEEPTIME = 10,		/* time to sleep between samples */
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
    99
	IDLE_SLEEPTIME = 45,		/* time to sleep when idle */
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   100
	ONECPU_SLEEPTIME = 60 * 15,	/* used if only 1 CPU on system */
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   101
} sleeptime_t;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   102
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   103
int using_scengen;			/* 1 if using scenario simulator */
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   104
int debug;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   105
int foreground;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   106
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   107
int max_cpus;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   108
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   109
sleeptime_t sleeptime = NORMAL_SLEEPTIME;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   110
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   111
float idle_intrload = 0.1; 		/*  idle if interrupt load < 10% */
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   112
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   113
float timerange_toohi = 0.1;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   114
int statslen = 60;	/* time period (in secs) to keep in @deltas */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   115
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   116
int main(int argc, char **argv)
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   117
{
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   118
	const char *cmdname;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   119
	kstat_ctl_t *kc;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   120
	kstat_t *ksp;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   121
	intr_stat_t stat;
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   122
	char c;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   123
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   124
	max_cpus = sysconf(_SC_CPUID_MAX) + 1;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   125
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   126
	cmdname = basename(argv[0]);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   127
/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   128
 * Parse arguments. intrd does not accept any public arguments; the two
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   129
 * arguments below are meant for testing purposes. -D generates a significant
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   130
 * amount of syslog output. -S <filename> loads the filename as a perl
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   131
 * script. That file is expected to implement a kstat "simulator" which
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   132
 * can be used to feed information to intrd and verify intrd's responses.
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   133
 */
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   134
 	while ((c = getopt(argc, argv, "S:Df")) != EOF) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   135
		switch (c) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   136
		case 'S':
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   137
			using_scengen = 1;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   138
			foreground = 1;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   139
			load_simulator(optarg);
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   140
			break;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   141
		case 'D':
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   142
			debug = 1;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   143
			break;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   144
		case 'f':
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   145
			foreground = 1;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   146
			break;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   147
		default:
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   148
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   149
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   150
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   151
	if (!foreground) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   152
		if (daemon(0, 0) == -1) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   153
			return 1;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   154
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   155
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   156
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   157
	if (!using_scengen) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   158
		openlog(cmdname, LOG_PID, LOG_DAEMON);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   159
		(void) setlogmask(LOG_UPTO(debug ? LOG_DEBUG : LOG_INFO));
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   160
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   161
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   162
	if (!using_scengen) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   163
		kc = kstat_open();
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   164
		if (kc == NULL) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   165
			return 1;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   166
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   167
	} else {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   168
		/* scengen not implemented */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   169
		return 1;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   170
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   171
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   172
/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   173
 * If no pci_intrs kstats were found, we need to exit, but we can't because
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   174
 * SMF will restart us and/or report an error to the administrator. But
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   175
 * there's nothing an administrator can do. So print out a message to syslog
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   176
 * and silently pause forever.
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   177
 */
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   178
	for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   179
		if ((ksp->ks_type == KSTAT_TYPE_NAMED) &&
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   180
		    (strcmp(ksp->ks_module, "pci_intrs") == 0)) {
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   181
		    break;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   182
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   183
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   184
	if (ksp == NULL) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   185
		kstat_close(kc);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   186
		syslog(LOG_INFO, "no interrupts were found: " \
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   187
			"your I/O bus may not yet be supported\n");
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   188
		do {} while (sleep(ONECPU_SLEEPTIME) == 0);
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   189
		return 0;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   190
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   191
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   192
	stat.cpus = malloc(sizeof (cpu_stat_t) * max_cpus);
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   193
	if (stat.cpus == NULL) {
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   194
		return 1;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   195
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   196
}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   197
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   198
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   199
static int verify(int condition, const char *msg)
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   200
{
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   201
	int bad = !condition;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   202
	if (bad) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   203
		syslog(LOG_DEBUG, "VERIFY: %s", msg);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   204
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   205
	return bad;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   206
}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   207
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   208
static void load_simulator(const char *file)
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   209
{
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   210
}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   211
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   212
static int getstat($$);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   213
/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   214
int generate_delta($$);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   215
int compress_deltas($);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   216
int dumpdelta($);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   217
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   218
int goodness($);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   219
int imbalanced($$);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   220
int do_reconfig($);
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   221
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   222
int goodness_cpu($$);		# private function
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   223
int move_intr($$$$);		# private function
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   224
int ivecs_to_string(@);		# private function
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   225
int do_find_goal($$$$);		# private function
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   226
int find_goal($$);		# private function
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   227
int do_reconfig_cpu2cpu($$$$);	# private function
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   228
int do_reconfig_cpu($$$);	
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   229
*/
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   230
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   231
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   232
/*
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   233
 *
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   234
 * What follow are the basic data structures routines of intrd.
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   235
 *
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   236
 * getstat() is responsible for reading the kstats and generating a "stat" hash.
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   237
 *
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   238
 * generate_delta() is responsible for taking two "stat" hashes and creating
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   239
 * a new "delta" hash that represents what has changed over time.
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   240
 *
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   241
 * compress_deltas() is responsible for taking a list of deltas and generating
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   242
 * a single delta hash that encompasses all the time periods described by the
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   243
 * deltas.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   244
*/
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   245
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   246
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   247
/*
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   248
 *
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   249
 * getstat() is handed a reference to a kstat and generates a hash, returned
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   250
 * by reference, containing all the fields from the kstats which we need.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   251
 * If it returns the scalar 0, it failed to gather the kstats, and the caller
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   252
 * should react accordingly.
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   253
 *
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   254
 * getstat() is also responsible for maintaining a reasonable $sleeptime.
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   255
 *
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   256
 * {"snaptime"}          kstat's snaptime
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   257
 * {<cpuid>}             one hash reference per online cpu
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   258
 *  ->{"tot"}            == cpu:<cpuid>:sys:cpu_nsec_{user + kernel + idle}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   259
 *  ->{"crtime"}         == cpu:<cpuid>:sys:crtime
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   260
 *  ->{"ivecs"}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   261
 *     ->{<cookie#>}     iterates over pci_intrs::<nexus>:cookie
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   262
 *        ->{"time"}     == pci_intrs:<ivec#>:<nexus>:time (in nsec)
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   263
 *        ->{"pil"}      == pci_intrs:<ivec#>:<nexus>:pil
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   264
 *        ->{"crtime"}   == pci_intrs:<ivec#>:<nexus>:crtime
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   265
 *        ->{"ino"}      == pci_intrs:<ivec#>:<nexus>:ino
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   266
 *        ->{"num_ino"}  == num inos of single device instance sharing this entry
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   267
 *				Will be > 1 on pcplusmp X86 systems for devices
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   268
 *				with multiple MSI interrupts.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   269
 *        ->{"buspath"}  == pci_intrs:<ivec#>:<nexus>:buspath
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   270
 *        ->{"name"}     == pci_intrs:<ivec#>:<nexus>:name
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   271
 *        ->{"ihs"}      == pci_intrs:<ivec#>:<nexus>:ihs
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   272
 *
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   273
*/
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   274
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   275
int getstat(kstat_ctl_t *kc, intr_stat_t *stat)
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   276
{
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   277
	int cpucnt = 0;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   278
	kstat_t *ksp;
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   279
	hrtime_t minsnap, maxsnap;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   280
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   281
	/* Hash of hash which matches (MSI device, ino) combos to kstats. */
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   282
	msi_dev_t *msidevs;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   283
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   284
	/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   285
	 * kstats are not generated atomically. Each kstat hierarchy will
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   286
	 * have been generated within the kernel at a different time. On a
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   287
	 * thrashing system, we may not run quickly enough in order to get
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   288
	 * coherent kstat timing information across all the kstats. To
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   289
	 * determine if this is occurring, $minsnap/$maxsnap are used to
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   290
	 * find the breadth between the first and last snaptime of all the
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   291
	 * kstats we access. $maxsnap - $minsnap roughly represents the
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   292
	 * total time taken up in getstat(). If this time approaches the
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   293
	 * time between snapshots, our results may not be useful.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   294
	*/
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   295
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   296
	minsnap = -1;		/* snaptime is always a positive number */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   297
	maxsnap = minsnap;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   298
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   299
	/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   300
	 * iterate over the cpus in cpu:<cpuid>::. check
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   301
	 * cpu_info:<cpuid>:cpu_info<cpuid>:state to make sure the
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   302
	 * processor is "on-line". if not, it isn't accepting interrupts
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   303
	 * and doesn't concern us.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   304
	 *
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   305
	 * record cpu:<cpuid>:sys:snaptime, and check $minsnap/$maxsnap.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   306
	 */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   307
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   308
	cpu_stats = stat->cpus;
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   309
	bzero(cpu_stats, sizeof (cpu_stat_t) * max_cpus);
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   310
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   311
	for (ksp = kc->kc_chain; ksp != null; ksp = ksp->ks_next) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   312
		kstat_t *ksp_sys;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   313
		kstat_named_t *knp;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   314
		int cpu;
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   315
		hrtime_t snaptime;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   316
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   317
		if ((ksp->ks_type != kstat_type_named) ||
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   318
		    strcmp(ksp->ks_module, "cpu_info") ||
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   319
		    (kstat_read(kc, ksp) == -1)) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   320
		    continue;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   321
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   322
		knp = kstat_data_lookup(ksp, "state");
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   323
		if ((knp == NULL) || strcmp(knp->name, PS_ONLINE) ||
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   324
		    ((cpu = ksp->ks_instance) >= max_cpus)) {
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   325
			continue;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   326
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   327
		ksp_sys = kstat_lookup(kc, "cpu", cpu, "sys");
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   328
		if ((ksp_sys == NULL) || (kstat_read(kc, ksp_sys) == -1)) {
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   329
			continue;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   330
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   331
		cpu_stats[cpu].state = P_ONLINE;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   332
		knp = ksp_sys->ks_data;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   333
		for (i = 0; i < ksp_sys->ks_ndata; i++) {
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   334
			if ((strcmp(knp[i].name, "cpu_nsec_idle") == 0) ||
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   335
			    (strcmp(knp[i].name, "cpu_nsec_user") == 0) ||
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   336
			    (strcmp(knp[i].name, "cpu_nsec_kernel") == 0)) {
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   337
				cpu_stats[cpu].tot += knp[i].value.ui64;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   338
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   339
		cpu_stats[cpu].crtime = ksp_sys->crtime;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   340
		snaptime = ksp_sys->snaptime;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   341
		if (minsnap == -1 || snaptime < minsnap) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   342
			minsnap = snaptime;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   343
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   344
		if (snaptime > maxsnap) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   345
			maxsnap = snaptime;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   346
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   347
		cpucnt++;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   348
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   349
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   350
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   351
	if (cpucnt <= 1) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   352
		sleeptime = ONECPU_SLEEPTIME;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   353
		return 0;	/* nothing to do with 1 CPU */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   354
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   355
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   356
	/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   357
	 * Iterate over the ivecs. If the cpu is not on-line, ignore the
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   358
	 * ivecs mapped to it, if any.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   359
	 *
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   360
	 * Record pci_intrs:{inum}:<nexus>:time, snaptime, crtime, pil,
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   361
	 * ino, name, and buspath. Check $minsnap/$maxsnap.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   362
	 */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   363
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   364
	for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   365
		kstat_named_t *knp;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   366
		int cpu;
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   367
		int ino;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   368
		cpu_stat_t *cpup;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   369
		bus_dev_t *busp;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   370
		bus_dev_t *bus_last;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   371
		ivec_t *ivecp;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   372
		hrtime_t snaptime;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   373
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   374
		if ((ksp->ks_type != KSTAT_TYPE_NAMED) ||
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   375
		    strcmp(ksp->ks_module, "pci_intrs") ||
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   376
		    (kstat_read(kc, ksp) == -1)) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   377
			continue;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   378
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   379
		knp = kstat_data_lookup(ksp, "cpu");
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   380
		if ((knp == NULL) || ((cpu = knp->value.ui32) >= max_cpus) ||
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   381
		    (cpu_stats[cpu].state != P_ONLINE)) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   382
			continue;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   383
		}
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   384
		cpup = &cpu_stats[cpu];
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   385
		knp = kstat_data_lookup(ksp, "type");
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   386
		if ((knp == NULL) || strcmp(knp->value.c, "disabled")) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   387
			continue;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   388
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   389
		knp = kstat_data_lookup(ksp, "buspath");
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   390
		if (knp == NULL) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   391
			continue;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   392
		}
4
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   393
		
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   394
		for (bus_last = NULL, busp = cpup->bus_head; busp != NULL;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   395
		     bus_last = busp, busp = busp->next) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   396
			if (strcmp(knp->value.c, busp->buspath) == 0) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   397
				break;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   398
			}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   399
		}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   400
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   401
		if (busp == NULL) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   402
			busp = malloc(sizeof (bus_dev_t));
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   403
			if (busp == NULL) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   404
				return -1;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   405
			}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   406
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   407
			busp->next = NULL;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   408
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   409
			strlcpy(busp->buspath, knp->value.c, MAXPATHLEN);
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   410
			busp->is_pcplusmp =
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   411
			    intrinfo(busp->buspath, &(busp->num_intr));
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   412
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   413
			busp->ivecs = malloc(sizeof (ivec_t) * busp->num_intr);
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   414
			if (busp->ivecs == NULL) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   415
				free(busp);
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   416
				return -1;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   417
			}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   418
			bzero(busp->ivecs, sizeof (ivec_t) * busp->num_intr);
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   419
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   420
			if (bus_last == NULL) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   421
				cpup->bus_head = busp;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   422
			} else {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   423
				bus_last->next = busp;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   424
			}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   425
		}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   426
		knp = kstat_data_lookup(ksp, "ino");
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   427
		if ((knp == NULL) ||
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   428
		    ((ino = knp->value.ui32) >= busp->num_intr)) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   429
			continue;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   430
		}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   431
		ivecp = &(busp->ivecs[ino]);
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   432
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   433
		knp = kstat_data_lookup(ksp, "time");
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   434
		if (knp == NULL) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   435
			continue;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   436
		}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   437
		ivecp->time = knp->value.ui64;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   438
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   439
		if (busp->is_pcplusmp) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   440
			knp = kstat_data_lookup(ksp, "type");
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   441
			if (knp == NULL) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   442
				continue;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   443
			}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   444
			if (strcmp(knp->value.c, "msi") == 0) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   445
				for (msi_last = NULL, msip = busp->msi_head;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   446
				     msip != NULL;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   447
				     msi_last = msip, msip = msip->next) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   448
					if (ivecp->cookie == msip->cookie) {
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   449
						break;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   450
					}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   451
			}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   452
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   453
		}
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   454
			
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   455
		ivecp->num_ino = 1;
a42e422f55c0 More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents: 3
diff changeset
   456
		ivecp->crtime = ksp->crtime;
3
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   457
		snaptime = ksp->snaptime;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   458
		if (minsnap == -1 || snaptime < minsnap) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   459
			minsnap = snaptime;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   460
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   461
		if (snaptime > maxsnap) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   462
			maxsnap = snaptime;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   463
		}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   464
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   465
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   466
	/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   467
	 * All MSI interrupts of a device instance share a single MSI address.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   468
	 * On X86 systems with an APIC, this MSI address is interpreted as CPU
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   469
	 * routing info by the APIC.  For this reason, on these platforms, all
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   470
	 * interrupts for MSI devices must be moved to the same CPU at the same
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   471
	 * time.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   472
	 *
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   473
	 * Since all interrupts will be on the same CPU on these platforms, all
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   474
	 * interrupts can be consolidated into one ivec entry.  For such devices,
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   475
	 * num_ino will be > 1 to denote that a group move is needed.  
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   476
	 */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   477
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   478
	/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   479
	 * Loop thru all MSI devices on X86 pcplusmp systems.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   480
	 * Nop on other systems.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   481
	 */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   482
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   483
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   484
	/*
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   485
	 * We define the timerange as the amount of time spent gathering the
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   486
	 * various kstats, divided by our sleeptime. If we take a lot of time
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   487
	 * to access the kstats, and then we create a delta comparing these
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   488
	 * kstats with a prior set of kstats, that delta will cover
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   489
	 * substaintially different amount of time depending upon which
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   490
	 * interrupt or CPU is being examined.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   491
	 *
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   492
	 * By checking the timerange here, we guarantee that any deltas
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   493
	 * created from these kstats will contain self-consistent data,
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   494
	 * in that all CPUs and interrupts cover a similar span of time.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   495
	 *
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   496
	 * $timerange_toohi is the upper bound. Any timerange above
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   497
	 * this is thrown out as garbage. If the stat is safely within this
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   498
	 * bound, we treat the stat as representing an instant in time, rather
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   499
	 * than the time range it actually spans. We arbitrarily choose minsnap
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   500
	 * as the snaptime of the stat.
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   501
	 */
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   502
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   503
	 stat->snaptime = minsnap;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   504
	 if (((maxsnap - minsnap) / sleeptime) > timerange_toohi) {
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   505
	 	return 0;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   506
	}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   507
	return 1;
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   508
}
380ada8fd621 Start of intrd implementation.
Albert Lee <trisk@forkgnu.org>
parents:
diff changeset
   509