Linux Kernel module programming-Symmetric Multi-processing

Source: Internet
Author: User
Linux Kernel module programming-Symmetric Multi-processing-general Linux technology-Linux programming and kernel information. The following is a detailed description. The simplest way to improve hardware performance is to add multiple CPUs to the motherboard (reading is the cheapest way ). Either let different CPUs do different work (Asymmetric Multi-processing), or let them run the same job in parallel (Symmetric Multi-processing, abbreviated as SMP ). Effective use of Asymmetric Multi-processing requires the knowledge of the tasks that computers will do, which is impossible on general operating systems such as LINUX. On the other hand, the implementation of Symmetric Multi-processing is relatively simple. Relatively simple, I mean exactly-it's not really simple. In a Symmetric Multi-processing environment, multiple CPUs share the same memory. The result is that the Code running on one CPU can affect the memory used by the other. You can no longer ensure that the values of a variable you set in the previous lines keep the same value-the other CPU may modify it when you don't see it. Obviously, problems such as programs cannot be tolerated.

This is usually not a problem in process programming, because a process is usually at the same time (except for threads, they can run on several CPUs at the same time .) Run on only one CPU. On the other hand, the kernel may be called by different processes running on different CPUs. SPIN

In version 2.0.x, this is not a problem because the entire kernel is in a large spin lock. This means that when a CPU is in the kernel, and another CPU, for example, needs to enter the kernel due to system calls, it has to get the first CPU to complete its work. This ensures linux smp Security (meaning it is safe to use it with SMP. ), But seriously inefficient.

In version 2.2.x, several CPUs are simultaneously in the kernel. This should be noted by some module writers. I get someone's right to use an SMP unit for me, so the next version of this book may include more information.

Common traps

Before I send you to this world and write kernel modules, I need to warn you about some issues. If I fail to warn you about some bad things, please report the problem to me and ask me for the full amount you paid for this book.

1. You cannot do that using standard library files. In the kernel module, you can only use kernel functions, which can be seen in/proc/ksyms.

2. You may need to close the interruption for a short time, but it won't be a problem. But if you cannot open them later, your system will be stuck and you have to power it off.

3. I may not have warned you about sticking my head to a huge meat animal, but I will do it in case of anything.

Changes Between version 2.0 and Version 2.2

I don't fully understand the kernel to write all the changes. I encountered the following differences in the Process of sample conversion (or adapting to the changes in Emmanuel Papirakis. I will list all the things I know here to help module programmers, especially those who have learned from the previous version of this book and who are mostly similar to the technologies I use, convert to a new version.
A useful additional resource for anyone who wants to convert to Version 2.2 in http://www.atnf.csiro.au /~ Rgooch/linux/docs/porting-to-2.2.html.

1. asm/uaccess. h if you need put_user or get_user, You Need To # include it.

2. In version 2.2, get_user receives the pointer to the user memory segment and the kernel memory segment to fill in the information. The reason is that if the read variable is two or four bytes long, get_user can now read the variable at one time.

3. The file_operations structure has a refresh function between the open and close functions.

4. In file_operations, the close function is in version 2.2. The close function returns an integer, So it allows failure.

5. the header file of the read/write functions in file_operations has changed. They now return ssize_t instead of an integer, and their parameter lists are also different. The node is no longer a parameter but a file offset.

6. The proc_register_dynamic function no longer exists. You can call the common proc_register function and set the node Member of the structure to 0.

7. The signal in the Signals task structure is no longer a 32-bit integer but an array of _ NSIG_WORDS integers.

8. queue_task_irq even if you want to schedule a task from the interrupt handle, you should use queue_task instead of queue_task_irq.

9. You cannot declare module parameters as global variables only. In version 2.2, you must also use MODULE_PARM to declare its type. This is a huge improvement. For example, it allows the module to receive string parameters starting with numbers without confusion.

10. The Symmetric Multi-Processing Kernel is no longer limited to a huge rotation lock, which means that the kernel module must be aware of Symmetric Multi-processing.

From here to where?

I can easily add more chapters to this book. I can join the chapter on creating a new file system or add a new protocol stack (as if you need it here-you have to discover a protocol stack not supported by Linux ). I can also add explanations of kernel mechanisms that we have not yet come into contact with, such as self-lifting or disk interfaces.

However, I did not choose to do this. I wrote this book to provide the basic beginning and general technology for the mysterious kernel module programming. For those who are really interested in kernel programming, I recommend located in http://jungla.dit.upm.es /~ Kernel source file list for jmseyas/linux/kernel/hackers-docs.html. As Linus said, the best way to learn the kernel is to read the source code by yourself.

If you are interested in more short kernel module examples, I recommend Phrack. Even if you are not interested in security (you should be interested as a programmer), there are many good examples of kernel modules that let you know what can be done in the kernel, they are short enough, so that you can understand it without too much effort.

I hope that I have helped you to become a better programmer or at least provide fun through technology. Moreover, if you have written a useful kernel module, I want you to publish it under the GNU General Public License protocol so that I can also use them.

Products and Services

I hope no one has noticed the shameful publicity here. They are all useful to programmers who start Linux kernel modules.



Get the printed version of this book

The Coriolis group is preparing to print the book in the summer of 99. If it's already summer and you want to get the printed version of this book, you can buy it from your printer.

Thank you!

This is a free document. You are not liable for anything except the terms of the GNU Public License Agreement. However, if you want to do something in return for this book, you can do it.

Send me a postcard
Ori Pomerantz
Apt. #1032.
2355 N Hwy 360
Grand Prairie
TX 1, 75050
USA

If you want to receive a thank-you reply, please enter your email address.

Donate money or better time to the Free Software Group. Compile and publish programs or documents under the GNU Public License Agreement. Teach others how to use free software, such as Linux or Perl.

Explaining to people that selfishness is in conflict with living in a society or helping others. I like writing this document and I believe it will be helpful for my future. At the same time, I wrote a book to help you (if you get it ). Remember, to make others happy is generally more useful to you than to make others unhappy, and to make people go on the road better than to make people unhappy.

Happy. If I meet you, it will make the meeting more pleasant and make you more useful to me. ;-).
This document...
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.