Patchwork [16/22] Introduce VCPU self-signaling service

login
register
mail settings
Submitter Jan Kiszka
Date Jan. 27, 2011, 1:10 p.m.
Message ID <7e0c7b87e31857bf017d7dd96074ed11e7257529.1296133797.git.jan.kiszka@siemens.com>
Download mbox | patch
Permalink /patch/80688/
State New
Headers show

Comments

Jan Kiszka - Jan. 27, 2011, 1:10 p.m.
Introduce qemu_cpu_kick_self to send SIG_IPI to the calling VCPU
context. First user will be kvm.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 cpus.c        |   21 +++++++++++++++++++++
 qemu-common.h |    1 +
 2 files changed, 22 insertions(+), 0 deletions(-)
Marcelo Tosatti - Feb. 1, 2011, 1:14 p.m.
On Thu, Jan 27, 2011 at 02:10:00PM +0100, Jan Kiszka wrote:
> Introduce qemu_cpu_kick_self to send SIG_IPI to the calling VCPU
> context. First user will be kvm.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  cpus.c        |   21 +++++++++++++++++++++
>  qemu-common.h |    1 +
>  2 files changed, 22 insertions(+), 0 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index bba59e5..88bed4e 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -531,6 +531,17 @@ void qemu_cpu_kick(void *env)
>      return;
>  }
>  
> +void qemu_cpu_kick_self(void)
> +{
> +#ifndef _WIN32
> +    assert(cpu_single_env);
> +
> +    raise(SIG_IPI);
> +#else
> +    abort();
> +#endif
> +}
> +
>  void qemu_notify_event(void)
>  {
>      CPUState *env = cpu_single_env;
> @@ -808,6 +819,16 @@ void qemu_cpu_kick(void *_env)
>      }
>  }
>  
> +void qemu_cpu_kick_self(void)
> +{
> +    assert(cpu_single_env);
> +
> +    if (!cpu_single_env->thread_kicked) {
> +        qemu_thread_signal(cpu_single_env->thread, SIG_IPI);
> +        cpu_single_env->thread_kicked = true;
> +    }
> +}
> +

There is no need to use cpu_single_env, can pass CPUState instead.
Jan Kiszka - Feb. 1, 2011, 1:33 p.m.
On 2011-02-01 14:14, Marcelo Tosatti wrote:
> On Thu, Jan 27, 2011 at 02:10:00PM +0100, Jan Kiszka wrote:
>> Introduce qemu_cpu_kick_self to send SIG_IPI to the calling VCPU
>> context. First user will be kvm.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>>  cpus.c        |   21 +++++++++++++++++++++
>>  qemu-common.h |    1 +
>>  2 files changed, 22 insertions(+), 0 deletions(-)
>>
>> diff --git a/cpus.c b/cpus.c
>> index bba59e5..88bed4e 100644
>> --- a/cpus.c
>> +++ b/cpus.c
>> @@ -531,6 +531,17 @@ void qemu_cpu_kick(void *env)
>>      return;
>>  }
>>  
>> +void qemu_cpu_kick_self(void)
>> +{
>> +#ifndef _WIN32
>> +    assert(cpu_single_env);
>> +
>> +    raise(SIG_IPI);
>> +#else
>> +    abort();
>> +#endif
>> +}
>> +
>>  void qemu_notify_event(void)
>>  {
>>      CPUState *env = cpu_single_env;
>> @@ -808,6 +819,16 @@ void qemu_cpu_kick(void *_env)
>>      }
>>  }
>>  
>> +void qemu_cpu_kick_self(void)
>> +{
>> +    assert(cpu_single_env);
>> +
>> +    if (!cpu_single_env->thread_kicked) {
>> +        qemu_thread_signal(cpu_single_env->thread, SIG_IPI);
>> +        cpu_single_env->thread_kicked = true;
>> +    }
>> +}
>> +
> 
> There is no need to use cpu_single_env, can pass CPUState instead.
> 

It's done intentionally this way: function shall not be used for a
remote env.

Jan
Marcelo Tosatti - Feb. 1, 2011, 1:50 p.m.
On Tue, Feb 01, 2011 at 02:33:45PM +0100, Jan Kiszka wrote:
> >> +++ b/cpus.c
> >> @@ -531,6 +531,17 @@ void qemu_cpu_kick(void *env)
> >>      return;
> >>  }
> >>  
> >> +void qemu_cpu_kick_self(void)
> >> +{
> >> +#ifndef _WIN32
> >> +    assert(cpu_single_env);
> >> +
> >> +    raise(SIG_IPI);
> >> +#else
> >> +    abort();
> >> +#endif
> >> +}
> >> +
> >>  void qemu_notify_event(void)
> >>  {
> >>      CPUState *env = cpu_single_env;
> >> @@ -808,6 +819,16 @@ void qemu_cpu_kick(void *_env)
> >>      }
> >>  }
> >>  
> >> +void qemu_cpu_kick_self(void)
> >> +{
> >> +    assert(cpu_single_env);
> >> +
> >> +    if (!cpu_single_env->thread_kicked) {
> >> +        qemu_thread_signal(cpu_single_env->thread, SIG_IPI);
> >> +        cpu_single_env->thread_kicked = true;
> >> +    }
> >> +}
> >> +
> > 
> > There is no need to use cpu_single_env, can pass CPUState instead.
> > 
> 
> It's done intentionally this way: function shall not be used for a
> remote env.
> 
> Jan

Can assert on qemu_cpu_self(env) for that.
Jan Kiszka - Feb. 1, 2011, 1:59 p.m.
On 2011-02-01 14:50, Marcelo Tosatti wrote:
> On Tue, Feb 01, 2011 at 02:33:45PM +0100, Jan Kiszka wrote:
>>>> +++ b/cpus.c
>>>> @@ -531,6 +531,17 @@ void qemu_cpu_kick(void *env)
>>>>      return;
>>>>  }
>>>>  
>>>> +void qemu_cpu_kick_self(void)
>>>> +{
>>>> +#ifndef _WIN32
>>>> +    assert(cpu_single_env);
>>>> +
>>>> +    raise(SIG_IPI);
>>>> +#else
>>>> +    abort();
>>>> +#endif
>>>> +}
>>>> +
>>>>  void qemu_notify_event(void)
>>>>  {
>>>>      CPUState *env = cpu_single_env;
>>>> @@ -808,6 +819,16 @@ void qemu_cpu_kick(void *_env)
>>>>      }
>>>>  }
>>>>  
>>>> +void qemu_cpu_kick_self(void)
>>>> +{
>>>> +    assert(cpu_single_env);
>>>> +
>>>> +    if (!cpu_single_env->thread_kicked) {
>>>> +        qemu_thread_signal(cpu_single_env->thread, SIG_IPI);
>>>> +        cpu_single_env->thread_kicked = true;
>>>> +    }
>>>> +}
>>>> +
>>>
>>> There is no need to use cpu_single_env, can pass CPUState instead.
>>>
>>
>> It's done intentionally this way: function shall not be used for a
>> remote env.
>>
>> Jan
> 
> Can assert on qemu_cpu_self(env) for that.
> 

We already assert on cpu_single_env which is the right condition.
Removing env from the parameter list avoids that someone even thinks
about misusing it.

Jan

Patch

diff --git a/cpus.c b/cpus.c
index bba59e5..88bed4e 100644
--- a/cpus.c
+++ b/cpus.c
@@ -531,6 +531,17 @@  void qemu_cpu_kick(void *env)
     return;
 }
 
+void qemu_cpu_kick_self(void)
+{
+#ifndef _WIN32
+    assert(cpu_single_env);
+
+    raise(SIG_IPI);
+#else
+    abort();
+#endif
+}
+
 void qemu_notify_event(void)
 {
     CPUState *env = cpu_single_env;
@@ -808,6 +819,16 @@  void qemu_cpu_kick(void *_env)
     }
 }
 
+void qemu_cpu_kick_self(void)
+{
+    assert(cpu_single_env);
+
+    if (!cpu_single_env->thread_kicked) {
+        qemu_thread_signal(cpu_single_env->thread, SIG_IPI);
+        cpu_single_env->thread_kicked = true;
+    }
+}
+
 int qemu_cpu_self(void *_env)
 {
     CPUState *env = _env;
diff --git a/qemu-common.h b/qemu-common.h
index 63d9943..220c8c8 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -287,6 +287,7 @@  void qemu_notify_event(void);
 
 /* Unblock cpu */
 void qemu_cpu_kick(void *env);
+void qemu_cpu_kick_self(void);
 int qemu_cpu_self(void *env);
 
 /* work queue */