~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to kernel/kthread.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
        /* Information passed to kthread() from kthreadd. */
28
28
        int (*threadfn)(void *data);
29
29
        void *data;
 
30
        int node;
30
31
 
31
32
        /* Result passed back to kthread_create() from kthreadd. */
32
33
        struct task_struct *result;
98
99
        do_exit(ret);
99
100
}
100
101
 
 
102
/* called from do_fork() to get node information for about to be created task */
 
103
int tsk_fork_get_node(struct task_struct *tsk)
 
104
{
 
105
#ifdef CONFIG_NUMA
 
106
        if (tsk == kthreadd_task)
 
107
                return tsk->pref_node_fork;
 
108
#endif
 
109
        return numa_node_id();
 
110
}
 
111
 
101
112
static void create_kthread(struct kthread_create_info *create)
102
113
{
103
114
        int pid;
104
115
 
 
116
#ifdef CONFIG_NUMA
 
117
        current->pref_node_fork = create->node;
 
118
#endif
105
119
        /* We want our own signal handler (we take no signals by default). */
106
120
        pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
107
121
        if (pid < 0) {
111
125
}
112
126
 
113
127
/**
114
 
 * kthread_create - create a kthread.
 
128
 * kthread_create_on_node - create a kthread.
115
129
 * @threadfn: the function to run until signal_pending(current).
116
130
 * @data: data ptr for @threadfn.
 
131
 * @node: memory node number.
117
132
 * @namefmt: printf-style name for the thread.
118
133
 *
119
134
 * Description: This helper function creates and names a kernel
120
135
 * thread.  The thread will be stopped: use wake_up_process() to start
121
136
 * it.  See also kthread_run().
122
137
 *
 
138
 * If thread is going to be bound on a particular cpu, give its node
 
139
 * in @node, to get NUMA affinity for kthread stack, or else give -1.
123
140
 * When woken, the thread will run @threadfn() with @data as its
124
141
 * argument. @threadfn() can either call do_exit() directly if it is a
125
 
 * standalone thread for which noone will call kthread_stop(), or
 
142
 * standalone thread for which no one will call kthread_stop(), or
126
143
 * return when 'kthread_should_stop()' is true (which means
127
144
 * kthread_stop() has been called).  The return value should be zero
128
145
 * or a negative error number; it will be passed to kthread_stop().
129
146
 *
130
147
 * Returns a task_struct or ERR_PTR(-ENOMEM).
131
148
 */
132
 
struct task_struct *kthread_create(int (*threadfn)(void *data),
133
 
                                   void *data,
134
 
                                   const char namefmt[],
135
 
                                   ...)
 
149
struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
 
150
                                           void *data,
 
151
                                           int node,
 
152
                                           const char namefmt[],
 
153
                                           ...)
136
154
{
137
155
        struct kthread_create_info create;
138
156
 
139
157
        create.threadfn = threadfn;
140
158
        create.data = data;
 
159
        create.node = node;
141
160
        init_completion(&create.done);
142
161
 
143
162
        spin_lock(&kthread_create_lock);
164
183
        }
165
184
        return create.result;
166
185
}
167
 
EXPORT_SYMBOL(kthread_create);
 
186
EXPORT_SYMBOL(kthread_create_on_node);
168
187
 
169
188
/**
170
189
 * kthread_bind - bind a just-created kthread to a cpu.
183
202
                return;
184
203
        }
185
204
 
186
 
        p->cpus_allowed = cpumask_of_cpu(cpu);
187
 
        p->rt.nr_cpus_allowed = 1;
 
205
        /* It's safe because the task is inactive. */
 
206
        do_set_cpus_allowed(p, cpumask_of(cpu));
188
207
        p->flags |= PF_THREAD_BOUND;
189
208
}
190
209
EXPORT_SYMBOL(kthread_bind);