今天在在公司做网络驱动开发测试时,随机包出现收包计数停止的现象,当时怀疑是DMA rx buffer不足导致,想通过对比收发包正常和收发包不正常是DMA相关寄存器的情况。
后跟踪代码,若在收发包里面增加打印,必定回降低收发包性能,对比结果也就不准了,分析代码分析来分析去,最终发现做合适的就是采用proc。
1 /* 2 * procfs_example.c: an example proc interface 3 * 4 * Copyright (C) 2001, Erik Mouw (mouw@nl.linux.org) 5 * 6 * This file accompanies the procfs-guide in the Linux kernel 7 * source. Its main use is to demonstrate the concepts and 8 * functions described in the guide. 9 * 10 * This software has been developed while working on the LART 11 * computing board (http://www.lartmaker.nl), which was sponsored 12 * by the Delt University of Technology projects Mobile Multi-media 13 * Communications and Ubiquitous Communications. 14 * 15 * This program is free software; you can redistribute 16 * it and/or modify it under the terms of the GNU General 17 * Public License as published by the Free Software 18 * Foundation; either version 2 of the License, or (at your 19 * option) any later version. 20 * 21 * This program is distributed in the hope that it will be 22 * useful, but WITHOUT ANY WARRANTY; without even the implied 23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 24 * PURPOSE. See the GNU General Public License for more 25 * details. 26 * 27 * You should have received a copy of the GNU General Public 28 * License along with this program; if not, write to the 29 * Free Software Foundation, Inc., 59 Temple Place, 30 * Suite 330, Boston, MA 02111-1307 USA 31 * 32 */ 33 34 #include <linux/module.h> 35 #include <linux/kernel.h> 36 #include <linux/init.h> 37 #include <linux/proc_fs.h> 38 #include <linux/jiffies.h> 39 #include <asm/uaccess.h> 40 41 42 #define MODULE_VERS "1.0" 43 #define MODULE_NAME "procfs_example" 44 45 #define FOOBAR_LEN 8 46 47 struct fb_data_t { 48 char name[FOOBAR_LEN + 1]; 49 char value[FOOBAR_LEN + 1]; 50 }; 51 52 53 static struct proc_dir_entry *example_dir, *foo_file, 54 *bar_file, *jiffies_file, *symlink; 55 56 57 struct fb_data_t foo_data, bar_data; 58 59 60 static int proc_read_jiffies(char *page, char **start, 61 off_t off, int count, 62 int *eof, void *data) 63 { 64 int len; 65 66 len = sprintf(page, "jiffies = %ld ", 67 jiffies); 68 69 return len; 70 } 71 72 73 static int proc_read_foobar(char *page, char **start, 74 off_t off, int count, 75 int *eof, void *data) 76 { 77 int len; 78 struct fb_data_t *fb_data = (struct fb_data_t *)data; 79 80 /* DON'T DO THAT - buffer overruns are bad */ 81 len = sprintf(page, "%s = '%s' ", 82 fb_data->name, fb_data->value); 83 84 return len; 85 } 86 87 88 static int proc_write_foobar(struct file *file, 89 const char *buffer, 90 unsigned long count, 91 void *data) 92 { 93 int len; 94 struct fb_data_t *fb_data = (struct fb_data_t *)data; 95 96 if(count > FOOBAR_LEN) 97 len = FOOBAR_LEN; 98 else 99 len = count; 100 101 if(copy_from_user(fb_data->value, buffer, len)) 102 return -EFAULT; 103 104 fb_data->value[len] = '