[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 hprocess * | hprocess_get (int pid) |
Get process by PID. | |
struct hprocess * | hprocess_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 hprocess * | hprocess_get_next (struct hprocess *process) |
Get next process in the list of processes. | |
struct hprocess * | hprocess_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 hsqueue * | hprocess_get_parent_queue (struct hprocess *process) |
Get pointer to the queue the process belongs to. |
[Hardware OS Process Interface] Interface for a process on the FPGA.
Author (2011): Sindre Hansen
Definition in file hprocess.h.
enum hpstate |
Definition of states for a process in the HWOS.
Definition at line 21 of file hprocess.h.
const int hprocess_base_priority | ( | ) |
Get base priority.
Returns the priority given to processes when they are first accepted to the system.
Definition at line 146 of file hprocess.c.
{
return 49;
}
struct hprocess* hprocess_create | ( | int | nice | ) | [read] |
Create process.
nice | User defined value to define priority for process. |
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.
pid | Process ID. |
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.
Definition at line 245 of file hprocess.c.
{ if (process == NULL) return NULL; return process->bitfilename; }
Get next process in the list of processes.
process | Pointer to process that has the next field. |
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.
process | Pointer to process. |
Definition at line 267 of file hprocess.c.
{ if (process == NULL) return -1; return process->nice; }
Get pointer to the queue the process belongs to.
process | Pointer to process. |
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.
process | Pointer to process. |
Definition at line 276 of file hprocess.c.
{ if (process == NULL) return -1; return process->pid; }
Get previous process in the list of processes.
process | Pointer to process that has the previous field. |
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.
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.
process | Pointer to process. |
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.
process | Pointer to process. |
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.
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.
process | Pointer to process. |
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.
filename | Filename. | |
filename | Name of file where the FPGA bitstream is. |
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.
process | Affected process. | |
nice | Nice value for process. |
Definition at line 334 of file hprocess.c.
int hprocess_set_priority | ( | struct hprocess * | process, | |
int | priority | |||
) |
Set priority for process.
pid | Process ID for process. | |
priority | Priority for process. |
Definition at line 311 of file hprocess.c.