ioctl


//user space
int ioctl(int fd,unsigned long cmd,...);

//kernel space
int (*ioctl)(struct inode *inode,struct file* filp,unsigned int cmd,unsigned long arg)

Blocking I/O

#include <linux/wait.h>

wait_queue_head_t my_queue;

DECLARE_WAIT_QUEUE_HEAD(name);

init_waitqueue_head(&my_queue);
wait_event(queue,condition);

wait_event_interruptible(queue,condition);

wait_event_timeout(queue,condition,timeout);

wait_event_interruptible_timeout(queue,condition,timeout);

void wake_up(wait_queue_head_t *queue);

void wake_up_interruptible(wait_queue_head_t *queue);

Manual sleeps

DEFINE_WAIT(my_wait);

void prepare_to_wait(wait_queue_head_t *queue,wait_queue_t *wait,int state);

void schedule();//combine with condition check 

void finish_wait(wait_queue_head_t *queue,wait_queue_t *wait);

poll and select

unsigned int (*poll)(struct file *filp,struct poll_table *wait);

eg:

static unsigned int scull_p_poll(struct file *filp, poll_table *wait)
{
    struct scull_pipe *dev = filp->private_data;
    unsigned int mask = 0;
    /*
    * The buffer is circular; it is considered full
    * if "wp" is right behind "rp" and empty if the
    * two are equal.
    */
    down(&dev->sem);
    poll_wait(filp, &dev->inq, wait);
    poll_wait(filp, &dev->outq, wait);
    if (dev->rp != dev->wp)
        mask |= POLLIN | POLLRDNORM; /* readable */
    if (spacefree(dev))
        mask |= POLLOUT | POLLWRNORM; /* writable */
    up(&dev->sem);
    return mask;
}

Linux kernel Programming - Advanced Char Driver Operations的更多相关文章

  1. Linux kernel Programming - Allocating Memory

    kmalloc #include <linux/slab.h> void *kmalloc(size_t size,int flags); void kfree(void *addr); ...

  2. Linux kernel support docker storage driver aufs

    How to make docker use aufs in CentOS 7? - Server Faulthttps://serverfault.com/questions/650208/how- ...

  3. Linux kernel Programming - Concurrency and Race Conditions

    Concurrency and Its Management Race condition can often lead to system crashes, memory leak,corrupte ...

  4. Linux Kernel Programming - Time,Delays,and Deferred Work

    Measuring Time Lapses The counter and the utility functions to read it live in <linux/jiffies.h&g ...

  5. Linux kernel AACRAID Driver Compat IOCTL 本地安全绕过漏洞

    漏洞名称: Linux kernel AACRAID Driver Compat IOCTL 本地安全绕过漏洞 CNNVD编号: CNNVD-201311-390 发布时间: 2013-11-29 更 ...

  6. linux内核可以接受的参数 | Linux kernel启动参数 | 通过grub给内核传递参数

    在Linux中,给kernel传递参数以控制其行为总共有三种方法: 1.build kernel之时的各个configuration选项. 2.当kernel启动之时,可以参数在kernel被GRUB ...

  7. Intel 80x86 Linux Kernel Interrupt(中断)、Interrupt Priority、Interrupt nesting、Prohibit Things Whthin CPU In The Interrupt Off State

    目录 . 引言 . Linux 中断的概念 . 中断处理流程 . Linux 中断相关的源代码分析 . Linux 硬件中断 . Linux 软中断 . 中断优先级 . CPU在关中断状态下编程要注意 ...

  8. Linux Kernel中断子系统来龙去脉浅析【转】

    转自:http://blog.csdn.net/u011461299/article/details/9772215 版权声明:本文为博主原创文章,未经博主允许不得转载. 一般来说,在一个device ...

  9. Linux kernel的中断子系统之(七):GIC代码分析

    返回目录:<ARM-Linux中断系统>. 总结: 原文地址:<linux kernel的中断子系统之(七):GIC代码分析> 参考代码:http://elixir.free- ...

随机推荐

  1. Java基础——Oracle(一)

    Oracle是目前最流行的数据库之一.功能强大,性能卓越.所以学起来比较困难.学习Oracle需要具备一定的基础.比如学习过一门编程语言,或者学过其他的数据库等,没有一些基础很难下手. 一.Oracl ...

  2. 【github&&git】3、git图像化界面GUI的使用

    GIT学习笔记 一.        基础内容 1.git是一个版本控制软件,与svn类似,特点是分布式管理,不需要中间总的服务器,可以增加很多分支. 2.windows下的git叫msysgit,下载 ...

  3. 深入理解JVM——虚拟机GC

    对象是否存活 Java的GC基于可达性分析算法(Python用引用计数法),通过可达性分析来判定对象是否存活.这个算法的基本思想是通过一系列"GC Roots"的对象作为起始点,从 ...

  4. csharp: Configuring ASP.NET with Spring.NET and FluentNHibernate

    Domain: FluentNhibernateLocalSessionFactoryObject.cs using System; using System.Collections.Generic; ...

  5. (网页)jQuery的时间datetime控件在AngularJs中使用实例

    百度一下,自己也想了一下,有一种简单,无脑的方式分享给你: <input ng-model="start" id="start" placeholder= ...

  6. [20171206]rman与truncate2.txt

    [20171206]rman与truncate2.txt --//上午测试发现truncate的表在做rman备份时还要做8个extents的备份.--//不知道自己的猜测是否正确,选择一个使用UNI ...

  7. 成功清除 windows2008 内部版本7601 字眼

    cmd—>bcdedit -set testsigning off重启电脑就好了

  8. EntityFramework Code-First 简易教程(九)-------一对多

    一对多(One-to-Many)关系: 下面,我们来介绍Code-First的一对多关系,比如,在一个Standard(年级)类中包含多个Student类. 如果想了解更多关于one-to-one,o ...

  9. Jmeter压力测试简单教程(包括服务器状态监控)

    前段时间公司需要对服务器进行压力测试,包括登录前的页面和登录后的页面,主要目的是测试负载均衡的实现效果.不知道是不是因为Jmeter不如loadRunner火爆还是什么,网上关于Jmeter的资料有很 ...

  10. Windows10 内存泄漏

    之前遇到win10开机idle一段时间后, 内存噌噌的往上彪, 16G内存基本什么东西没开就90%多.查了网上的一些解决方案: 方法1. 关闭Ndu服务 sc config Ndu start=dis ...