今天在在公司做网络驱动开发测试时,随机包出现收包计数停止的现象,当时怀疑是DMA rx buffer不足导致,想通过对比收发包正常和收发包不正常是DMA相关寄存器的情况。

后跟踪代码,若在收发包里面增加打印,必定回降低收发包性能,对比结果也就不准了,分析代码分析来分析去,最终发现做合适的就是采用proc。

 /*
* procfs_example.c: an example proc interface
*
* Copyright (C) 2001, Erik Mouw (mouw@nl.linux.org)
*
* This file accompanies the procfs-guide in the Linux kernel
* source. Its main use is to demonstrate the concepts and
* functions described in the guide.
*
* This software has been developed while working on the LART
* computing board (http://www.lartmaker.nl), which was sponsored
* by the Delt University of Technology projects Mobile Multi-media
* Communications and Ubiquitous Communications.
*
* This program is free software; you can redistribute
* it and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA
*
*/ #include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/jiffies.h>
#include <asm/uaccess.h> #define MODULE_VERS "1.0"
#define MODULE_NAME "procfs_example" #define FOOBAR_LEN 8 struct fb_data_t {
char name[FOOBAR_LEN + ];
char value[FOOBAR_LEN + ];
}; static struct proc_dir_entry *example_dir, *foo_file,
*bar_file, *jiffies_file, *symlink; struct fb_data_t foo_data, bar_data; static int proc_read_jiffies(char *page, char **start,
off_t off, int count,
int *eof, void *data)
{
int len; len = sprintf(page, "jiffies = %ld\n",
jiffies); return len;
} static int proc_read_foobar(char *page, char **start,
off_t off, int count,
int *eof, void *data)
{
int len;
struct fb_data_t *fb_data = (struct fb_data_t *)data; /* DON'T DO THAT - buffer overruns are bad */
len = sprintf(page, "%s = '%s'\n",
fb_data->name, fb_data->value); return len;
} static int proc_write_foobar(struct file *file,
const char *buffer,
unsigned long count,
void *data)
{
int len;
struct fb_data_t *fb_data = (struct fb_data_t *)data; if(count > FOOBAR_LEN)
len = FOOBAR_LEN;
else
len = count; if(copy_from_user(fb_data->value, buffer, len))
return -EFAULT; fb_data->value[len] = '\0'; return len;
} static int __init init_procfs_example(void)
{
int rv = ; /* create directory */
example_dir = proc_mkdir(MODULE_NAME, NULL);
if(example_dir == NULL) {
rv = -ENOMEM;
goto out;
}
/* create jiffies using convenience function */
jiffies_file = create_proc_read_entry("jiffies",
, example_dir,
proc_read_jiffies,
NULL);
if(jiffies_file == NULL) {
rv = -ENOMEM;
goto no_jiffies;
} /* create foo and bar files using same callback
* functions
*/
foo_file = create_proc_entry("foo", , example_dir);
if(foo_file == NULL) {
rv = -ENOMEM;
goto no_foo;
} strcpy(foo_data.name, "foo");
strcpy(foo_data.value, "foo");
foo_file->data = &foo_data;
foo_file->read_proc = proc_read_foobar;
foo_file->write_proc = proc_write_foobar; bar_file = create_proc_entry("bar", , example_dir);
if(bar_file == NULL) {
rv = -ENOMEM;
goto no_bar;
} strcpy(bar_data.name, "bar");
strcpy(bar_data.value, "bar");
bar_file->data = &bar_data;
bar_file->read_proc = proc_read_foobar;
bar_file->write_proc = proc_write_foobar; /* create symlink */
symlink = proc_symlink("jiffies_too", example_dir,
"jiffies");
if(symlink == NULL) {
rv = -ENOMEM;
goto no_symlink;
} /* everything OK */
printk(KERN_INFO "%s %s initialised\n",
MODULE_NAME, MODULE_VERS);
return ; no_symlink:
remove_proc_entry("bar", example_dir);
no_bar:
remove_proc_entry("foo", example_dir);
no_foo:
remove_proc_entry("jiffies", example_dir);
no_jiffies:
remove_proc_entry(MODULE_NAME, NULL);
out:
return rv;
} static void __exit cleanup_procfs_example(void)
{
remove_proc_entry("jiffies_too", example_dir);
remove_proc_entry("bar", example_dir);
remove_proc_entry("foo", example_dir);
remove_proc_entry("jiffies", example_dir);
remove_proc_entry(MODULE_NAME, NULL); printk(KERN_INFO "%s %s removed\n",
MODULE_NAME, MODULE_VERS);
} module_init(init_procfs_example);
module_exit(cleanup_procfs_example); MODULE_AUTHOR("Erik Mouw");
MODULE_DESCRIPTION("procfs examples");
MODULE_LICENSE("GPL");

驱动编译脚本Makefile文件如下:

    obj-m += proc.o
CURRENT_PATH:=$(shell pwd)
LINUX_KERNEL_PATH:=/lib/modules/$(shell uname -r)/build
all:
$(MAKE) -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions

本人是在ubuntu10.04下编译。

proc的妙用的更多相关文章

  1. python -c 妙用

    前言 python -c 命令还是有用的哈 正文 python的 -c 可以在命令行中调用 python 代码, 实际上 -c 就是 command 的意思 官方文档中解释为(节选自: python ...

  2. 【CSS进阶】伪元素的妙用--单标签之美

    最近在研读 <CSS SECRET>(CSS揭秘)这本大作,对 CSS 有了更深层次的理解,折腾了下面这个项目: CSS3奇思妙想 -- Demo (请用 Chrome 浏览器打开,非常值 ...

  3. angular2系列教程(十)两种启动方法、两个路由服务、引用类型和单例模式的妙用

    今天我们要讲的是ng2的路由系统. 例子

  4. JavaScript的妙与乐(一)之 函数优化

    JavaScript的妙与乐系列文章主要是展示一些JavaScript上面比较好玩一点的特性和一些有用的技巧,里面很多内容都是我曾经在项目中使用过的一些内容(当然,未必所有技巧的使用频率都很高^_^) ...

  5. Promise的前世今生和妙用技巧

    浏览器事件模型和回调机制 JavaScript作为单线程运行于浏览器之中,这是每本JavaScript教科书中都会被提到的.同时出于对UI线程操作的安全性考虑,JavaScript和UI线程也处于同一 ...

  6. 【CSS进阶】伪元素的妙用2 - 多列均匀布局及title属性效果

    最近无论是工作还是自我学习提升都很忙,面对长篇大论的博文总是心有余而力不足,但又不断的接触学习到零碎的但是很有意义的知识点,很想分享给大家,所以本篇可能会很短. 本篇接我另一篇讲述 CSS 伪元素的文 ...

  7. 不太被人提起的%%lockres%%的妙用

    %%lockres%% 这个值似乎很少被大家提到,甚至微软在官方文档中. 它返回是一个Hash Value,看乎这个值没什么用. 后来在实践也有它的妙用之处,比如在出现性能问题如LOCK时,一般先通过 ...

  8. linux内核调试技术之自构proc

    1.简介 在上一篇中,在内核中使用printk可以讲调试信息保存在log_buf缓冲区中,可以使用命令 #cat /proc/kmsg  将缓冲区的数区的数数据打印出来,今天我们就来研究一下,自己写k ...

  9. mysq l错误Table ‘./mysql/proc’ is marked as crashed and should be repaired

    续上一篇,解决了上一篇中的问题后,启动成功,但是在数据库中操作会存在一些问题,一些操作报一下异常: Table './mysql/proc' is marked as crashed and shou ...

随机推荐

  1. 给浏览器绑定鼠标滚动事件(兼容FireFox)

    var bs = new Browser(); if(bs.userBrowser() == 'firefox'){ document.body.addEventListener("DOMM ...

  2. 发布MVC网站的时候出现缺少WebHost等程序集问题的解决办法

    将一下几个dll 拷贝到bin文件夹下就行 链接:https://pan.baidu.com/s/17xhTdakzM_SQmOjJdZvviw 密码:c976

  3. ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第八天(非原创)

    文章大纲 一.课程介绍二.Solr基本介绍三.ssm整合Solr四.项目源码与资料下载五.参考文章   一.课程介绍 一共14天课程(1)第一天:电商行业的背景.淘淘商城的介绍.搭建项目工程.Svn的 ...

  4. 【mysql】mysql 配置

    安装完mysql后, 要及得配置一下 /etc/mysql/my.cnf 配置字符编码为utf8 [client] default-character-set = utf8 [mysqld] defa ...

  5. nmon 工具的使用

    原文链接:https://www.ibm.com/developerworks/cn/aix/library/analyze_aix/ 引言 nmon 工具可以为 AIX 和 Linux 性能专家提供 ...

  6. python 学习之FAQ:find 与 find_all 使用

      FAQ记录   1. 错误源码 错误源码如下 def fillUnivList(_html,_ulist): soup =BeautifulSoup(_html,'html.parser') fo ...

  7. Altera FFT核使用详解

    简介 快速傅里叶变换(Fast Fourier Transform)最为一种高效的算法,被广泛的用于信号处理与数据分析等领域.对于设计工程师来讲,自己动手采样可编程语言来实现一个FFT/IFFT模块, ...

  8. [转贴] 2016一月12日起.NET 4, 4.5 and 4.5.1 停止安全更新、技术支持 or hotfix

    [转贴] 2016一月12日起.NET 4, 4.5 and 4.5.1 停止安全更新.技术支持 or hotfix https://www.dotblogs.com.tw/mis2000lab/20 ...

  9. java核心技术 要点笔记1

    第1章 1.java特性 简单性,java语法是一个C++语法的纯净版本. 面向对象,java将重点放在数据和对象的接口上.java与C++的主要不同点在于多继承,在java中实现多继承的机制是采用接 ...

  10. java poi读取excel公式,返回计算值(转)

    http://blog.csdn.net/CYZERO/article/details/6573015 经测试,确实可以 1 package hrds.zpf.poi;  2  3  import o ...