user3543832
user3543832

Reputation: 21

Simple I/O Round Robin Scheduler

I am trying to make a very specialized round robin I/O scheduler. I though I could take the well know cfq scheduler and refit it to my needs. Turns out I don’t know much C code to desifer what all those 4000 lines of code in the linux cfq mean. I get the normal function calls and structs like any other programming language but there are things I don’t understand.

Is there a simpler version of cfq or any other round robin scheduler out there that I can use for learning purposes? (all I found was the same cfq code)

Upvotes: 1

Views: 396

Answers (1)

Lelanthran
Lelanthran

Reputation: 1529

You can implement a round-robin scheduler by storing the elements in an array and using the array as a circular array. For example to round-robin 20 file descriptors and assuming non-blocking IO:

int index = 0;
int file_descriptors[20];
// Open all the descriptors here

while (!end_condition) {
   int working_fd = file_descriptors[index++ % 20];
   // Work with the file descriptor here
}

Of course, it's better to replace the magic number with a constant or (in the case of malloc'ed arrays) the variable that was used to malloc.

Upvotes: 1

Related Questions