Upload
others
View
10
Download
0
Embed Size (px)
Citation preview
CS 1550Week 7 – Project 2 Discussion
Teaching Assistant
Henrique Potter
CS 1550 – Project 2 is out
• Due: Monday, October 22, 2018 @11:59pm
• Late: Wednesday, October 24, 2018 @11:59pm • 10% reduction per late day
Careful when submitting your Project
• Check twice if the file you sent is not corrupt
• Check twice if you are not sending an empty zip
Project 2 - Syscalls and IPC
Project 2 - Syscalls and IPC
Project 2 - Syscalls and IPC
Project 2 - Syscalls and IPC
Project 2 - Syscalls and IPC
• The first car can appear in either way.
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
• Each car takes 2 seconds to go trough.
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
• Each car takes 2 seconds to go trough.
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
• Each car takes 2 seconds to go trough.
• After the first car, another may follow it with 80% chance.
Another car follows with 80% chance
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
• Each car takes 2 seconds to go trough.
• After the first car, another may follow it with 80% chance.
• If not wait 20 seconds until another car shows up.
If not sleep for 20 seconds
Project 2 - Syscalls and IPC
• When the flagperson switch to the other queue?
Project 2 - Syscalls and IPC
• If there are no cars in the current queue the flag person switch.
• When the flagperson switch to the other queue?
Project 2 - Syscalls and IPC
• If there are no cars in the current queue the flag person switch.
• When the flagperson switch to the other queue?
Project 2 - Syscalls and IPC
• If 10 cars happens to line in the other queue. The flagperson will switch and allows cars from the other side to go trough.
• When the flagperson switch to the other queue?
Project 2 - Syscalls and IPC
We want to avoid a car crash.
Project 2 - Syscalls and IPC
We want to avoid a deadlock.
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 2
Car 3 Car 6
Car 4 Car 7
Car 5 Car 8
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 2
Car 3 Car 6
Car 4 Car 7
Car 5 Car 8
• A Producer will keep adding cars to the Left(Process)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 2
Car 3 Car 6
Car 4 Car 7
Car 5 Car 8
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 6
Car 3 Car 7
Car 4 Car 8
Car 5
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
The flag person (process) will consume carsfrom a queue until a switch conditionhappens. Then it consume cars from theother queue until there is no more cars.
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 7
Car 3 Car 8
Car 4
Car 5
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
The flag person (process) will consume carsfrom a queue until a switch conditionhappens. Then it consume cars from theother queue until there is no more cars.
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1
Car 3
Car 4
Car 5
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
The flag person (process) will consume carsfrom a queue until a switch conditionhappens. Then it consume cars from theother queue until there is no more cars.
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 3
Car 4
Car 5
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
The flag person (process) will consume carsfrom a queue until a switch conditionhappens. Then it consume cars from theother queue until there is no more cars.
Project 2 - Syscalls and IPC
struct cs1550_sem{
//Some queue of your devising};
Project 2 - Syscalls and IPC
struct cs1550_sem{
//Some queue of your devising};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
Project 2 - Syscalls and IPC
struct cs1550_sem{
//Some queue of your devising};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
Project 2 - Syscalls and IPC
Left Producerwhile (true){
}
• The producers will add cars to queues
Right Producerwhile (true){
}
Consumerwhile (true){
}
Project 2 - Syscalls and IPC
Left Producerwhile (true){
}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
else
}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
elsesleep(20)
}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue1_semaphore)else
sleep(20)}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue1_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue1_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
• The producers will add cars to queues
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue2_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue1_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
• The producers will add cars to queues
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue2_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
Project 2 - Syscalls and IPC
Consumerwhile (true){}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)check and pick a queue
}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)check and pick a queueconsume a car from a queue
}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)check and pick a queueconsume a car from a queueup(queue_semaphore)
}
• The producers will add cars to queues
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)check and pick a queueconsume a car from a queueup(queue_semaphore)
}
• The producers will add cars to queues • consumes from the same queue until switch condition happens
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
• Here the process can sleep.
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
• Here the process can sleep.• Mark the task as not ready
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
• Here the process can sleep.• Mark the task as not ready• set the current stat as “TASK_INTERRUPTIBLE”
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
• Here the process can sleep.• Mark the task as not ready• set the current stat as “TASK_INTERRUPTIBLE”• Invoke schedule() to get next task.
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
• wake_up_process(sleeping_task);
Struct that represents a process put to sleep by the down() method
Project 2 - Syscalls and IPC
• The semaphores need to be implemented as part of the kernel • We can use spin locks for that
spin_lock(&sem_lock);
spin_unlock(&sem_lock);
Project 2 - Syscalls and IPC
• The implementation is composed:• Syscalls for the semaphore• The trafficsim program
Project 2 - Syscalls and IPC
• Syscalls you will modify the files• Actual implementation
• linux-2.6.23.1/kernel/sys.c
• Syscall Number map• linux-2.6.23.1/arch/i386/kernel/syscall_table.S
• Exposes syscall number to C programs• linux-2.6.23.1/include/asm/unistd.h
Project 2 - Syscalls and IPC
• You should print in the format:
• The flagperson is now asleep.• The flagperson is now awake.
• Car %d coming from the %c direction, blew their horn at time %d• Car %d coming from the %c direction arrived in the queue at time %d• Car %d coming from the %c direction left the construction zone at time %d.
CS 1550Week 7 – Project 2 Discussion
Teaching Assistant
Henrique Potter