私はこれをかなり検索しましたが、間違いなく何かを見逃している可能性があり、http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.htmlとこのhttp:/を読んでいます。 /www.amazon.com/Essential-Device-Drivers-Sreekrishnan-Venkateswaran/dp/0132396556ですが、Linuxカーネルモジュールで作成した大きなアレイを1つあたり200kBまで読み取るのに問題があります。私はARMベースのti-omap3530で開発しています。私は次のように配列を割り当てます:
static unsigned int* captured_params;
static unsigned int* time_params;
captured_params=vmalloc(3500*7*sizeof(unsigned int));
time_params=vmalloc(3500*7*sizeof(unsigned int));
私の読み取り関数は次のようになります(私はこれをおそらく最善の方法で行っていないことに気づきました):
ssize_t tgdev_read(struct file *file, char *buf, size_t count, loff_t *ppos){
/*This file will expect reads in 8-byte chunks, 4 for the data parameter
and 4 for the time parameter*/
struct tg_dev *tg_devp = file->private_data;
unsigned int num_pairs=sample_counter;
static unsigned int pairs_out=0;
static unsigned int sent_successfully=0;
unsigned int* param_ptr;
unsigned int* time_ptr;
pairs_out=(tg_devp->current_pointer)/8;
num_pairs=sample_counter;
if(pairs_out==num_pairs){//all returned end of file
return 0; //EOF
}
while((pairs_out*8)<count){
//update data pointers
time_ptr=&time_params[pairs_out];
param_ptr=&captured_params[pairs_out];
//send user time first
sent_successfully=copy_to_user(&buf[tg_devp->current_pointer],time_ptr,4);
//send param value for that time
sent_successfully=copy_to_user(&buf[tg_devp->current_pointer+4],param_ptr,4);
//update number of pairs sent to user
pairs_out+=1;
//update file_pointer
tg_devp->current_pointer +=8;
}
return pairs_out*8;
}
そして、私はこのようなユーザースペースプログラムでそれを読みました:
int fp;
char* mode="r";
char* fname="/dev/my_device";
unsigned int param[3500*7]={0};
unsigned int time[3500*7]={0};
unsigned int* param_ptr;
unsigned int* time_ptr;
char buff[3500*7*4*2];
int i=0;
int rc=0;
int completed_reads;
fp=open(fname,O_RDONLY);
if(fp<0){
printf("failed to open file EXITING\n");
return 1;
}
rc=read(fp,buff,3500*7*4*2);
completed_reads=(rc-rc%8)/8;
printf("rc=%i cr=%i\n",rc,completed_reads);
for(i=0;i<completed_reads;i++){
param_ptr=¶m[i];
time_ptr=&time[i];
memcpy(param_ptr,&buff[i*8],4);
memcpy(time_ptr,&buff[i*8+4],4);
printf("[%i]%u,%u\n",i,param[i],time[i]);
}
close(fp);
ユーザースペースの読み取りは常に正しいバイト数の読み取りを報告しますが、正しいデータを取得できません。
このソリューションは、上記の3500をもっと小さいものに置き換えるとうまくいくようです(最大1000は問題なく動作します)が、それより上では、ゼロを読み取った配列が各配列の最後のN(同じ数の要素)を埋めるという奇妙な動作が発生します2つの配列のそれぞれの同じポイントで)、シリーズの後半で開始します。たとえば、time / param[0]=読み取りたい元の配列のはるか下にある値。
これは、メモリ処理を十分に理解していないためだと思いますが、これを実行する方法がわかりません。つまり、これらのデータ配列を、読み取りたいまでモジュールに格納します。ユーザースペースに。私が間違っている提案やアイデアは大歓迎です。
お手数をおかけしますが、何卒よろしくお願い申し上げます。