All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Mark Burton <mark.burton@greensocs.com>
Cc: mttcg@greensocs.com, QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] Fwd: [RFC] Adding multithreads to LDREX/STREX.
Date: Tue, 03 Mar 2015 18:09:12 +0100	[thread overview]
Message-ID: <54F5EAB8.30202@redhat.com> (raw)
In-Reply-To: <2FD1FA8F-D2B7-4088-9BB8-2EF1179A27F9@greensocs.com>



On 03/03/2015 17:47, Mark Burton wrote:
> +inline void arm_exclusive_lock(void)
> +{
> +    if (!cpu_have_exclusive_lock) {
> +        qemu_mutex_lock(&cpu_exclusive_lock);
> +        cpu_have_exclusive_lock = true;
> +    }
> +}
> +
> +inline void arm_exclusive_unlock(void)
> +{
> +    if (cpu_have_exclusive_lock) {
> +        cpu_have_exclusive_lock = false;
> +        qemu_mutex_unlock(&cpu_exclusive_lock);
> +    }
> +}
> +

This is almost but not quite a recursive mutex.  What about changing it
like this:

- arm_exclusive_lock just takes the lock and sets the flag; no "if"

- arm_exclusive_unlock does the opposite, again no "if"

- raise_exception checks the flag and skips "arm_exclusive_lock()" if
already set

The only other question I have is this:

> +    gen_helper_atomic_check(success, cpu_env, addr);
> +    tcg_gen_brcondi_i32(TCG_COND_EQ, success, 0, done_label);

Are you setting cpu_R[rd] correctly in this case?  That is, should you
be jumping to fail_label instead?  That could case a failure to be
reported as a success.

Paolo

> +    tcg_temp_free_i32(success);
> +
> +    /* Store shoudl be OK lets check the value */
> +    tmp = load_reg(s, rt);
> +    TCGv_i64 val64=tcg_temp_new_i64();
>     switch (size) {
>     case 0:
>         gen_aa32_ld8u(tmp, addr, get_mem_index(s));
> @@ -7450,21 +7447,19 @@ static void gen_store_exclusive(DisasContext *s,
> int rd, int rt, int rt2,
>         abort();
>     }
> 
> -    val64 = tcg_temp_new_i64();
>     if (size == 3) {
>         TCGv_i32 tmp2 = tcg_temp_new_i32();
>         TCGv_i32 tmp3 = tcg_temp_new_i32();
> +
>         tcg_gen_addi_i32(tmp2, addr, 4);
>         gen_aa32_ld32u(tmp3, tmp2, get_mem_index(s));
> -        tcg_temp_free_i32(tmp2);
>         tcg_gen_concat_i32_i64(val64, tmp, tmp3);
> -        tcg_temp_free_i32(tmp3);
> +        tcg_temp_free_i32(tmp2);
>     } else {
> -        tcg_gen_extu_i32_i64(val64, tmp);
> +      tcg_gen_extu_i32_i64(val64, tmp);
>     }
>     tcg_temp_free_i32(tmp);
> -
> -    tcg_gen_brcond_i64(TCG_COND_NE, val64, cpu_exclusive_val, fail_label);
> +    tcg_gen_brcond_i64(TCG_COND_NE, cpu_exclusive_val, val64, fail_label);
>     tcg_temp_free_i64(val64);
> 
>     tmp = load_reg(s, rt);
> @@ -7489,12 +7484,16 @@ static void gen_store_exclusive(DisasContext *s,
> int rd, int rt, int rt2,
>         gen_aa32_st32(tmp, addr, get_mem_index(s));
>         tcg_temp_free_i32(tmp);
>     }
> +
> +    gen_helper_atomic_release(cpu_env);
>     tcg_gen_movi_i32(cpu_R[rd], 0);
>     tcg_gen_br(done_label);
> +
>     gen_set_label(fail_label);
> +    gen_helper_atomic_release(cpu_env);
>     tcg_gen_movi_i32(cpu_R[rd], 1);
> +
>     gen_set_label(done_label);
> -    tcg_gen_movi_i64(cpu_exclusive_addr, -1);

  reply	other threads:[~2015-03-03 17:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1425400476-24047-1-git-send-email-fred.konrad@greensocs.com>
2015-03-03 16:47 ` [Qemu-devel] Fwd: [RFC] Adding multithreads to LDREX/STREX Mark Burton
2015-03-03 17:09   ` Paolo Bonzini [this message]
2015-03-03 17:22     ` [Qemu-devel] " Mark Burton

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=54F5EAB8.30202@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=mark.burton@greensocs.com \
    --cc=mttcg@greensocs.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.