Skip to contentSkip to conversation

kthread abstraction

RFC PATCH Andi Kleen 2 participants 3 messages Feb 1, 2002 1 message not in the archive

lore
Share & tools
lore

Andi Kleen

author
#1 lore raw
In reply to a message not in the archive
Quoted 3 lines · Christoph Hellwig

void *data;

Opaque data for the thread's use.

That requires to dynamically allocate and initialize kthread if you can have potentially multiple threads (= too much to write)

I think it would be better to pass data as a separate argument. You can put the kthread and the data into a private structure on the stack, pass the address of it to kernel_thread and wait until the thread has read it using a completion.

That would make a nicer API.

-Andi

#2 lore raw
In reply to a message not in the archive
Quoted 7 lines · Andi Kleen
Quoted 3 lines · Christoph Hellwig

void *data;

Opaque data for the thread's use.

Quoted 7 lines

That requires to dynamically allocate and initialize kthread if you can have potentially multiple threads (= too much to write)

I think it would be better to pass data as a separate argument. You can put the kthread and the data into a private structure on the stack, pass the address of it to kernel_thread and wait until the thread has read it using a completion.

Agreed. I will rework the patch to follow your suggestion.

Christoph

Signature · 1 line
Of course it doesn't work. We've performed a software upgrade.
#3 lore raw
In reply to a message not in the archive
Quoted 4 lines · Andi Kleen

I think it would be better to pass data as a separate argument. You can put the kthread and the data into a private structure on the stack, pass the address of it to kernel_thread and wait until the thread has read it using a completion.

Reworked version below.

include/linux/kthread.h renamed from master/linux-2.5.3/include/linux/kthread.h +22 -0
diff -uNr -Xdontdiff ../master/linux-2.5.3/include/linux/kthread.h linux/include/linux/kthread.h
@@ -0,0 +1,22 @@
+#ifndef _LINUX_KTHREAD_H
+#define _LINUX_KTHREAD_H
+
+struct task_struct;
+
+struct kthread {
+	const char *name;
+	struct task_struct *task;
+	struct completion done;
+#define KTH_RUNNING	1
+#define KTH_SHUTDOWN	2
+	long state;
+	int (*init)(struct kthread *, void *);
+	void (*cleanup)(struct kthread *, void *);
+	void (*main)(struct kthread *, void *);
+};
+
+extern int kthread_start(struct kthread *, void *);
+extern void kthread_stop(struct kthread *);
+extern int kthread_running(struct kthread *);
+
+#endif /* _LINUX_KTHREAD_H */
kernel/Makefile renamed from master/linux-2.5.3/kernel/Makefile +2 -2
diff -uNr -Xdontdiff ../master/linux-2.5.3/kernel/Makefile linux/kernel/Makefile
@@ -10,12 +10,12 @@
 O_TARGET := kernel.o
 
 export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
-		printk.o 
+		printk.o kthread.o
 
 obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o info.o time.o softirq.o resource.o \
 	    sysctl.o acct.o capability.o ptrace.o timer.o user.o \
-	    signal.o sys.o kmod.o context.o 
+	    signal.o sys.o kmod.o context.o kthread.o
 
 obj-$(CONFIG_UID16) += uid16.o
 obj-$(CONFIG_MODULES) += ksyms.o
kernel/kthread.c renamed from master/linux-2.5.3/kernel/kthread.c +149 -0

149 lines not on this page · raw message