[comp.sys.transputer] PRE

anc@camcon.co.uk (Adrian Cockcroft) (09/26/88)

Here's a program that I have been getting round to writing for a long time,
I finally did it while messing around with PRE (Parallel Runtime Enviroment)
which is Niche's version of Trillium/Trollius. The way it works could be
duplicated in Occam, 3L C or Helios fairly easily.

Adrian

#!/bin/sh
# Archived: Mon Sep 26 15:01:49 GMT 1988
#
# Contents:
#  README
#  idled.c
#  tidle.c
#
echo x - README
sed 's/^X//' >README <<'*-*-END-of-README-*-*'
X
X                     Trillium Idle Daemon and Interrogator
X                     -------------------------------------
X
XAdrian Cockcroft, Cambridge Consultants 26/9/88
X
XThe idle daemon 'idled' runs (one copy) on each transputer in the system
Xstarted by: % loadgo 1.0 idled; loadgo 2.0 idled; etc
X
XIt counts the amount of time that it appears to be the only thing in
Xthe process queue and the amount of time that something busy delays its
Xreappearance and produces idle% as idle*100/(idle+busy). It also shows
Xthe idle time over the last second.
X
XIt polls trillium once per second to see if a request has occurred.
X
XTo see what the current state is use the SUN command 'tidle' e.g.
X
X% tidle 1.0; tidle 2.0; etc
X
XTo reset the baseline for the calculation use: tidle 1.0 -r
XTo kill a daemon completely use: tidle 1.0 -k
X
XCompile with
X
Xcc -o tidle tidle.c -ltrillium -lfreq -lnreq -lkreq
Xtcc8d -o idled idled.c -lstdio -ltrillium
X
XNiche have a copy of this and may produce a perfmeter-like program that
Xuses it sometime. I am putting it in the public domain for anyone to do
Xwhatever they want with it.
X
X  |   Adrian Cockcroft                  ..!uunet!mcvax!ukc!camcon!anc
X-[T]- Cambridge Consultants Ltd,        anc@uk.co.camcon or anc@camcon.uucp
X  |   Science Park, Cambridge CB4 4DW, England, UK    (0223) 358855
X      (You are in a maze of twisty little C004's, all alike...)
*-*-END-of-README-*-*
echo x - idled.c
sed 's/^X//' >idled.c <<'*-*-END-of-idled.c-*-*'
X/* idletime daemon for Trillium */
X
X#include <trillium/net.h>
X#include <trillium/stdio.h>
X#include <trillium/c.h>
X
X#define IDLEDEVENT   -999
X
Xmain()
X    {
X    char action;
X    struct nmsg header;
X    unsigned int start,max,min,count,now,idle,lastidle,busy,diff,poll;
X
X    if (kinit(10)) kexit(1);
X
X    header.nh_event = IDLEDEVENT;
X    header.nh_length = 1;
X    header.nh_msg = &action;
X    header.nh_type = 0;
X    header.nh_flags = 0;
X
X    printf("Idle time daemon running on node %x\n",getnodeid());
X
X    max = count = idle = busy = 0;
X    start = ldtimer();
X    flick();
X    min = ldtimer() - start;
X    poll = start = ldtimer();
X
X    while(1)
X        {
X        flick();        /* send this process to the back of the queue */
X        now = ldtimer();
X        diff = now - start;
X        if ((diff == 1) || (diff <= min))
X            {
X            min = diff;
X            idle += diff;
X            }
X        else
X            busy += diff;
X        ++count;
X        if (now > (poll+15625))
X            {
X            /* poll trillium for an enquiry once a second */
X            if (ntry_recv(&header) == 0) /* someone is talking */
X                {
X         printf("Idle time after %d flicks in %d seconds on node %x is %d%%\n",
X                        count, (idle+busy)/15625, getnodeid(), 
X                        (idle*100)/(idle+busy));
X                printf("Idle time over the last second is %d%%\n",
X                    ((idle-lastidle)*100)/15625);
X                switch (action)
X                    {
X                    case 0:
X                        count = idle = busy = 0;
X                        break;
X                    case 1:
X                        printf("Idle daemon terminating...\n");
X                        kexit(0);
X                        break;
X                    }
X                }
X            poll = start = ldtimer(); /* reset time to disallow system call */
X            lastidle = idle;
X            }
X        else
X            start = now;
X        }
X    kexit(1); /* shouldn't ever get here */
X    }
X
X
*-*-END-of-idled.c-*-*
echo x - tidle.c
sed 's/^X//' >tidle.c <<'*-*-END-of-tidle.c-*-*'
X/* this trillium process runs OTB and wakes up the idle daemon */
X
X#include <stdio.h>
X#include <ctype.h>
X#include <trillium/net.h>
X
Xmain(argc,argv)
X    int argc;
X    char *argv[];
X    {
X    int node;
X    char action = 2; /* safe value means just report times */
X    struct nmsg header;
X    if (kinit(100)) _kexit(1);
X    if (argc < 2)
X        {
X        printf("usage: tidle nodeid [-r|-k]\n-r to reset count\n-k to kill\n");
X        kexit(1);
X        }
X    while(--argc > 0)
X        {
X        if (*argv[argc] == '-')
X            {
X            switch(*(argv[argc]+1))
X                {
X                case 'r': action = 0; /* reset counts */
X                        break;
X                case 'k': action = 1; /* terminate daemon */
X                        break;
X                default:  printf("Bad option %c\n",*(argv[argc]+1));
X                }
X            }
X        else
X            {
X            if (isdigit(*argv[argc]))
X                node = 0x10000 * (*argv[argc]++ - '0');
X            else
X                continue;
X            if (*argv[argc]++ == '.')
X                if (isdigit(*argv[argc]))
X                    node += (*argv[argc] - '0');
X                else
X                    continue;
X            else
X                continue;
X            }
X        }
X    printf("Requesting idle from node %x\n",node);
X    header.nh_msg = &action;
X    header.nh_length = 1;
X    header.nh_node = ator(node);
X    header.nh_event = -999;
X    header.nh_type = 0;
X    header.nh_flags = 0;
X    if (nsend(&header))
X        kexit(2);
X    kexit(0);
X    }
X
*-*-END-of-tidle.c-*-*
echo End of Archive
exit

-- 
  |   Adrian Cockcroft                  ..!uunet!mcvax!ukc!camcon!anc
-[T]- Cambridge Consultants Ltd,        anc@uk.co.camcon or anc@camcon.uucp
  |   Science Park, Cambridge CB4 4DW, England, UK    (0223) 358855
      (You are in a maze of twisty little C004's, all alike...)