0% found this document useful (0 votes)
5 views

Linux Kernel Device Driver

The document provides a comprehensive overview of Linux kernel device drivers and operating system interview questions, covering basic concepts like device drivers, character vs. block drivers, and the role of udev. It also addresses intermediate topics such as I/O operations, interrupt handling, and synchronization mechanisms, along with advanced concepts like DMA-BUF and device memory management. Each question is paired with concise answers to aid in understanding key Linux kernel functionalities and programming practices.

Uploaded by

swathibhat217
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Linux Kernel Device Driver

The document provides a comprehensive overview of Linux kernel device drivers and operating system interview questions, covering basic concepts like device drivers, character vs. block drivers, and the role of udev. It also addresses intermediate topics such as I/O operations, interrupt handling, and synchronization mechanisms, along with advanced concepts like DMA-BUF and device memory management. Each question is paired with concise answers to aid in understanding key Linux kernel functionalities and programming practices.

Uploaded by

swathibhat217
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Linux Kernel Device Driver & OS Interview Questions with Answers

1. Basic Concepts

1. What is a device driver, and why is it needed?


A device driver is a software component that allows the operating system (OS) to
communicate with hardware devices. It abstracts hardware complexities and
provides a uniform interface for user applications. Without device drivers, the OS
cannot control or interact with hardware peripherals such as keyboards, mice, and
storage devices.

2. Explain the difference between a character driver and a block driver.

o Character drivers handle data as a stream of bytes (e.g., serial ports,


keyboards).

o Block drivers handle data in fixed-size blocks and support random access
(e.g., hard disks, SSDs).

3. What is the role of the udev daemon in Linux?


udev is the device manager for the Linux kernel. It dynamically manages device
nodes in /dev/ and handles device events, such as hot-plugging USB devices.

4. How does the kernel communicate with hardware devices?


The kernel communicates with hardware using:

o I/O ports (IN/OUT instructions for older architectures)

o Memory-mapped I/O (MMIO) (direct access to device memory via ioremap)

o Interrupts (hardware-generated signals for event handling)

5. What are major and minor numbers in device files?

o Major number identifies the driver associated with a device.

o Minor number differentiates multiple instances of a device managed by the


same driver.

6. How does manual device registration differ from dynamic registration?

o Manual registration: Uses static major/minor numbers (register_chrdev).

o Dynamic registration: Allocates numbers dynamically (alloc_chrdev_region).

7. What are the key functions used in basic Linux kernel module programming?

o module_init(): Registers the module when loaded.

o module_exit(): Cleans up when the module is removed.


o register_chrdev(), alloc_chrdev_region(), cdev_add() for device registration.

8. How does a kernel module differ from a user-space application?

o Kernel modules run in kernel space with high privileges, whereas user-space
applications run in user space with restricted access.

o Kernel code can directly access hardware, but user-space applications require
system calls.

9. What is kmalloc, and how does it differ from vmalloc?

o kmalloc allocates contiguous physical memory in kernel space.

o vmalloc allocates virtually contiguous memory, but physical pages may be


scattered.

10. Explain ioremap and why it is used in memory-mapped I/O.


ioremap maps device physical memory into the kernel’s virtual address space,
enabling access to memory-mapped registers.

2. Intermediate Concepts

11. What are blocking and non-blocking I/O operations? Provide an example.

o Blocking I/O: Process waits until data is available (e.g., read() on an empty
pipe).

o Non-blocking I/O: Returns immediately if data is unavailable (e.g.,


O_NONBLOCK flag in open()).

12. What is the purpose of wait queues? How do they help in process synchronization?
Wait queues put processes to sleep until an event occurs, avoiding busy-waiting.
Example: wait_event() in device drivers.

13. How does sysfs differ from debugfs and procfs?

o sysfs: Exposes kernel objects (e.g., /sys/class/net/ for network devices).

o debugfs: Used for debugging (not meant for stable APIs).

o procfs: Exposes process-related information (e.g., /proc/meminfo).

14. Explain IOCTL and its use cases.


IOCTL (ioctl()) is used for device-specific operations not covered by standard file
operations (e.g., adjusting screen brightness, sending commands to devices).

15. What are the different ways to implement interrupt handling in Linux?

o Top-half: Executes quickly in interrupt context.


o Bottom-half: Defers heavy processing using tasklets, workqueues, or SoftIRQ.

16. Explain top-half and bottom-half processing in interrupts.

o Top-half: Handles critical tasks immediately (e.g., acknowledging an


interrupt).

o Bottom-half: Schedules deferred work (e.g., processing received data).

17. What are tasklets, workqueues, and SoftIRQ, and when should each be used?

o Tasklets: Lightweight, non-blocking bottom-half handlers.

o Workqueues: Run in process context, allowing sleep.

o SoftIRQ: Used for high-priority networking and timer handling.

18. How does a semaphore differ from a mutex in Linux kernel programming?

o Semaphore: Can be used for inter-process synchronization, allowing multiple


holders.

o Mutex: Allows only one holder and is optimized for mutual exclusion.

19. Explain memory barriers and their importance in kernel development.


Memory barriers prevent reordering of memory operations, ensuring consistency in
multiprocessor environments.

20. What is the difference between spinlocks and mutexes?

o Spinlocks: Used for short critical sections where blocking is not feasible.

o Mutexes: Allow sleeping and are used when longer waiting is acceptable.

3. Advanced Topics

21. What is DMA-BUF, and why is it important in buffer sharing?


DMA-BUF is a framework for sharing buffers between kernel subsystems (e.g., GPU
and display drivers) efficiently.

22. Explain the role of the IOMMU/MMU in device memory management.

o MMU: Translates virtual addresses to physical addresses.

o IOMMU: Provides similar translation for DMA-capable devices, enabling


protection and isolation.

23. What is a platform driver, and how does it differ from other device drivers?
Platform drivers handle devices without standard discovery mechanisms (e.g., SoC
peripherals).
24. What happens during driver probe()?
The kernel matches a driver to a device and calls its probe() function to initialize it.

25. Explain clock, regulator, GPIO, and pin control subsystems in Linux.

o Clock framework: Manages device clocks to optimize power.

o Regulators: Control voltage levels.

o GPIO: Handles general-purpose input/output pins.

o Pin control: Manages pin multiplexing and configurations.

26. How does Linux handle cache coherency?


Uses cache flushing, invalidation, and write policies to ensure data consistency.

27. Explain memory-mapped I/O vs. I/O-mapped I/O.

o MMIO: Uses the system’s regular memory space.

o I/O-mapped I/O: Uses a separate address space.

Next Steps:

• Would you like to start the mock Q&A session?

• Do you need additional examples or explanations?

You might also like