You are on page 1of 4

Lab 3- Concurrency

Katherine Bau
kb577
Kevin Gao
kg349

Lab Overview:
Our task for lab 3 was to implement a process concurrency system. Much of the emphasis for
this lab was on whether or not we understood how context switching worked and how it could be
implemented using the ARM architecture.

The Functions:
We started by implementing a linkedlist data structure, that was called process_state to be able to
implement the queue and the processes. We used a struct, because it had already been declared as
typedef in a 3140.concur.h. In our process_state we kept track of the stack pointer, the next
process_state, the original stack pointer and the original size.

To implement process_create, we were essentially implementing an initial stack of size n, that


would return -1 at fail and 0 at success. We used the malloc function and initialized the stack
using the given function process_stack_init(f,n). We then checked if the stack pointer of the
process was null, and if so we freed the process and return -1 because it failed. Otherwise, we
created the next pointer as null, and created the process_queue that is the global variable and
changed the pointers in effect.

Process_start was very simple to implement. The functionality of process_start involved enabling
the IRQ, enabling the clock to the PIT module, clearing the control register, and providing the
PIT bit with a low enough load value. This is done so that when the LED toggles during
execution, it will create the illusion that multiple processes are happening concurrently (at the
same time).

Process_select was an implementation to either returning null or the stack pointer to the next
ready process. We implemented this by implementing two helper functions, one helper function
that removed process_t from the queue and another helper function that added to the queue, in
terms of switching pointers. To implement process_select, we checked if the cursp was null, and
if the current process was not null, we freed from the stack. If cursp was not null, we changed the
current stack pointer of the current process to cursp and then added the current_process to the
end of the queue. Then we popped off the top process and if the current process was null, then
we would return null, otherwise we returned the current stack pointer.

Important Data Structures:


One of the primary data structures used for the lab was the process queue. The process queue is
essentially just a linked list, where each node is a process_t object that points to the next
process node, and the last node points to NULL to indicate that it is the last process on the queue.
Initially, the process queue is set to NULL, but once the program starts, it can add new processes
to the queue that have been created with process_create.

Our code has two helper functions that make using the process queue easier to manipulate.
Process_queue_rem removes the process that is at the head of the queue. It does this by checking
if the process_queue is NULL, which would mean if the process queue has no processes inside it,
in which case it would set current_process to NULL as well. If the queue isnt empty, then it
proceeds with storing the process_queue in the current_process variable, and setting the
process_queue pointer to the next process in the queue. As you might have seen in the code,
process_queue_rem is needed in process_select, which is required to update the current_process
and to free up no longer needed memory in the process stack.

Process_queue_add() adds a new process to the end of the process queue. It does this by first
checking if the process queue is empty. If it is, then the process_queue becomes the element that
is being added in, and the new process will now have its next field pointing to NULL, to
indicate that this node is at the end of the process queue. If the queue is not empty, then it will
store the current process address into a temporary process_t object, then it will begin traversing
through the entire queue, checking if the next process has a next field that points to NULL.
Once it satisfies this loop condition, the function knows that it has reached the end of the process
queue, and then adds the new element onto the end of the queue as before.

Current_process is the pointer object that points to the process that is currently running. The
current_process is NULL when a process finishes, and is set to NULL until process_start() is
called. Essentially, current_process will be NULL when no process is running, before the
scheduler starts, and after the scheduler ends.
(The process queue is a simpler visualization of how each process is stored in its own separate
stack, as shown in the heap. All the information about each process is stored to each different
stack, and the stack pointer information is kept inside the process_t object, which resembles the
PCB system)

Testing the implementations:

To test our code, we used the given test case file, as well as the two files that we wrote ourselves.
For the test case that was provided with the lab handout, the FRDM board operated as expected.
Because our load value was low enough, the FRDM board LED was able to create the
appearance of simultaneous processes, in this case, the red and the blue LED lights toggled
together at the same frequency. The LED finished with the green light turned on perpetually.
For test case 1, we wanted to see what would happen if we only called process_create once. We
kept one process that toggled the red LED, and the result was as expected: the red LED was
toggled multiple times, and then followed by the green LED being turned on perpetually.
For test case 2, we wanted to see what would happen if one of the processes ended immediately
without executing any instructions. We wrote one process and left the body of the process blank.
The results was just as expected: the green LED was left on perpetually.

Work Distribution: the work distribution was divided into two different groups. Katherine
worked on most of the mplementation of the function algorithms and data structures, while
Kevin worked on the data structures and testing/review.

You might also like