Commit f7a0d131 authored by 张雪芹's avatar 张雪芹
Browse files

add oscource shiyan3 task1

parent 97185070
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11,6 +11,6 @@ BBFILE_PRIORITY_meta-oscourse = "8"
LAYERVERSION_meta-oscourse = "1"
LAYERDEPENDS_meta-oscourse = "core"
LAYERSERIES_COMPAT_meta-oscourse = "honister"
MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "hello kmalloc-mod vmalloc-mod request-region request-mem-region "    
MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "hello kmalloc-mod vmalloc-mod request-region request-mem-region kthread"    
KERNEL_MODULE_AUTOLOAD += "hello kmalloc-mod vmalloc-mod request-region request-mem-region "
+13 −0
Original line number Diff line number Diff line
obj-m += kthread.o

SRC := $(shell pwd)

all:
	$(MAKE) -C $(KERNEL_SRC) M=$(SRC)

modules_install:
	$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install

clean:
	$(MAKE) -C $(KERNEL_SRC) M=$(SRC) clean
+48 −0
Original line number Diff line number Diff line

#include <linux/module.h>
#include <linux/kthread.h> 
#include <linux/delay.h> 

static int demo_thr(void *data)
{
    while(!kthread_should_stop())
    {
         printk(KERN_ALERT"Name:Stu No.\n");
		 printk(KERN_ALERT"New thread is  running!\n");
         msleep(9000);      
     }
    return 0;
}

static struct task_struct *thr = NULL;
static int __init kthread_init(void)
{
 
	printk(KERN_ALERT"Create kernel  thread!\n");
	
    thr = kthread_run(demo_thr,NULL,"kthread-demo");
    if(!thr)
    {
         printk(KERN_ALERT"kthread_run fail\n");
         return -1;
    }
	return 0;
}
 

static void __exit kthread_exit(void)
{
   if(thr)
   { 
         kthread_stop(thr);
         thr =NULL;
    }
	printk(KERN_ALERT"Kill kernel  thread.\n");
 
}
 
module_init(kthread_init);
module_exit(kthread_exit);
MODULE_LICENSE("GPL");

+14 −0
Original line number Diff line number Diff line
LICENSE = "CLOSED"

SRC_URI = "file://kthread.c \
           file://Makefile \
         "

inherit module 

S = "${WORKDIR}"

# The inherit of module.bbclass will automatically name module packages with
# "kernel-module-" prefix as required by the oe-core build environment.

RPROVIDES:${PN} += "kernel-module-kthread"