DOC PREVIEW
U of I CS 498 - Lecture 5

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 498 Lecture 5 /Proc File System and Timer UtilitiesThe Proc File SystemSlide 3proc_dir_entry StructureHandling of /proc Entries.Handling of /proc EntriesControl of Time FlowTaskletsTasklet ExampleKernel TimersTimer OperationsUse of Wait QueueSlide 13CS 498 Lecture 5/Proc File System and Timer UtilitiesJennifer HouDepartment of Computer Science University of Illinois at Urbana-ChampaignThe Proc File SystemReading: Linux Kernel Procfs Guidehttp://kernelnewbies.org/documents/kdoc/procfs-guide/lkprocfsguide.htmlThe Proc File SystemAll files in /proc are virtual files, and are generated to export the kernel information in the user space.The files and directories are based on proc_dir_entry.proc_dir_entry Structurestruct proc_dir_entry { unsigned short low_ino; /* Inode number; automatically filled by proc_register */ unsigned short namelen; /* length of the file or directory name */ const char *name; /* a pointer to the name of the file */ mode_t mode; /* the file’s mode */ nlink_t nlink; /* the number of links to this file (default = 1) */ uid_t uid; /* user ID of the file */ gid_t gid; /* group id of the file */ unsigned long size; /* length of the file as shown when the directory is displayed. */ struct inode_operations * proc_iops; struct file_operations * proc_fops; get_info_t *get_info(buffer, start, off, count); struct module *owner; struct proc_dir_entry *next, *parent, *subdir; /* pointers to link the proc directory structure. */ void *data; /* a pointer to private data */ read_proc_t *read_proc (buffer, start, off, count, eof, data); write_proc_t *write_proc(file, buffer,count,data); atomic_t count; /* use count */ int deleted; /* delete flag */ kdev_t rdev;};Handling of /proc Entries.create_proc_entry(name,mode,parent): creates a file with name in the proc directory; returns a pointer to the proc_dir_entry structure.The name is relative to /proc/test_entry = create_proc_entry(“test”, 0600, proc_net);test_entrynlink = 1;test_entrydata = (void *) &test_data;test_entryread_proc = test_read_proc;test_entrywrite_proc = test_write_proc;remove_proc_entry(name,parent) removes the proc file specified in name.Handling of /proc Entriesproc_mkdir(name,parent) creates directories in the proc directory; returns a pointer to the proc_dir_entry structure.create_proc_read_entry(name,mode,base,get_info) creates the proc file name and uses the function get_info() to initialize read accesses.test_entry=create_proc_read_entry(“test”, 0600, proc_net, test_get_info);Control of Time FlowLinux Device Drivers, 2nd EditionChapter 5, pages 141-146Chapter 6: Flow of Timehttp://www.xml.com/ldd/chapter/book/ch06.htmlTaskletsA more formal mechanism of scheduling software interrupts (and other tasks).The macro DECLARE_TASKLET(name, func,data)name: a name for the tasklet_struct data structurefunc: the tasklet’s handling routine.data: a pointer to private data to be passed to func().tasklet_schedule(&tasklet_struct) schedules a tasklet for execution.tasklet_disable() stops a tasklet from running, even if it has been scheduled for execution.tasklet_enable() reactivates a deactivated tasklet.Tasklet Example#include <linux/interrupt.h>/* Handling routine of new tasklet */void test_func(unsigned long);/* Data of new tasklet */char test_data[] = “Hello, I am a test tasklet”;DECLARE_TASKLET(test_tasklet, test_func, (unsigned long) &test_data);void test_func(unsigned long data){printk(KERN_DEBUG, “%s\n”, (char *) data);}….tasklet_schedule(&test_tasklet);Kernel Timersstruct timer_list { struct timer_list *next; /* never touch this */ struct timer_list *prev; /* never touch this */ unsigned long expires; /* the timeout, in jiffies */ unsigned long data; /* argument to the handler */ void (*function)(unsigned long); /* handler of the timeout */ volatile int running; /* added in 2.4; don't touch */ };Timer Operations(i) void init_timer(struct timer_list *timer): Initializes the timer structure.(ii) void add_timer(struct timer_list *timer): Inserts a timer into the global list of active timers.(iii) mod_timer(struct timer_list *timer, unsigned long expires): Changes the time at which a timer expires.(iv) int del_timer(struct timer_list *timer): Removes a timer from the list before it expires.(v) int del_timer_sync(struct timer_list *timer): Same as del_timer, and guarantees that when the function returns, the timer function is not running on any CPU.Use of Wait Queuewait_queue_head_t my_queue;init_waitqueue_head(&my_queue); or DECLARE_WAIT_QUEUE_HEAD(my_queue) Operations on the queue:sleep_on(wait_queue_head_t *queue): puts the process to sleep on this queue; not interruptible.interruptible_sleep_on(wait_queue_head_t *queue): Same as sleep_on, but the sleep can be interrupted.sleep_on_timeout(wait_queue_head_t *queue, long timeout): puts the process into sleep on this queue, but the sleep will not be longer than timeout.interruptible_sleep_on_timeout(wait_queue_head_t *queue, long timeout)Use of Wait QueueOperations on the queuewake_up(wait_queue_head_t *queue): wakes up all the processes that are waiting on this event queue.wake_up_interruptible(wait_queue_head_t *queue): wakes up on the processes that are in interruptible sleeps.wake_up_sync(wait_queue_head_t *queue)wake_up_interruptible_sync(wait_queue_head_t *queue): The synchronous variants make any awakened processes runnable, but do not reschedule the


View Full Document

U of I CS 498 - Lecture 5

Documents in this Course
LECTURE

LECTURE

39 pages

Assurance

Assurance

44 pages

LECTURE

LECTURE

36 pages

Pthreads

Pthreads

29 pages

Load more
Download Lecture 5
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 5 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 5 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?