Arizona State University SER334: Operating Systems & Networks TA Jain, Lecturer Acuña Revised 10/22/2019 Implementing a Loadable Kernel Module Summary: In this homework, you will be implement a...

1 answer below »
Looking write up and source code


Arizona State University SER334: Operating Systems & Networks TA Jain, Lecturer Acuña Revised 10/22/2019 Implementing a Loadable Kernel Module Summary: In this homework, you will be implement a loadable kernel module that uses Linux data structures to display details about the processes executing in the kernel. 1 Background The kernel is a program that is the core of a computer's operating system, with complete control over everything in the system. It is the �rst program loaded on start-up. It performs tasks such as running processes, handling interrupts and all other handling that happens behind the scenes in kernel space whereas everything user does is executed in user-space. This separation prevents user data and kernel data from interfering with each other and causing instability and slowness. Kernel modules are pieces of code which provide functionality to the kernel. The word �Loadable� is pre�xed to kernel module to show that it eases the process of integrating the module with the kernel. Generally, if any functionality is to be provided in the kernel, it has to incorporated by compiling the kernel with the proposed changes. Loadable Kernel Modules (LKM) ease that process by providing the facility to integrate itself within the kernel instead of requiring kernel re-compilation. For information on creating LKMs, see your textbook (Operating System Concepts 9th edition) page 96. You will need to use a so-called "make�le" to manage the compilation of your module. It will not be possible to use NetBeans to develop your code. The best way to start is with the sample LKM provided on the textbook's website. In this assignment you will write a LKM for the Linux kernel that displays the certain details of the processes (along with its parent and child) executing in the kernel. As an important step to implementing the program, you should review the section on include �les to get an idea of what functionality is available. From there, you may choose to outline your program in pseudocode, and then convert it into actual source code, while reading the documentation for any functions you used. Expect that a signi�cant part of your time on this assignment will be spent reading/researching/understanding LKM documentation and reviewing kernel source code �les (linux/sched.h, and linux/list.h). The source code should be relatively short. For kernel source code, visit www.kernel.org/. Any lines numbers mentioned in this document refer to Linux 4.9.6; please reference that version as well. This document is separated into �ve sections: Background, Requirements, Make�les, Include Files, and Submission. You have almost �nished reading the Background section already. In Requirements, we will discuss what is expected of you in this homework. In Include Files, we discuss several header �les that include functionality related to �le and directory manipulation. Lastly, Submission discusses how your source code should be submitted on BlackBoard. 2 Requirements [36 points total] In this assignment you will write a LKM for the Linux kernel that displays the following details for all the processes whose PID is greater than an integer given by the user as a module parameter: [26 points] • PROCESS NAME • PID • STATE • PRIORITY • STATIC-PRIORITY 1 http://os-book.com/ http://www.kernel.org/ • NORMAL-PRIORITY As shown below, the PID is given as arguments while inserting the module in the kernel. The next screenshot shows the required details for a process, its child processes (may have 0 or more), and its parent process. You are expected to keep a similar format (not an exact one) for your output which is readable. Your programs must compile and run under Xubuntu (or another variant of Ubuntu) 18.04. 2.1 Writeup [10 points] You are to provide a short write up that illustrates what you found when looking at the Linux source �les and documentation. Include the following: • For your main source �le, list each function that you de�ned and describe its purpose. • For each header �le (except linux/module.h), document each function/macro/struct used: � Functions: Include the function's signature, what �le/line it is de�ned, and a description (include parameters and return values). Example: printf De�ned on line 133 in stdio.h. Signature: int printf(const char *format, ...); Parameters: The �rst parameter (format) takes a string, followed by any number of other parameters (see below). Description: This string will be displayed as standard console output. The string may contain special formatting called control characters. For example, including �%c� indicates a position in the string where a character should appear. The variable containing the string should be passed as the second parameter. The function may take any number of parameters, where the �rst is always the main string, and everything else is a value that may be subsituted into it. After completion, the function returns the number of displayed (an int). 2 � Macro: same as function. � Struct: Indicate what �le/line it is de�ned, and document each of the attributes used. The purpose of the write up is show the �research� you did when creating your program. Do not quote (or paraphrase) any 3rd party documentation - use your own words and understanding. Although there is no mandatory format, please be professional. Your document should be self-contained, well styled (e.g., no comic sans, random font sizes), and readable (e.g., no spelling or grammar errors). 3 Make�les A make�le is a �le containing a set of directives used with the make tool to automate the build process for a �le or a set of �les. For example, assume we have a codebase that has hundreds of �les with lots of dependencies between them. Generally, we would compile each �le, generate an object �le and link all the object �les together to generate an executable. Even if there is a small change in one of the �les, we would have to recompile and link them which is quite a cumbersome and ine�cient process. Using Make�les, you can ensure that only the �les that have been modi�ed since the last build and those which are dependent on the changed �les are the ones which are compiled. make uses the timestamp on a �le to check if the �le has been modi�ed and whether it has to be recompiled or not. If you have a "make�le" in your directory which speci�es the rules for compiling the �les (including the dependencies), all you have to do is run "make". If you want to run only speci�c rules, you can specify using "make ". A make�le consists of �rules� in the following form: target: dependencies system command(s) where target is usually the name of a �le that is generated by a program like executable or object �les; a dependency (also called prerequisite) is a �le that is used as input to create the target; the system command(s) (also called recipe) is an action that make carries out. Note the use of meaningful indentation in specifying commands; also note that the indentation must consist of a single character. For example, if we have following dependency stated in the Make�le: Algorithm 1 Generic make�le for project containing main.c and display.c. The above snapshot speci�es that the target edit depends on main.o and display.o for its build, which further depend on their source �les main.c and display.c respectively. For executing above, we need to have all the above �les along with Make�le in the same directory. When we execute the command make in the same directory, the make tool tries to build the target edit by �guring out whether any dependencies have been modi�ed since their last build and if so, builds those desired dependencies and produces the target edit. For more information on make visit GNU Make�le For this assignment, you will use a specially set up make�le. See Algorithm 2 below. In this make �le, we have two targets, all and clean. Rather than being dependent on a speci�c �le, they are more actions that the make�le can execute. In this case, all is used to build the �le, while clean is to clean the build outputs. 3 https://www.gnu.org/software/make/manual/html_node/Simple-Makefile.html For us, we would only need to type �make� in the correct folder to use this make�le. The top most line is special, it says �obj-m += simple.o�. This say takes the result of compiling the �le simple.c (which will be called simple.o), and combine it with the default binaries for creating an module. This produce the .ko �le that represents a built LKM that you can load into the operating system. Algorithm 2 Sample LKM make�le (from Operating System Concepts by Silberschatz, Galvin, Gagne) obj−m += simple . o a l l : make −C / l i b /modules/$ ( s h e l l uname −r )/ bu i ld M=$ (PWD) modules c l ean : make −C / l i b /modules/$ ( s h e l l uname −r )/ bu i ld M=$ (PWD) c l ean 4 Include Files To complete this assignment, you may �nd the following include �les useful: • linux/sched.h: De�nes processes and their associated details. � Useful types: ∗ struct task_struct - A structure to contain process details (see line 1475) � Useful macros: ∗ for_each_process - A macro to loop over each currently running process (see line 503). (On more recent kernels, this may be de�ned in linux/sched/signal.h) • linux/list.h: Implements a circular-linked list in C language which could be used to fetch the child processes. � Useful types: ∗ struct list_head � Useful functions: ∗ list_for_each ∗ list_entry Note that you are not limited to using these functions, nor are you required to use all of them. 5 Submission The submission for this assignment has two parts: a write up, and the source code (optional: include the Make�le which compiles the module). The �le(s) should be attached to the homework submission link on BlackBoard. Writeup: For this assignment, you should provide a write up as discussed in PDF format. Please name your �le as "LastNameLKM.pdf" (e.g. "JainLKM.pdf") using the write up submission link. Source Code: Please name your �le(s) as "LastNameLKM.zip" (e.g. "JainLKM.zip"), which should contain a �.c� of the same name (e.g., JainLKM.c), and optionally a make�le. Do NOT include your write up or any binaries. 4 • If your program fails to compile out-of-the-box, there will be a mandatory deduction 20% from the assignment points. • If you do not follow the file submission standards (e.g., the submission contains project files, lacks a proper header), there will be a mandatory deduction of 10% from the assignment points. • If compiling or running your program differs from stated on the assignment and it is not specified as a requirement, please include a readme file with steps to execute the program. If you do not, there will be a mandatory 10% deduction from
Answered 2 days AfterSep 01, 2021

Answer To: Arizona State University SER334: Operating Systems & Networks TA Jain, Lecturer Acuña Revised...

Karthi answered on Sep 04 2021
142 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here