A summary of questions on Linux drive surface

Source: Internet
Author: User
Tags mutex semaphore

1. What is the main difference between a character device and a block device in a Linux device? Please list some of the actual equipment to say what kind of equipment they belong to.

character device: A character device is a device that can be accessed like a byte stream (like a file) and is implemented by a character device driver. Character device drivers typically implement at least Open,close,read and write system calls. Character terminals, serial ports, mice, keyboards, cameras, sound cards, and video cards are typical character devices.

block device : Like a character device, a block device is also accessed through a file system node in the/dev directory. Block devices can accommodate file systems such as: U-disk, SD card, disk, etc.

the difference between a character device and a block device is only the way the kernel manages the data, which is the software interface between the kernel and the driver, which is transparent to the user. In the kernel, the block driver has a completely different interface than the character driver.


2. What command should I use to view the printed information in the driver module? How can I view information about a character device that is already in the kernel? How do I see which interrupt numbers are being used?

1) View the commands for printing information in the driver module:DMESG

2) View character device information can be used lsmod and modprobe, lsmod can see the dependencies of the module, modprobe loading the module will load other dependent modules.

3) Display the currently used interrupt number Cat/proc/interrupt


3. What are the benefits of introducing a module mechanism into Linux?

First, the module is pre-registering itself in order to serve a future request, and then his initialization function ends immediately. In other words, the task of the module initialization function is to prepare for the subsequent invocation of the function.

Benefits:

1) The application can exit, regardless of the release of resources or other cleanup work, but the module's exit function must be careful to undo the initialization function to do everything.

2) This mechanism helps to shorten the development cycle of the module. That is, the registration and uninstallation are very flexible and convenient.


4, Copy_to_user () and Copy_from_user () are mainly used to achieve what function? What functions are generally used for file_operations structures?

because kernel space and user space are not accessible to each other, the kernel function must be used to read and write data if access is required. Copy_to_user (): Complete kernel space to user space replication, Copy_from_user (): Is the completion of user space to the kernel space replication. It is commonly used in file_operations structure of READ,WRITE,IOCTL and other functions of memory data exchange function. Of course, if the IOCTL does not use memory data replication, then these two functions will not be used.


5, please describe the main device number and the use of the secondary device number. If you do Mknod chartest C 4 64, create a chartest device. Please analyze the type of device driver that Chartest is using.

1) main device number: The main device number identifies the driver that corresponds to the device. While the modern Linux kernel allows multiple drivers to share the main device number, most of the devices we look at are still organized according to the principle "one master device corresponds to one driver".

Secondary device number: The secondary device number is used by the kernel to correctly determine the device that the device file refers to. Depending on how the driver is written, we can get a direct pointer to the kernel device via the secondary device number, or use this device number as an index to the device's local array.

2) Chartest is managed by Driver 4, which refers to device number 64th. (Feel similar to serial terminal or character device terminal).


6. How to register a character device in the device driver? Explain the meanings of several of its parameters separately.

There are two ways to register a character device driver:

1) void Cdev_init (struct cdev *cdev, struct file_operations *fops)

The registration function can embed the CDEV structure in its own device-specific structure. Cdev is a pointer to the struct CDEV, and FoPs is a pointer to a file_operations structure (which can be a file_operations structure, but not limited to that structure).

2) int register_chrdev (unsigned int major, const char *namem, struct file) operations *fopen);

The registration function is an earlier registration function, major is the device's main device number, name is the driver's names, and FoPs is the default file_operations structure (this is limited to the file_operations structure). the call to Register_chrdev will register 0-255 as the secondary device number for the given main device number and a corresponding default CDEV structure for each device .


7. Please describe the difference between interrupt and DMA. In a Linux device driver, which function is used to register and unregister an interrupt handler?

1) DMA: is a kind of hardware mechanism that can make two-way data transfer between peripheral and system memory without the participation of CPU, using DMA can get rid of the system CPU from the actual I/O data transfer, thus greatly improve the throughput rate of the system.

Interrupt: refers to the CPU in the process of executing the program, there are some unexpected events when the CPU must suspend the execution of the current program, go to handle the emergency, after processing the CPU returned to the location of the source program was interrupted and continue to execute.

So the difference between interrupts and DMA is that DMA does not require CPU involvement and interrupts require CPU involvement .


2) Interrupt registration function and interrupt logoff function

Registration interrupted:

int REQUEST_IRQ (unsigned int IRQ, irqreturn_t (*handler) (int, void *, struct pt_regs *), unsigned long flags, const char * Dev_name, void *dev_id);

The meaning of the parameters is: Interrupt number, interrupt handler function, interrupt management related mask, interrupt request device name, interrupt signal line.

The process is:dev_name device Request Interrupt->cpu Assignment interrupt number, set interrupt management mask, allocation interrupt signal line, and processing interrupt function, and then return to the original handler based on the settings to continue processing the program.

Logoff interrupts

void Free_irq (unsigned int irq, void *dev_id);

Releasing interrupts and interrupt signal lines


8. What is the high efficiency of interrupts and polls? How to decide whether to use the interrupt mode or the polling method to achieve the drive?

a interrupt is a signal that the CPU is in a passive state to accept the device, and polling is the CPU actively querying the device for requests . Everything is a two-sided, so, look at efficiency can not simply say that the high efficiency. If the request device is a device that requests the CPU frequently, or a network device with a large number of data requests, the polling efficiency is higher than the interrupt. If it is a generic device and the device requests a CPU frequency comparison, the interrupt efficiency is higher. mainly depends on the frequency of requests.


9. Simply describe the process of sending data frame and receiving data frame in cs8900 drive design.

1) The sending process is as follows:

(1) The network device driver obtains the valid data and the length of the packet from the Sk_buff parameter passed by the upper layer protocol, and puts the valid data into the temporary buffer.
(2) for Ethernet, if the length of the valid data is less than the minimum length of the data frame required by Ethernet collision detection, the end of the temporary buffer is populated with 0
(3) set up the hardware register, drive the network device to send the data operation.

2) Receiving process

The network device receives the data mainly by interrupts to trigger the device's interrupt processing function , the interrupt processing function determines the interrupt type, if receives the interruption, reads the received data, allocates the Sk_buff data structure and the data buffer, copies the received information to the data buffer, and invokes the Netif The _rx () function passes sk_buff to the upper layer protocol.


10, CS8900.C Drive, the process of sending data frame why need to shut down? The process of receiving data frame why do I need to shut down?

when receiving data, it is necessary to open the interrupt, because the corresponding received data in time. If the interrupt is closed, the receiver may not receive the data because of a high priority interrupt.


11, simple description Skbuff This data structure in the network structure plays the role, why need a skbuff, its distribution and release mainly in what part

The Sk_buff structure is very important, meaning "socket buffer", which is used to pass data between the cover layers in the Linux network subsystem.

When sending a packet, the network processing module of the Linux kernel must create a sk_buff that contains the packets to be transmitted, and then submit the Sk_buff to the lower layer, each of which adds different protocol headers to the sk_buff until it is sent to the network device. Similarly, when a network device receives a packet from a network medium, it must convert the received data into a sk_buff data structure and pass it on to the upper layer, and the cover does not throw away the corresponding protocol header until it is handed over to the user. The allocation sk_buff should be allocated at the beginning of the acceptance and can be released after the data has been sent Sk_buff


12, character type drive device how to create a device file

manually created: mknod/dev/led C 0 where dev/led for Device node C represents the character device 250 represents the primary device number 0 represents the secondary device number

There are also Etc/init.d/rcs script files that perform mdev-s to automatically create device nodes.


13, write an interrupt service need to pay attention to what? What do you do if you have to do more things after the interruption?

The interrupt processing routines should be as short as possible, placing the tasks that can be placed in the second half (Tasklet, waiting for queues, etc.) as far as possible in the second half of the time.

Write an interrupt service program to pay attention to fast forward and fast out, in the Interrupt service program as fast as possible to collect information, including hardware information, and then quit the interrupt, to do other things can use the work queue or Tasklet way. That is, the upper and lower halves of the interrupt.

Second: There is no blocking operation in the Interrupt service program. The interrupt period should be fully CPU-intensive (that is, there is no kernel scheduling), the interrupt is blocked, other processes will be unable to operate;

Third: The Interrupt Service program takes note of the return value, using the macro defined by the operating system as the return value, rather than the ok,fail of its own definition.


14, the spin lock and the signal volume in mutually exclusive use need to notice Which? Is the mutex used in the interrupt service program a spin lock or semaphore? Or can they both be used? Why?

processes that use spin locks cannot sleep, and processes that use semaphores can sleep.

The mutex in the interrupt service routine uses a spin lock because the hard interrupt is closed in the interrupt processing routine, but be aware that it will lose the possible interrupts.


15, atomic operation How do you understand? In order to implement a mutex, define a variable as a tag to use as a resource with only one consumer row?

Atomic manipulation refers to an operation that cannot be interrupted.

The second sentence means:

Define a variable, such as int flag = 0;

if (flag = = 0)
{
flag = 1;


Operation Critical Area;
Flag = 0;
}


16, Insmod a driver module, which function in the module will be executed? Where's rmmod? What are the two functions designed to pay attention to? Have you encountered an abnormal uninstallation drive? What is causing the problem?

Insmod calls the Init function, Rmmod calls the Exit function. What do these two functions pay attention to at design time? Uninstallation failed when uninstalling the module because there was a process using the module, and after examining the code, a deadlock problem occurred.

The corresponding virtual address is obtained through Ioremap .


18, device drive model three important members are? What is the matching rule for the Platfoem bus? Do you want to register the device before registering the drive in the specific application? Do you have a sequence yet?

Device drive model Three important members are bus, device, drive;

Platfoem Bus matching rules are: to match the device and drivers are to be registered;


19, the Linux kernel inside, the memory application has what several functions, each difference?

Kmalloc () __get_free_page () mempool_create ( )


20. What is the difference between IRQ and Fiq, and how does it work in the CPU ?


21st

int *a;
Char *b;

What are the types of a and B itself?

A, b inside itself is stored only an address, is this two addresses have different?


22, the upper part of the interruption and the bottom half of the problem: the reasons for dividing into the upper half and the lower part, why should be divided? How to achieve?

The first half of the hardware-related processing requirements are fast, and some drivers in the interrupt handler need to complete a lot of work, which constitutes a contradiction, so Linux has so-called bottom half mechanism, interrupt handlers in all not requiring immediate completion, in the open interrupt environment, The bottom half of the program is then completed.

The bottom half of Linux is actually built on the soft interrupt mechanism of the kernel. How do I implement this mechanism?

Two different ways

"Tasklet Task Force column"

1. Defining and initializing

struct Tasklet_struct tlet;

Tasklet_init (&tlet, JIT_TASKLET_FN, (unsigned long) data);
Parameters
First: Define the Tasklet variable
Second One: function
Third: Data passed to a callback function

2. Defining functions

}

3. Call the following function where dispatch is required

Tasklet_schedule (&tlet);

Usually dispatched in the interrupt function before the next clock tick is executed


"The difference between a tasklet and a regular device"

1. Execution time

Timer execution: Time is OK
Tasklet: not sure.

2.tasklet performs time-consuming operations.


23, the kernel function mmap implementation principle, mechanism?

The Mmap function implements mapping a file to a memory area so that we can read and write files like read-write memory, and he is much faster than simply calling Read/write. At some point we can copy the contents of the memory to a file for memory backup, and of course, we can also map the contents of the file to memory to restore some services. In addition,MMAP implementation of shared memory is also one of its main applications, and MMAP system calls enable the process to share memory by mapping the same common file .


24, the driver inside why should have concurrency, mutual exclusion control? How is it implemented? Tell me an example?


25, Spinlock spin lock is how to achieve?

Spin locks can only be held at most one kernel task at a time, so only one thread at a time is allowed to exist in the critical section. This can be applied to a multi-processing machine, or to the locking service required in a preemptive kernel running on a single processor.



26, the signal volume introduction

The concept of the semaphore is also described here, as its usage and spin lock have similar places.

The semaphore in Linux is a sleep lock. If there is a task trying to get a semaphore that has been held, the semaphore pushes it into the waiting queue and then lets it sleep. The processor then gets free to execute other code. When the semaphore-holding process releases the semaphore, a task in the waiting queue will be awakened, thereby obtaining the semaphore.


27, the task scheduling mechanism?


28. What is a gpio?

General Purpose Input/output

Gpio is relative to the chip itself, such as a PIN is the chip's gpio foot, then the foot can be used as input or output high or low-level use, of course, a foot has the function of multiplexing, can do gpio can also do other purposes. That means you can use these pins for any general-purpose input output, such as a pin connected to the led to control its light-out, or a (some) pin to a sensor to obtain the state of the sensor, which gives the CPU a convenient way to control the peripheral devices. If there are not enough gpio pins to control some peripherals, it is possible to use CPLD to help manage the system.

29, in Linux C, ls This command is how to be executed?

use fork to create a process or EXEC function family to overwrite the original process.


30. What do the socket sockets under Linux have in common with the Winsock under Windows? Please read the C + + language

A) both TCP SOCK-oriented and non-connected UDP SOCK are provided based on the TCP/IP protocol.

b) is a sock structure.

c) are accessed using the sock file handle.

D) have a buffering mechanism.


31, a plan to run the Linux system arm system bootloader burned in, after power on the serial port without any output, hardware and software should be to check what?

Tip: 1. Linux-run systems generally require external DRAM, and general systems often have nor or NAND FLASH

Bootloader is generally compiled and C-written by the bare-Ben program [5 points]

A summary of questions on Linux drive surface

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.