COP4610: Operating Systems & Concurrent Programming | up ↑ |
Spring 2015 |
See course calendar.
This assignment is intended as a warm-up for the assignments that will come later, but it also intended to introduce you to a number of concepts and skills. You will make a set of specified modifications to a simple discrete-event simulation program. This program was a partial solution to one of the COP 4610 assignments another term, and may (no promise) be used as the bare-bones basis for your last progamming project this term. The main changes you will make will be replace the ad hoc linked list structures by uses of the circular linked list structure used in the Linux kernel, based on struct list_head. The other change will be to correct an error in one of the functions that handles command-line arguments. The main effort should be reading and understanding the existing code, and then working through any misunderstandings. You will also be expected to verify that your code compiles and works the same on both Linux and Solaris systems.
baker@linprog3.cs.fsu.edu: make make[1]: Entering directory `/home/faculty/baker/courses/cop4610.S15/assign/P1/test/Linux' make[1]: Leaving directory `/home/faculty/baker/courses/cop4610.S15/assign/P1/test/Linux' make[1]: Entering directory `/home/faculty/baker/courses/cop4610.S15/assign/P1/test/SunOS' make[1]: Leaving directory `/home/faculty/baker/courses/cop4610.S15/assign/P1/test/SunOS' make[1]: Entering directory `/home/faculty/baker/courses/cop4610.S15/assign/P1/test/Linux' gcc -Wall -Wextra -pedantic -DDEBUG -c -o random.o random.c gcc -Wall -Wextra -pedantic -DDEBUG -o testrand testrand.c random.o -lm gcc -Wall -Wextra -pedantic -DDEBUG -o testargs testargs.c random.o -lm gcc -Wall -Wextra -pedantic -DDEBUG -c -o simulator_old.o simulator_old.c gcc -Wall -Wextra -pedantic -DDEBUG -c -o events_old.o events_old.c gcc -Wall -Wextra -pedantic -DDEBUG -o sim_old sim.c simulator_old.o events_old.o random.o -lm gcc -Wall -Wextra -pedantic -DDEBUG -c -o simulator.o simulator.c gcc -Wall -Wextra -pedantic -DDEBUG -c -o events.o events.c events.c: In function 'queue_dump': events.c:89: warning: ISO C forbids braced-groups within expressions events.c:89: warning: value computed is not used events.c:89: warning: ISO C forbids braced-groups within expressions events.c:89: warning: value computed is not used events.c: In function 'dispatch': events.c:103: warning: ISO C forbids braced-groups within expressions events.c:105: warning: ISO C forbids braced-groups within expressions gcc -Wall -Wextra -pedantic -DDEBUG -o sim sim.c simulator.o events.o random.o -lm make[1]: Leaving directory `/home/faculty/baker/courses/cop4610.S15/assign/P1/test/Linux'
There are three list structures that you can/need to modify:
You will need to change all the lists to doubly linked circular lists, to fit the model of "list.h". You should be able to use macros and functions from "list.h", directly, for most of the operations, resulting in a net reduction in the code of the files you are modifying. The one place you will need to "roll your own" algorithm is in the function simulator_schedule, where a node is inserted into a list that is used as a priority queue, ordered by increasing event time, and ordered with equal event times by event kind.
See how I already replaced one of the four original list structures, by comparing the files events.c against events_old.c. (I have also created a back-up copy of simulator.c, called simulator_old.c, but there are not yet any modifications.) Leave the "_old.c" files unchanged.
Some important aspects to keep in mind:
The following diagram may be helpful in understanding the list structure and the macro container_of(), also known as list_entry(). The diagram is incomplete in not showing how the list is circular. The blue arrow corresponding to New->list.next might be directly equal to &P->list, or point to another node in a chain that eventually gets back to P->list. Similarly, the orange arrow corresponding to P->list->prev should eventually lead back to New->list.
There is a little bit of explanation of Linux kernel lists on pages 99-101 of the text, but for more detailed explanation I'd recommend on the of the tutorials listed under References below.
Some typical C programming errors to look out for:
I appreciate that some of the vulnerabilities trace back to the parameters, but please don't change the header file! The submit script only copies random.c, simulator.c, and events.c, so if you rely on changes to any other files your submission will fail when we attempt to compile and test it.
gcc -E events.c >& events.x
You can then use a text editor to view the file events.x, and search for the context of the macro call that is causing the problem. (You will not see the macro name, unless the macro is undefined, since the macro call should have been replaced by the macro body.) If you have trouble finding the error in a long line of expanded macro text, there is a hack you can use to help locate it. Try pasting the expanded macro text in place of the macro call, with line breaks inserted, and then recompiling (without the "-E"). Once you have used the line number reported by the compiler for the error to identify the problem, you replace the pasted code by the original macro call.
One warning message comes from the macro "container_of", which declares a local temporary constant inside braces. The use of such braces in side a for-loop specification is a gcc language extension. The second message comes from the calls to the "prefetch" macro inside the "loop_for_each_entry" macro, which result in expressions whose value is discarded. That is normally not a good thing, so you get a warning.
I would normally require that your code compile with no warnings, since there is no practical way to achieve that using these Linux kernel macros I decided that for this one assignment it would be better to eliminate the "-ansi" and relax the "no warnings" rule. However, the two messages mentioned above, about braced-groups and unused values, are the only ones you should see.
First read the Study Guide section on Submitting Assignments, for general instructions.
Review the general Grading Criteria for Programming Assignments section of the Study Guide.
You can expect to have your score on this assignment reduced if your code does not adhere to the instructions above.
For a minumum passing score (70) you must replace at least one of the three existing list structures listed under step 4 above with the ones from list.h. Your score will be higher if you successfully replace more of the list structures with those from list.h and correct at least the one bug in command_check_args().
Criterion | Points |
One of the three list structures correctly replaced by application of struct_list_header, and program sim produces exactly the same output as original version, using unmodified versions of files Makefile, sim.c, events.h, random.h, and simulator.h, when tested with a variety of command line parameters. | 60 |
In addition, comments revised appropriately in all modified files, and coding style preserved. | 10 |
In addition, another of the three list structures replaced. | 10 |
In addition, the third of the list structures replaced. | 10 |
In addition, type 7 string comparison error in command_check_args() corrected | 10 |
T. P. Baker. ($Id) |