DOC PREVIEW
U of I CS 498 - Proc File System and Timer Utilities

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 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_tmode; /* the file’s mode */nlink_tnlink; /* the number of links to this file (default = 1) */uid_tuid; /* user ID of the file */gid_tgid; /* 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_tcount; /* use count */ int deleted; /* delete flag */ kdev_trdev;};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_entrystructure.z 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).z The macro DECLARE_TASKLET(name, func,data)z name: a name for the tasklet_struct data structurez func: the tasklet’s handling routine.z data: a pointer to private data to be passed to func().z tasklet_schedule(&tasklet_struct) schedules a tasklet for execution.z tasklet_disable() stops a tasklet from running, even if it has been scheduled for execution.z 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:z sleep_on(wait_queue_head_t *queue): puts the process to sleep on this queue; not interruptible.z interruptible_sleep_on(wait_queue_head_t *queue): Same as sleep_on, but the sleep can be interrupted.z 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.z interruptible_sleep_on_timeout(wait_queue_head_t *queue, long timeout)Use of Wait QueueOperations on the queuez wake_up(wait_queue_head_t *queue): wakes up all the processes that are waiting on this event queue.z wake_up_interruptible(wait_queue_head_t *queue): wakes up on the processes that are in interruptible sleeps.z wake_up_sync(wait_queue_head_t *queue)z 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 - Proc File System and Timer Utilities

Documents in this Course
Lecture 5

Lecture 5

13 pages

LECTURE

LECTURE

39 pages

Assurance

Assurance

44 pages

LECTURE

LECTURE

36 pages

Pthreads

Pthreads

29 pages

Load more
Download Proc File System and Timer Utilities
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 Proc File System and Timer Utilities 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 Proc File System and Timer Utilities 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?