From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  3-MAR-1992 21:19:11.17
To:	ARISIA::EVERHART
CC:	
Subj:	MWAIT V1.06, part 1 of 7

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.123)
	 id AA15672; Tue, 3 Mar 92 20:38:53 EST
Message-Id:  <9203040138.AA15672@crdgw1.ge.com>
Received: From SUN2.NSFNET-RELAY.AC.UK by CRVAX.SRI.COM with TCP; Tue,  3 MAR 92 17:31:04 PST
Received: from ncdlab.ulcc.ac.uk by sun2.nsfnet-relay.ac.uk via JANET 
          with NIFTP id <3509-3@sun2.nsfnet-relay.ac.uk>;
          Tue, 3 Mar 1992 08:46:50 +0000
Date: Tue, 3 Mar 92 8:24 GMT
From: Nick de Smith <NICK@ncdlab.ulcc.ac.uk>
To: INFO-VAX <@nsfnet-relay.ac.uk:INFO-VAX@KL.SRI.com>
Subject: MWAIT V1.06, part 1 of 7

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
$!   On 21-FEB-1992 11:49:37.72   By user NICK 
$!
$! This VMS_SHARE Written by:
$!    Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$!    James Gray       - Original VMS_SHARE
$!    Michael Bednarek - Original Concept and implementation
$!
$!+ THIS PACKAGE DISTRIBUTED IN 7 PARTS, TO KEEP EACH PART
$!  BELOW 30 BLOCKS
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. AAAREADME.1ST;1
$!       2. BUILD.COM;1
$!       3. MWAIT.MAR;1
$!       4. MWAIT.TXT;1
$!       5. MWAIT_MACROS.MAR;1
$!       6. TEST0.C;1
$!       7. TEST1.C;1
$!       8. TEST2.C;1
$!       9. TEST3.C;1
$!      10. TEST4.C;1
$!      11. TEST5.C;1
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
$e="write sys$error  ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if f$trnlnm("SHARE_LOG") then $ w = "!"
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$UNPACK: SUBROUTINE ! P1=filename, P2=checksum
$ if f$search(P1) .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped."
$ delete 'f'*
$ exit
$file_absent:
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'."
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
$ delete 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:=
CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b));
LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1);
IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE;
MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1;
ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")=
1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF";
POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r);
ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1;
COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,
"output_file"));ENDPROCEDURE;Unpacker;QUIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create 'f'
XMWAIT`09V1.06
X
X`09Nick de Smith, Applied Telematics Group Ltd.,
X`09Telematics House, Vale Avenue,
X`09Tunbridge Wells, Kent TN1 1DJ
X`09England
X`09+44 892 511000 (Fax: +44 892 515402)
X`09PSI%234213300154::NICK
X`09NICK@NCDLAB.ULCC.AC.UK
X
XMWAIT is a powerful utility that attempts to determine the reason for a proc
Vess
Xgoing into a wait state. Detail is given about LEF/CEF wait state, including
V the
Xnames of common event blocks being used. The length of time that the process
V has
Xbeen in a wait state is also displayed, as is a fairly full breakdown of MWA
VIT
Xreasons, especially RWAST, RWMBX and job quota related waits. You will need
V VMS
XV5.x and CMEXEC to run MWAIT.
X
XMWAIT.TXT`09Full documentation of VMS wait states/reasons and the MWAIT
X`09`09utility.
X
XMWAIT.MAR`09Source for MWAIT utility.
XMWAIT_MACROS.MAR
X`09`09Source of macro library for MWAIT.
X
XBUILD.COM`09Command file to build the MWAIT utility from source.
X
XTESTx.C`09`09Various test programs to demonstrate MWAIT's capabilities.
X
X`5Bend`5D
$ CALL UNPACK AAAREADME.1ST;1 1047887474
$ create 'f'
X$ Set Symbol /Scope=(NoLocal, NoGlobal)
X$!
X$ Library /Macro /Create /Log MWAIT_MACROS MWAIT_MACROS
X$ Macro /List MWAIT
X$ Link /NoTraceback /NoDebug /Map /Full /Cross MWAIT
X$!
$ CALL UNPACK BUILD.COM;1 53509217
$ create 'f'
X`09.title`09MWAIT`09System display of wait reasons
X`09.ident`09"X01.06"
X;+
X; MWAIT
X;
X; Author`09: Nick de Smith
X; Creation date`09: 09-Dec-91
X;
X; Description
X;
X;`09This program runs in EXEC mode to try to determine the reason for
X;`09a process being in a wait state. All the event flag information is
X;`09displayed, as is the process state. MWAIT tries to get the best detail
X;`09it can on process state, including JIB, RSN and MWAIT states.
X;`09MWAIT also displays the delta time since the process last entered a
X;`09wait state. This can be very useful for detecting dormant processes,
X;`09and processes that should be dormant and are not.
X;
X; Notes
X;
X;`09For various reasons, mainly concerned with ensuring that MWAIT returns
X;`09something, and because it only uses read access, MWAIT does not use any
X;`09locking on the memory databases it accesses and does not use $GETJPI.
X;`09This means that there is a finite possibility of MWAIT getting an
X;`09ACCVIO. This is no cause for concern - it will not blow away your
X;`09system, just re-run the program. If the process is jammed in an MWAIT,
X;`09it isn't going anywhere anyway! Note that if MWAIT gets an exception
X;`09in EXEC mode, it will cause the current (not the target) process to
X;`09terminate. This should never happen, but if it is a problem, run
X;`09MWAIT in a sub-process.
X;
X; Edit`09Edit date`09By`09Why
X;  06`0907-Feb-92`09NMdS`09Cosmetic change in some strings (a conditional
X;`09`09`09`09$FAO was wrong - did not affect data).
X;`09`09`09`09Add in driver offset PC resolution.
X;  05`0914-Jan-92`09NMdS`09Add more detail on process modes and AST modes.
X;`09`09`09`09Change the CHME/CHMK vector location code to do
X;`09`09`09`09a search, rather than relying on fixed offsets.
X;  04`0909-Jan-92`09NMdS`09Enhance messaging. Add action routines for
X;`09`09`09`09some of the RWAST causes.
X;  03`0906-Jan-92`09NMdS`09Change mutex references to be .WEAK
X;`09`09`09`09Added in RWMBX decoding.
X;  02`0923-Dec-91`09NMdS`09Change way RWAST_TABLE is re-vectored to account
X;`09`09`09`09for CHME/CHMK routines. Add in current priority.
X;`09`09`09`09Improve messaging. Many other minor changes.
X;  01`0909-Dec-91`09NMdS`09New
X;-
X
X.link`09`09"SYS$SYSTEM:SYS.STB" /SELECTIVE_SEARCH`09; Save typing later
X.library`09"SYS$LIBRARY:LIB.MLB"
X.library`09"SYS$DISK:`5B`5DMWAIT_MACROS.MLB"
X
X`09$cebdef`09`09`09`09; Common event flag wait definitions
X`09$ddbdef`09`09`09`09; Device data block definitions
X`09$dispdef`09`09`09; Change mode dispatcher offsets
X`09$dptdef`09`09`09`09; Driver prologue table offsets
X`09$dscdef`09`09`09`09; VMS descriptors
X`09$irpdef`09`09`09`09; I/O request packet offsets
X`09$jibdef`09`09`09`09; Job Information Block
X`09$ldrimgdef`09`09`09; Loadable image block definitions
X`09$opdef`09`09`09`09; Define VAX instructions
X`09$pcbdef`09`09`09`09; Process Control Block Definitions
X`09$phddef`09`09`09`09; Process header definitions
X`09$psldef`09`09`09`09; Processor status longword definitions
X`09$rsndef`09`09`09`09; Resource name definitions
X`09$sfdef`09`09`09`09; Saved frame offsets
X`09$splcoddef`09`09`09; Spinlock index definitions
X`09$ssdef`09`09`09`09; Define system statii
X`09$statedef`09`09`09; Define SCH$C_xxxx
X`09$ucbdef`09`09`09`09; Unit control block offsets
X
X`09.psect`09$RWDATA`09pic, noshr, rd, wrt, noexe, byte
XEPID_DESC:`09`09`09`09; Descriptor for ascii PID
X`09.ascid`09-               -`09; 15 characters
X
XE_ARGS:`09.long`091`09`09`09; $CMEXEC argument list
XEPID:`09.blkl`091`09`09`09; Target PID
X
XCMOD$AR_EXEC_DISPATCH_VECTOR:`09`09; Address of CHME dispatch vector
X`09.blkl`091
XCMOD$AR_KERNEL_DISPATCH_VECTOR:`09`09; Address of CHMK dispatch vector
X`09.blkl`091
X
X`09.psect`09$RODATA`09pic, shr, rd, nowrt, noexe, byte
X
XMAX_VECTOR_OFFSET = `5Ex2000`09`09; Maximum offset in EXCEPTION to vectors
XKERNEL_CHECK:
X`09.long`090, 0, `5Ex00010008`09; CHMK vector check values
X
XEXEC_CHECK:
X`09.long`090, 0, `5Ex0002000C`09; CHME vector check values
X
XEXCEPTION:`09`09`09`09; Name of CHMx handling exec image
X`09.ascic`09"EXCEPTION.EXE"
X
XPID_PROMPT:`09`09`09`09; Prompt to use for PID
X`09.ascid`09-_Target PID: -
XTITLE:`09.ascid "  Pid    User name    Process name    Prior  State  Port"
XFAOCTL:`09.ascid "!XL !12AF !15AF !5<!2UB/!UB!>  !6AC!+ !AC"
XFAOCTL_SMP:
X`09.ascid "!XL !12AF !15AF !5<!2UB/!UB!>  !3AC !2UB !AC"
XEFAOCTL:.word`0920$-10$, 0
X`09.address 10$
X10$:`09.ascii`09"!_Wait mask: !XL!0UL!1%C (all EFNs)!%F,"
X`09.ascii`09" Cluster: !UB, Time: !%D!/"
X`09.ascii`09"!_0: !XL, 1: !XL"
X20$:
XCEFAOCTL:
X`09.ascid`09"!_!UB: !XL (!%I!AF)"
X;
X; This $FAO control string assumes that the addresses of the saved register
X; values in a process header (PHD) are in the contiguous order shown below.
X;
XPHDCTL:`09.word`0920$-10$, 0
X`09.address 10$
X10$:`09.ascii`09"`09Process registers:!/"
X`09.ascii`09"!_!_R0:  !XL!_R1:  !XL!_R2:  !XL!_R3:  !XL!/"
X`09.ascii`09"!_!_R4:  !XL!_R5:  !XL!_R6:  !XL!_R7:  !XL!/"
X`09.ascii`09"!_!_R8:  !XL!_R9:  !XL!_R10: !XL!_R11: !XL!/"
X`09.ascii`09"!_!_AP:  !XL!_FP:  !XL!_PC:  !XL!_PSL: !XL"
X20$:
X
XNULL_USERNAME:`09.byte`09`5Ea' '`5BJIB$S_USERNAME`5D
XBATCH_MODE:`09.ascic`09"-Bat-"
XNETWORK_MODE:`09.ascic`09"-Net-"
XDETACH_MODE:`09.ascic`09"-Det-"
XSUB_MODE:`09.ascic`09"-Sub-"
X
X; This table corresponds to the order for SCH$C_xxx values for process state
Vs
X; from $STATEDEF
X
XSCH_TABLE:
X`09SCH`09<?????,Colpg,Mwait,Cef,Pfw,Lef,Lefo,Hib,-
X`09`09Hibo,Susp,Suspo,Fpg,Com,Como,Cur>
X
X; Table of known system resource wait states. The table is in the order
X; of the RSN$_xxx values from $RSNDEF
X
XRSN_TABLE:
X`09SCH`09<RW???,RWAST,RWMBX,RWNPG,RWPFF,RWPAG,RWBRK,RWIMG,RWQUO,-
X`09`09 RWLCK,RWSWP,RWMPE,RWMPB,RWSCS,RWCLU,RWCAP,RWCSV,SNPFU>
X
X; Table of known JIB wait states. These states are contained in JIB$B_FLAGS.
X
XASSUME`09JIB$M_BYTCNT_WAITERS`09eq`091
XASSUME`09JIB$M_TQCNT_WAITERS`09eq`092
X
XJIB_TABLE:
X`09SCH`09<J????,JIBYT,JITQE,JBYTQ>
X
X; Table of AST names vs. bits set (<0> = K, <1> = E, <2> = S, <3> = U)
X
XAST_TABLE:
X`09SCH`09<(none),K,E,KE,S,KS,ES,KES,U,KU,EU,KEU,SU,KSU,ESU,KESU>
X
X; Processor mode table - corresponds to PSL$C_xxx values
X
XMODE_TABLE:
X`09SCH`09<KERNEL,EXEC,SUPERVISOR,USER>
X
X; Table of known system MUTEXs and strings to display.
X; This is taken from table 8.3 in the V5.2 IDSM.
X
XMTX_TABLE: MTX`09<-
X`09<LNM$AL_MUTEX,MLogNm>,<IOC$GL_MUTEX,MIOdb>,<EXE$GL_CEBMTX,MCEB>,-
X`09<SMP$GL_CPU_MUTEX,MSMP>,<EXE$GL_PGDYNMTX,MPgDyn>,<EXE$GL_GSDMTX,MGSD>,-
X`09<EXE$GL_ACLMTX,MACL>,<EXE$GL_ENQMTX,MEnq>,<EXE$GL_SHMGSMTX,MShMGS>,-
X`09<EXE$GL_SHMMBMTX,MShMMb>,<CIA$GL_MUTEX,MCIA>,<EXE$GL_BASIMGMTX,MBsVMS>,-
X`09<QMAN$GL_MUTEX,MQMan>,<-1,MWAIT?>,-
X`09>
X
X; Table of known address ranges within the VMS executive where an RSN$_ASTWA
VIT
X; can be generated.
X; The RWPC macro takes up to 5 arguments:
X;
X;`09RWPC`09base, length, text `5B,action`5D `5B, backup`5D
X;
X;`09base`09Name of executive vectored routine in which the ASTWAIT occurs.
X;`09length`09Number of bytes offset from the start of the routine to allow
X;`09`09as the waiting PC. ie. the ASTWAIT must occur within this number
X;`09`09of bytes from the start of the routine.
X;`09text`09Message to display if a match is found.
X;`09action`09Action routine number to call to fill in detail.
X;`09backup`09Number of bytes preceding the start of the routine to allow in
X;`09`09the "hit range". This is required in some cases where code has
X;`09`09been placed prior to the start of the routine to overcome branch
X;`09`09range restrictions (EXE$QIO does this).
X;
X
XRWAST_TABLE:
X`09RWPC`09EXE$CANCEL`09, <`5Ex1E0>,-
X`09`09<!_$CANCEL needs BIOCNT: R5 = UCB, R6 = CCB, R7 = channel!/!_(Device:
V !AC!UW:, Channel: !XW)>, 1
X`09RWPC`09EXE$DASSGN`09, <`5Ex100>,-
X`09`09<!_$DASSGN while channel busy: R5 = channel, R6 = CCB!/!_(Channel: !XW
V)>`09`09, 2
X`09RWPC`09EXE$DELPRC`09, <`5Ex120>, <!_$DELPRC XQP still active: R4 = PCB.>`
V09`09`09, 0
X`09RWPC`09EXE$DELPRC`09, <`5Ex180>, <!_$DELPRC subprocesses active: R4 = PCB
V.>`09`09`09, 0
X`09RWPC`09EXE$QIO`09`09, <`5Ex100>,-
X`09`09<!_EXE$QIO access/deaccess pending: R4 = PCB, R5 = UCB, R7 = CCB!/!_(D
Vevice: !AC!UW:)>`09, 3, <`5Ex50>
X`09RWPC`09EXE$SUSPND`09, <`5Ex1A0>, <!_$SUSPEND XQP still active: R4 = PCB.>
V`09`09`09, 0
X`09RWPC`09EXE$PSCAN_LOCKCTX, <`5Ex80>, <!_$PROCESS_SCAN context busy.>`09`09
V`09`09, 0
X`09RWPC`09MMG$DELPAG`09, <`5Ex700>, <!_DIO active when PFN mapped page delet
Ved: R2 = VA, R3 = SAVPTE, R4 = PCB.>, 0
X`09RWPC`09EXE$SNGLEQUOTA`09, <`5Ex100>,-
X`09<!_Quota: R1 = quantity, R2 = address, R3 = width(bits)!/!_(Requested: !U
VL. unit!%S, Available: !UL. unit!%S)>, 4
X`09RWPC`090`09`09, <0 `09>, <!_Can't calculate reason from PC.>
X
X; Define local storage requirements
X
X; The following data structure is allocated on the stack and referenced with
V R6.
X
XMWAIT_C_FAOBUFLEN`09= 512
X
X$defini`09MWAIT
X$def`09MWAIT_Q_FAODSC`09.blkq`091
X$def`09MWAIT_T_FAOBUF`09.blkb`09<MWAIT_C_FAOBUFLEN>
X$def`09MWAIT_L_FLAGS`09.blkl`091`09`09; Program status flags
X`09_vield`09MWAIT,0,<-
X`09`09<TITLE,1,M>,-`09`09`09; Title has been displayed
X`09`09<CMVECT,1,M>,-`09`09`09; Set if CHMx vectors looked for
X`09`09<CHMK,1,M>,-`09`09`09; CHMK vectors found
X`09`09<CHME,1,M>,-`09`09`09; CHME vectors found
X`09`09<RWAST,1,M>,-`09`09`09; Process is in RWAST
X`09`09<RWMBX,1,M>,-`09`09`09; Process is in RWMBX
X`09`09<JIBWAIT,1,M>,-`09`09`09; Process is in a JIB related wait
X`09`09>
X$def MWAIT_R_PRMLST`09`09`09`09; $FAOL parameter list
X$def`09MWAIT_L_EPID`09.blkl`091`09`09; EPID of process
X$def`09MWAIT_S_USERNAME .blkl`091`09`09; JIB$S_USERNAME
X$def`09MWAIT_T_USERNAME .blkl`091`09`09; => JIB$T_USERNAME
X$def`09MWAIT_S_LNAME`09.blkl`091`09`09; = PCB$T_LNAME<0:8> (namelength)
X$def`09MWAIT_T_LNAME`09.blkl`091`09`09; => PCB$T_LNAME (process name)
X$def`09MWAIT_L_PRI`09.blkl`091`09`09; 31 - PCB$B_PRI
X$def`09MWAIT_L_PRIB`09.blkl`091`09`09; 31 - PCB$B_PRIB
X$def`09MWAIT_T_STATE`09.blkl`091`09`09; => ascic state string
X$def`09MWAIT_L_CPU_ID`09.blkl`091`09`09; PCB$L_CPU_ID if state=CUR
X$def`09MWAIT_T_TERMINAL .blkl`091`09`09; => PCB$T_TERMINAL
+-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-

