Skip to contentSkip to conversation

kvmtool: Add parameter to specifiy number of threads in thread_pool

PATCH New Andreas Herrmann 1 participant 1 message Jan 6, 2015 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvmtool: Add parameter to specifiy number of threads in thread_pool

With current code the number of threads added to the thread_pool equals number of online CPUs. IMHO on systems with many CPUs 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. of a system with 48 cores

 # 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
---
 tools/kvm/builtin-run.c            |    2 ++
 tools/kvm/include/kvm/kvm-config.h |    1 +
 tools/kvm/util/threadpool.c        |    5 ++++-
 3 files changed, 7 insertions(+), 1 deletion(-)
tools/kvm/builtin-run.c +2 -0
index 1ee75ad..86de53d 100644
@@ -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",	\
tools/kvm/include/kvm/kvm-config.h +1 -0
index 386fa8c..9cc50f5 100644
@@ -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;
tools/kvm/util/threadpool.c +4 -1
index e64aa26..620fdbd 100644
@@ -124,7 +124,10 @@ 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;
+
+	thread_count = kvm->cfg.nrthreads ? kvm->cfg.nrthreads :
+		sysconf(_SC_NPROCESSORS_ONLN);
 
 	running = true;
 
Signature · 1 line
1.7.9.5