Professional Documents
Culture Documents
05 Kernel Structure
05 Kernel Structure
05 Kernel Structure
Infrastructure
David Ferry, Chris Gill, Brian Kocoloski, Marion Sudvarg
CSE 422S - Operating Systems Organization
Washington University in St. Louis
St. Louis, MO 63130
1
Kernel vs. Application Coding
Two major differences:
– The core kernel has no standard libraries
– The core kernel must be a monolithic, statically linked
library
No standard libraries:
– No libc (malloc, pthreads, string handling, etc.)
– Partly because of chicken/egg situation
– Also, standard libraries can be too slow
Features:
– Utilities: kmalloc, kthreads, string parsing, etc.
– Containers: hash tables, binary trees etc.
– Algorithms: sorting, compression
struct fox {
unsigned long tail_length;
unsigned long weight;
bool is_fantastic;
};
Disadvantage: need to “roll your own code” for each list you create
Duplicate code throughout the kernel
Introduce bugs
Lose optimizations (placement within cache lines, etc.)
struct list_head {
struct list_head *next;
struct list_head *prev;
};
struct fox{
unsigned long tail_length;
unsigned long weight;
bool is_fantastic;
struct list_head list_node;
};
static LIST_HEAD(fox_list_head);
list_node.prev list_node.next
/*
list_entry(
arg 1: Pointer to list_head structure,
arg 2: Type of outer “containing structure”,
arg 3: Struct member of list_head within containing
structure
)
*/
Adding:
Deleting:
list_del(&new_data->list);
kfree(new_data); //if dynamic
Also:
list_for_each_entry_reverse()
list_for_each_entry_safe() //for modifying list elements