Programming problems are to be done in your assigned groups using the VM that has been assigned to your group. For all programming problems you will be required to submit source code, a README file documenting your files and code, and a test run of your programs. For source code submissions, you only need to submit new source code files that you created and kernel source code files that you changed. You should clearly indicate your names, email addresses, and assigned group number on your submission. Each group is required to submit one writeup for the programming assignment using the SUBMIT program. Refer to the homework submission page on the class web site for additional submission instructions.
For this assignment you will add to the Linux kernel a new synchronization mechanism, a reader-writer lock that supports priority inheritance. You will learn about wait queues and some of the synchronization primitives that the kernel provides. Finally you will construct a test program "proving" that your method works.
rwlock
, that
provides a reader-writer lock. It should consist of the following
prototype:
action
parameter:
EVENT_CREATE: A new event is created. This event is a reader-writer lock that guarantees mutual exclusion for certain critical sections. If the parameter key
is a number between 1 and 126 a new event is created
with this value as its id number. If key
is zero, then
the kernel allocates the first unused id that it finds. If the
inputed key
value is a number above 126 or below 0, the
system call returns an error code of -EINVAL
. If there
are no free slots -EAGAIN
is returned. If the value of
key
matches a preexisting event, the system call returns
-EBUSY
. Otherwise the value of the new id is
returned, signifying the key
to be used in the future
EVENT_DESTROY: An event is destroyed. If the parameter
key
matches a previously created event with no processes
waiting on it, this event is de-allocated and a zero is returned to
indicate success. If there are processes waiting on this event,
-EBUSY
is returned. If this event does not exist, your
system call should return -EINVAL
.
READ_WAIT: A process wants shared access to a critical section
protected by key
. If nobody is using this resource - or
the resource is only read-locked - then the system call returns zero
to indicate success and the process is free to proceed. If the event
is write-locked, the process is then put to sleep and made to wait for
the event to be unlocked. Keep in mind that once the event is
unlocked, you must make sure that correct lock operation is ensured
among waiting processes and new processes that arrive. Also, if a waiting process is awakened (through a signal or an interrupt) and it is unsafe to proceed into the critical section, then you must put the process back to sleep. Otherwise, the
system call returns zero and your process may proceed. As usual, if
key
refers to a non-existant event, you must return
-EINVAL
.
READ_SIGNAL: Once a process is done reading data from its
critical section it should call rwlock
with this value.
If key
does not exist -EINVAL
is returned.
If key
refers to an event to which our process does not
have shared access, -EPERM
is returned. Otherwise a zero
is returned to indicate success, and the event is one step closer to
not being read-locked (you will probably want to keep track of the number of readers). If the process making this system call unlocks the event, the appropriate processes are awakened. Ideally, you will test the type of lock requested by the first process in the waitqueue. If it is a readlock (this case should not typically occur, as readers do not block on readlocks), then you are to wake up every process requesting a readlock and allow them to
proceed. Otherwise, if the process requests a writelock, you are to wake up only that one process.
WRITE_WAIT: This value indicates that a process wants to have exclusive access to a critical section. If the event is protected by either a read-lock or a write-lock, this requesting process is put to sleep. As with READ_WAIT
, if the sleeping process is awakened, it must ensure that is is safe to proceed. If it is not safe, it goes back to sleep on the waitqueue. Otherwise a zero is returned to indicate sucess. As usual, if key
refers to an event that does not exist, -EINVAL
is
returned.
WRITE_SIGNAL: This value indicates that a process is done
needing exclusive access to its critical section. As with READ_SIGNAL
the appropriate waiting processes are awakened and a zero is returned to indicate success. If the first process waiting requests a readlock, then you should wake up every process on the waitqueue requesting a readlock. Otherwise, the first process waiting is requesting a writelock, and you should only wake up that one process.
If the value of key
refers to a non-existent event then
-EINVAL
is returned. If key
refers to an
event to which our process does not have exclusive access,
-EPERM
is returned.
LOCK_STATUS: This action indicates that you are to return one of 4 values indicating the lock's status: CREATED, UNCREATED, READ_LOCKED and WRITE_LOCKED. If the key
value is out of range, you are to return -EINVAL here as well.
Note: For all other action
values your system call
should return -EINVAL
.
All file access should be syncronized through use of your system call as in the following example (of course you will be responsible for error handling as well):
task_struct
extra fields to save the policy, priority and rt_priority of any
boosted process. In addition these values must be restored once the
process is no longer waiting on the event.
Once again, every access to this file should be synchronized by your system call.
sleep_on
and __wake_up
functions (defined in kernel/sched.c
).
__wake_up
function wakes up every single process on the wait_queue. You will want to have a separate version that has been tweaked to only wake processes up in accordance with the rwlock
system call's requirements. Therefore, you don't have to worry about waking up seven writers only to put six back to sleep.
wake_up
function. Afterwards, replace it with your special version.