DSRT 2.0  Distribution


Back to DSRT homepage



Installation


CpuSvc



CpuDestroy




CpuCli

Running Sample Applications


C++ Application Program Interface


class CpuApi
struct CpuReserve A more detailed description about the various service classes are described as follows:
struct AdaptStrategy A more detailed description is given as follows:
struct ProcStats
struct SchedStats

Java Application Program Interface



class cpuJApi.CpuJApi
  • static boolean init();

  • Contact the CPU server.
  • static boolean reserve(CpuReserve* cr);
  • static boolean reserve(CpuReserve* cr, int pid);

  • Make a reservation specified in cr for the calling process or a real time process pid.  The calling process must have the right privilege to make a reservation for the process pid.  Note that after the reserve()call, the process still runs at normal time sharing priority.  The real time execution is started by calling start().  Return true/false for success/failure.
  • static boolean modify(CpuReserve* cr);
  • static boolean modify(CpuReserve* cr, int pid);

  • Modify the current reservation specified in cr for the calling process or a real time process pid.  The calling process must have the right privilege to modify the reservation for the process pid.  Return true/false for success/failure.
  • static boolean free();
  • static boolean free(int pid=0);

  • Free the current reservation for the calling process or a real time process pid.  The calling process must have the right privilege to free the reservation for the process pid.  Return true/false for success/failure.
  • static boolean start();
  • static boolean start(int pid);

  • Start the real time scheduling for the calling process or a real time process pid immediately.  A reservation must be made prior to start().  Return true/false for success/failure.
  • static boolean stop();
  • static boolean stop(int pid);

  • Temporarily stop the real time scheduling for the calling process or a real time process pid.  The calling process must have the right privilege to modify the reservation for the process pid.  The process pid becomes a normal time sharing priority process.  However, its reservation is still valid.  The process must have called start() prior to stop().   The process can be restarted by calling start()again. Return true/false for success/failure.
  • static void yield();

  • Mark the end of one executing iteration (or period) for the calling process. This applies to both periodic and aperiodic reservations. The calling process must have started the real time scheduling by calling start().  The process is blocked until the beginning of the next period.
  • static boolean setAdaptStrategy(AdaptStrategy* as);
  • static boolean setAdaptStrategy(AdaptStrategy* as, int pid);

  • Set the adaptation strategy specified in as for the calling process or a real time process pid.  The calling process must have the right privilege to set the adaptation strategy for the process pid.  Return true/false for success/failure.
  • static boolean setApDeadline(int deadline);

  • This is for CPU_RT_ACPU(aperiodic service class) process to set the relative deadline (in us) for its next iteration.  Return true/false for success/failure.
  • static boolean probe();
  • static boolean probe(int period);

  • Mark the beginning of the probing phase for the calling process.  Probing is useful when you want to determine which CPU service class and how much processing time to use in a reservation.   The calling process must not have any valid reservation.  If the calling process is a periodic process (with fixed period), then it must specify period in us.  If the calling process is an aperiodic process, then it does not specify any period.  Return true/false for success/failure.
  • static boolean probeEnd();

  • Mark the end of the probing phase for the calling process.  Return true/false for success/failure.
  • static boolean probeMatch(CpuReserve* cr);

  • Determine the suitable CPU reservation for the probing process.  It can be called after probeEnd().  The CPU reservation is returned in cr.   Return true/false for success/failure.
  • static void svcDestroy();

  • Destroy the CPU server.  It requires root privilege.
  • static boolean destroy();
  • static boolean destroy(int pid);

  • Same as the destructor for CpuApi.  Return true/false for success/failure.
  • static boolean setRecordProcStats();
  • static boolean setRecordProcStats(char* fname);

  • Record the process usage statistics for the calling process in a file "fname-ps.dat".  If no fname is specified, the file name is "pid-ps.dat".  Return true/false for success/failure.
  • static boolean setRecordSchedStats();
  • static boolean setRecordSchedStats(char* fname);
  • static boolean setRecordSchedStats(int samplingInterval);

  • Record CPU server statistics in a file "fname-ss.dat" every interval samplingInterval us.  If no fname is specified, the file name is "pid-ss.dat".  If no samplingInterval is specified, it is 1,000,000 us.  Return true/false for success/failure.
  • static boolean getProcStats(ProcStats* ps);
  • static boolean getProcStats(ProcStats* ps, int pid);

  • Get the process usage statistics in the previous iteration for the calling process.
  • static boolean getSchedStats(SchedStats* ss);

  • Get the CPU server statistics.
  • static boolean isPermNonConform();

  • Return true/false if the calling process is/is not permanently non conforming.

    class cpuJApi.CpuReserve

    class cpuJApi.AdaptStrategy

    class cpuJApi.ProcStats

    class cpuJApi.SchedStats

    Example Program

    A detailed sample program is provided in sample.C.  A simplified sample code to demonstrate the proper use of the API is shown below:
     

    CpuApi cpu;
    AdaptStrategy as;
    CpuReserve cr;
    int period;
     

    /**************  Probing Phase **************/
    if (!cpu.probe(period)) {
        printf("probe error\n");
        goto error;
    }

    if (!cpu.start()) {
        printf("probe refuses to start\n");
        goto error;
    }

    for (int i=0; i<probeItr; i++) {
        doSomething();
        cpu.yield();
    }

    cpu.stop();

    if (!cpu.probeEnd()) {
        printf("probeEnd error\n");
        goto error;
    }

    if (!cpu.probeMatch(&cr)) {
        printf("probeMatch error\n");
        goto error;
    }
     

    /**************  Reservation Phase **************/
    if (!cpu.reserve(&cr)) {
        printf("svc rejects reservation\n");
        goto error;
    }

    if (!cpu.setAdaptStrategy(&as)) {
        printf("invalid adaptation strategy\n");
        goto error;
    }

    if (cr.serviceClass == CPU_RT_ACPU)
        cpu.setApDeadline(d);
     

    /**************  Execution Phase **************/
    if (!cpu.start()) {
        printf("svc refuses to start it\n");
        goto error;
    }

    for (int i=0; i<doItr; i++) {
        doSomething(i);
        if (cr.serviceClass == CPU_RT_ACPU)
            cpu.setApDeadline(d);
        cpu.yield();
        if (cpu.isPermNonconform()) {
            // increase your reservation here
            cpu.modify(&cr);
        }
    }

    cpu.stop();
    cpu.free();
     


    Copyright (©) 1997-2000, Multimedia Operating Systems and Networking Group,
    University of Illinois at Urbana-Champaign
    Phone: (217)333-1515 (USA)
    Updated at October 10, 2000