public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
To: Will Deacon <will.deacon@arm.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: [PATCH v2] kvmtool: Add parameter to specifiy number of threads in thread_pool
Date: Mon, 29 Jun 2015 13:43:33 +0200	[thread overview]
Message-ID: <20150629114333.GB3379@alberich> (raw)
In-Reply-To: <20150629094502.GA17474@arm.com>


With current code the number of threads added to the thread_pool
equals number of online CPUs. So on cn78xx we usually have 48 threads
per guest just for the thread_pool. IMHO this is overkill for guests
that just have a few vCPUs and/or if a guest is pinned to a subset of
host CPUs. E.g.

 # numactl -C 4,5,7,8 ./lkvm run -c 2 -m 256 -k paravirt -d rootfs.ext3 ...
 # ps -La | grep threadpool-work | wc -l
 48

Don't change default behaviour (for sake of compatibility) but
introduce a new parameter ("-t" or "--threads") that allows to specify
number of threads to be created for the thread_pool:

 # numactl -C 4,5,7,8 ./lkvm run -c 2 -m 256 --threads 4 -k paravirt -d ...
 # ps -La | grep threadpool-work | wc -l
 4

Signed-off-by: Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
---
 builtin-run.c            |    6 ++++++
 include/kvm/kvm-config.h |    1 +
 util/threadpool.c        |    2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

New in v2: paramter must be in range [1, number of online cpus]
otherwise the default (number of online cpus) will be used.


Andreas

diff --git a/builtin-run.c b/builtin-run.c
index 1ee75ad..40ab9c6 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -131,6 +131,8 @@ void kvm_run_set_wrapper_sandbox(void)
 			" rootfs"),					\
 	OPT_STRING('\0', "hugetlbfs", &(cfg)->hugetlbfs_path, "path",	\
 			"Hugetlbfs path"),				\
+	OPT_INTEGER('t', "threads", &(cfg)->nrthreads,			\
+			 "Number of threads in thread_pool"),		\
 									\
 	OPT_GROUP("Kernel options:"),					\
 	OPT_STRING('k', "kernel", &(cfg)->kernel_filename, "kernel",	\
@@ -590,6 +592,10 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
 	if (!kvm->cfg.network)
                 kvm->cfg.network = DEFAULT_NETWORK;
 
+	if (!kvm->cfg.nrthreads || (kvm->cfg.nrthreads < 0) ||
+		((unsigned int) kvm->cfg.nrthreads > nr_online_cpus))
+		kvm->cfg.nrthreads = nr_online_cpus;
+
 	memset(real_cmdline, 0, sizeof(real_cmdline));
 	kvm__arch_set_cmdline(real_cmdline, kvm->cfg.vnc || kvm->cfg.sdl || kvm->cfg.gtk);
 
diff --git a/include/kvm/kvm-config.h b/include/kvm/kvm-config.h
index 386fa8c..9cc50f5 100644
--- a/include/kvm/kvm-config.h
+++ b/include/kvm/kvm-config.h
@@ -27,6 +27,7 @@ struct kvm_config {
 	int active_console;
 	int debug_iodelay;
 	int nrcpus;
+	int nrthreads;
 	const char *kernel_cmdline;
 	const char *kernel_filename;
 	const char *vmlinux_filename;
diff --git a/util/threadpool.c b/util/threadpool.c
index e64aa26..43595b8 100644
--- a/util/threadpool.c
+++ b/util/threadpool.c
@@ -124,7 +124,7 @@ static int thread_pool__addthread(void)
 int thread_pool__init(struct kvm *kvm)
 {
 	unsigned long i;
-	unsigned int thread_count = sysconf(_SC_NPROCESSORS_ONLN);
+	unsigned int thread_count = kvm->cfg.nrthreads;
 
 	running = true;
 
-- 
1.7.9.5


  parent reply	other threads:[~2015-06-29 11:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-29  7:45 [PATCH] kvmtool: Add parameter to specifiy number of threads in thread_pool Andreas Herrmann
2015-06-29  9:45 ` Will Deacon
2015-06-29 10:14   ` Andreas Herrmann
2015-06-29 11:43   ` Andreas Herrmann [this message]
2015-06-30 14:03     ` [PATCH v2] " Will Deacon

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=20150629114333.GB3379@alberich \
    --to=andreas.herrmann@caviumnetworks.com \
    --cc=kvm@vger.kernel.org \
    --cc=will.deacon@arm.com \
    /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