Defines | Enumerations | Functions

/home/sindre/dev_uclinux/suzaku_shared/hwos_sw/libhwos/hprocess.h File Reference

[Hardware OS Process Interface] Interface for a process on the FPGA. More...

#include "hstructures.h"

Go to the source code of this file.

Defines

#define HPROCESS_MAX_FILENAME_SIZE   100
 Lowest priority possible for a process.
#define HPS_NUMBER   5
 Number of possible states.

Enumerations

enum  hpstate {
  HPS_NEW, HPS_READY, HPS_BLOCKED, HPS_BLOCKED_PLACED,
  HPS_RUNNING
}
 

Definition of states for a process in the HWOS.

More...

Functions

const int hprocess_base_priority ()
 Get base priority.
const int hprocess_max_processes ()
 Get maximum processes in system.
int hprocess_set_bitfilename (struct hprocess *process, char *filename)
 Set bitfilename for the process.
char * hprocess_get_bitfilename (struct hprocess *process)
 Get bitfilename for the process.
struct hprocesshprocess_get (int pid)
 Get process by PID.
struct hprocesshprocess_create (int nice)
 Create process.
int hprocess_set_priority (struct hprocess *process, int priority)
 Set priority for process.
int hprocess_get_priority (struct hprocess *process)
 Get priority for process.
int hprocess_set_nice (struct hprocess *process, int nice)
 Set nice value for process.
int hprocess_get_nice (struct hprocess *process)
 Get nice value for process.
int hprocess_get_pid (struct hprocess *process)
 Get PID for process.
struct hprocesshprocess_get_next (struct hprocess *process)
 Get next process in the list of processes.
struct hprocesshprocess_get_prev (struct hprocess *process)
 Get previous process in the list of processes.
int hprocess_get_state (struct hprocess *process)
 Get state of process.
int hprocess_is_valid_pid (int pid)
 Get state of process.
int hprocess_remove (struct hprocess *process)
 Remove process.
struct hsqueuehprocess_get_parent_queue (struct hprocess *process)
 Get pointer to the queue the process belongs to.

Detailed Description

[Hardware OS Process Interface] Interface for a process on the FPGA.

Author (2011): Sindre Hansen

Definition in file hprocess.h.


Enumeration Type Documentation

enum hpstate

Definition of states for a process in the HWOS.

Enumerator:
HPS_NEW 

Not running, just registered. An application has just asked to run this process.

HPS_READY 

Not running, but is scheduled for placement and runtime on the FPGA. Not placed on FPGA.

HPS_BLOCKED 

Blocked (waiting for an event or preempted). Not placed on FPGA.

HPS_BLOCKED_PLACED 

Blocked (waiting for an event or preempted). Placed on FPGA.

HPS_RUNNING 

Running. Process is placed and running on the FPGA.

Definition at line 21 of file hprocess.h.


Function Documentation

const int hprocess_base_priority (  ) 

Get base priority.

Returns the priority given to processes when they are first accepted to the system.

Returns:
Base priority of processes.

Definition at line 146 of file hprocess.c.

{
        return 49;
}

struct hprocess* hprocess_create ( int  nice  )  [read]

Create process.

Parameters:
nice User defined value to define priority for process.
Returns:
Process pointer on success. NULL on failure.

Definition at line 294 of file hprocess.c.

{
        struct hprocess* process = calloc(1, sizeof(*process));
        set_next_(process, NULL);
        set_prev_(process, NULL);
        set_state_(process, HPS_NEW);
        set_parent_queue_(process, NULL);
        set_pid_(process, increment_pid_counter_());
        hprocess_set_nice(process, nice);

        hsqueue_register_signal(HSIGNAL_ADD_PROCESS, enqueue_process_callback_);
        hsqueue_register_signal(HSIGNAL_REMOVE_PROCESS, remove_process_callback_);

        return process;
}

struct hprocess* hprocess_get ( int  pid  )  [read]

Get process by PID.

Worst case time of this function is O(n), where n is the number of processes.

Parameters:
pid Process ID.
Returns:
Pointer to the process on success. NULL on failure.

Definition at line 164 of file hprocess.c.

{
        if (pid < 0 || pid > get_pid_count_())
                return NULL;

        /*  This is probably a quite naive way of
         *  searching for the process with the given
         *  PID.
         *
         *  All processes in the scheduler are essentially linked
         *  together in one long list, making the search time
         *  O(n), where n are the number of processes.
         */

        int list_i = 0;
        struct hsqueue* queue = NULL;
        struct hprocess* process = NULL;
        // Walk through all lists.
        for (list_i = 0; list_i < HPS_NUMBER; list_i++) {
                queue = hsqlist_get_first_queue(list_i);
                // Walk through all queues.
                while (queue != NULL) {
                        process = hsqueue_get_first_process(queue);
                        // Walk through all processes and return the one with the given pid.
                        while (process != NULL) {
                                if (hprocess_get_pid(process) == pid)
                                        return process;
                                process = hprocess_get_next(process);        
                        }
                        queue = hsqueue_get_next(queue);
                }
        }

        return NULL;
}

char* hprocess_get_bitfilename ( struct hprocess process  ) 

Get bitfilename for the process.

Returns:
Name of file where the FPGA bitstream is.

Definition at line 245 of file hprocess.c.

{
        if (process == NULL)
                return NULL;

        return process->bitfilename;
}

struct hprocess* hprocess_get_next ( struct hprocess process  )  [read]

Get next process in the list of processes.

Parameters:
process Pointer to process that has the next field.
Returns:
Pointer to the next process. NULL on failure.

Definition at line 201 of file hprocess.c.

{
        if (process == NULL)
                return NULL;

        return process->next;
}

int hprocess_get_nice ( struct hprocess process  ) 

Get nice value for process.

Parameters:
process Pointer to process.
Returns:
The nice value for the process on success. Negative on failure.

Definition at line 267 of file hprocess.c.

{
        if (process == NULL)
                return -1;

        return process->nice;
}

struct hsqueue* hprocess_get_parent_queue ( struct hprocess process  )  [read]

Get pointer to the queue the process belongs to.

Parameters:
process Pointer to process.
Returns:
Pointer to the queue on success. NULL on failure.

Definition at line 219 of file hprocess.c.

{
        if (process == NULL)
                return NULL;

        return process->parent_queue;
}

int hprocess_get_pid ( struct hprocess process  ) 

Get PID for process.

Parameters:
process Pointer to process.
Returns:
The PID for the process on success. Negative on failure.

Definition at line 276 of file hprocess.c.

{
        if (process == NULL)
                return -1;

        return process->pid;
}

struct hprocess* hprocess_get_prev ( struct hprocess process  )  [read]

Get previous process in the list of processes.

Parameters:
process Pointer to process that has the previous field.
Returns:
Pointer to the previous process. NULL on failure.

Definition at line 210 of file hprocess.c.

{
        if (process == NULL)
                return NULL;

        return process->prev;
}

int hprocess_get_priority ( struct hprocess process  ) 

Get priority for process.

Returns:
The priority for the process on success. Negative on failure.

Definition at line 326 of file hprocess.c.

{
        if (process == NULL)
                return -1;

        return process->priority;
}

int hprocess_get_state ( struct hprocess process  ) 

Get state of process.

Parameters:
process Pointer to process.
Returns:
State (positive integer) for process. Negative on failure.

Definition at line 344 of file hprocess.c.

{
        if (process == NULL)
                return -1;

        return process->state;
}

int hprocess_is_valid_pid ( int  pid  ) 

Get state of process.

Parameters:
process Pointer to process.
Returns:
State (positive integer) for process. Negative on failure.

Definition at line 285 of file hprocess.c.

{
        if (pid < 0 || pid > (hprocess_max_processes() - 1))
                return 0;

        return 1;
}

const int hprocess_max_processes (  ) 

Get maximum processes in system.

Returns:
Maximum number of processes in the system.

Definition at line 152 of file hprocess.c.

{
        // Maximum number of processes (set to 50 for testing only).
        return 50;
}

int hprocess_remove ( struct hprocess process  ) 

Remove process.

Parameters:
process Pointer to process.
Returns:
0 on success. Negative on failure.

Definition at line 254 of file hprocess.c.

{
        if (process == NULL)
                return -1;
       
        // Remove the process from the queue (and update internal structure).
        int ret = hsqueue_remove_process(hprocess_get_parent_queue(process), process);
        free(process);

        return ret;
}

int hprocess_set_bitfilename ( struct hprocess process,
char *  filename 
)

Set bitfilename for the process.

Parameters:
filename Filename.
filename Name of file where the FPGA bitstream is.
Returns:
Maximum number of processes in the system.

Definition at line 228 of file hprocess.c.

{
        if (process == NULL)
                return -1;
        else if (strlen(filename) > hprocess_max_filename_size())
                return -1;
        
        // Just keep enough memory to store the new string and nothing more.
        if (process->bitfilename == NULL || strlen(process->bitfilename) < strlen(filename))
                process->bitfilename = realloc(process->bitfilename, strlen(filename) + 1);

        strcpy(process->bitfilename, filename);

        return 0;
}

int hprocess_set_nice ( struct hprocess process,
int  nice 
)

Set nice value for process.

This is a user defined value that affects the priority of the process.

Parameters:
process Affected process.
nice Nice value for process.
Returns:
The new nice value (larger than 0) on success. Negative on failure.

Definition at line 334 of file hprocess.c.

{
        if (process == NULL)
                return -1;

        process->nice = nice;
        return 0;
}

int hprocess_set_priority ( struct hprocess process,
int  priority 
)

Set priority for process.

Parameters:
pid Process ID for process.
priority Priority for process.
Returns:
The new priority (larger than 0) on success. Negative on failure.

Definition at line 311 of file hprocess.c.

{
        if (process == NULL)
                return -1;

        if (priority > 0)
                process->priority = priority;
        else {
                hlog_write(HLOG_ERROR, "hprocess_set_priority: Can't set negative priority.\n");
                return -1;
        }

        return priority;
}

 All Data Structures Files Functions Variables Enumerations Enumerator Defines