8000 内核线程无限提供数据给 共享内存 · home-coder/ring-buffer@50f404f · GitHub
[go: up one dir, main page]

Skip to content

Commit 50f404f

Browse files
committed
内核线程无限提供数据给 共享内存
1 parent 775792d commit 50f404f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

helper/kernel/pages.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22
#include <linux/module.h>
33
#include <linux/kernel.h>
44
#include <linux/mm.h>
5+
#include <linux/delay.h>
56

67
static unsigned long p = 0;
78
static unsigned long pp = 0;
9+
int count = 0;
10+
char buf[32];
11+
12+
static int put_pages(void *p)
13+
{
14+
while (1) {
15+
msleep(20);
16+
sprintf(buf, "hello %d\n", count++ % 1000);
17+
strcpy((char *)p, buf);
18+
}
19+
return 0;
20+
}
821

922
static int __init shao_init(void)
1023
{
@@ -18,8 +31,7 @@ static int __init shao_init(void)
1831
printk("<1> pp = 0x%lx\n", pp);
1932

2033
//在共享内存中写上一个字符串
21-
22-
strcpy((char *)p, "hello\n");
34+
kernel_thread(put_pages, (void *)p, 0);
2335
return 0;
2436
}
2537

helper/linux/mmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#define PAGE_SIZE (4*1024)
88
#define PAGE_OFFSET 0xc0000000
9-
#define KERNEL_VIRT_ADDR 0x20207000 //此处地址即为内核模块打印的地址p,动态的不固定,需要自行修改
9+
#define KERNEL_VIRT_ADDR 0x22cb7000 //此处地址即为内核模块打印的地址p,动态的不固定,需要自行修改
1010

1111
int main()
1212
{
@@ -22,6 +22,7 @@ int main()
2222
buf = mmap(0, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, phy_addr);
2323
if (buf == MAP_FAILED)
2424
perror("mmap");
25+
while (1)
2526
puts(buf); //打印共享内存的内容
2627
munmap(buf, PAGE_SIZE);
2728
close(fd);

0 commit comments

Comments
 (0)
0