小编Dig*_*lee的帖子

使用Linux sysfs_notify调用

我试图在内核驱动程序和用户空间程序之间异步通信(我知道这里有很多问题需要类似的信息,但我找不到任何处理sysfs_notify的问题).

我将离开Vilhelm的编辑,但是将源添加到使用sysfs的简单驱动程序和用户空间程序进行轮询.驱动程序工作正常(我从网上得到了大部分;它缺少了学分,但是当我回去添加它们时我找不到它们).不幸的是,投票计划不起作用.它总是立即返回成功.有趣的是,如果我在轮询之前不执行两次读取,则revents成员将设置为POLLERR | 如程序输出中所见,POLLIN而不仅仅是POLLIN.

节目输出:

root @ ubuntu:/ home/wmulcahy/demo#./ readhello
triggered
属性文件值:74(t)[0]
revents [0]:00000001
revents [1]:00000001

这是驱动程序:hello.c(你可以看到我开始的地方......)

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/slab.h>

struct my_attr {
    struct attribute attr;
    int value;
};

static struct my_attr notify = {
    .attr.name="notify",
    .attr.mode = 0644,
    .value = 0,
};

static struct my_attr trigger = {
    .attr.name="trigger",
    .attr.mode = 0644,
    .value = 0,
};

static struct attribute * myattr[] = {
    &notify.attr,
    &trigger.attr,
    NULL
};

static ssize_t show(struct kobject *kobj, …
Run Code Online (Sandbox Code Playgroud)

linux kernel polling linux-kernel sysfs

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

kernel ×1

linux ×1

linux-kernel ×1

polling ×1

sysfs ×1