译文的标题叫在用户空间做:有点难以接受

A Unix programmer who's addressing kernel issues for the first time might be nervous about writing a module. Writing a user program that reads and writes directly to the device ports may be easier.

Indeed, there are some arguments in favor of user-space programming, and sometimes writing a so-called user-space device driver is a wise alternative to kernel hacking. In this section, we discuss some of the reasons why you might write a driver in user space. This book is about kernel-space drivers, however, so we do not go beyond this introductory discussion.

The advantages of user-space drivers are:

  • The full C library can be linked in. The driver can perform many exotic tasks without resorting to external programs (the utility programs implementing usage policies that are usually distributed along with the driver itself).-----没法理解...

  • The programmer can run a conventional debugger on the driver code without having to go through contortions to debug a running kernel.

  • If a user-space driver hangs, you can simply kill it. Problems with the driver are unlikely to hang the entire system, unless the hardware being controlled is really misbehaving.

  • User memory is swappable, unlike kernel memory. An infrequently used device with a huge driver won't occupy RAM that other programs could be using, except when it is actually in use.

  • A well-designed driver program can still, like kernel-space drivers, allow concurrent access to a device.

  • If you must write a closed-source driver, the user-space option makes it easier for you to avoid ambiguous licensing situations and problems with changing kernel interfaces.

For example, USB drivers can be written for user space; see the (still young) libusb project at libusb.sourceforge.net and "gadgetfs" in the kernel source. Another example is the X server: it knows exactly what the hardware can do and what it can't, and it offers the graphic resources to all X clients. Note, however, that there is a slow but steady drift toward frame-buffer-based graphics environments, where the X server acts only as a server based on a real kernel-space device driver for actual graphic manipulation.

Usually, the writer of a user-space driver implements a server process, taking over from the kernel the task of being the single agent in charge of hardware control. Client applications can then connect to the server to perform actual communication with the device; therefore, a smart driver process can allow concurrent access to the device. This is exactly how the X server works.

But the user-space approach to device driving has a number of drawbacks. The most important are:

  • Interrupts are not available in user space. There are workarounds for this limitation on some platforms, such as the vm86 system call on the IA32 architecture.

  • Direct access to memory is possible only by mmapping /dev/mem, and only a privileged user can do that.

  • Access to I/O ports is available only after calling ioperm or iopl. Moreover, not all platforms support these system calls, and access to /dev/port can be too slow to be effective. Both the system calls and the device file are reserved to a privileged user.

  • Response time is slower, because a context switch is required to transfer information or actions between the client and the hardware.

  • Worse yet, if the driver has been swapped to disk, response time is unacceptably long. Using the mlock system call might help, but usually you'll need to lock many memory pages, because a user-space program depends on a lot of library code. mlock, too, is limited to privileged users.

  • The most important devices can't be handled in user space, including, but not limited to, network interfaces and block devices.

As you see, user-space drivers can't do that much after all. Interesting applications nonetheless exist: for example, support for SCSI scanner devices (implemented by the SANE package) and CD writers (implemented by cdrecord and other tools). In both cases, user-level device drivers rely on the "SCSI generic" kernel driver, which exports low-level SCSI functionality to user-space programs so they can drive their own hardware.

One case in which working in user space might make sense is when you are beginning to deal with new and unusual hardware. This way you can learn to manage your hardware without the risk of hanging the whole system. Once you've done that, encapsulating the software in a kernel module should be a painless operation.

转载于:https://www.cnblogs.com/michile/archive/2013/02/07/2908807.html

Doing It in User Space相关推荐

  1. Could not install packages due to an EnvironmentError: [Errno 28] No space left on device

    Could not install packages due to an EnvironmentError: [Errno 28] No space left on device 1. 问题现象 安装 ...

  2. c4d教程-太空火车站场景创作视频教程Skillshare – Create A Space Train Scene With Cinema 4D Redshift Render

    c4d教程-太空火车站场景创作视频教程Skillshare – Create A Space Train Scene With Cinema 4D & Redshift Render 教程大小 ...

  3. ceph osd 由于“No space left on device” 异常down,通过扩容文件系统或者显式运行osd进程解决

    文章目录 ceph版本: 环境配置: 异常问题: 问题解决: 总结 ceph版本: ceph 12.2.1 环境配置: tier_pool 16个分区大小800G 的osd容量 3副本 data_po ...

  4. java.lang.OutOfMemoryError: PermGen space及其解决方法

    PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决 ...

  5. Missing space before value for key ‘routes‘ key-spacing

    vue项目报错: Missing space before value for key 'routes' key-spacing 解决办法: 字母new前面应该是1个空格,我写了两个空格,删去一个空格 ...

  6. Space X的火箭上天,Tesla的业绩落地

    作者 | 明明 昨日,Space X 的重型猎鹰火箭(Falcon Heavy)发射成功,作为压舱物的特斯拉 Roadster跑车也飞向了浩瀚无垠的宇宙当中,朋友圈又一次被马斯克刷屏,就连我国官媒也发 ...

  7. java.lang.OutOfMemoryError: Java heap space错误及...

    为什么80%的码农都做不了架构师?>>>    以下是从网上找到的关于堆空间溢出的错误解决办法: java.lang.OutOfMemoryError: Java heap spac ...

  8. 宝塔面板遇到No space left on device错误的解决方法

    问题描述 说明:今天登陆阿里云服务器的宝塔面板,遇到了磁盘爆满的情况,登陆的时候提示IOError: [Errno 28] No space left on device等错误信息,导致登录面板不显示 ...

  9. jvm from space 很小_JVM真香系列:堆内存详解

    前面的文章中已经有所提到过堆,只是大致介绍了一下.本文就来详细聊聊JVM中的堆. 在 JVM中,堆被划分成两个不同的区域:新生代 ( Young ).老年代 ( Old ). 新生代 ( Young ...

  10. Determine whether an integer is a palindrome. Do this without extra space.

    看到这个题目的时候,首先不认识 Determine这个单词.英文不好没办法,查了下是确认的意思,然后不懂 palindrome这个单词, 查了下是回文的意思. 问题是 回文是个什么东西,官方解释: A ...

最新文章

  1. [Spring cloud 一步步实现广告系统] 20. 系统运行测试
  2. ETL流程概述及常用实现方法
  3. ES6一些新特性记录
  4. server2016安装mysql_windows server2016安装MySQL5.7.19解压缩版教程详解
  5. 选择通过更改内容类型返回的详细程度,第二部分
  6. 网站缩略图在线生成PHP源码
  7. python和matlab矩阵运算效率_如何写出比 MATLAB 更快的矩阵运算程序?
  8. 【电子技术实验设计】简易水位控制器设计报告
  9. 整理了一份嵌入式相关开源项目、库、资料
  10. ARM的存储控制器以及如何使用SDRAM
  11. 四性检测功能在档案系统中的实现
  12. 在Docker中创建应用
  13. 潜入蓝翔技校二十天 探究蓝翔黑客真正的奥秘
  14. 【C#】未能添加对“*.dll”的引用。请确保此文件可访问并且是一个有效的程序集或 COM 组件。
  15. 大数据——Flink Window(窗口)机制
  16. 长安大学微型计算机原理与接口技术答案,长安大学考研专业课《815微机原理与接口技术》真题解析 考点 冲刺.pdf...
  17. 缓存为王:老码农眼中的分布式缓存
  18. 制作符合EIA/TIA标准的RJ-45两种双绞线的压线顺序
  19. OmniPlan Pro 4:项目流程管理工具
  20. 使用python计算圆周率(有进度条)

热门文章

  1. day12--k近邻算法KNN
  2. python 3.5版本安装landsat-uti包
  3. 解决eclispe SVN 创建资源库报错,无法验证:SVN…… 504 Connection to server timed out
  4. Python爬虫基础-02-提取数据
  5. hibernate一对多双向关联中怎么配置list
  6. LeakCanary的原理,你知道么?
  7. 手把手图文教你从Eclipse项目迁移Android Studio
  8. js ajax mysql_Ajax与mysql数据交互实现留言板功能
  9. 怎么调节手机的刷新率_【W21 5G性能篇】120Hz自适应刷新率,用了再也回不去
  10. python一定要有主函数_Python 为什么没有 main 函数?为什么我不推荐写 main 函数?...