Kyu Ho Park Sept. 22, 2015 1 Lecture 4 proc file system(procfs) (Project 2 included) Sept.19,4pm.

Slides:



Advertisements
Similar presentations
Parallel Virtual Machine Rama Vykunta. Introduction n PVM provides a unified frame work for developing parallel programs with the existing infrastructure.
Advertisements

A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
DEVICE DRIVER VINOD KAMATH CS691X PROJECT WORK. Introduction How to write/install device drivers Systems, Kernel Programming Character, Block and Network.
Linux device-driver issues
Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /
Computer System Laboratory
CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Memory management.
Module 8 - Process Management. 1.Linux boot loader 2.Linux boot process 3.Linux processes 4.Linux services 5.Linux top 6.Remember proc ? 7.Linux Device.
1 Case Study 1: UNIX and LINUX Chapter History of unix 10.2 Overview of unix 10.3 Processes in unix 10.4 Memory management in unix 10.5 Input/output.
How to make a pseudo-file As a follow-up to our first lab, we examine the steps needed to create our own ‘/proc’ file.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Project 3: File System Design COS318 Fall Last Time Web Server Extensive use of a file system on server machine without actually worrying about.
Linux Operating System
Tutorial and Demos on Linux Virtual Machine
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
1 Week 6 Intro to Kernel Modules, Project 2 Sarah Diesburg Florida State University.
Operating System Program 5 I/O System DMA Device Driver.
Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux.
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
Project 2. “Linux Fundamental” procfs By Dong Jae Shin.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CSE 451: Operating Systems
Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
---- IT Acumens. COM IT Acumens. COMIT Acumens. COM.
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
UNIX Files File organization and a few primitives.
Guide To UNIX Using Linux Third Edition Chapter 8: Exploring the UNIX/Linux Utilities.
Using the /proc File System with “scull” Sarah Diesburg COP 5641.
Chapter Two Exploring the UNIX File System and File Security.
CSE1301 Computer Programming: Lecture 14 I/O and Files.
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Project 6 Unix File System. Administrative No Design Review – A design document instead 2-3 pages max No collaboration with peers – Piazza is for clarifications.
Lab 3 + Using the Terminal 1. "Under Linux there are GUIs (graphical user interfaces). where you can point and click and drag, and hopefully get work.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
Project 4. “File System Implementation”
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Linux Kernel Programming (LKP). LKP New sub-course New sub-course We will learn together We will learn together Evaluation of this part of course will.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
1 CSC103: Introduction to Computer and Programming Lecture No 27.
Project 3. “System Call and Synchronization” By Dongjin Kim
Security Architecture and Design Chapter 4 Part 2 Pages 319 to 357.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
Chapter Eight Exploring the UNIX Utilities. 2 Lesson A Using the UNIX Utilities.
CSC414 “Introduction to UNIX/ Linux” Lecture 3
ECE 456 Computer Architecture Lecture #9 – Input/Output Instructor: Dr. Honggang Wang Fall 2013.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
File table: a list of opened files Each entry contains: – Index: file descriptors – Pointer to the file in memory – Access mode File descriptor is a positive.
Guide to Parallel Operating Systems with Windows 7 and Linux Chapter 10 Operating System Management.
به نام خدای مهربان زبان تخصصی دانشجویان کامپیوتر English for Computer Students درس 3 جوانمرد Ejavanmard.blogfa.com
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
Project 4. “File System Implementation”
EE516: Embedded Software Project 1
Lecture 5 proc file system(procfs) (Project 2 included)
Introduction to Operating Systems
Case Study 1: UNIX and LINUX
Avani R.Vasant V.V.P. Engineering College
Computer System Laboratory
Project 3. “System Call and Synchronization”
Linux Kernel Driver.
Introduction to Operating Systems
Intro to Kernel Modules and /proc
Implementation of Embedded OS
Computer System Laboratory
Chapter 12: File-System Implementation CSS503 Systems Programming
Presentation transcript:

Kyu Ho Park Sept. 22, Lecture 4 proc file system(procfs) (Project 2 included) Sept.19,4pm

Computer Engineering Research Laboratory Why do we need the procfs?  To access the various information of the Linux kernel easily, procfs has been provided(firstly by Tom J. Killan, 1984 for UNIX on VAX machine).  Why we do not use the conventional file system using open, close, read, write system calls ?  It is always available and is accessible to all users, of course,with appropriate permissions only. 2

Computer Engineering Research Laboratory ls /proc 3

Computer Engineering Research Laboratory /proc/cd 1 4

Computer Engineering Research Laboratory cat cpuinfo 5

Computer Engineering Research Laboratory meminfo 6

Computer Engineering Research Laboratory Size of file at /proc directory 7

Computer Engineering Research Laboratory Cat /proc/cpuinfo  The contents of files under /proc directory are created dynamically when you give commands such as ‘cat /proc/meminfo’. 8

Computer Engineering Research Laboratory proc file system(procfs) functions  proc_mkdir( ); //make a directory under /proc.  create_proc_entry( ); //make a file under /proc.  create_proc_read_entry( ); //make a readonly file.  remove_proc_entry( ); //remove dirs or files. --procfs uses [struct proc_dir_entry] defined as follows; struct proc_dir_entry{..... struct inode_operations *proc_iops; struct file_operations *proc_fops;.. struct proc_dir_entry *next, *parent, *subdir; void *data; read_proc_t *read_proc; write_proc_t *write_proc; atomic_t count; int deleted;//in case of delete, this flag should be 0, if in use this flag is 1. }; 9 //mostly used

Computer Engineering Research Laboratory Making a directory under /proc  struct proc_dir_entry *proc_mkdir(const char *name, struct proc_dir_entry *parent); // name: the directory name to create, //parent: the parent of the directory to create. parent struct proc_dir_entry *son; struct proc_dir_entry *grand_son; son=proc_mkdir(“son”,NULL); grand_son=proc_mkdir(“grand_son”, son); 10 son grand_son Ex:

Computer Engineering Research Laboratory File creation under /proc  struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode, struct proc_dir_entry *parent); //name: the RW file name to create. mode:file permission.  To create read_only file, struct proc_dir_entry *create_proc_read_entry(const char *name,mode_t mode,struct proc_dir_entry *parent); Ex:[create a ‘test’ file at /proc/test] struct proc_dir_entry *test_proc; test_proc=create_proc_entry(“test”, 0, NULL); // if mode is set to 0, the default permission is

Computer Engineering Research Laboratory Delete proc_files and directories  void remove_proc_entry(const char *name, struct proc_dir_entry *parent); 12 remove_proc_entry(“test”,NULL); remove_proc_entry(“grand_son”, son); remove_proc_entry(“son”,NULL); test

Computer Engineering Research Laboratory read  static int my_read(char *page, char **start, off_t off, int count, int *eof, void *data) { ……//program codes *eof =1 ; when this function is called only one time. return len; //len: length of data read. } -The memory space used in procfs is a page whose size is typically 4KBytes. The location to save the data. -eof : end-of-file, if eof =1, no read anymore. -start: it is used rarely. -off: current location of the file. -data: not used in read. 13

Computer Engineering Research Laboratory write  static int my_write(struct file *file, const char *buffer, unsigned long count, void *data) {char *proc_data; proc_data=(char *)data; copy_from_user(kernel_data, buffer, count); … return count; } -buffer: user space data, -count: written data size, -*data: kernel address to store the data of buffer. 14

Computer Engineering Research Laboratory for_each_process( ) at #include int read_process(char *buf, char **start, off_t offset,int count,int *eof,void *data ) { int len=0; struct task_struct *task_list; for_each_process(task_list) { len += sprintf(buf+len, "\n %s %d\n", task_list->comm,task_list->pid); } return len; } 15 void create_new_proc_entry() { create_proc_read_entry("proc_list",0,NULL,read_process,NULL); } int ps_init (void) { int ret; create_new_proc_entry(); return 0; } void ps_exit(void) { remove_proc_entry("proc_list",NULL); } module_init(ps_init); module_exit(ps_exit); MODULE_LICENSE("GPL");

Computer Engineering Research Laboratory cat /proc/proc_list 16

Computer Engineering Research Laboratory proc_create( ) using seq_file 17

Computer Engineering Research Laboratory proc_create() or create_proc_entry() #include If (LINUX_VERSION_CODE )< VERSION(3,11,0)&&defined(CONFIG_PROC_FS) create_proc_entry(); else proc_create( ); 18

Project 2. “Linux Fundamental” procfs By Dong Jae Shin

Computer Engineering Research Laboratory Introduction to Projects  Project 1: Setting up Environment for Project  Project 2: Linux Fundamental(procfs)  Project 3: System Call and Synchronization  Project 4: File System  Project 5: Device Driver for Embedded H/W  Especially, including “BeagleBoard Development” 20

Computer Engineering Research Laboratory Contents  Follow-on Tasks  1. Linux System Administration  2. File System & Software Management  3. Build your own Linux Kernel  Project Tasks  Write a System Monitoring Tools  1. Analyse the given skeleton program (10%)  2. Traverse Process tasklist (20%)  3. per Process Memory Usage (20%)  4. per Process I/O Usage (20%)  5. Process CPU Utilization (20% point Bonus)  Report (30%) Max. 100%

Computer Engineering Research Laboratory (1)Kernel Debugging  Print Kernel-level Message  printk  Kernel version of printf  usage) printk(“%s %d %lu”, str, i, j );  Kernel Log Message  tail -f /var/log/kern.log  See also (optional)  for advanced debugging  procfs

Computer Engineering Research Laboratory (2)/proc File System  /proc  a special file system which displays the present of the system  pseudo and virtual file system which resides in the RAM  provides a method of communication between kernel space and user space  Various information provided by proc  proc.txt proc.txt 23 procfs

Computer Engineering Research Laboratory (3)/proc File System  CPU Information  cat /proc/cpuinfo 24  Main Memory Information  cat /proc/meminfo Kernel Debugging

Computer Engineering Research Laboratory (4)Create a proc entry  Download Skeleton Files  # wget  # wget ple.c ple.c  Compile  # make  Useful ref)  procfs

Computer Engineering Research Laboratory (5)Test proc entry  Kernel Log  # tail -f /var/log/kern.log  Insert Module  insmod proc_sample.ko  Write Proc File  # echo blahblah > /proc/proc_sample  Read Proc File  # cat /proc/proc_sample  Remove Module  # rmmod proc_sample 26 procfs

Computer Engineering Research Laboratory Project Tasks  Make a System Monitoring Tools  System monitoring is an important job especially on the embedded system  Low computing power, Less memory, Limited resources  Monitoring tools  top, ps, netstat, gnome-system-monitor  Tasks  1.Analyze the given skeleton procfs program. (10%)  2. Traverse Process tasklist (30%)  3. per Process Memory Usage (30%)  4. per Process I/O Usage (30%)  5. Process CPU Utilization (10% point Bonus Task) 27 Project Tasks

Computer Engineering Research Laboratory Task 1  Analyze the given skeleton of promon.c.  Find the functions that you do not know and explain the operations of those functions referring to references and Google. 28

Computer Engineering Research Laboratory Task2. Traverse Task List  Every Linux Tasks are managed by doubly linked list 29  Print every task’s PID and Process Name in your proc file system  Textbook Chapter 3. Understanding the Linux Kernel, 3 rd Project Tasks

Computer Engineering Research Laboratory task_struct  task_struct (=Process Descriptor) 30  KERNEL/include/linux/sch ed.h  Useful materials : Textbook Chapter 3. of ULK  free e-book version : Courses/c4022/code/mem ory/understanding.pdf Courses/c4022/code/mem ory/understanding.pdf Project Tasks

Computer Engineering Research Laboratory task_struct 31 ………

Computer Engineering Research Laboratory Task3. Memory Usage  Memory Mapping  RSS : Resident Set Size  VIRT : Virtual Memory Size  Print every task’s VIRT and RSS Memory Size 32 VIRT RSS VIRT Project Tasks

Computer Engineering Research Laboratory Task4. Process I/O Stat  I/O Stat is stored in struct task_io_accounting  include/linux/task_io_accounting.h  Hint)  # cat /proc/PID/io  rchar : read bytes by process  wchar : written bytes by process  syscr : # of read system calls  syscw : # of write system calls  read_bytes : read bytes from disk  write_bytes : written bytes to disk 33 write_bytesread_bytes Disk Cache in DRAM Process wcharrchar Project Tasks

Computer Engineering Research Laboratory Task5. CPU Utilization  “top” command  shows the CPU utilization per process 34  Challenging Task (Bonus Point 10%)  Kernel manages CPU ticks consumed by each process in struct task_cputime 5. Project Tasks

Computer Engineering Research Laboratory Example of Output Project Tasks

Computer Engineering Research Laboratory Check your results  Check the correctness of your results  Task 2.  # ps -ef  Task 3.  # top -b -n 1  Task 4.  Browser is a good test case (# firefox)  Get pid  ps -ef |grep firefox  # cat /proc/PID/io  Task 5.  # top Project Tasks

Computer Engineering Research Laboratory Submission  Contents  Source Code  Report Project Tasks1~5  Key point of your Source Code  Final Screenshots  Page Limit : about 5 pages for Project Tasks1~5. (except figures)  Submission  Due Date : Oct. 8, PM 23:59  Delay Penalty  10%/day (AM 00:00)   [EE516 Project2] student_number.zip  (various compression format is allowed)