Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thehajime
Copy link
Member

@thehajime thehajime commented Nov 21, 2016

This will allow us to reimplpement atomic ops with lock/touch/unlock way
if underlying hosts don't support a particular atomic ops.

Signed-off-by: Hajime Tazaki [email protected]


This change is Reviewable

@@ -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((int *)&threads_counter, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its probably better to just convert threads_counter to long instead of casting here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

atomic_lock = lkl_ops->sem_alloc(1);
return 0;
}
early_initcall(lkl_atomic_ops_init);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are missing the lock free.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. added cleanups.

@@ -0,0 +1,86 @@
#include <linux/kernel.h>
Copy link
Member

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?

Copy link
Member Author

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 ?

Copy link
Member

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.

This will allow us to reimplpement atomic ops with lock/touch/unlock way
if underlying hosts don't support a particular atomic ops.

Signed-off-by: Hajime Tazaki <[email protected]>
@thehajime thehajime force-pushed the fix-atomic-outsource branch from 0865053 to 31e75dd Compare November 22, 2016 12:58
@thehajime
Copy link
Member Author

one thing that I wasn't sure is how to emulate __sync_synchronize() with semaphore in ARM environment. do you see any good idea ?

@tavip
Copy link
Member

tavip commented Nov 22, 2016

about __sync_synchronize() : mutex_lock / mutex_unlock should do it.

I forgot, but what platform is this that gcc doesn't support this builtins?

@thehajime
Copy link
Member Author

about __sync_synchronize() : mutex_lock / mutex_unlock should do it.

don't understand what you described.. do you mean like this ?

void lkl__sync_synchronize(void)
{
	lkl_ops->sem_down(atomic_lock);
	lkl_ops->sem_up(atomic_lock);
}

I forgot, but what platform is this that gcc doesn't support this builtins?

% arm-none-eabi-gcc --version
arm-none-eabi-gcc (Fedora 5.2.0-4.fc24) 5.2.0

@tavip
Copy link
Member

tavip commented Nov 22, 2016

don't understand what you described.. do you mean like this ?
void lkl__sync_synchronize(void)
{
lkl_ops->sem_down(atomic_lock);
lkl_ops->sem_up(atomic_lock);
}

Yes, or the mutex ops, if we have it for that host.

I forgot, but what platform is this that gcc doesn't support this builtins?
% arm-none-eabi-gcc --version
arm-none-eabi-gcc (Fedora 5.2.0-4.fc24) 5.2.0

Hmm, I think you can get the buitins if you switch to using -mcpu=cortex-m4. Do you really need to support anything less then m4?

@tavip
Copy link
Member

tavip commented Nov 22, 2016

Hmm, I think you can get the buitins if you switch to using -mcpu=cortex-m4. Do you really need to support anything less then m4?

Actually it looks that -march=armv7 is better, since it covers both MCUs and CPUs

@thehajime
Copy link
Member Author

Hmm, I think you can get the buitins if you switch to using -mcpu=cortex-m4. Do you really need to support anything less then m4?
Actually it looks that -march=armv7 is better, since it covers both MCUs and CPUs

I'm currently using arm926ej-s cpu (-mcpu arm926ej-s) for the target. This is just a randomly picked (not written by myself). for the qemu test, it might be built/tested with -march=armv7 with available atomic builtins, but for the bare-metal use case, the arm926 target might be also useful.

the atomic ops wrapper is useful for such situations if it is really needed.

@@ -5,7 +5,7 @@
#include <asm/cpu.h>
#include <asm/sched.h>

static volatile int threads_counter;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange that no "threads_counter" is defined in my version ( based on a063e16 - Merge pull request #340 from libos-nuse/fix-checkpath-tak2).

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thehajime The patch doesn't work for me right now.
After changing to lkl__sync_ functions, the __sync_synchronize used in lib/virtio.c becomes undefined once again. Then, I tried to change it to lkl__sync_synchronize and compile, what I got is that there're two lkl__sync_synchronize symbols in liblkl-hijack.so:

00061454 l     F .text	00000044              lkl__sync_synchronize
00000000         *UND*	00000000              lkl__sync_synchronize

The undefined symbol comes from lib/lkl-in.o, the defined one comes from lib/lkl.o. When running AR to generate liblkl.a based on lkl-in.o and lkl.o, the two symbols are joint together.

What should I do to get rid of it? I am not professional on GCC toolchain....

@@ -220,7 +220,7 @@ void threads_init(void)

void threads_cnt_dec(void)
Copy link

Choose a reason for hiding this comment

The 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants