Kernel data structures. outline linked list queues maps binary trees algorithmic complexity.

Slides:



Advertisements
Similar presentations
Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Advertisements

Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Linked Lists in C and C++ CS-2303, C-Term Linked Lists in C and C++ CS-2303 System Programming Concepts (Slides include materials from The C Programming.
Processes CSCI 444/544 Operating Systems Fall 2008.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Data Structures in the Kernel Sarah Diesburg COP 5641.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
Data Types in the Kernel Ted Baker  Andy Wang CIS 4930 / COP 5641.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
1 CSE 1342 Programming Concepts Lists. 2 Basic Terminology A list is a finite sequence of zero or more elements. –For example, (1,3,5,7) is a list of.
Data structures Abstract data types Java classes for Data structures and ADTs.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 10 & 11: File-System Interface and Implementation.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Data Structure & Algorithms
LINKED LISTS.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
CSE 1342 Programming Concepts
Review Array Array Elements Accessing array elements
Cpt S 122 – Data Structures Abstract Data Types
Data Structures Using C, 2e
CS505 Data Structures and Algorithms
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Understanding Algorithms and Data Structures
Chapter 6 Queue.
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Queue ADT (Abstract Data Type) N …
Chapter 12 – Data Structures
COSC160: Data Structures: Lists and Queues
Week 4 - Friday CS221.
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Introduction to Linked Lists
Lectures linked lists Chapter 6 of textbook
UNIT – I Linked Lists.
Chapter 15 Lists Objectives
UNIT-3 LINKED LIST.
Standard Template Library (STL)
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Queues Queues Queues.
Stack and Queue APURBO DATTA.
Queues Chapter 4.
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Introduction to Linked Lists
Stacks, Queues, and Deques
Chapter 18: Linked Lists.
CSC 143 Queues [Chapter 7].
Programming Abstractions
Queues A first-in, first-out or FIFO data structure.
Linked Lists in C and C++
Queues Jyh-Shing Roger Jang (張智星)
Containers: Queue and List
File Organization.
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Dynamic allocation (continued)
CSCS-200 Data Structure and Algorithms
Queues and Priority Queue Implementations
Presentation transcript:

kernel data structures

outline linked list queues maps binary trees algorithmic complexity

singly linked lists

doubly lined lists

circular linked lists

the Linux kernel’s implementation The linked-list code is declared in the header file and the data structure is simple

usage

container_of() Using the macro container_of(), we can easily find the parent structure containing any given member variable. #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );})

container_of() #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) list_head 0x00 0xYZ offset = 0xYZ

container_of() #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) list_head member offset = 0xYZ container

// Keil 8051 compiler #define offsetof(s,m) (size_t)&(((s *)0)->m) // Microsoft x86 compiler (version 7) #define offsetof(s,m) (size_t)(unsigned long)&(((s *)0)->m) // Diab Coldfire compiler #define offsetof(s,memb) ((size_t)((char *)&((s *)0)->memb-(char *)0) offsetof

1.((s *)0) takes the integer zero and casts it as a pointer to s. 2.((s *)0)->m dereferences that pointer to point to structure member m. 3.&(((s *)0)->m) computes the address of m. 4.(size_t)&(((s *)0)->m) casts the result to an appropriate data type. offsetof in Keil’s C reference:

functions list_addlist_add — add a new entry list_dellist_del — deletes entry from list list_movelist_move — delete from one list and add as another's head list_emptylist_empty — tests whether a list is empty list_entrylist_entry — get the struct for this entry list_for_eachlist_for_each — iterate over a list list_for_each_entrylist_for_each_entry — iterate over list of given type

#define list_entry(ptr, type, member) \ container_of(ptr, type, member) list_entry

QUEUES

kfifo Linux’s kfifo works like most other queue abstractions, providing two primary operations: – enqueue (unfortunately named in ) and – dequeue (out ). The kfifo object maintains two offsets into the queue: an in offset and an out offset. The enqueue (in) operation copies data into the queue, starting at the in offset.

functions kfifo_reset — removes the entire FIFO contents kfifo_reset kfifo_put — puts some data into the FIFO kfifo_put kfifo_get — gets some data from the FIFO kfifo_get kfifo_len — returns the number of bytes available in the FIFO kfifo_len kfifo_init — allocates a new FIFO using a preallocated buffer kfifo_init kfifo_alloc — allocates a new FIFO and its internal buffer kfifo_alloc kfifo_free — frees the FIFO kfifo_free

MAPS

definition A map, also known as an associative array, is a collection of unique keys, where each key is associated with a specific value. The relationship between a key and its value is called a mapping. Maps support at least three operations:

definition: operator Add (key, value) Remove (key) value = Lookup (key)

implementation The Linux kernel provides a simple and efficient map data structure, but it is not a general-purpose map It is designed for one specific use case: mapping a unique identification number (UID) to a pointer.