        .title  cpuload
        .link   "sys$share:spishr.exe"/shareable
MAXCPU=6
NSEC=5
SPI$_MODES=^x1000
        .psect  $PDATA quad,pic,con,lcl,shr,noexe,nowrt
argl_schdwk:                            ; argumentlist SYS$SCHDWK
        .long   4
        .long   0                       ; pidadr
        .long   0                       ; prcnam
        .address timadr                 ; daytim
        .long   0                       ; reptim
items1: .word   4+MAXCPU*33             ; item-list CPU usage
        .word   SPI$_MODES
        .address cpu
        .long   0
        .long   0
        .psect  $LOCAL quad,pic,con,lcl,noshr,noexe,wrt
argl_getspi:                            ; argumentlist EXE$GETSPI
        .long   7
        .long   0                       ; efn
        .long   0                       ; csiadr
        .long   0                       ; nodename
        .blkl   1                       ; item-list
        .address stats                  ; iosb
        .long   0                       ; astadr
        .long   0                       ; astprm
; L number of CPUs
; B CPU number
; L ticks interrupt stack
; L ticks MP synchronisation
; L ticks kernel mode
; L ticks executive mode
; L ticks supervisor mode
; L ticks user mode
; L ticks compatibility mode
; L ticks idle time
cpu:    .blkl   1                       ; CPU usage
        .repeat MAXCPU
        .blkb   1
        .blkl   8
        .endr
        .blkb   128
timadr: .blkq   1                       ; time address
stats:  .blkq   1                       ; status
        .psect  $CODE quad,pic,con,lcl,shr,exe,nowrt
;***************************************
;
;  CPULOAD (CPU)
;
;  get CPU load
;
;***************************************
        .entry  cpuload,^m<r2,r3,r4,r5>
        movc5   #0,#0,#0,#32,@B^4(ap)
        moval   items1,argl_getspi+16
        callg   argl_getspi,G^EXE$GETSPI; get information
        movl    B^4(ap),r0
        moval   cpu,r1
        movl    #MAXCPU,r2
100$:   addl2   B^5(r1),(r0)            ; accumulate for all CPU's
        addl2   B^9(r1),B^4(r0)
        addl2   B^13(r1),B^8(r0)
        addl2   B^17(r1),B^12(r0)
        addl2   B^21(r1),B^16(r0)
        addl2   B^25(r1),B^20(r0)
        addl2   B^29(r1),B^24(r0)
        addl2   B^33(r1),B^28(r0)
        sobgtr  r2,100$
        emul    #-10000000,#NSEC,#0,timadr
        callg   argl_schdwk,G^SYS$SCHDWK
        calls   #0,G^SYS$HIBER
        callg   argl_getspi,G^EXE$GETSPI; get information
        movl    B^4(ap),r0
        moval   cpu,r1
        movl    #MAXCPU,r2
200$:   subl2   B^5(r1),(r0)            ; accumulate for all CPU's
        subl2   B^9(r1),B^4(r0)
        subl2   B^13(r1),B^8(r0)
        subl2   B^17(r1),B^12(r0)
        subl2   B^21(r1),B^16(r0)
        subl2   B^25(r1),B^20(r0)
        subl2   B^29(r1),B^24(r0)
        subl2   B^33(r1),B^28(r0)
        sobgtr  r2,200$
        mnegl   (r0),(r0)               ; negate all values
        mnegl   B^4(r0),B^4(r0)
        mnegl   B^8(r0),B^8(r0)
        mnegl   B^12(r0),B^12(r0)
        mnegl   B^16(r0),B^16(r0)
        mnegl   B^20(r0),B^20(r0)
        mnegl   B^24(r0),B^24(r0)
        mnegl   B^28(r0),B^28(r0)
        subl2   B^28(r0),(r0)           ; make special subtraction
        ret
        .end
