From: "Bob George" <BOB@aeneas.ims.disa.mil>
Newsgroups: vmsnet.internals
Subject: Artificial CPU Load.
Date: 29 Sep 92 11:09:00 EST
Organization: Macro32<==>Vmsnet.Internals Gateway
X-Gateway-Source-Info: Mailing List

   Before I go re-inventing the wheel (excuse for being to lazy to look at
it anymore), does anyone have any programs that will simulate a normal load
on a VAX system.  Our performance shop is evaluating some monitoring packages,
and wants to do this off hours.  Why - I don't know - don't want to affect the
users until it's too late and already purchased, I guess.  Basically all they
look at is the CPU busy and occasionally the processing modes.  Does anyone
have anything that make the CPU look arbitarily (adjustable) busy with a fairly
consistant balance of modes.  Actually, I was playing with it a little bit by
adjusting the settings of the locations in the CPU database (probably a much
more difficult plan of attack than warranted, but also much more interesting).
I could make the system look 100% idle, 100% busy, or even 200% busy (single
processor), but if I tried to make it look in the 50-100% range, monitoring
would look the same whether the program was running or not.  The code and the
several lines that changed is attached after my signature.  What I was doing to
get 1/2 of all changes in the kernel, interupt, exec, and idle time counts
(subtract the 1/2 of the changes from the original locations) and add the total
subtracted back into the user mode location.  If I added all the locations, I
could make it look 100% busy, doubled the changes and make it look almost 200%
busy, or cleared all the locations - 100% idle.  My writing isn't always (ever)
very clear, so ask if you need any further explanations.
                                                               :\/\/\/:
                                    bob                        :______:
                                                               : (o)(o)
+----------------------------------------------------------+  c:   ___:
| Bob George     Internet : BOB@AENEAS.IMS.DISA.MIL        |   :     _)
| Disclaimer:    Opinions expressed are mine and mine only.|   : ,___:
+----------------------------------------------------------+   : __ /
                                                               /____\

This version runs at 100% user mode (from monitor), and changes are noted
in comments about how to get the other methods.
-----------------cut here ----------------------------------------------
; some of this blatently stolen from show_idle.mar in hitchhikers guide...
        .library        /sys$library:lib.mlb/
        .link           /sys$system:sys.stb/
        $cpudef
        $pcbdef
        $phddef
exec = 4        ;offsets into the processor time spent in different modes
super = 8       ;of the per-cpu database
user = 12
int = 16
compat = 20
mpsynch = 24
idle = 28
delay:  .long   -1*100*1000     ;very short hibernation time
        .long   -1
save:   .blkl   9
real_int:
        .blkl   1
        .entry sh_idle,^m<r2,r3,r4,r5>
st:     movl    g^smp$gl_active_cpus,r2
get_next:               ; stolen from show idle to dig up the addresses of
        ffs     #0,#32,r2,r3    ;the per-cpu databases, only run on a single
        bneq    process_this_guy        ;processor, but had this typed in and
        brw     got_em_all      ;it works
process_this_guy:
        bbcc    r3,r2,10$
10$:
        movl    smp$gl_cpu_data[r3],r4
        moval   cpu$l_kernel(r4),r5
        $schdwk_s       daytim=delay
        $hiber_s        ;wait so not running constantly
        moval   save,r6
        tstl    save    ;pop save location into memory
        $cmkrnl_s       routin=krnl
        brw     get_next
got_em_all:
        brw     st
        movl    #ss$_normal,r0
        ret
        .entry  krnl,^m<>
        lock    mmg,#ipl$_mmg
        clrl    r8              ;zero out total-changes-variable
        subl3   (r6),(r5),r7    ;r5 is the address of the initial (kernel)
                                ;time count in the cpu database array
;if I remove the comments from these ashl commands (div/2), no change is
;noticed in the monitor mode or system.
;       ashl    #-1,r7,r7
        addl2   r7,r8
        subl2   r7,(r5)
;if I remove the coments from these clrl commands, the system runs at a constant
;100% idle.
;       clrl    (r5)
        movl    (r5),(r6)       ;kernel done
        subl3   exec(r6),exec(r5),r7
;       ashl    #-1,r7,r7
        addl2   r7,r8
        subl2   r7,exec(r5)
;       clrl    exec(r5)
        movl    exec(r5),exec(r6)       ;exec done
        subl3   super(r6),super(r5),r7
;       ashl    #-1,r7,r7
        addl2   r7,r8
        subl2   r7,super(r5)
;       clrl    super(r5)
        movl    super(r5),super(r6)     ;super done
        subl3   int(r6),int(r5),r7
;       ashl    #-1,r7,r7
        addl2   r7,r8
        subl2   r7,int(r5)
;       clrl    int(r5)
        movl    int(r5),int(r6)         ;int done
        subl3   idle(r6),cpu$l_nullcpu(r4),r7
;       ashl    #-1,r7,r7
        addl2   r7,r8
        subl2   r7,cpu$l_nullcpu(r4)
;       clrl    cpu$l_nullcpu(r4)
        movl    cpu$l_nullcpu(r4),idle(r6)      ;idle done
;if I add a state to ashl (mult*2) ashl #1,r8,r8 , it becomes 200% user mode
        addl2   r8,user(r5)     ; add total changes into user mode time
        addl2   r7,mpsynch(r5)          ;easy way to see if r7 is changed since
                                        ;this is a monoprocessor and no mpsynch
                                        ;time (mon mode detects changes).
        unlock  mmg
        ret
        .end    sh_idle