From: alan@shodha.enet.dec.com ( Alan's Home for Wayward Notes File.)
Subject: Re: dec 5500's and hang problem
Date: 25 Aug 91 21:12:53 GMT [thread overview]
Message-ID: <3920@shodha.enet.dec.com> (raw)
In-Reply-To: 1991Aug25.172518.29456@scrumpy@.bnr.ca
Here is a faster version of the swap data collection
function. It should work same. If it doesn't let me
know and maybe I'll get to it someday. This version
will only work on ULTRIX V4 systems. If there is ever
a V1.4 of Monitor something resembling this version
show up.
/*
* Author: Alan Rollow, EIS/CXO, Digital Equipment Corp.
* File: swap.c
* Date: 5/22/91
* Version: 1.3
*
* swap.c - Collect and display data on swap space usage.
*/
#ifndef lint
static char SccsId[] = "@(#)swap.c 1.3 (monitor) 5/22/91" ;
#endif
/*
* Modification history.
*
* Jan. 15, 1989 -- arr
*
* Check the namelist in the setup function.
*
* Jan. 16, 1989 -- arr
*
* Added code for the display function.
*
* Feb. 15, 1989 -- arr
*
* Use the function version of BTOK() and BTOK() instead
* of the macros.
*
* Dec. 25, 1989 -- arr
*
* Setup private namelist.
*
* Dec. 26, 1989 -- arr
*
* Add code to handle V4.0 differences. This may all get backed out
* by Engineering, but works at the moment.
*
* Mar. 26, 1990 -- arr
*
* Added hack to work-around DECmumble include file problem.
*
* October 5, 1990 -- arr
*
* Rather than #ifdef the V4.0 display differences, base them
* off the value of mon_dmmin.
*
* February 14, 1991 -- arr
*
* Rather than use mon_dmmin as a version flag, I added one
* to the mon_flag field. This is a HACK, but will work
* until I can work on a V4 only version. The display stuff
* will still recognize mon_dmmin == 0 as a V4 flag.
*
* The reason for this is that I now overload mon_dmmin with
* the reserved swap space on V4 systems.
*/
#include <nlist.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/dk.h>
#include <sys/buf.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/vm.h>
#include <sys/dir.h>
#if defined(mips)
# include <mips/cpu.h>
#endif
#include <sys/param.h>
#include <sys/user.h>
#include <sys/proc.h>
#include <sys/text.h>
#include <sys/map.h>
#include <sys/conf.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <net/if.h>
#include <netinet/in.h>
#include <machine/pte.h>
#include <machine/param.h>
#include <monitor.h>
#define BTOK(x) (x >> 1)
/*
* This bit will be set in the flag field when data was
* collected on a V4 system. This is done to denote the
* presense of reserved page/swap space overloaded on
* mon_dmmin.
*/
#define MON$M_V4 (020)
/*
* Functions that don't return (int).
*/
char *calloc() ;
void free(), nlist() ;
long rmalloc() ;
/*
* Somewhere to store the swap data.
*/
struct mon_swap mon_swap ;
/*
* Passed to the error message routines.
*/
static char *module = "swap" ;
/*
* Things only used locally. These will be initialized
* in setup_swap(). Some of them aren't needed in V4 so
* we'll #ifdef around them.
*/
static struct swapu_t swapu ;
/*
* These are needed for all versions.
*/
static int start, end ; /* loop counters for the display function */
static struct map *swapmap, *smp_addr ;
static struct swdevt *swdevt, *swp_addr ;
static int nswapmap ;
static int nswdev ;
static int dmmax ; /* this will double as swapfrag from V4.0 */
static int swap_ticks = 0 ;
static int swapfrag ; /* this will be set when dmmax is */
/*
* After little consideration, it looks like the easiest
* way to handle the namelist differents between V4 and
* pre-V4 are two different name lists and sets of constants.
*
* This has the advantage that the V4 namelist is smaller
* and therefore nlist(3) will be quicker. It also makes
* checking for all the required namelist enties easier
* because we can just walk down the array.
*/
/*
* This is the local namelist for V4.0.
*/
struct nlist swap_nm[] = {
{ "_swapmap" }, /* SWAP_NM_SWAPMAP */
{ "_nswapmap" }, /* SWAP_NM_NSWAPMAP */
{ "_swdevt" }, /* SWAP_NM_SWDEVT */
{ "_nswdev" }, /* SWAP_NM_NSWDEV */
{ "_swapfrag" }, /* SWAP_NM_SWAPFRAG */
{ "_swapu" }, /* SWAP_NM_SWAPU */
{ "_availvas" }, /* SWAP_NM_AVAIL */
{ 0 }
};
/*
* Constants for local namelist.
*/
#define SWAP_NM_SWAPMAP (0)
#define SWAP_NM_NSWAPMAP (1)
#define SWAP_NM_SWDEVT (2)
#define SWAP_NM_NSWDEV (3)
#define SWAP_NM_SWAPFRAG (4)
#define SWAP_NM_SWAPU (5)
#define SWAP_NM_AVAIL (6)
/*
* Free the space allocated tables for the swap information.
*/
free_swap()
{
if( swapmap )
free((char *)swapmap) ;
if( swdevt )
free((char *)swdevt) ;
}
/*
* Allocate space for the various data structures we're
* to need. Reading them as a block is VERY much faster
* than one at time. If Ultrix ever makes these data
* structures lists instead of arrays, then the code will
* have to change. Hopefully by then there will be an
* ioctl(2) or getsysinfo(2) call to get information.
*/
setup_swap()
{
register i ;
(void)nlist("/vmunix", swap_nm) ;
/*
* This just walks through the array to see if all the
* needed symbols are there.
*/
for(i = 0; i < sizeof(swap_nm)/sizeof(swap_nm[0]) - 1; i++) {
if( swap_nm[i].n_value == 0 )
fatal("Swap space data is not available: %s.\n",
swap_nm[i].n_name, module) ;
}
/*
* Allocate space for the swap maps.
*/
nswapmap = get_word((long)swap_nm[SWAP_NM_NSWAPMAP].n_value);
smp_addr = (struct map *)get_word((long)swap_nm[SWAP_NM_SWAPMAP].n_value) ;
if((swapmap = (struct map *)calloc((unsigned)nswapmap,
sizeof(struct map))) == (struct map *) NULL) {
fatal("Can't allocate space for swap map: %s.\n", module) ;
}
/*
* Allocate space for the swap device table.
*/
nswdev = get_word((long)swap_nm[SWAP_NM_NSWDEV].n_value);
swp_addr = (struct swdevt *)swap_nm[SWAP_NM_SWDEVT].n_value ;
if((swdevt = (struct swdevt *)calloc((unsigned)nswdev,
sizeof (struct swdevt))) == (struct swdevt *) NULL) {
fatal("Can't allocate space for swapdev table: %s.\n", module) ;
}
/*
* Swapfrag is the interesting size in V4.0, but to
* make some of the other code simpiler we'll overload
* dmmax to hold swapfrag.
*
* We'll also overload dmmin with the reserved swap
* space.
*/
dmmax = swapfrag = get_word(swap_nm[SWAP_NM_SWAPFRAG].n_value) ;
mon_swap.mon_flag |= MON$M_V4 ;
mon_swap.mon_dmmax = swapfrag ;
}
/*
* Fill a mon_swap structure. This is closely derived from
* the source of pstat.c.
*/
collect_swap()
{
register leftover ;
register struct mapent *me;
register struct swdevt *sw;
/*
* Read the swap device table.
*/
readk((long)swp_addr, (char *)swdevt, nswdev * sizeof(struct swdevt)) ;
/*
* Read the swap maps.
*/
readk((long)smp_addr, (char *)swapmap, nswapmap * sizeof(struct map)) ;
swapmap->m_name = "swap";
swapmap->m_limit = (struct mapent *)&swapmap[nswapmap];
/*
* Read the swap usage structure.
*/
readk((long)swap_nm[SWAP_NM_SWAPU].n_value, (caddr_t)&swapu,
sizeof(struct swapu_t)) ;
/*
* Initialize the members of the mon_swap structure.
*/
mon_swap.mon_total = 0 ;
mon_swap.mon_free = 0 ;
mon_swap.mon_text = 0 ;
mon_swap.mon_smem = 0 ;
mon_swap.mon_wasted = 0 ;
/*
* Add up the amount of swap space.
*/
for (sw = swdevt; sw < &swdevt[nswdev]; sw++)
mon_swap.mon_total += sw->sw_nblks;
/*
* This is where the two different version of counting
* swap swap space get ugly. V4 provides a data structure
* where the kernel keeps track of this information. Before
* that we had to wander through all sorts of other kernel
* structure to count it up.
*/
/*
* The subtractions are because V4 appears to reserve
* two CLICKS. Doing this makes the numbers match with
* those of pstat(8).
*/
mon_swap.mon_total = mon_swap.mon_total - ctod(CLSIZE) - ctod(CLSIZE) ;
mon_swap.mon_text = swapu.txt ;
mon_swap.mon_smem = swapu.smem ;
mon_swap.mon_used = swapu.total_used ;
mon_swap.mon_wasted = swapu.wasted ;
mon_swap.mon_free = mon_swap.mon_total - mon_swap.mon_used ;
mon_swap.mon_dmmin = mon_swap.mon_total -
btodb(ctob(get_word(swap_nm[SWAP_NM_AVAIL].n_value))) ;
/*
* This will calculate how the swap space is
* divided up. There are two versions.
*/
swap_available(swapmap) ;
f_swap(&mon_swap) ;
}
/*
* V4.0 makes this simpler. The swap space consists of
* of swapfrag size pieces. Those that are free are
* available.
*/
swap_available(map)
register struct map *map ;
{
register i = 0, frags, leftover ;
register struct mapent *ep = (struct mapent *)(map+1);
register struct mapent *bufp;
frags = leftover = i = 0 ;
/*
* This is the quick and dirty method of calculating
* fragmentation of page/swap space. We look at each
* entry of the swapmap and determine how many full
* sized blocks and how many leftover 1 KB blocks there
* there and count them. This doesn't do any fake
* calculation.
*/
for (bufp = ep; bufp->m_size; bufp++) {
/*
* Do the interleave check. First it probably only
* matters if there are more than one page/swap device.
*
* Second, it has to be big enough for a full size
* block.
*
* Finally, the has to be evenly aligned on a swapfrag
* boundry. If not then we have to allow for the
* alignment.
*/
if( nswdev > 1 && bufp->m_size / swapfrag && bufp->m_addr % swapfrag ) {
/*
* We actually have one. Since we're not actually
* allocating space we can take a short cut. Because
* the blocks are not well aligned we have have N-1
* of them instead of N. So we subtract a swapfrag
* size piece from the size and then figure out how
* many there are. The subtracted gets added to the
* number of leftovers.
*/
frags += ((bufp->m_size / swapfrag) - 1) ;
leftover += swapfrag ;
}
else
frags += (bufp->m_size / swapfrag) ;
leftover += (bufp->m_size % swapfrag) ;
}
mon_swap.mon_avail[ffs(swapfrag)-2] = frags ;
mon_swap.mon_avail[0] = BTOK(leftover) ;
}
#define mon_resvm mon_dmmin
f_swap(p)
struct mon_swap *p ;
{
register i, missing ;
missing = mon_swap.mon_total - (mon_swap.mon_used + mon_swap.mon_free) ;
printf("%dk swap configured\n", BTOK(p->mon_total)) ;
printf("%dk reserved virtual address space\n", BTOK(p->mon_resvm)) ;
printf("\t%dk used (%dk text, %dk smem)\n",
BTOK(p->mon_used), BTOK(p->mon_text), BTOK(p->mon_smem)) ;
printf("\t%dk free, %dk wasted, %dk missing\n",
BTOK(p->mon_free), BTOK(p->mon_wasted), BTOK(missing)) ;
printf("avail: ") ;
for(i = 1; i < MON$C_MAXSWAP; i++)
if( p->mon_avail[i] )
printf("%d*%dk ", p->mon_avail[i], 1 << i) ;
printf("%d*1k\n", p->mon_avail[0]) ;
}
--
Alan Rollow alan@nabeth.cxn.dec.com
next prev parent reply other threads:[~1991-08-25 21:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-08-22 4:49 dec 5500's and hang problem Jim Ray
1991-08-25 17:25 ` Larry Dunkelman
1991-08-25 21:12 ` Alan's Home for Wayward Notes File. [this message]
1991-08-28 2:00 ` Bill Trost
1991-08-28 20:16 ` Peter Wolfe
1991-08-28 3:16 ` Bill Trost
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox