-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lkl: let atomic ops outsourced #273
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
extra-y := vmlinux.lds | ||
|
||
obj-y = setup.o threads.o irq.o time.o syscalls.o misc.o console.o \ | ||
syscalls_32.o cpu.o | ||
syscalls_32.o cpu.o atomic.o |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include <linux/kernel.h> | ||
#include <linux/init.h> | ||
#include <asm/host_ops.h> | ||
|
||
#if defined(__ARMEL__) | ||
static void *atomic_lock; | ||
|
||
long lkl__sync_fetch_and_or(long *ptr, long value) | ||
{ | ||
lkl_ops->sem_down(atomic_lock); | ||
*ptr = value; | ||
lkl_ops->sem_up(atomic_lock); | ||
return 0; | ||
} | ||
|
||
long lkl__sync_fetch_and_and(long *ptr, long value) | ||
{ | ||
int tmp; | ||
|
||
lkl_ops->sem_down(atomic_lock); | ||
tmp = *ptr; | ||
*ptr *= value; | ||
lkl_ops->sem_up(atomic_lock); | ||
return tmp; | ||
} | ||
|
||
int lkl__sync_fetch_and_add(int *ptr, int value) | ||
{ | ||
int tmp; | ||
|
||
lkl_ops->sem_down(atomic_lock); | ||
tmp = *ptr; | ||
*ptr += value; | ||
lkl_ops->sem_up(atomic_lock); | ||
return tmp; | ||
} | ||
|
||
int lkl__sync_fetch_and_sub(int *ptr, int value) | ||
{ | ||
int tmp; | ||
|
||
lkl_ops->sem_down(atomic_lock); | ||
tmp = *ptr; | ||
*ptr -= value; | ||
lkl_ops->sem_up(atomic_lock); | ||
return tmp; | ||
} | ||
|
||
void lkl__sync_synchronize(void) | ||
{ | ||
} | ||
|
||
void atomic_ops_init(void) | ||
{ | ||
atomic_lock = lkl_ops->sem_alloc(1); | ||
} | ||
|
||
void atomic_ops_cleanup(void) | ||
{ | ||
lkl_ops->sem_free(atomic_lock); | ||
} | ||
|
||
#else | ||
long lkl__sync_fetch_and_or(long *ptr, long value) | ||
{ | ||
return __sync_fetch_and_or(ptr, value); | ||
} | ||
|
||
long lkl__sync_fetch_and_and(long *ptr, long value) | ||
{ | ||
return __sync_fetch_and_and(ptr, value); | ||
} | ||
|
||
int lkl__sync_fetch_and_add(int *ptr, int value) | ||
{ | ||
return __sync_fetch_and_add(ptr, value); | ||
} | ||
|
||
int lkl__sync_fetch_and_sub(int *ptr, int value) | ||
{ | ||
return __sync_fetch_and_sub(ptr, value); | ||
} | ||
|
||
void lkl__sync_synchronize(void) | ||
{ | ||
return __sync_synchronize(); | ||
} | ||
|
||
void atomic_ops_init(void) | ||
{ | ||
} | ||
|
||
void atomic_ops_cleanup(void) | ||
{ | ||
} | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
#include <asm/cpu.h> | ||
#include <asm/sched.h> | ||
|
||
static volatile int threads_counter; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this PR is a bit outdated: need to update/rebase in advance to apply the latest lkl. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added the code changes to the latest release, so we can see if the patch works for the ARM 32bit platforms. Will let you know if it works or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @thehajime The patch doesn't work for me right now.
The undefined symbol comes from What should I do to get rid of it? I am not professional on GCC toolchain.... |
||
static int threads_counter; | ||
|
||
static int init_ti(struct thread_info *ti) | ||
{ | ||
|
@@ -123,7 +123,7 @@ struct task_struct *__switch_to(struct task_struct *prev, | |
} | ||
|
||
if (_prev->dead) { | ||
__sync_fetch_and_sub(&threads_counter, 1); | ||
lkl__sync_fetch_and_sub(&threads_counter, 1); | ||
lkl_ops->thread_exit(); | ||
} | ||
|
||
|
@@ -193,7 +193,7 @@ int copy_thread(unsigned long clone_flags, unsigned long esp, | |
return -ENOMEM; | ||
} | ||
|
||
__sync_fetch_and_add(&threads_counter, 1); | ||
lkl__sync_fetch_and_add(&threads_counter, 1); | ||
|
||
return 0; | ||
} | ||
|
@@ -220,7 +220,7 @@ void threads_init(void) | |
|
||
void threads_cnt_dec(void) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No such one function is defined and used in the latest code base (a063e16). |
||
{ | ||
__sync_fetch_and_sub(&threads_counter, 1); | ||
lkl__sync_fetch_and_sub(&threads_counter, 1); | ||
} | ||
|
||
void threads_cleanup(void) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this to tools/lkl/lib?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree. I actually wanted to do it in toolks/lkl/lib but was reluctant to add new lkl_host_ops entries for various atomic ops. do you think it's nicer to do int host_ops or have better idea to do it in tools/lkl ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any nicer way to do it and we will need them anyway for SMP support. We may need a different set for SMP, but we can change that later.