class: title # CPU Scheduling ## CSC 213 – October 6, 2025 --- # Agenda for Today 1. Department Events 2. Upcoming Work 3. Filesystem Implementation *(from Friday)* 4. CPU Scheduling 5. Wrap Up --- # Department Events ## Rosenfield Program: Marisa Kabas .indent[ Wednesday, October 8th at 4pm in HSSC A1231 ] ## CS Extra: Finding Internships and Entry Level Jobs .indent[ Thursday, October 9th at 4:15pm in Noyce 3821 ] ## *No CS Table This Week* *To receive 0.25% extra credit, send an email to let me know you attended no more than 48 hours after the event.* --- class: section, blue # Upcoming Work --- # Lab: Malloc **Due:** Wednesday, October 8th by 11:59pm **Late Deadline:** Wednesday, October 15th by 11:59pm ## Questions **Why does my allocator make programs crash on startup?** Almost all programs make one very large allocation during startup. You'll need to handle requests for more than 2048 bytes before you can run test programs, even inside gdb. **What should we do to debug if the allocator makes programs crash during startup?** Your best bet is to add logging. It helps to know what sizes are being requested, what your allocator is doing, and the resulting pointer that you return. You can use `snprintf` and `log_message` to do this safely: ```c char buffer[256]; snprintf(buffer, 256, "xxmalloc(%d) called\n", size); log_message(buffer); ``` --- # Assignment: Listing Directories **Due:** Monday, October 6th by 11:59pm ## Questions **My program passes some tests, but fails the ones that test a different directory. What could cause that?** Make sure you try this locally as well. Run `./myls somedir` and compare the output to `ls -l`. You'll see results in a different order, but all the permissions, sizes, etc. should match. If they don't, you may have forgotten to check for errors returned by some of the functions you're using in this assignment. --- class: section, blue # Filesystem Implementation --- # A Simple Filesystem .left-col[ ## Disk Parameters 256 blocks, each 4KB 1 byte disk addresses ## inodes 56 bytes of metadata 8 direct block pointers ## Disk Layout 1 superblock 1 block for inode bitmap 1 block for data block bitmap 4 blocks for inode entries ] .right-col[ ## Questions 1. What is the total size of the disk? 2. How many inode entries or data blocks can be tracked with a single bitmap block? 3. What is the size of an inode entry? 4. How many inodes does this filesystem support? 5. How many data blocks does this filesystem have? 6. What is the largest supported file size? ] --- # A (Slightly) Better Simple Filesystem .left-col[ ## Disk Parameters 256 blocks, each 4KB 1 byte disk addresses ## inodes 56 bytes of metadata ***7 direct block pointers*** ***1 indirect block pointer*** ## Disk Layout 1 superblock 1 block for inode bitmap 1 block for data block bitmap 4 blocks for inode entries ] .right-col[ ## Questions This is almost the same as the filesytem from before, but now each inode entry contains an indirect block pointer. **What is the effect of this change?** Describe the effect, and calculate any new limits for the updated filesystem. ] --- class: section, blue # CPU Scheduling --- # Discussion: Scheduling Basics **Questions for think, pair, share:** 1. Why does the OS have a scheduler, and what does it do? 2. What do each of these terms mean in the context of CPU scheduling? - Batch Scheduling - Preemption - Quantum - Context Switch *Start by thinking of answers on your own. I will let you know when to start discussion.* --- # Discussion: Basic Scheduling Algorithms The textbook introduced four simple scheduling algorithms. Answer the following questions about these algorithms: 1. What are the four scheduling algorithms? 2. For each algorithm, how does it choose the next task to run? 3. Which of these scheduling algorithms are preemptive? *Start by thinking of answers on your own. I will let you know when to start discussion.* --- # Discussion: Evaluating Schedulers **Questions for think, pair, share:** 1. How can we measure a scheduler's performance? Think of at least two ways. 2. For each measurement you identified in question 1, what is the impact when the scheduler does well? What if it does poorly? Try to think of specific examples. *Start by thinking of answers on your own. I will let you know when to start discussion.* --- # Scheduling a Sample Workload What will FIFO, SJF, STCF, and RR (with a 2ms quantum) do with this workload? - Job A arives at time 0ms and runs for 4ms - Job B arrives at time 1ms and runs for 2ms - Job C arrives at time 3ms and runs for 1ms Calculate response time and turnaround time for each schedule. *You may work on your own or collaborate with neighbors to answer these questions.* --- class: section, blue # Wrap Up --- # Reminders ## Lab The malloc lab is due on Wednesday. ## Assignment The listing directories assignment is due tonight. ## Need Help? My office hours are full today, but I have lots of open time tomorrow. You can also attend Tuesday's mentor session from 5–6pm. ## Reading - **Review lab before class**