Re: [PATCH repost] sched: export sched_set/getaffinity to modules

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Sridhar Samudrala
Date: Monday, July 26, 2010 - 10:51 am

On Mon, 2010-07-26 at 20:12 +0300, Michael S. Tsirkin wrote:


I have been testing out a similar patch that uses kernel_thread() without CLONE_FILES
flag rather than create_kthread() and then closing the files.
Either version should be fine.

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index aabc8a1..634eaf7 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -9,6 +9,11 @@ struct task_struct *kthread_create(int (*threadfn)(void *data),
 				   const char namefmt[], ...)
 	__attribute__((format(printf, 3, 4)));
 
+struct task_struct *kthread_clone(int (*threadfn)(void *data),
+				  void *data,
+				  const char namefmt[], ...)
+	__attribute__((format(printf, 3, 4)));
+
 /**
  * kthread_run - create and wake a thread.
  * @threadfn: the function to run until signal_pending(current).
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 83911c7..806dae5 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -149,6 +149,38 @@ struct task_struct *kthread_create(int (*threadfn)(void *data),
 }
 EXPORT_SYMBOL(kthread_create);
 
+struct task_struct *kthread_clone(int (*threadfn)(void *data),
+				  void *data,
+				  const char namefmt[],
+				  ...)
+{
+	struct kthread_create_info create;
+	int pid;
+
+	create.threadfn = threadfn;
+	create.data = data;
+	init_completion(&create.done);
+	INIT_LIST_HEAD(&create.list);
+
+	pid = kernel_thread(kthread, &create, CLONE_FS);
+	if (pid < 0) {
+		create.result = ERR_PTR(pid);
+		complete(&create.done);
+	}
+	wait_for_completion(&create.done);
+
+	if (!IS_ERR(create.result)) {
+		va_list args;
+		va_start(args, namefmt);
+		vsnprintf(create.result->comm, sizeof(create.result->comm),
+			  namefmt, args);
+		va_end(args);
+	}
+
+	return create.result;
+}
+EXPORT_SYMBOL(kthread_clone);
+
 /**
  * kthread_bind - bind a just-created kthread to a cpu.
  * @p: thread created by kthread_create().





--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 2/3] workqueue: Add an API to create a singlethread ..., Sridhar Samudrala, (Tue May 18, 5:04 pm)
Re: [PATCH 2/3] workqueue: Add an API to create a singleth ..., Michael S. Tsirkin, (Thu May 27, 2:14 am)
Re: [PATCH 2/3] workqueue: Add an API to create a singleth ..., Michael S. Tsirkin, (Thu May 27, 6:12 am)
Re: [PATCH 2/3] workqueue: Add an API to create a singleth ..., Sridhar Samudrala, (Thu May 27, 9:24 am)
Re: [PATCH 2/3] workqueue: Add an API to create a singleth ..., Michael S. Tsirkin, (Thu May 27, 9:41 am)
Re: [PATCH 2/3] workqueue: Add an API to create a singleth ..., Michael S. Tsirkin, (Thu May 27, 10:32 am)
Re: [PATCH 2/3] workqueue: Add an API to create a singleth ..., Michael S. Tsirkin, (Fri May 28, 8:08 am)
Re: [PATCH 2/3] workqueue: Add an API to create a singleth ..., Michael S. Tsirkin, (Sun May 30, 4:29 am)
Re: [PATCH 1/3] vhost: replace vhost_workqueue with per-vh ..., Michael S. Tsirkin, (Mon May 31, 8:22 am)
Re: [PATCH 1/3] vhost: replace vhost_workqueue with per-vh ..., Michael S. Tsirkin, (Mon May 31, 9:00 am)
Re: [PATCH 3/3] vhost: apply cpumask and cgroup to vhost w ..., Michael S. Tsirkin, (Tue Jun 1, 3:17 am)
Re: [PATCH 3/3] vhost: apply cpumask and cgroup to vhost w ..., Sridhar Samudrala, (Tue Jun 1, 10:19 am)
Re: [PATCH 3/3] vhost: apply cpumask and cgroup to vhost p ..., Michael S. Tsirkin, (Thu Jun 24, 1:11 am)
Re: [PATCH 3/3] vhost: apply cpumask and cgroup to vhost p ..., Sridhar Samudrala, (Thu Jun 24, 3:45 pm)
[PATCH] sched: export sched_set/getaffinity (was Re: [PATC ..., Michael S. Tsirkin, (Fri Jun 25, 3:10 am)
[PATCH repost] sched: export sched_set/getaffinity to modules, Michael S. Tsirkin, (Thu Jul 1, 4:07 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Thu Jul 1, 4:55 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Thu Jul 1, 5:23 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Thu Jul 1, 5:50 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Thu Jul 1, 6:08 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Thu Jul 1, 6:22 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Sridhar Samudrala, (Fri Jul 2, 11:01 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Sun Jul 4, 2:00 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Sridhar Samudrala, (Mon Jul 12, 11:59 pm)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Tue Jul 13, 4:09 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Sridhar Samudrala, (Wed Jul 14, 4:26 pm)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Thu Jul 22, 8:58 am)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Sat Jul 24, 12:14 pm)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Sun Jul 25, 3:04 am)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 8:25 am)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 8:50 am)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 8:51 am)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 9:23 am)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 9:31 am)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 9:51 am)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 9:57 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Mon Jul 26, 10:12 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Sridhar Samudrala, (Mon Jul 26, 10:51 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Mon Jul 26, 12:55 pm)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 12:57 pm)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 12:59 pm)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Mon Jul 26, 1:19 pm)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Mon Jul 26, 1:27 pm)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Mon Jul 26, 9:55 pm)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Tue Jul 27, 8:41 am)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Tue Jul 27, 12:19 pm)
Re: [PATCH UPDATED 1/3] vhost: replace vhost_workqueue wit ..., Michael S. Tsirkin, (Wed Jul 28, 3:48 am)
Re: [PATCH repost] sched: export sched_set/getaffinity to ..., Michael S. Tsirkin, (Sun Aug 1, 1:50 am)