Linux 如何加速读取/写入属性数据?
我在sys文件系统中使用了文件属性,它允许用户空间使用SysFS与驱动程序通信。问题是我有很多数据要传输,所以我浪费了很多时间。这是一个非常缓慢的过程 在犬舍模块中,我有这部分代码:Linux 如何加速读取/写入属性数据?,linux,module,filesystems,Linux,Module,Filesystems,我在sys文件系统中使用了文件属性,它允许用户空间使用SysFS与驱动程序通信。问题是我有很多数据要传输,所以我浪费了很多时间。这是一个非常缓慢的过程 在犬舍模块中,我有这部分代码: static DEVICE_ATTR(writeFile,S_IWUSR,NULL,writeFunction); static DEVICE_ATTR(resultFile,S_IRUSR, readFunction, NULL); static ssize_t writeFunction(struc
static DEVICE_ATTR(writeFile,S_IWUSR,NULL,writeFunction);
static DEVICE_ATTR(resultFile,S_IRUSR, readFunction, NULL);
static ssize_t writeFunction(struct device *dev, struct device_attribute *attr,
const char * buf, size_t count) {
if(count >0){
resp_ready = 1;
sscanf(buf,"%2x,",&src_vect[0]);
for (i=0;i<80;i++)
{
sscanf(buf+3+12*i,"%2x,%2x,%2x,%2x,",&src_vect[4*i+1],&src_vect[4*i+2],&src_vect[4*i+3],&src_vect[4*i+4]);
}
.
.
.
}
static ssize_t readFunction(struct device *dev, struct device_attribute *attr, char *buf) {
//write the result to buf
for (i=0;i<6;i++)
{
sprintf(buf+72*i,"%8x,%8x,%8x,%8x,%8x,%8x,%8x,%8x,",dst_f[8*i],dst_f[8*i+1],dst_f[8*i+2],dst_f[8*i+3],dst_f[8*i+4],dst_f[8*i+5],dst_f[8*i+6],dst_f[8*i+7]);
}
.
.
.
}
静态设备属性(writeFile、S\u IWUSR、NULL、writeFunction);
静态设备属性(resultFile,S\u IRUSR,readFunction,NULL);
静态ssize_t writeFunction(结构设备*dev,结构设备属性*attr,
常量字符*buf,大小(计数){
如果(计数>0){
resp_ready=1;
sscanf(buf、%2x、&src_vect[0]);
对于(i=0;i任何建议或帮助请求printf/sscanf相当慢。请将其更改为读/写二进制数据。您使用的“%x”至少比“%d”快得多,但仍然比根本不进行转换慢得多。