From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Add support for atomic operations on sh user emulation
Date: Sun, 18 Jan 2009 17:59:45 +0100 [thread overview]
Message-ID: <1232297985.10124.23.camel@cocoduo.atr> (raw)
Hi all,
I've got some problem with threads and sh4 user emulation. Let's take a
little example :
------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
static pthread_mutex_t mutex;
static void *
thread_task (int id)
{
while (1)
{
pthread_mutex_lock (&mutex);
printf ("%i Got it !\n", id);
pthread_mutex_unlock (&mutex);
}
}
int
main (int argc, char *argv[])
{
int i, n = 42;
pthread_t th;
pthread_mutex_init (&mutex, NULL);
for (i = 0 ; i < n ; i++)
{
pthread_create (&th, NULL, thread_task, (void *) i);
}
thread_task (n);
return EXIT_SUCCESS;
}
------------------------------------------------------
For those who would like to test, here is a stripped rootfs
http://djdeath.atr.free.fr/rootfs_sh4.tar.gz (from stlinux.com) with
everything to execute this like test (you will find the previous example
compiled in /tmp).
So when starting this program with the current qemu, you will probably
got an assertion (after a random amonth of time) from the libc :
mutex->__data.__owner == 0
The problem is that on SH4 (and probably others) uniprocessor
architectures, there is no atomic instructions (or very few). Atomic
operations related to locking etc... are provided by a kernel emulation
(gUSA). In user mode emulation qemu has to provide this emulation
instead of the kernel that is unaware of the state of the emulated
program (register, stack, etc...) and is probably everytime from a
different architecture.
The following patch provide a way to emulate gUSA, maybe not the best.
This patch is a rewrite of the previous patch I sent on tas.b atomic
operation.
Regards,
--
Lione Landwerlin
O p e n W i d e 14, rue Gaillon 75002 Paris
next reply other threads:[~2009-01-18 16:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-18 16:59 Lionel Landwerlin [this message]
2009-01-18 17:03 ` [Qemu-devel] [PATCH] Add support for atomic operations on sh user emulation Lionel Landwerlin
2009-01-18 18:21 ` Lionel Landwerlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1232297985.10124.23.camel@cocoduo.atr \
--to=lionel.landwerlin@openwide.fr \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).