Newsgroups: comp.sys.transputer
From: ABack@vega.dcs.exeter.ac.uk (A.Back)
Subject: Re: Scheduling list...
Organization: Department of Computer Science, University of Exeter, U.K.
Date: 15 Aug 1994 10:30:02 GMT
Message-ID: <ABACK.94Aug15113003@vega.dcs.exeter.ac.uk>


tomas@marilyn.bion.kth.se (Tomas Uhlin) writes:
> ... I would like to do is for a process to be able to see if
> there are other processes waiting to be executed on the scheduling
> list.  In the literature this is referred to as the "FRONT POINTER",
> but I haven't been able to find out how to get access to it.
>
> What I'm looking for is the opposite of the "STHF" instruction.

The instructions are SAVEL and SAVEH, heres some ANSI C code showing
how they are used:

        {
          int* pair[2];

          __asm {
            ld &pair[0];
            savel;
          }

          printf("fptr = 0x%08x\n", pair[0]);
          printf("bptr = 0x%08x\n", pair[1]);
        }

However you have to be muy careful with these things as the fptr and
bptr can change at *any* time.  The best you can hope for is a
snapshot of the processor state.

        #if _PTYPE == '2' || _PTYPE == '3'
        #define NotProcess_p 0x8000
        #else
        #define NotProcess_p 0x80000000
        #endif

        #define NEXT_PROCESS_PTR -2

        int procs_waiting( void ) {
          int* pair[2];
          __asm {
            ld &pair[0];
            savel;        /* or saveh for hi pri proc queue */
          }
          return pair[0] != (int*) NotProcess_p;
        }

> PS.  If somebody can tell me something about exactly when processes
> are moved from the "time waiting queue" to the list of processes to
> be executed, that would also be very helpful.

Not sure though I would have thought they would be added immediately.

You can look to see how many processes are queued by looking along the
linked list of runnable process wptrs starting at fptr:

        #define NEXT_PROCESS_PTR -2

        int n_procs( void ) {
          int n = 0;
          int* pair[2];
          int* ptr;

          __asm {
            ld &pair[0];
            savel;
          }
          ptr = pair[0];
          if ( ptr == NotProcess_p ) return 0;
          while ( ptr != pair[1] ) {
            n++;
            ptr = (int*) ptr[ NEXT_PROCESS_PTR ];
          }
          return n;
        }

However this would probably only be safe if ran as a high priority
process, the loop may not terminate if run as a low pri. process and
the loop got time-sliced!  The system only adds things at the bptr end
of the queue so the fact that the processor may add processes after
you take the snapshot should be safe, provided you are not descheduled
while you are traversing the linked list.

Adam
--
_______________________________________________________________
email:aba@dcs.exeter.ac.uk        http://dcs.exeter.ac.uk/~aba/


