Skip to content

Commit b43930b

Browse files
author
Octavian Purdila
committed
Merge pull request torvalds#114 from pscollins/atomic-thread-counter
lkl: Replace threads_counter_lock with atomic ops
2 parents 0cfb248 + 93fa441 commit b43930b

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

arch/lkl/kernel/threads.c

+4-38
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,7 @@
33
#include <linux/sched.h>
44
#include <asm/host_ops.h>
55

6-
static int threads_counter;
7-
static void *threads_counter_lock;
8-
9-
static inline void threads_counter_inc(void)
10-
{
11-
lkl_ops->sem_down(threads_counter_lock);
12-
threads_counter++;
13-
lkl_ops->sem_up(threads_counter_lock);
14-
}
15-
16-
static inline void threads_counter_dec(void)
17-
{
18-
lkl_ops->sem_down(threads_counter_lock);
19-
threads_counter--;
20-
lkl_ops->sem_up(threads_counter_lock);
21-
}
22-
23-
static inline int threads_counter_get(void)
24-
{
25-
int counter;
26-
27-
lkl_ops->sem_down(threads_counter_lock);
28-
counter = threads_counter;
29-
lkl_ops->sem_up(threads_counter_lock);
30-
31-
return counter;
32-
}
6+
static volatile int threads_counter;
337

348
struct thread_info *alloc_thread_info_node(struct task_struct *task, int node)
359
{
@@ -123,7 +97,7 @@ struct task_struct *__switch_to(struct task_struct *prev,
12397

12498
if (ei.dead) {
12599
lkl_ops->sem_free(ei.sched_sem);
126-
threads_counter_dec();
100+
__sync_fetch_and_sub(&threads_counter, 1);
127101
lkl_ops->thread_exit();
128102
}
129103

@@ -175,7 +149,7 @@ int copy_thread(unsigned long clone_flags, unsigned long esp,
175149
return -ENOMEM;
176150
}
177151

178-
threads_counter_inc();
152+
__sync_fetch_and_add(&threads_counter, 1);
179153

180154
return 0;
181155
}
@@ -209,13 +183,6 @@ int threads_init(void)
209183
goto out;
210184
}
211185

212-
threads_counter_lock = lkl_ops->sem_alloc(1);
213-
if (!threads_counter_lock) {
214-
pr_early("lkl: failed to alllocate threads counter lock\n");
215-
ret = -ENOMEM;
216-
goto out_free_init_sched_sem;
217-
}
218-
219186
return 0;
220187

221188
out_free_init_sched_sem:
@@ -241,9 +208,8 @@ void threads_cleanup(void)
241208
kill_thread(ti->exit_info);
242209
}
243210

244-
while (threads_counter_get())
211+
while (threads_counter)
245212
;
246213

247214
lkl_ops->sem_free(init_thread_union.thread_info.sched_sem);
248-
lkl_ops->sem_free(threads_counter_lock);
249215
}

0 commit comments

Comments
 (0)