public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] kvm tools: Introduce a helper to block a singal for a thread
@ 2011-06-15 16:48 Asias He
  2011-06-15 16:48 ` [PATCH 2/6] kvm tools: Block SIGALRM for both rx and tx thread for virtio net Asias He
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Asias He @ 2011-06-15 16:48 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
	Asias He

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/include/kvm/util.h |    2 ++
 tools/kvm/util.c             |   13 +++++++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index a9425cc..95d86b9 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -68,4 +68,6 @@ static inline const char *skip_prefix(const char *str, const char *prefix)
 	return strncmp(str, prefix, len) ? NULL : str + len;
 }
 
+int sig_block(int n);
+
 #endif /* KVM__UTIL_H */
diff --git a/tools/kvm/util.c b/tools/kvm/util.c
index 4efbce9..204230e 100644
--- a/tools/kvm/util.c
+++ b/tools/kvm/util.c
@@ -3,6 +3,7 @@
  */
 
 #include "kvm/util.h"
+#include <signal.h>
 
 static void report(const char *prefix, const char *err, va_list params)
 {
@@ -99,3 +100,15 @@ size_t strlcat(char *dest, const char *src, size_t count)
 
 	return res;
 }
+
+int sig_block(int n)
+{
+	sigset_t sigset;
+	int ret;
+
+	sigemptyset(&sigset);
+	sigaddset(&sigset, n);
+	ret = pthread_sigmask(SIG_BLOCK, &sigset, NULL);
+
+	return ret;
+}
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/6] kvm tools: Block SIGALRM for both rx and tx thread for virtio net
  2011-06-15 16:48 [PATCH 1/6] kvm tools: Introduce a helper to block a singal for a thread Asias He
@ 2011-06-15 16:48 ` Asias He
  2011-06-15 16:48 ` [PATCH 3/6] kvm tools: Block SIGALRM for theadpool thread Asias He
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Asias He @ 2011-06-15 16:48 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
	Asias He

In the user mode network development process, SIGALRM makes getaddrinfo()
fails in virtio net thread. Blocking SIGALRM solves this problem.

SIGALRM is used by the console code to inject interrupt periodically.

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/virtio/net.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 6916af6..ad5fa3f 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -91,6 +91,8 @@ static void *virtio_net_rx_thread(void *p)
 	u16 head;
 	int len;
 
+	sig_block(SIGALRM);
+
 	kvm	= p;
 	vq	= &ndev.vqs[VIRTIO_NET_RX_QUEUE];
 
@@ -125,6 +127,8 @@ static void *virtio_net_tx_thread(void *p)
 	u16 head;
 	int len;
 
+	sig_block(SIGALRM);
+
 	kvm	= p;
 	vq	= &ndev.vqs[VIRTIO_NET_TX_QUEUE];
 
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/6] kvm tools: Block SIGALRM for theadpool thread
  2011-06-15 16:48 [PATCH 1/6] kvm tools: Introduce a helper to block a singal for a thread Asias He
  2011-06-15 16:48 ` [PATCH 2/6] kvm tools: Block SIGALRM for both rx and tx thread for virtio net Asias He
@ 2011-06-15 16:48 ` Asias He
  2011-06-15 16:48 ` [PATCH 4/6] kvm tools: Block SIGALRM for ioeventfd thread Asias He
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Asias He @ 2011-06-15 16:48 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
	Asias He

thread pool thread is not interested in SIGALRM as well.

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/threadpool.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/threadpool.c b/tools/kvm/threadpool.c
index 2db02184..fbd4887 100644
--- a/tools/kvm/threadpool.c
+++ b/tools/kvm/threadpool.c
@@ -5,6 +5,7 @@
 #include <linux/list.h>
 #include <pthread.h>
 #include <stdbool.h>
+#include <signal.h>
 
 struct thread_pool__job {
 	kvm_thread_callback_fn_t	callback;
@@ -85,6 +86,9 @@ static void thread_pool__threadfunc_cleanup(void *param)
 
 static void *thread_pool__threadfunc(void *param)
 {
+
+	sig_block(SIGALRM);
+
 	pthread_cleanup_push(thread_pool__threadfunc_cleanup, NULL);
 
 	for (;;) {
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/6] kvm tools: Block SIGALRM for ioeventfd thread
  2011-06-15 16:48 [PATCH 1/6] kvm tools: Introduce a helper to block a singal for a thread Asias He
  2011-06-15 16:48 ` [PATCH 2/6] kvm tools: Block SIGALRM for both rx and tx thread for virtio net Asias He
  2011-06-15 16:48 ` [PATCH 3/6] kvm tools: Block SIGALRM for theadpool thread Asias He
@ 2011-06-15 16:48 ` Asias He
  2011-06-15 16:48 ` [PATCH 5/6] kvm tools: Block SIGALRM for vcpu thread using sig_block() helper Asias He
  2011-06-15 16:48 ` [PATCH 6/6] kvm tools: Introduce a helper to show the blocked signals Asias He
  4 siblings, 0 replies; 7+ messages in thread
From: Asias He @ 2011-06-15 16:48 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
	Asias He

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/ioeventfd.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/ioeventfd.c b/tools/kvm/ioeventfd.c
index 3a240e4..0683868 100644
--- a/tools/kvm/ioeventfd.c
+++ b/tools/kvm/ioeventfd.c
@@ -99,6 +99,9 @@ void ioeventfd__del_event(u64 addr, u64 datamatch)
 
 static void *ioeventfd__thread(void *param)
 {
+
+	sig_block(SIGALRM);
+
 	for (;;) {
 		int nfds, i;
 
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/6] kvm tools: Block SIGALRM for vcpu thread using sig_block() helper
  2011-06-15 16:48 [PATCH 1/6] kvm tools: Introduce a helper to block a singal for a thread Asias He
                   ` (2 preceding siblings ...)
  2011-06-15 16:48 ` [PATCH 4/6] kvm tools: Block SIGALRM for ioeventfd thread Asias He
@ 2011-06-15 16:48 ` Asias He
  2011-06-15 20:23   ` Ingo Molnar
  2011-06-15 16:48 ` [PATCH 6/6] kvm tools: Introduce a helper to show the blocked signals Asias He
  4 siblings, 1 reply; 7+ messages in thread
From: Asias He @ 2011-06-15 16:48 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
	Asias He

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/kvm-cpu.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 1fb1c74..782a3b2 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -420,12 +420,8 @@ static void kvm_cpu__handle_coalesced_mmio(struct kvm_cpu *cpu)
 
 int kvm_cpu__start(struct kvm_cpu *cpu)
 {
-	sigset_t sigset;
 
-	sigemptyset(&sigset);
-	sigaddset(&sigset, SIGALRM);
-
-	pthread_sigmask(SIG_BLOCK, &sigset, NULL);
+	sig_block(SIGALRM);
 
 	signal(SIGKVMEXIT, kvm_cpu_signal_handler);
 	signal(SIGKVMPAUSE, kvm_cpu_signal_handler);
@@ -485,6 +481,7 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
 		default:
 			goto panic_kvm;
 		}
+
 		kvm_cpu__handle_coalesced_mmio(cpu);
 	}
 
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 6/6] kvm tools: Introduce a helper to show the blocked signals
  2011-06-15 16:48 [PATCH 1/6] kvm tools: Introduce a helper to block a singal for a thread Asias He
                   ` (3 preceding siblings ...)
  2011-06-15 16:48 ` [PATCH 5/6] kvm tools: Block SIGALRM for vcpu thread using sig_block() helper Asias He
@ 2011-06-15 16:48 ` Asias He
  4 siblings, 0 replies; 7+ messages in thread
From: Asias He @ 2011-06-15 16:48 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
	Asias He

This helper shows  the blocked signals of the calling thread.

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/include/kvm/util.h |    1 +
 tools/kvm/util.c             |   17 +++++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index 95d86b9..6fd0f7e 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -68,6 +68,7 @@ static inline const char *skip_prefix(const char *str, const char *prefix)
 	return strncmp(str, prefix, len) ? NULL : str + len;
 }
 
+void sig_prt_blocked(const char *str);
 int sig_block(int n);
 
 #endif /* KVM__UTIL_H */
diff --git a/tools/kvm/util.c b/tools/kvm/util.c
index 204230e..2f2dcf6 100644
--- a/tools/kvm/util.c
+++ b/tools/kvm/util.c
@@ -101,6 +101,23 @@ size_t strlcat(char *dest, const char *src, size_t count)
 	return res;
 }
 
+void sig_prt_blocked(const char *str)
+{
+	sigset_t sigset;
+	int i;
+
+	printf("-> %s : Blocked sig: ", str);
+
+	if (pthread_sigmask(0, NULL, &sigset) < 0)
+		return;
+	for (i = 1; i < _NSIG; i++) {
+		if (sigismember(&sigset, i))
+			printf("%d ", i);
+	}
+	printf("\n");
+
+}
+
 int sig_block(int n)
 {
 	sigset_t sigset;
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 5/6] kvm tools: Block SIGALRM for vcpu thread using sig_block() helper
  2011-06-15 16:48 ` [PATCH 5/6] kvm tools: Block SIGALRM for vcpu thread using sig_block() helper Asias He
@ 2011-06-15 20:23   ` Ingo Molnar
  0 siblings, 0 replies; 7+ messages in thread
From: Ingo Molnar @ 2011-06-15 20:23 UTC (permalink / raw)
  To: Asias He; +Cc: Pekka Enberg, Cyrill Gorcunov, Sasha Levin, Prasad Joshi, kvm


* Asias He <asias.hejun@gmail.com> wrote:

> Signed-off-by: Asias He <asias.hejun@gmail.com>
> ---
>  tools/kvm/kvm-cpu.c |    7 ++-----
>  1 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
> index 1fb1c74..782a3b2 100644
> --- a/tools/kvm/kvm-cpu.c
> +++ b/tools/kvm/kvm-cpu.c
> @@ -420,12 +420,8 @@ static void kvm_cpu__handle_coalesced_mmio(struct kvm_cpu *cpu)
>  
>  int kvm_cpu__start(struct kvm_cpu *cpu)
>  {
> -	sigset_t sigset;
>  
> -	sigemptyset(&sigset);
> -	sigaddset(&sigset, SIGALRM);
> -
> -	pthread_sigmask(SIG_BLOCK, &sigset, NULL);
> +	sig_block(SIGALRM);

Is there no way to get a signal delivered to only one thread, instead 
of trying to broadcast all threads?

Playing with the blocked mask has a performance disadvantage: the 
kernel will iterate through all threads of the thread-group to find 
the single one that 'can' receive the SIGALRM. This will be a real 
scalability issue with 64 or more vcpus.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-06-15 20:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-15 16:48 [PATCH 1/6] kvm tools: Introduce a helper to block a singal for a thread Asias He
2011-06-15 16:48 ` [PATCH 2/6] kvm tools: Block SIGALRM for both rx and tx thread for virtio net Asias He
2011-06-15 16:48 ` [PATCH 3/6] kvm tools: Block SIGALRM for theadpool thread Asias He
2011-06-15 16:48 ` [PATCH 4/6] kvm tools: Block SIGALRM for ioeventfd thread Asias He
2011-06-15 16:48 ` [PATCH 5/6] kvm tools: Block SIGALRM for vcpu thread using sig_block() helper Asias He
2011-06-15 20:23   ` Ingo Molnar
2011-06-15 16:48 ` [PATCH 6/6] kvm tools: Introduce a helper to show the blocked signals Asias He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox