Skip to contentSkip to conversation

Enhance perf to collect KVM guest os statistics from host side

PATCH In review Zhang, Yanmin 36 participants 377 messages Mar 16, 2010 – Apr 8, 2010 Page 1 of 2

Subsystems (5)
x86 KVM perf events KVM x86 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Enhance perf to collect KVM guest os statistics from host side

From: Zhang, Yanmin <[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

--------------------------------------------------------------------------------------------------------------------------
PerfTop: 16010 irqs/sec kernel:59.1% us: 1.5% guest kernel:31.9% guest us: 7.5% exact: 0.0% [1000Hz cycles], (all, 16 CPUs)
--------------------------------------------------------------------------------------------------------------------------

             samples  pcnt function                  DSO
             _______ _____ _________________________ _______________________

            38770.00 20.4% __ticket_spin_lock        [guest.kernel.kallsyms]
            22560.00 11.9% ftrace_likely_update      [kernel.kallsyms]
             9208.00  4.8% __lock_acquire            [kernel.kallsyms]
             5473.00  2.9% trace_hardirqs_off_caller [kernel.kallsyms]
             5222.00  2.7% copy_user_generic_string  [guest.kernel.kallsyms]
             4450.00  2.3% validate_chain            [kernel.kallsyms]
             4262.00  2.2% trace_hardirqs_on_caller  [kernel.kallsyms]
             4239.00  2.2% do_raw_spin_lock          [kernel.kallsyms]
             3548.00  1.9% do_raw_spin_unlock        [kernel.kallsyms]
             2487.00  1.3% lock_release              [kernel.kallsyms]
             2165.00  1.1% __local_bh_disable        [kernel.kallsyms]
             1905.00  1.0% check_chain_key           [kernel.kallsyms]
             1737.00  0.9% lock_acquire              [kernel.kallsyms]
             1604.00  0.8% tcp_recvmsg               [kernel.kallsyms]
             1524.00  0.8% mark_lock                 [kernel.kallsyms]
             1464.00  0.8% schedule                  [kernel.kallsyms]
             1423.00  0.7% __d_lookup                [guest.kernel.kallsyms]

If you want to just show host data, pls. don't use parameter --guest. The headline includes guest os kernel and userspace percentage.

2) perf kvm record
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules record -f -a sleep 60
[ perf record: Woken up 15 times to write data ]
[ perf record: Captured and wrote 29.385 MB perf.data.kvm (~1283837 samples) ]

3) perf kvm report

	3.1) [root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms

--guestmodules=/home/ymzhang/guest/modules report --sort pid --showcpuutilization>norm.host.guest.report.pid # Samples: 2453796285126
#
# Overhead sys us guest sys guest us Command: Pid

# ........  .....................
#
    43.67%     1.35%     0.01%    39.06%     3.26%  qemu-system-x86: 3913
     3.78%     3.58%     0.20%     0.00%     0.00%           tbench:13519
     3.69%     3.66%     0.03%     0.00%     0.00%       tbench_srv:13526

Some performance guys require perf to show sys/us/guest_sys/guest_us per KVM guest instance which is actually just a multi-threaded process. Above sub parameter --showcpuutilization does so.

	3.2) [root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms

--guestmodules=/home/ymzhang/guest/modules report >norm.host.guest.report # Samples: 2466991384118
#
# Overhead Command Shared Object Symbol

# ........  ...............  ........................................................................  ......
#
    29.11%  qemu-system-x86  [guest.kernel.kallsyms]                                                   [g] __ticket_spin_lock
     5.88%       tbench_srv  [kernel.kallsyms]                                                         [k] ftrace_likely_update
     5.76%           tbench  [kernel.kallsyms]                                                         [k] ftrace_likely_update
     3.88%  qemu-system-x86                                                                34c3255482  [u] 0x000034c3255482
     1.83%           tbench  [kernel.kallsyms]                                                         [k] __lock_acquire
     1.81%       tbench_srv  [kernel.kallsyms]                                                         [k] __lock_acquire
     1.38%       tbench_srv  [kernel.kallsyms]                                                         [k] trace_hardirqs_off_caller
     1.37%           tbench  [kernel.kallsyms]                                                         [k] trace_hardirqs_off_caller
     1.13%  qemu-system-x86  [guest.kernel.kallsyms]                                                   [g] copy_user_generic_string
     1.04%       tbench_srv  [kernel.kallsyms]                                                         [k] validate_chain
     1.00%           tbench  [kernel.kallsyms]                                                         [k] trace_hardirqs_on_caller
     1.00%       tbench_srv  [kernel.kallsyms]                                                         [k] trace_hardirqs_on_caller
     0.95%           tbench  [kernel.kallsyms]                                                         [k] do_raw_spin_lock

[u] means it's in guest os user space. [g] means in guest os kernel. Other info is very direct. If it shows a module such like [ext4], it means guest kernel module, because native host kernel's modules are start from something like /lib/modules/XXX.

Below is the patch against tip/master tree of 15th March.

---

arch/x86/include/asm/perf_event.h +4 -11
diff -Nraup linux-2.6_tipmaster0315/arch/x86/include/asm/perf_event.h linux-2.6_tipmaster0315_perfkvm/arch/x86/include/asm/perf_event.h
@@ -143,17 +143,10 @@ extern void perf_events_lapic_init(void)
  */
 #define PERF_EFLAGS_EXACT	(1UL << 3)
 
-#define perf_misc_flags(regs)				\
-({	int misc = 0;					\
-	if (user_mode(regs))				\
-		misc |= PERF_RECORD_MISC_USER;		\
-	else						\
-		misc |= PERF_RECORD_MISC_KERNEL;	\
-	if (regs->flags & PERF_EFLAGS_EXACT)		\
-		misc |= PERF_RECORD_MISC_EXACT;		\
-	misc; })
-
-#define perf_instruction_pointer(regs)	((regs)->ip)
+struct pt_regs;
+extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
+extern unsigned long perf_misc_flags(struct pt_regs *regs);
+#define perf_misc_flags(regs)	perf_misc_flags(regs)
 
 #else
 static inline void init_hw_perf_events(void)		{ }
arch/x86/include/asm/ptrace.h +9 -0
diff -Nraup linux-2.6_tipmaster0315/arch/x86/include/asm/ptrace.h linux-2.6_tipmaster0315_perfkvm/arch/x86/include/asm/ptrace.h
@@ -167,6 +167,15 @@ static inline int user_mode(struct pt_re
 #endif
 }
 
+static inline int user_mode_cs(u16 cs)
+{
+#ifdef CONFIG_X86_32
+	return (cs & SEGMENT_RPL_MASK) == USER_RPL;
+#else
+	return !!(cs & 3);
+#endif
+}
+
 static inline int user_mode_vm(struct pt_regs *regs)
 {
 #ifdef CONFIG_X86_32
arch/x86/kernel/cpu/perf_event.c +27 -0
diff -Nraup linux-2.6_tipmaster0315/arch/x86/kernel/cpu/perf_event.c linux-2.6_tipmaster0315_perfkvm/arch/x86/kernel/cpu/perf_event.c
@@ -1707,3 +1707,30 @@ void perf_arch_fetch_caller_regs(struct 
 	local_save_flags(regs->flags);
 }
 EXPORT_SYMBOL_GPL(perf_arch_fetch_caller_regs);
+
+unsigned long perf_instruction_pointer(struct pt_regs *regs)
+{
+	unsigned long ip;
+	if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
+		ip = perf_guest_cbs->get_guest_ip();
+	} else
+		ip = instruction_pointer(regs);
+	return ip;
+}
+
+unsigned long perf_misc_flags(struct pt_regs *regs)
+{
+	int misc = 0;
+	if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
+		misc |= perf_guest_cbs->is_user_mode() ?
+			PERF_RECORD_MISC_GUEST_USER :
+			PERF_RECORD_MISC_GUEST_KERNEL;
+	} else
+		misc |= user_mode(regs) ? PERF_RECORD_MISC_USER :
+			PERF_RECORD_MISC_KERNEL;
+	if (regs->flags & PERF_EFLAGS_EXACT)
+		misc |= PERF_RECORD_MISC_EXACT;
+
+	return misc;
+}
+
arch/x86/kvm/vmx.c +46 -1

78 lines not on this page · raw message

include/linux/perf_event.h +21 -1
diff -Nraup linux-2.6_tipmaster0315/include/linux/perf_event.h linux-2.6_tipmaster0315_perfkvm/include/linux/perf_event.h
@@ -288,11 +288,13 @@ struct perf_event_mmap_page {
 	__u64	data_tail;		/* user-space written tail */
 };
 
-#define PERF_RECORD_MISC_CPUMODE_MASK		(3 << 0)
+#define PERF_RECORD_MISC_CPUMODE_MASK		(7 << 0)
 #define PERF_RECORD_MISC_CPUMODE_UNKNOWN	(0 << 0)
 #define PERF_RECORD_MISC_KERNEL			(1 << 0)
 #define PERF_RECORD_MISC_USER			(2 << 0)
 #define PERF_RECORD_MISC_HYPERVISOR		(3 << 0)
+#define PERF_RECORD_MISC_GUEST_KERNEL		(4 << 0)
+#define PERF_RECORD_MISC_GUEST_USER		(5 << 0)
 
 #define PERF_RECORD_MISC_EXACT			(1 << 14)
 /*
@@ -446,6 +448,13 @@ enum perf_callchain_context {
 # include <asm/perf_event.h>
 #endif
 
+struct perf_guest_info_callbacks {
+	int (*is_in_guest) (void);
+	int (*is_user_mode) (void);
+	unsigned long (*get_guest_ip) (void);
+	void (*reset_in_guest) (void);
+};
+
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
 #include <asm/hw_breakpoint.h>
 #endif
@@ -913,6 +922,12 @@ static inline void perf_event_mmap(struc
 		__perf_event_mmap(vma);
 }
 
+extern struct perf_guest_info_callbacks *perf_guest_cbs;
+extern int perf_register_guest_info_callbacks(
+		struct perf_guest_info_callbacks *);
+extern int perf_unregister_guest_info_callbacks(
+		struct perf_guest_info_callbacks *);
+
 extern void perf_event_comm(struct task_struct *tsk);
 extern void perf_event_fork(struct task_struct *tsk);
 
@@ -982,6 +997,11 @@ perf_sw_event(u32 event_id, u64 nr, int 
 static inline void
 perf_bp_event(struct perf_event *event, void *data)			{ }
 
+static inline int perf_register_guest_info_callbacks
+(struct perf_guest_info_callbacks *)   {return 0; }
+static inline int perf_unregister_guest_info_callbacks
+(struct perf_guest_info_callbacks *)   {return 0; }
+
 static inline void perf_event_mmap(struct vm_area_struct *vma)		{ }
 static inline void perf_event_comm(struct task_struct *tsk)		{ }
 static inline void perf_event_fork(struct task_struct *tsk)		{ }
kernel/perf_event.c +22 -1
diff -Nraup linux-2.6_tipmaster0315/kernel/perf_event.c linux-2.6_tipmaster0315_perfkvm/kernel/perf_event.c
@@ -2796,6 +2796,27 @@ void perf_arch_fetch_caller_regs(struct 
 }
 
 /*
+ * We assume there is only KVM supporting the callbacks.
+ * Later on, we might change it to a list if there is
+ * another virtualization implementation supporting the callbacks.
+ */
+struct perf_guest_info_callbacks *perf_guest_cbs;
+
+int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks * cbs)
+{
+	perf_guest_cbs = cbs;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
+
+int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks * cbs)
+{
+	perf_guest_cbs = NULL;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks);
+
+/*
  * Output
  */
 static bool perf_output_space(struct perf_mmap_data *data, unsigned long tail,
@@ -3738,7 +3759,7 @@ void __perf_event_mmap(struct vm_area_st
 		.event_id  = {
 			.header = {
 				.type = PERF_RECORD_MMAP,
-				.misc = 0,
+				.misc = PERF_RECORD_MISC_USER,
 				/* .size */
 			},
 			/* .pid */
tools/perf/builtin-diff.c +4 -1
diff -Nraup linux-2.6_tipmaster0315/tools/perf/builtin-diff.c linux-2.6_tipmaster0315_perfkvm/tools/perf/builtin-diff.c
@@ -33,7 +33,7 @@ static int perf_session__add_hist_entry(
 		return -ENOMEM;
 
 	if (hit)
-		he->count += count;
+		__perf_session__add_count(he, al, count);
 
 	return 0;
 }
@@ -225,6 +225,9 @@ int cmd_diff(int argc, const char **argv
 			input_new = argv[1];
 		} else
 			input_new = argv[0];
+	} else if (symbol_conf.guest_vmlinux_name || symbol_conf.guest_kallsyms) {
+		input_old = "perf.data.host";
+		input_new = "perf.data.guest";
 	}
 
 	symbol_conf.exclude_other = false;
tools/perf/builtin.h +1 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/builtin.h linux-2.6_tipmaster0315_perfkvm/tools/perf/builtin.h
@@ -32,5 +32,6 @@ extern int cmd_version(int argc, const c
 extern int cmd_probe(int argc, const char **argv, const char *prefix);
 extern int cmd_kmem(int argc, const char **argv, const char *prefix);
 extern int cmd_lock(int argc, const char **argv, const char *prefix);
+extern int cmd_kvm(int argc, const char **argv, const char *prefix);
 
 #endif
tools/perf/builtin-kvm.c +123 -0

123 lines not on this page · raw message

tools/perf/builtin-record.c +42 -2

60 lines not on this page · raw message

tools/perf/builtin-report.c +3 -1
diff -Nraup linux-2.6_tipmaster0315/tools/perf/builtin-report.c linux-2.6_tipmaster0315_perfkvm/tools/perf/builtin-report.c
@@ -104,7 +104,7 @@ static int perf_session__add_hist_entry(
 		return -ENOMEM;
 
 	if (hit)
-		he->count += data->period;
+		__perf_session__add_count(he, al,  data->period);
 
 	if (symbol_conf.use_callchain) {
 		if (!hit)
@@ -428,6 +428,8 @@ static const struct option options[] = {
 		   "sort by key(s): pid, comm, dso, symbol, parent"),
 	OPT_BOOLEAN('P', "full-paths", &symbol_conf.full_paths,
 		    "Don't shorten the pathnames taking into account the cwd"),
+	OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
+		    "Show sample percentage for different cpu modes"),
 	OPT_STRING('p', "parent", &parent_pattern, "regex",
 		   "regex filter to identify parent, see: '--sort parent'"),
 	OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
tools/perf/builtin-top.c +34 -7

75 lines not on this page · raw message

tools/perf/Makefile +1 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/Makefile linux-2.6_tipmaster0315_perfkvm/tools/perf/Makefile
@@ -462,6 +462,7 @@ BUILTIN_OBJS += builtin-trace.o
 BUILTIN_OBJS += builtin-probe.o
 BUILTIN_OBJS += builtin-kmem.o
 BUILTIN_OBJS += builtin-lock.o
+BUILTIN_OBJS += builtin-kvm.o
 
 PERFLIBS = $(LIB_FILE)
 
tools/perf/perf.c +1 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/perf.c linux-2.6_tipmaster0315_perfkvm/tools/perf/perf.c
@@ -308,6 +308,7 @@ static void handle_internal_command(int 
 		{ "probe",	cmd_probe,	0 },
 		{ "kmem",	cmd_kmem,	0 },
 		{ "lock",	cmd_lock,	0 },
+		{ "kvm",	cmd_kvm,	0 },
 	};
 	unsigned int i;
 	static const char ext[] = STRIP_EXTENSION;
tools/perf/perf.h +2 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/perf.h linux-2.6_tipmaster0315_perfkvm/tools/perf/perf.h
@@ -133,4 +133,6 @@ struct ip_callchain {
 	u64 ips[0];
 };
 
+extern int perf_host, perf_guest;
+
 #endif
tools/perf/util/event.c +151 -40

293 lines not on this page · raw message

tools/perf/util/event.h +10 -3
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/event.h linux-2.6_tipmaster0315_perfkvm/tools/perf/util/event.h
@@ -119,10 +119,17 @@ int event__synthesize_thread(pid_t pid, 
 void event__synthesize_threads(event__handler_t process,
 			       struct perf_session *session);
 int event__synthesize_kernel_mmap(event__handler_t process,
-				  struct perf_session *session,
-				  const char *symbol_name);
+				struct perf_session *session,
+				const char *kallsyms_name,
+				const char *mmap_name,
+				struct map **maps,
+				const char *symbol_name,
+				unsigned int misc);
+
 int event__synthesize_modules(event__handler_t process,
-			      struct perf_session *session);
+			      struct perf_session *session,
+			      struct map_groups *kmaps,
+			      unsigned int misc);
 
 int event__process_comm(event_t *self, struct perf_session *session);
 int event__process_lost(event_t *self, struct perf_session *session);
tools/perf/util/hist.c +63 -4

110 lines not on this page · raw message

tools/perf/util/hist.h +3 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/hist.h linux-2.6_tipmaster0315_perfkvm/tools/perf/util/hist.h
@@ -12,6 +12,9 @@ struct addr_location;
 struct symbol;
 struct rb_root;
 
+void __perf_session__add_count(struct hist_entry *he,
+			struct addr_location *al,
+			u64 count);
 struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
 						  struct addr_location *al,
 						  struct symbol *parent,
tools/perf/util/session.c +23 -9
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/session.c linux-2.6_tipmaster0315_perfkvm/tools/perf/util/session.c
@@ -54,7 +54,12 @@ out_close:
 
 static inline int perf_session__create_kernel_maps(struct perf_session *self)
 {
-	return map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps);
+	int ret;
+	ret = map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps);
+	if (ret >= 0)
+		ret = map_groups__create_guest_kernel_maps(&self->guest_kmaps,
+				self->guest_vmlinux_maps);
+	return ret;
 }
 
 struct perf_session *perf_session__new(const char *filename, int mode, bool force)
@@ -77,6 +82,7 @@ struct perf_session *perf_session__new(c
 	self->cwdlen = 0;
 	self->unknown_events = 0;
 	map_groups__init(&self->kmaps);
+	map_groups__init(&self->guest_kmaps);
 
 	if (mode == O_RDONLY) {
 		if (perf_session__open(self, force) < 0)
@@ -356,7 +362,8 @@ int perf_header__read_build_ids(struct p
 		if (read(input, filename, len) != len)
 			goto out;
 
-		if (bev.header.misc & PERF_RECORD_MISC_KERNEL)
+		if ((bev.header.misc & PERF_RECORD_MISC_CPUMODE_MASK)
+			==  PERF_RECORD_MISC_KERNEL)
 			head = &dsos__kernel;
 
 		dso = __dsos__findnew(head, filename);
@@ -519,26 +526,33 @@ bool perf_session__has_traces(struct per
 	return true;
 }
 
-int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self,
+int perf_session__set_kallsyms_ref_reloc_sym(struct map ** maps,
 					     const char *symbol_name,
 					     u64 addr)
 {
 	char *bracket;
 	enum map_type i;
+	struct ref_reloc_sym *ref;
 
-	self->ref_reloc_sym.name = strdup(symbol_name);
-	if (self->ref_reloc_sym.name == NULL)
+	ref = zalloc(sizeof(struct ref_reloc_sym));
+	if (ref == NULL)
 		return -ENOMEM;
 
-	bracket = strchr(self->ref_reloc_sym.name, ']');
+	ref->name = strdup(symbol_name);
+	if (ref->name == NULL) {
+		free(ref);
+		return -ENOMEM;
+	}
+
+	bracket = strchr(ref->name, ']');
 	if (bracket)
 		*bracket = '\0';
 
-	self->ref_reloc_sym.addr = addr;
+	ref->addr = addr;
 
 	for (i = 0; i < MAP__NR_TYPES; ++i) {
-		struct kmap *kmap = map__kmap(self->vmlinux_maps[i]);
-		kmap->ref_reloc_sym = &self->ref_reloc_sym;
+		struct kmap *kmap = map__kmap(maps[i]);
+		kmap->ref_reloc_sym = ref;
 	}
 
 	return 0;
tools/perf/util/session.h +3 -16
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/session.h linux-2.6_tipmaster0315_perfkvm/tools/perf/util/session.h
@@ -16,16 +16,17 @@ struct perf_session {
 	unsigned long		size;
 	unsigned long		mmap_window;
 	struct map_groups	kmaps;
+	struct map_groups	guest_kmaps;
 	struct rb_root		threads;
 	struct thread		*last_match;
 	struct map		*vmlinux_maps[MAP__NR_TYPES];
+	struct map		*guest_vmlinux_maps[MAP__NR_TYPES];
 	struct events_stats	events_stats;
 	struct rb_root		stats_by_id;
 	unsigned long		event_total[PERF_RECORD_MAX];
 	unsigned long		unknown_events;
 	struct rb_root		hists;
 	u64			sample_type;
-	struct ref_reloc_sym	ref_reloc_sym;
 	int			fd;
 	int			cwdlen;
 	char			*cwd;
@@ -67,26 +68,12 @@ bool perf_session__has_traces(struct per
 int perf_header__read_build_ids(struct perf_header *self, int input,
 				u64 offset, u64 file_size);
 
-int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self,
+int perf_session__set_kallsyms_ref_reloc_sym(struct map ** maps,
 					     const char *symbol_name,
 					     u64 addr);
 
 void mem_bswap_64(void *src, int byte_size);
 
-static inline int __perf_session__create_kernel_maps(struct perf_session *self,
-						struct dso *kernel)
-{
-	return __map_groups__create_kernel_maps(&self->kmaps,
-						self->vmlinux_maps, kernel);
-}
-
-static inline struct map *
-	perf_session__new_module_map(struct perf_session *self,
-				     u64 start, const char *filename)
-{
-	return map_groups__new_module(&self->kmaps, start, filename);
-}
-
 #ifdef NO_NEWT_SUPPORT
 static inline void perf_session__browse_hists(struct rb_root *hists __used,
 					      u64 session_total __used,
tools/perf/util/sort.h +4 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/sort.h linux-2.6_tipmaster0315_perfkvm/tools/perf/util/sort.h
@@ -44,6 +44,10 @@ extern enum sort_type sort__first_dimens
 struct hist_entry {
 	struct rb_node		rb_node;
 	u64			count;
+	u64			count_sys;
+	u64			count_us;
+	u64			count_guest_sys;
+	u64			count_guest_us;
 	struct thread		*thread;
 	struct map		*map;
 	struct symbol		*sym;
tools/perf/util/symbol.c +156 -21

345 lines not on this page · raw message

tools/perf/util/symbol.h +18 -4
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/symbol.h linux-2.6_tipmaster0315_perfkvm/tools/perf/util/symbol.h
@@ -63,10 +63,14 @@ struct symbol_conf {
 			show_nr_samples,
 			use_callchain,
 			exclude_other,
-			full_paths;
+			full_paths,
+			show_cpu_utilization;
 	const char	*vmlinux_name,
 			*field_sep;
-	char            *dso_list_str,
+	const char	*guest_vmlinux_name,
+			*guest_kallsyms,
+			*guest_modules;
+	char		*dso_list_str,
 			*comm_list_str,
 			*sym_list_str,
 			*col_width_list_str;
@@ -95,6 +99,13 @@ struct addr_location {
 	u64	      addr;
 	char	      level;
 	bool	      filtered;
+	unsigned int  cpumode;
+};
+
+enum dso_kernel_type {
+	DSO_TYPE_USER = 0,
+	DSO_TYPE_KERNEL,
+	DSO_TYPE_GUEST_KERNEL
 };
 
 struct dso {
@@ -104,7 +115,7 @@ struct dso {
 	u8		 adjust_symbols:1;
 	u8		 slen_calculated:1;
 	u8		 has_build_id:1;
-	u8		 kernel:1;
+	enum dso_kernel_type	kernel;
 	u8		 hit:1;
 	u8		 annotate_warned:1;
 	unsigned char	 origin;
@@ -119,6 +130,7 @@ struct dso {
 
 struct dso *dso__new(const char *name);
 struct dso *dso__new_kernel(const char *name);
+struct dso *dso__new_guest_kernel(const char *name);
 void dso__delete(struct dso *self);
 
 bool dso__loaded(const struct dso *self, enum map_type type);
@@ -131,7 +143,7 @@ static inline void dso__set_loaded(struc
 
 void dso__sort_by_name(struct dso *self, enum map_type type);
 
-extern struct list_head dsos__user, dsos__kernel;
+extern struct list_head dsos__user, dsos__kernel, dsos__guest_user, dsos__guest_kernel;
 
 struct dso *__dsos__findnew(struct list_head *head, const char *name);
 
@@ -160,6 +172,8 @@ enum dso_origin {
 	DSO__ORIG_BUILDID,
 	DSO__ORIG_DSO,
 	DSO__ORIG_KMODULE,
+	DSO__ORIG_GUEST_KERNEL,
+	DSO__ORIG_GUEST_KMODULE,
 	DSO__ORIG_NOT_FOUND,
 };
 
tools/perf/util/thread.h +4 -1
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/thread.h linux-2.6_tipmaster0315_perfkvm/tools/perf/util/thread.h
@@ -82,6 +82,9 @@ int __map_groups__create_kernel_maps(str
 int map_groups__create_kernel_maps(struct map_groups *self,
 				   struct map *vmlinux_maps[MAP__NR_TYPES]);
 
+int map_groups__create_guest_kernel_maps(struct map_groups *self,
+				   struct map *vmlinux_maps[MAP__NR_TYPES]);
+
 struct map *map_groups__new_module(struct map_groups *self, u64 start,
-				   const char *filename);
+				   const char *filename, int guest);
 #endif	/* __PERF_THREAD_H */
#1 lore raw
Quoted 15 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

Quoted 9 lines

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels? Perhaps a symbol server that perf can connect to (and that would connect to guests in turn)?

Quoted 17 lines

diff -Nraup linux-2.6_tipmaster0315/arch/x86/kvm/vmx.c linux-2.6_tipmaster0315_perfkvm/arch/x86/kvm/vmx.c

arch/x86/kvm/vmx.c +3 -0
@@ -26,6 +26,7 @@
  #include<linux/sched.h>
  #include<linux/moduleparam.h>
  #include<linux/ftrace_event.h>
+#include<linux/perf_event.h>
  #include "kvm_cache_regs.h"
  #include "x86.h"
 
@@ -3632,6 +3633,43 @@ static void update_cr8_intercept(struct
  	vmcs_write32(TPR_THRESHOLD, irr);
  }
 
+DEFINE_PER_CPU(int, kvm_in_guest) = {0};
+

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct · line 3647

Quoted 10 lines
arch/x86/kvm/vmx.c +9 -0
+static void kvm_set_in_guest(void)
+{
+	percpu_write(kvm_in_guest, 1);
+}
+
+static int kvm_is_in_guest(void)
+{
+	return percpu_read(kvm_in_guest);
+}
 

There is already PF_VCPU for this.

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct

Quoted 7 lines
arch/x86/kvm/vmx.c +6 -0
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+	.is_in_guest 		= kvm_is_in_guest,
+	.is_user_mode		= kvm_is_user_mode,
+	.get_guest_ip		= kvm_get_guest_ip,
+	.reset_in_guest		= kvm_reset_in_guest,
+};
 

Should be in common code, not vmx specific.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#2 lore raw
Quoted 25 lines · Avi Kivity
Quoted 15 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

Quoted 8 lines

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Quoted 6 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels? Perhaps a symbol server that perf can connect to (and that would connect to guests in turn)?

The highest quality solution would be if KVM offered a 'guest extension' to the guest kernel's /proc/kallsyms that made it easy for user-space to get this information from an authorative source.

That's the main reason why the host side /proc/kallsyms is so popular and so
useful: while in theory it's mostly redundant information which can be gleaned from the System.map and other sources of symbol information, it's easily available and is _always_ trustable to come from the host kernel.

Separate System.map's have a tendency to go out of sync (or go missing when a devel kernel gets rebuilt, or if a devel package is not installed), and server ports (be that a TCP port space server or an UDP port space mount-point) are both a configuration hassle and are not guest-transparent.

So for instrumentation infrastructure (such as perf) we have a large and well founded preference for intrinsic, built-in, kernel-provided information: i.e. a largely 'built-in' and transparent mechanism to get to guest symbols.

Thanks,

Ingo

#334 lore raw
In reply to Avi Kivity
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Quoted 20 lines

Perhaps a
symbol server that perf can connect to (and that would connect to guests in turn)?

Quoted 15 lines

diff -Nraup linux-2.6_tipmaster0315/arch/x86/kvm/vmx.c linux-2.6_tipmaster0315_perfkvm/arch/x86/kvm/vmx.c

arch/x86/kvm/vmx.c +1 -0
@@ -26,6 +26,7 @@
  #include<linux/sched.h>
  #include<linux/moduleparam.h>
  #include<linux/ftrace_event.h>
+#include<linux/perf_event.h>
  #include "kvm_cache_regs.h"
  #include "x86.h"
 
@@ -3632,6 +3633,43 @@ static void update_cr8_intercept(struct
  	vmcs_write32(TPR_THRESHOLD, irr);
  }
 
Quoted 15 lines

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct

Quoted 12 lines
arch/x86/kvm/vmx.c +11 -0
+DEFINE_PER_CPU(int, kvm_in_guest) = {0};
+
+static void kvm_set_in_guest(void)
+{
+	percpu_write(kvm_in_guest, 1);
+}
+
+static int kvm_is_in_guest(void)
+{
+	return percpu_read(kvm_in_guest);
+}
 

There is already PF_VCPU for this.

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

Quoted 10 lines

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct

Quoted 8 lines
arch/x86/kvm/vmx.c +6 -0
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+	.is_in_guest 		= kvm_is_in_guest,
+	.is_user_mode		= kvm_is_user_mode,
+	.get_guest_ip		= kvm_get_guest_ip,
+	.reset_in_guest		= kvm_reset_in_guest,
+};
 

Should be in common code, not vmx specific.

Right. I discussed with Yangsheng. I will move above data structures and callbacks to file arch/x86/kvm/x86.c, and add get_ip, a new callback to kvm_x86_ops.

Yanmin

#3 lore raw
In reply to Ingo Molnar
Quoted 45 lines · Ingo Molnar
Quoted 26 lines · Avi Kivity
Quoted 15 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

Quoted 9 lines

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Quoted 7 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels? Perhaps a symbol server that perf can connect to (and that would connect to guests in turn)?

The highest quality solution would be if KVM offered a 'guest extension' to the guest kernel's /proc/kallsyms that made it easy for user-space to get this information from an authorative source.

That's the main reason why the host side /proc/kallsyms is so popular and so
useful: while in theory it's mostly redundant information which can be gleaned from the System.map and other sources of symbol information, it's easily available and is _always_ trustable to come from the host kernel.

Quoted 9 lines

Separate System.map's have a tendency to go out of sync (or go missing when a devel kernel gets rebuilt, or if a devel package is not installed), and server ports (be that a TCP port space server or an UDP port space mount-point) are both a configuration hassle and are not guest-transparent.

So for instrumentation infrastructure (such as perf) we have a large and well founded preference for intrinsic, built-in, kernel-provided information: i.e. a largely 'built-in' and transparent mechanism to get to guest symbols.

The symbol server's client can certainly access the bits through vmchannel.

Signature · 1 line
error compiling committee.c: too many arguments to function
#335 lore raw
In reply to Zhang, Yanmin
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yanmin

#343 lore raw
In reply to Zhang, Yanmin
Quoted 10 lines · Yanmin
Quoted 6 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

That certainly works, though automatic association of guest data with guest symbols is friendlier.

Quoted 30 lines
Quoted 29 lines
Quoted 28 lines

diff -Nraup linux-2.6_tipmaster0315/arch/x86/kvm/vmx.c linux-2.6_tipmaster0315_perfkvm/arch/x86/kvm/vmx.c

arch/x86/kvm/vmx.c +12 -0
@@ -26,6 +26,7 @@
   #include<linux/sched.h>
   #include<linux/moduleparam.h>
   #include<linux/ftrace_event.h>
+#include<linux/perf_event.h>
   #include "kvm_cache_regs.h"
   #include "x86.h"
 
@@ -3632,6 +3633,43 @@ static void update_cr8_intercept(struct
   	vmcs_write32(TPR_THRESHOLD, irr);
   }
 
+DEFINE_PER_CPU(int, kvm_in_guest) = {0};
+
+static void kvm_set_in_guest(void)
+{
+	percpu_write(kvm_in_guest, 1);
+}
+
+static int kvm_is_in_guest(void)
+{
+	return percpu_read(kvm_in_guest);
+}
 
 
Quoted 6 lines
Quoted 2 lines

There is already PF_VCPU for this.

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it. I guess NMIs will be disabled until the next IRET so it isn't racy, just tricky.

Quoted 10 lines
Quoted 10 lines

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct

Quoted 8 lines
arch/x86/kvm/vmx.c +6 -0
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+	.is_in_guest 		= kvm_is_in_guest,
+	.is_user_mode		= kvm_is_user_mode,
+	.get_guest_ip		= kvm_get_guest_ip,
+	.reset_in_guest		= kvm_reset_in_guest,
+};
 

Should be in common code, not vmx specific.

Quoted 4 lines

Right. I discussed with Yangsheng. I will move above data structures and callbacks to file arch/x86/kvm/x86.c, and add get_ip, a new callback to kvm_x86_ops.

You will need access to the vcpu pointer (kvm_rip_read() needs it), you can put it in a percpu variable. I guess if it's not null, you know you're in a guest, so no need for PF_VCPU.

Signature · 1 line
error compiling committee.c: too many arguments to function
#336 lore raw
In reply to Zhang, Yanmin
Quoted 7 lines · Yanmin

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

That seems like a worthwhile addition regardless of this thread. Profile all current threads and any new ones. It probably makes sense to call this --pid and rename the existing --pid to --thread.

Signature · 1 line
error compiling committee.c: too many arguments to function
#337 lore raw
In reply to Zhang, Yanmin
Quoted 39 lines · Zhang, Yanmin
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Quoted 8 lines

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yeah. For maximum utility i'd suggest to extend --pid to include this, and introduce --tid for the previous, limited-to-a-single-task functionality.

Most users would expect --pid to work like a 'late attach' - i.e. to work like strace -f or like a gdb attach.

Ingo

#4 lore raw
In reply to Avi Kivity
Quoted 47 lines · Avi Kivity
Quoted 46 lines · Ingo Molnar
Quoted 24 lines · Avi Kivity
Quoted 15 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

Quoted 8 lines

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Quoted 6 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels? Perhaps a symbol server that perf can connect to (and that would connect to guests in turn)?

The highest quality solution would be if KVM offered a 'guest extension' to the guest kernel's /proc/kallsyms that made it easy for user-space to get this information from an authorative source.

That's the main reason why the host side /proc/kallsyms is so popular and so
useful: while in theory it's mostly redundant information which can be gleaned from the System.map and other sources of symbol information, it's easily available and is _always_ trustable to come from the host kernel.

Separate System.map's have a tendency to go out of sync (or go missing when a devel kernel gets rebuilt, or if a devel package is not installed), and server ports (be that a TCP port space server or an UDP port space mount-point) are both a configuration hassle and are not guest-transparent.

Quoted 5 lines
Quoted 3 lines

So for instrumentation infrastructure (such as perf) we have a large and well founded preference for intrinsic, built-in, kernel-provided information: i.e. a largely 'built-in' and transparent mechanism to get to guest symbols.

The symbol server's client can certainly access the bits through vmchannel.

Ok, that would work i suspect.

Would be nice to have the symbol server in tools/perf/ and also make it easy to add it to the initrd via a .config switch or so.

That would have basically all of the advantages of being built into the kernel (availability, configurability, transparency, hackability), while having all the advantages of a user-space approach as well (flexibility, extensibility, robustness, ease of maintenance, etc.).

If only we had tools/xorg/ integrated via the initrd that way ;-)

Thanks,

Ingo

#5 lore raw
Quoted 65 lines · Ingo Molnar
Quoted 54 lines · Avi Kivity
Quoted 52 lines · Ingo Molnar
Quoted 26 lines · Avi Kivity
Quoted 15 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

Quoted 9 lines

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Quoted 7 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels? Perhaps a symbol server that perf can connect to (and that would connect to guests in turn)?

The highest quality solution would be if KVM offered a 'guest extension' to the guest kernel's /proc/kallsyms that made it easy for user-space to get this information from an authorative source.

That's the main reason why the host side /proc/kallsyms is so popular and so
useful: while in theory it's mostly redundant information which can be gleaned

from the System.map and other sources of symbol information, it's easily

available and is _always_ trustable to come from the host kernel.

Separate System.map's have a tendency to go out of sync (or go missing when a devel kernel gets rebuilt, or if a devel package is not installed), and server ports (be that a TCP port space server or an UDP port space mount-point) are both a configuration hassle and are not guest-transparent.

Quoted 6 lines
Quoted 4 lines

So for instrumentation infrastructure (such as perf) we have a large and well founded preference for intrinsic, built-in, kernel-provided information: i.e. a largely 'built-in' and transparent mechanism to get to guest symbols.

The symbol server's client can certainly access the bits through vmchannel.

Ok, that would work i suspect.

Quoted 8 lines

Would be nice to have the symbol server in tools/perf/ and also make it easy to add it to the initrd via a .config switch or so.

That would have basically all of the advantages of being built into the kernel (availability, configurability, transparency, hackability), while having all the advantages of a user-space approach as well (flexibility, extensibility, robustness, ease of maintenance, etc.).

Note, I am not advocating building the vmchannel client into the host kernel. While that makes everything simpler for the user, it increases the kernel footprint with all the disadvantages that come with that (any bug is converted into a host DoS or worse).

So, perf would connect to qemu via (say) a well-known unix domain socket, which would then talk to the guest kernel.

I know you won't like it, we'll continue to disagree on this unfortunately.

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw
Quoted 59 lines · Avi Kivity
Quoted 58 lines · Ingo Molnar
Quoted 47 lines · Avi Kivity
Quoted 46 lines · Ingo Molnar
Quoted 24 lines · Avi Kivity
Quoted 15 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

Quoted 8 lines

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Quoted 6 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels? Perhaps a symbol server that perf can connect to (and that would connect to guests in turn)?

The highest quality solution would be if KVM offered a 'guest extension' to the guest kernel's /proc/kallsyms that made it easy for user-space to get this information from an authorative source.

That's the main reason why the host side /proc/kallsyms is so popular and so
useful: while in theory it's mostly redundant information which can be gleaned from the System.map and other sources of symbol information, it's easily available and is _always_ trustable to come from the host kernel.

Separate System.map's have a tendency to go out of sync (or go missing when a devel kernel gets rebuilt, or if a devel package is not installed), and server ports (be that a TCP port space server or an UDP port space mount-point) are both a configuration hassle and are not guest-transparent.

Quoted 4 lines
Quoted 3 lines

So for instrumentation infrastructure (such as perf) we have a large and well founded preference for intrinsic, built-in, kernel-provided information: i.e. a largely 'built-in' and transparent mechanism to get to guest symbols.

The symbol server's client can certainly access the bits through vmchannel.

Ok, that would work i suspect.

Would be nice to have the symbol server in tools/perf/ and also make it easy to add it to the initrd via a .config switch or so.

Quoted 7 lines
Quoted 4 lines

That would have basically all of the advantages of being built into the kernel (availability, configurability, transparency, hackability), while having all the advantages of a user-space approach as well (flexibility, extensibility, robustness, ease of maintenance, etc.).

Note, I am not advocating building the vmchannel client into the host kernel. [...]

Neither am i. What i suggested was a user-space binary/executable built in tools/perf and put into the initrd.

That approach has the advantages i listed above, without having the disadvantages of in-kernel code you listed.

Thanks,

Ingo

#7 lore raw
Quoted 13 lines · Ingo Molnar
Quoted 13 lines
Quoted 13 lines
Quoted 3 lines

The symbol server's client can certainly access the bits through vmchannel.

Ok, that would work i suspect.

Would be nice to have the symbol server in tools/perf/ and also make it easy to add it to the initrd via a .config switch or so.

That would have basically all of the advantages of being built into the kernel (availability, configurability, transparency, hackability), while having all the advantages of a user-space approach as well (flexibility, extensibility, robustness, ease of maintenance, etc.).

Quoted 6 lines
Quoted 3 lines

Note, I am not advocating building the vmchannel client into the host kernel. [...]

Neither am i. What i suggested was a user-space binary/executable built in tools/perf and put into the initrd.

I'm confused - initrd seems to be guest-side. I was talking about the host side.

For the guest, placing the symbol server in tools/ is reasonable.

Signature · 1 line
error compiling committee.c: too many arguments to function
#8 lore raw
Quoted 12 lines · Avi Kivity
Quoted 11 lines · Ingo Molnar
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

The symbol server's client can certainly access the bits through vmchannel.

Ok, that would work i suspect.

Would be nice to have the symbol server in tools/perf/ and also make it easy to add it to the initrd via a .config switch or so.

That would have basically all of the advantages of being built into the kernel (availability, configurability, transparency, hackability), while having all the advantages of a user-space approach as well (flexibility, extensibility, robustness, ease of maintenance, etc.).

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Note, I am not advocating building the vmchannel client into the host kernel. [...]

Neither am i. What i suggested was a user-space binary/executable built in tools/perf and put into the initrd.

I'm confused - initrd seems to be guest-side. I was talking about the host side.

host side doesnt need much support - just some client capability in perf itself. I suspect vmchannels are sufficiently flexible and configuration-free for such purposes? (i.e. like a filesystem in essence)

Ingo

#9 lore raw
Quoted 8 lines · Ingo Molnar
Quoted 4 lines

I'm confused - initrd seems to be guest-side. I was talking about the host side.

host side doesnt need much support - just some client capability in perf itself. I suspect vmchannels are sufficiently flexible and configuration-free for such purposes? (i.e. like a filesystem in essence)

I haven't followed vmchannel closely, but I think it is. vmchannel is terminated in qemu on the host side, not in the host kernel. So perf would need to connect to qemu.

Signature · 1 line
error compiling committee.c: too many arguments to function
#10 lore raw
Quoted 11 lines · Avi Kivity
Quoted 6 lines · Ingo Molnar
Quoted 3 lines

I'm confused - initrd seems to be guest-side. I was talking about the host side.

host side doesnt need much support - just some client capability in perf itself. I suspect vmchannels are sufficiently flexible and configuration-free for such purposes? (i.e. like a filesystem in essence)

I haven't followed vmchannel closely, but I think it is. vmchannel is terminated in qemu on the host side, not in the host kernel. So perf would need to connect to qemu.

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way? Can we trust it? Is there some proper tooling available to do it, or do we have to push it through 2-3 packages to get such a useful feature done?

( That is the general thought process how many cross-discipline useful
desktop/server features hit the bit bucket before having had any chance of being vetted by users, and why Linux sucks so much when it comes to feature integration and application usability. )

Ingo

#11 lore raw
Quoted 8 lines · Ingo Molnar
Quoted 5 lines

I haven't followed vmchannel closely, but I think it is. vmchannel is terminated in qemu on the host side, not in the host kernel. So perf would need to connect to qemu.

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way?

We know its pid.

Quoted 1 line

Can we trust it?

No choice, it contains the guest address space.

Quoted 4 lines

Is there some proper tooling available to do
it, or do we have to push it through 2-3 packages to get such a useful feature done?

libvirt manages qemu processes, but I don't think this should go through libvirt. qemu can do this directly by opening a unix domain socket in a well-known place.

Quoted 5 lines

( That is the general thought process how many cross-discipline useful
desktop/server features hit the bit bucket before having had any chance of being vetted by users, and why Linux sucks so much when it comes to feature integration and application usability. )

You can't solve everything in the kernel, even with a well populated tools/.

Signature · 1 line
error compiling committee.c: too many arguments to function
#12 lore raw
Quoted 10 lines · Avi Kivity
Quoted 7 lines · Ingo Molnar
Quoted 4 lines

I haven't followed vmchannel closely, but I think it is. vmchannel is terminated in qemu on the host side, not in the host kernel. So perf would need to connect to qemu.

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way?

We know its pid.

How do i get a list of all 'guest instance PIDs', and what is the way to talk to Qemu?

Quoted 3 lines
Quoted 1 line

Can we trust it?

No choice, it contains the guest address space.

I mean, i can trust a kernel service and i can trust /proc/kallsyms.

Can perf trust a random process claiming to be Qemu? What's the trust mechanism here?

Quoted 6 lines
Quoted 2 lines

Is there some proper tooling available to do it, or do we have to push it through 2-3 packages to get such a useful feature done?

libvirt manages qemu processes, but I don't think this should go through libvirt. qemu can do this directly by opening a unix domain socket in a well-known place.

So Qemu has never run into such problems before?

( Sounds weird - i think Qemu configuration itself should be done via a
unix domain socket driven configuration protocol as well. )

Quoted 6 lines
Quoted 4 lines

( That is the general thought process how many cross-discipline useful
desktop/server features hit the bit bucket before having had any chance of being vetted by users, and why Linux sucks so much when it comes to feature integration and application usability. )

You can't solve everything in the kernel, even with a well populated tools/.

Certainly not, but this is a technical problem in the kernel's domain, so it's a fair (and natural) expectation to be able to solve this within the kernel project.

Ingo

#13 lore raw
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar
Quoted 5 lines

I haven't followed vmchannel closely, but I think it is. vmchannel is terminated in qemu on the host side, not in the host kernel. So perf would need to connect to qemu.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way?

We know its pid.

How do i get a list of all 'guest instance PIDs',

Libvirt manages all qemus, but this should be implemented independently of libvirt.

Quoted 3 lines

and what is the way to talk
to Qemu?

In general qemu exposes communication channels (such as the monitor) as tcp connections, unix-domain sockets, stdio, etc. It's very flexible.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Can we trust it?

No choice, it contains the guest address space.

I mean, i can trust a kernel service and i can trust /proc/kallsyms.

Can perf trust a random process claiming to be Qemu? What's the trust mechanism here?

Obviously you can't trust anything you get from a guest, no matter how you get it.

How do you trust a userspace program's symbols? you don't. How do you get them? they're on a well-known location.

Quoted 12 lines
Quoted 7 lines
Quoted 3 lines

Is there some proper tooling available to do it, or do we have to push it through 2-3 packages to get such a useful feature done?

libvirt manages qemu processes, but I don't think this should go through libvirt. qemu can do this directly by opening a unix domain socket in a well-known place.

So Qemu has never run into such problems before?

( Sounds weird - i think Qemu configuration itself should be done via a
unix domain socket driven configuration protocol as well. )

That's exactly what happens. You invoke qemu with -monitor unix:blah,server (or -qmp for a machine-readable format) and have your management application connect to that. You can redirect guest serial ports, console, parallel port, etc. to unix-domain or tcp sockets. vmchannel is an extension of that mechanism.

Quoted 11 lines
Quoted 7 lines
Quoted 5 lines

( That is the general thought process how many cross-discipline useful
desktop/server features hit the bit bucket before having had any chance of being vetted by users, and why Linux sucks so much when it comes to feature integration and application usability. )

You can't solve everything in the kernel, even with a well populated tools/.

Certainly not, but this is a technical problem in the kernel's domain, so it's a fair (and natural) expectation to be able to solve this within the kernel project.

Someone writing perf-gui outside the kernel would have the same problems, no?

Signature · 1 line
error compiling committee.c: too many arguments to function
#14 lore raw
Quoted 9 lines · Avi Kivity
Quoted 4 lines · Ingo Molnar

I mean, i can trust a kernel service and i can trust /proc/kallsyms.

Can perf trust a random process claiming to be Qemu? What's the trust mechanism here?

Obviously you can't trust anything you get from a guest, no matter how you get it.

I'm not talking about the symbol strings and addresses, and the object contents for allocation (or debuginfo). I'm talking about the basic protocol of establishing which guest is which.

I.e. we really want to be able users to:

1) have it all working with a single guest, without having to specify 'which' guest (qemu PID) to work with. That is the dominant usecase both for developers and for a fair portion of testers.

2) Have some reasonable symbolic identification for guests. For example a usable approach would be to have 'perf kvm list', which would list all currently active guests:

$ perf kvm list
[1] Fedora
[2] OpenSuse
[3] Windows-XP
[4] Windows-7

And from that point on 'perf kvm -g OpenSuse record' would do the obvious thing. Users will be able to just use the 'OpenSuse' symbolic name for that guest, even if the guest got restarted and switched its main PID.

Any such facility needs trusted enumeration and a protocol where i can trust that the information i got is authorative. (I.e. 'OpenSuse' truly matches to the OpenSuse session - not to some local user starting up a Qemu instance that claims to be 'OpenSuse'.)

Is such a scheme possible/available? I suspect all the KVM configuration tools (i havent used them in some time - gui and command-line tools alike) use similar methods to ease guest management?

Ingo

#15 lore raw
Quoted 6 lines · Ingo Molnar
Quoted 6 lines
Quoted 6 lines

I mean, i can trust a kernel service and i can trust /proc/kallsyms.

Can perf trust a random process claiming to be Qemu? What's the trust mechanism here?

Quoted 7 lines
Quoted 3 lines

Obviously you can't trust anything you get from a guest, no matter how you get it.

I'm not talking about the symbol strings and addresses, and the object contents for allocation (or debuginfo). I'm talking about the basic protocol of establishing which guest is which.

There is none. So far, qemu only dealt with managing just its own guest, and left all multiple guest management to higher levels up the stack (like libvirt).

Quoted 6 lines

I.e. we really want to be able users to:

1) have it all working with a single guest, without having to specify 'which' guest (qemu PID) to work with. That is the dominant usecase both for developers and for a fair portion of testers.

That's reasonable if we can get it working simply.

Quoted 14 lines

2) Have some reasonable symbolic identification for guests. For example a usable approach would be to have 'perf kvm list', which would list all currently active guests:

$ perf kvm list
[1] Fedora
[2] OpenSuse
[3] Windows-XP
[4] Windows-7

And from that point on 'perf kvm -g OpenSuse record' would do the obvious thing. Users will be able to just use the 'OpenSuse' symbolic name for that guest, even if the guest got restarted and switched its main PID.

Quoted 9 lines

Any such facility needs trusted enumeration and a protocol where i can trust that the information i got is authorative. (I.e. 'OpenSuse' truly matches to the OpenSuse session - not to some local user starting up a Qemu instance that claims to be 'OpenSuse'.)

Is such a scheme possible/available? I suspect all the KVM configuration tools (i havent used them in some time - gui and command-line tools alike) use similar methods to ease guest management?

You can do that through libvirt, but that only works for guests started through libvirt. libvirt provides command-line tools to list and manage guests (for example autostarting them on startup), and tools built on top of libvirt can manage guests graphically.

Looks like we have a layer inversion here. Maybe we need a plugin system - libvirt drops a .so into perf that teaches it how to list guests and get their symbols.

Signature · 1 line
error compiling committee.c: too many arguments to function
#16 lore raw
Quoted 16 lines · Avi Kivity
Quoted 10 lines · Ingo Molnar
Quoted 7 lines
Quoted 5 lines

I mean, i can trust a kernel service and i can trust /proc/kallsyms.

Can perf trust a random process claiming to be Qemu? What's the trust mechanism here?

Obviously you can't trust anything you get from a guest, no matter how you get it.

I'm not talking about the symbol strings and addresses, and the object contents for allocation (or debuginfo). I'm talking about the basic protocol of establishing which guest is which.

There is none. So far, qemu only dealt with managing just its own guest, and left all multiple guest management to higher levels up the stack (like libvirt).

Quoted 7 lines
Quoted 5 lines

I.e. we really want to be able users to:

1) have it all working with a single guest, without having to specify 'which' guest (qemu PID) to work with. That is the dominant usecase both for developers and for a fair portion of testers.

That's reasonable if we can get it working simply.

IMO such ease of use is reasonable and required, full stop.

If it cannot be gotten simply then that's a bug: either in the code, or in the design, or in the development process that led to the design. Bugs need fixing.

Quoted 23 lines
Quoted 14 lines

2) Have some reasonable symbolic identification for guests. For example a usable approach would be to have 'perf kvm list', which would list all currently active guests:

$ perf kvm list
[1] Fedora
[2] OpenSuse
[3] Windows-XP
[4] Windows-7

And from that point on 'perf kvm -g OpenSuse record' would do the obvious thing. Users will be able to just use the 'OpenSuse' symbolic name for that guest, even if the guest got restarted and switched its main PID.

Quoted 8 lines

Any such facility needs trusted enumeration and a protocol where i can trust that the information i got is authorative. (I.e. 'OpenSuse' truly matches to the OpenSuse session - not to some local user starting up a Qemu instance that claims to be 'OpenSuse'.)

Is such a scheme possible/available? I suspect all the KVM configuration tools (i havent used them in some time - gui and command-line tools alike) use similar methods to ease guest management?

Quoted 8 lines

You can do that through libvirt, but that only works for guests started through libvirt. libvirt provides command-line tools to list and manage guests (for example autostarting them on startup), and tools built on top of libvirt can manage guests graphically.

Looks like we have a layer inversion here. Maybe we need a plugin system - libvirt drops a .so into perf that teaches it how to list guests and get their symbols.

Is libvirt used to start up all KVM guests? If not, if it's only used on some distros while other distros have other solutions then there's apparently no good way to get to such information, and the kernel bits of KVM do not provide it.

To the user (and to me) this looks like a KVM bug / missing feature. (and the user doesnt care where the blame is) If that is true then apparently the current KVM design has no technically actionable solution for certain categories of features!

Ingo

#17 lore raw
Quoted 6 lines · Ingo Molnar
Quoted 6 lines

You can do that through libvirt, but that only works for guests started through libvirt. libvirt provides command-line tools to list and manage guests (for example autostarting them on startup), and tools built on top of libvirt can manage guests graphically.

Quoted 9 lines
Quoted 4 lines

Looks like we have a layer inversion here. Maybe we need a plugin system - libvirt drops a .so into perf that teaches it how to list guests and get their symbols.

Is libvirt used to start up all KVM guests? If not, if it's only used on some distros while other distros have other solutions then there's apparently no good way to get to such information, and the kernel bits of KVM do not provide it.

Developers tend to start qemu from the command line, but the majority of users and all distros I know of use libvirt. Some users cobble up their own scripts.

Quoted 5 lines

To the user (and to me) this looks like a KVM bug / missing feature. (and the user doesnt care where the blame is) If that is true then apparently the current KVM design has no technically actionable solution for certain categories of features!

A plugin system allows anyone who is interested to provide the information; they just need to write a plugin for their management tool.

Since we can't prevent people from writing management tools, I don't see what else we can do.

Signature · 1 line
error compiling committee.c: too many arguments to function
#18 lore raw
In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar

[...]

Quoted 6 lines
Quoted 5 lines

I.e. we really want to be able users to:

1) have it all working with a single guest, without having to specify 'which' guest (qemu PID) to work with. That is the dominant usecase both for developers and for a fair portion of testers.

Quoted 6 lines
Quoted 1 line

That's reasonable if we can get it working simply.

IMO such ease of use is reasonable and required, full stop.
If it cannot be gotten simply then that's a bug: either in the code, or in the design, or in the development process that led to the design. Bugs need fixing. [...]

Perhaps the fact that kvm happens to deal with an interesting application area (virtualization) is misleading here. As far as the host kernel or other host userspace is concerned, qemu is just some random unprivileged userspace program (with some *optional* /dev/kvm services that might happen to require temporary root).

As such, perf trying to instrument qemu is no different than perf trying to instrument any other userspace widget. Therefore, expecting 'trusted enumeration' of instances is just as sensible as using 'trusted ps' and 'trusted /var/run/FOO.pid files'.

- FChE

#19 lore raw
Quoted 23 lines · Frank Ch. Eigler
Quoted 7 lines · Ingo Molnar

[...]

Quoted 6 lines
Quoted 5 lines

I.e. we really want to be able users to:

1) have it all working with a single guest, without having to specify 'which' guest (qemu PID) to work with. That is the dominant usecase both for developers and for a fair portion of testers.

Quoted 6 lines
Quoted 1 line

That's reasonable if we can get it working simply.

IMO such ease of use is reasonable and required, full stop.
If it cannot be gotten simply then that's a bug: either in the code, or in the design, or in the development process that led to the design. Bugs need fixing. [...]

Perhaps the fact that kvm happens to deal with an interesting application area (virtualization) is misleading here. As far as the host kernel or other host userspace is concerned, qemu is just some random unprivileged userspace program (with some *optional* /dev/kvm services that might happen to require temporary root).

Quoted 4 lines

As such, perf trying to instrument qemu is no different than perf trying to instrument any other userspace widget. Therefore, expecting 'trusted enumeration' of instances is just as sensible as using 'trusted ps' and 'trusted /var/run/FOO.pid files'.

You are quite mistaken: KVM isnt really a 'random unprivileged application' in this context, it is clearly an extension of system/kernel services.

( Which can be seen from the simple fact that what started the discussion was
'how do we get /proc/kallsyms from the guest'. I.e. an extension of the existing host-space /proc/kallsyms was desired. )

In that sense the most natural 'extension' would be the solution i mentioned a week or two ago: to have a (read only) mount of all guest filesystems, plus a channel for profiling/tracing data. That would make symbol parsing easier and it's what extends the existing 'host space' abstraction in the most natural way.

( It doesnt even have to be done via the kernel - Qemu could implement that
via FUSE for example. )

As a second best option a 'symbol server' might be used too.

Thanks,

Ingo

#20 lore raw

Hi -

Quoted 9 lines · Ingo Molnar

[...]

Quoted 4 lines

Perhaps the fact that kvm happens to deal with an interesting application area (virtualization) is misleading here. As far as the host kernel or other host userspace is concerned, qemu is just some random unprivileged userspace program [...]

You are quite mistaken: KVM isnt really a 'random unprivileged application' in this context, it is clearly an extension of system/kernel services.

I don't know what "extension of system/kernel services" means in this context, beyond something running on the system/kernel, like every other process. To clarify, to what extent do you consider your classification similarly clear for a host is running

* multiple kvm instances run as unprivileged users
* non-kvm OS simulators such as vmware or xen or gdb
* kvm instances running something other than linux

Quoted 4 lines

( Which can be seen from the simple fact that what started the discussion was 'how do we get /proc/kallsyms from the guest'. I.e. an extension of the existing host-space /proc/kallsyms was desired. )

(Sorry, that smacks of circular reasoning.)

It may be a charming convenience function for perf users to give them shortcuts for certain favoured configurations (kvm running freshest linux), but that says more about perf than kvm.

- FChE

#21 lore raw
Quoted 9 lines · Frank Ch. Eigler

Hi -

Quoted 5 lines · Ingo Molnar

[...]

Quoted 4 lines

Perhaps the fact that kvm happens to deal with an interesting application area (virtualization) is misleading here. As far as the host kernel or other host userspace is concerned, qemu is just some random unprivileged userspace program [...]

Quoted 7 lines
Quoted 3 lines

You are quite mistaken: KVM isnt really a 'random unprivileged application' in this context, it is clearly an extension of system/kernel services.

I don't know what "extension of system/kernel services" means in this context, beyond something running on the system/kernel, like every other process. [...]

It means something like my example of 'extended to guest space' /proc/kallsyms:

Quoted 7 lines
Quoted 5 lines

[...]

( Which can be seen from the simple fact that what started the
discussion was 'how do we get /proc/kallsyms from the guest'. I.e. an extension of the existing host-space /proc/kallsyms was desired. )

(Sorry, that smacks of circular reasoning.)

To me it sounds like an example supporting my point. /proc/kallsyms is a service by the kernel, and 'perf kvm' desires this to be extended to guest space as well.

Thanks,

Ingo

#35 lore raw
In reply to Ingo Molnar
Quoted 18 lines · Ingo Molnar
Quoted 11 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar

I mean, i can trust a kernel service and i can trust /proc/kallsyms.

Can perf trust a random process claiming to be Qemu? What's the trust mechanism here?

Obviously you can't trust anything you get from a guest, no matter how you get it.

I'm not talking about the symbol strings and addresses, and the object contents for allocation (or debuginfo). I'm talking about the basic protocol of establishing which guest is which.

Quoted 6 lines

I.e. we really want to be able users to:

1) have it all working with a single guest, without having to specify 'which' guest (qemu PID) to work with. That is the dominant usecase both for developers and for a fair portion of testers.

You're making too many assumptions.

There is no list of guests anymore than there is a list of web browsers.

You can have a multi-tenant scenario where you have distinct groups of virtual machines running as unprivileged users.

Quoted 10 lines

2) Have some reasonable symbolic identification for guests. For example a usable approach would be to have 'perf kvm list', which would list all currently active guests:

$ perf kvm list
[1] Fedora
[2] OpenSuse
[3] Windows-XP
[4] Windows-7

Quoted 4 lines

And from that point on 'perf kvm -g OpenSuse record' would do the obvious thing. Users will be able to just use the 'OpenSuse' symbolic name for that guest, even if the guest got restarted and switched its main PID.

Does "perf kvm list" always run as root? What if two unprivileged users both have a VM named "Fedora"?

If we look at the use-case, it's going to be something like, a user is creating virtual machines and wants to get performance information about them.

Having to run a separate tool like perf is not going to be what they would expect they had to do. Instead, they would either use their existing GUI tool (like virt-manager) or they would use their management interface (either QMP or libvirt).

The complexity of interaction is due to the fact that perf shouldn't be a stand alone tool. It should be a library or something with a programmatic interface that another tool can make use of.

Regards,

Anthony Liguori

Quoted 10 lines

Is such a scheme possible/available? I suspect all the KVM configuration tools (i havent used them in some time - gui and command-line tools alike) use similar methods to ease guest management?

Ingo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#22 lore raw
In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar

You are quite mistaken: KVM isnt really a 'random unprivileged application' in this context, it is clearly an extension of system/kernel services.

( Which can be seen from the simple fact that what started the discussion was
'how do we get /proc/kallsyms from the guest'. I.e. an extension of the existing host-space /proc/kallsyms was desired. )

Random tools (like perf) should not be able to do what you describe. It's a security nightmare.

If it's desirable to have /proc/kallsyms available, we can expose an interface in QEMU to provide that. That can then be plumbed through libvirt and QMP.

Then a management tool can use libvirt or QMP to obtain that information and interact with the kernel appropriately.

Quoted 9 lines

In that sense the most natural 'extension' would be the solution i mentioned a week or two ago: to have a (read only) mount of all guest filesystems, plus a channel for profiling/tracing data. That would make symbol parsing easier and it's what extends the existing 'host space' abstraction in the most natural way.

( It doesnt even have to be done via the kernel - Qemu could implement that
via FUSE for example. )

No way. The guest has sensitive data and exposing it widely on the host is a bad thing to do. It's a bad interface. We can expose specific information about guests but only through our existing channels which are validated through a security infrastructure.

Ultimately, your goal is to keep perf a simple tool with little dependencies. But practically speaking, if you want to add features to it, it's going to have to interact with other subsystems in the appropriate way. That means, it's going to need to interact with libvirt or QMP.

If you want all applications to expose their data via synthetic file systems, then there's always plan9 :-)

Regards,

Anthony Liguori

#36 lore raw
In reply to Anthony Liguori
Quoted 20 lines · Anthony Liguori
Quoted 13 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Ingo Molnar

I mean, i can trust a kernel service and i can trust /proc/kallsyms.

Can perf trust a random process claiming to be Qemu? What's the trust mechanism here?

Obviously you can't trust anything you get from a guest, no matter how you get it.

I'm not talking about the symbol strings and addresses, and the object contents for allocation (or debuginfo). I'm talking about the basic protocol of establishing which guest is which.

Quoted 5 lines

I.e. we really want to be able users to:

1) have it all working with a single guest, without having to specify 'which' guest (qemu PID) to work with. That is the dominant usecase both for developers and for a fair portion of testers.

Quoted 6 lines

You're making too many assumptions.

There is no list of guests anymore than there is a list of web browsers.

You can have a multi-tenant scenario where you have distinct groups of virtual machines running as unprivileged users.

"multi-tenant" and groups is not a valid excuse at all for giving crappy technology in the simplest case: when there's a single VM. Yes, eventually it can be supported and any sane scheme will naturally support it too, but it's by no means what we care about primarily when it comes to these tools.

I thought everyone learned the lesson behind SystemTap's failure (and to a certain degree this was behind Oprofile's failure as well): when it comes to tooling/instrumentation we dont want to concentrate on the fancy complex setups and abstract requirements drawn up by CIOs, as development isnt being done there. Concentrate on our developers today, and provide no-compromises usability to those who contribute stuff.

If we dont help make the simplest (and most common) use-case convenient then we are failing on a fundamental level.

Quoted 10 lines
Quoted 10 lines

2) Have some reasonable symbolic identification for guests. For example a usable approach would be to have 'perf kvm list', which would list all currently active guests:

$ perf kvm list
[1] Fedora
[2] OpenSuse
[3] Windows-XP
[4] Windows-7

Quoted 6 lines
Quoted 3 lines

And from that point on 'perf kvm -g OpenSuse record' would do the obvious thing. Users will be able to just use the 'OpenSuse' symbolic name for that guest, even if the guest got restarted and switched its main PID.

Does "perf kvm list" always run as root? What if two unprivileged users both have a VM named "Fedora"?

Again, the single-VM case is the most important case, by far. If you have multiple VMs running and want to develop the kernel on multiple VMs (sounds rather messy if you think it through ...), what would happen is similar to what happens when we have two probes for example:

 # perf probe schedule
 Added new event:
   probe:schedule                           (on schedule+0)

You can now use it on all perf tools, such as:

perf record -e probe:schedule -a sleep 1

 # perf probe -f schedule   
 Added new event:
   probe:schedule_1                         (on schedule+0)

You can now use it on all perf tools, such as:

perf record -e probe:schedule_1 -a sleep 1

 # perf probe -f schedule
 Added new event:
   probe:schedule_2                         (on schedule+0)

You can now use it on all perf tools, such as:

perf record -e probe:schedule_2 -a sleep 1

Something similar could be used for KVM/Qemu: whichever got created first is named 'Fedora', the second is named 'Fedora-2'.

Quoted 4 lines

If we look at the use-case, it's going to be something like, a user is creating virtual machines and wants to get performance information about them.

Quoted 8 lines

Having to run a separate tool like perf is not going to be what they would expect they had to do. Instead, they would either use their existing GUI tool (like virt-manager) or they would use their management interface (either QMP or libvirt).

The complexity of interaction is due to the fact that perf shouldn't be a stand alone tool. It should be a library or something with a programmatic interface that another tool can make use of.

But ... a GUI interface/integration is of course possible too, and it's being worked on.

perf is mainly a kernel developer tool, and kernel developers generally dont use GUIs to do their stuff: which is the (sole) reason why its first ~850 commits of tools/perf/ were done without a GUI. We go where our developers are.

In any case it's not an excuse to have no proper command-line tooling. In fact if you cannot get simpler, more atomic command-line tooling right then you'll probably doubly suck at doing a GUI as well.

Ingo

#23 lore raw
In reply to Anthony Liguori
Quoted 10 lines · Anthony Liguori
Quoted 6 lines · Ingo Molnar

You are quite mistaken: KVM isnt really a 'random unprivileged application' in this context, it is clearly an extension of system/kernel services.

( Which can be seen from the simple fact that what started the discussion was
'how do we get /proc/kallsyms from the guest'. I.e. an extension of the existing host-space /proc/kallsyms was desired. )

Random tools (like perf) should not be able to do what you describe. It's a security nightmare.

A security nightmare exactly how? Mind to go into details as i dont understand your point.

Quoted 13 lines

If it's desirable to have /proc/kallsyms available, we can expose an interface in QEMU to provide that. That can then be plumbed through libvirt and QMP.

Then a management tool can use libvirt or QMP to obtain that information and interact with the kernel appropriately.

Quoted 6 lines

In that sense the most natural 'extension' would be the solution i mentioned a week or two ago: to have a (read only) mount of all guest filesystems, plus a channel for profiling/tracing data. That would make symbol parsing easier and it's what extends the existing 'host space' abstraction in the most natural way.

Quoted 5 lines
Quoted 2 lines

( It doesnt even have to be done via the kernel - Qemu could implement that
via FUSE for example. )

No way. The guest has sensitive data and exposing it widely on the host is a bad thing to do. [...]

Firstly, you are putting words into my mouth, as i said nothing about 'exposing it widely'. I suggest exposing it under the privileges of whoever has access to the guest image.

Secondly, regarding confidentiality, and this is guest security 101: whoever can access the image on the host _already_ has access to all the guest data!

A Linux image can generally be loopback mounted straight away:

losetup -o 32256 /dev/loop0 ./guest-image.img
mount -o ro /dev/loop0 /mnt-guest

(Or, if you are an unprivileged user who cannot mount, it can be read via ext2 tools.)

There's nothing the guest can do about that. The host is in total control of guest image data for heaven's sake!

All i'm suggesting is to make what is already possible more convenient.

Ingo

#24 lore raw
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Anthony Liguori
Quoted 7 lines · Ingo Molnar

You are quite mistaken: KVM isnt really a 'random unprivileged application' in this context, it is clearly an extension of system/kernel services.

( Which can be seen from the simple fact that what started the discussion was
'how do we get /proc/kallsyms from the guest'. I.e. an extension of the existing host-space /proc/kallsyms was desired. )

Quoted 6 lines
Quoted 3 lines

Random tools (like perf) should not be able to do what you describe. It's a security nightmare.

A security nightmare exactly how? Mind to go into details as i dont understand your point.

Assume you're using SELinux to implement mandatory access control. How do you label this file system?

Generally speaking, we don't know the difference between /proc/kallsyms vs. /dev/mem if we do generic passthrough. While it might be safe to have a relaxed label of kallsyms (since it's read only), it's clearly not safe to do that for /dev/mem, /etc/shadow, or any file containing sensitive information.

Rather, we ought to expose a higher level interface that we have more confidence in with respect to understanding the ramifications of exposing that guest data.

Quoted 8 lines
Quoted 4 lines

No way. The guest has sensitive data and exposing it widely on the host is a bad thing to do. [...]

Firstly, you are putting words into my mouth, as i said nothing about 'exposing it widely'. I suggest exposing it under the privileges of whoever has access to the guest image.

That doesn't work as nicely with SELinux.

It's completely reasonable to have a user that can interact in a read only mode with a VM via libvirt but cannot read the guest's disk images or the guest's memory contents.

Quoted 5 lines

Secondly, regarding confidentiality, and this is guest security 101: whoever can access the image on the host _already_ has access to all the guest data!

A Linux image can generally be loopback mounted straight away:

Quoted 9 lines

losetup -o 32256 /dev/loop0 ./guest-image.img
mount -o ro /dev/loop0 /mnt-guest

(Or, if you are an unprivileged user who cannot mount, it can be read via ext2 tools.)

There's nothing the guest can do about that. The host is in total control of guest image data for heaven's sake!

It's not that simple in a MAC environment.

Regards,

Anthony Liguori

Quoted 4 lines

All i'm suggesting is to make what is already possible more convenient.

Ingo

#25 lore raw
Quoted 15 lines · Anthony Liguori
Quoted 6 lines · Ingo Molnar
Quoted 4 lines · Anthony Liguori
Quoted 3 lines · Ingo Molnar

You are quite mistaken: KVM isnt really a 'random unprivileged application' in this context, it is clearly an extension of system/kernel services.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

( Which can be seen from the simple fact that what started the discussion was
'how do we get /proc/kallsyms from the guest'. I.e. an extension of the existing host-space /proc/kallsyms was desired. )

Random tools (like perf) should not be able to do what you describe. It's a security nightmare.

A security nightmare exactly how? Mind to go into details as i dont understand your point.

Quoted 8 lines

Assume you're using SELinux to implement mandatory access control. How do you label this file system?

Generally speaking, we don't know the difference between /proc/kallsyms vs. /dev/mem if we do generic passthrough. While it might be safe to have a relaxed label of kallsyms (since it's read only), it's clearly not safe to do that for /dev/mem, /etc/shadow, or any file containing sensitive information.

What's your _point_? Please outline a threat model, a vector of attack, _anything_ that substantiates your "it's a security nightmare" claim.

Quoted 3 lines

Rather, we ought to expose a higher level interface that we have more confidence in with respect to understanding the ramifications of exposing that guest data.

Exactly, we want something that has a flexible namespace and works well with Linux tools in general. Preferably that namespace should be human readable, and it should be hierarchic, and it should have a well-known permission model.

This concept exists in Linux and is generally called a 'filesystem'.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

No way. The guest has sensitive data and exposing it widely on the host is a bad thing to do. [...]

Firstly, you are putting words into my mouth, as i said nothing about 'exposing it widely'. I suggest exposing it under the privileges of whoever has access to the guest image.

Quoted 5 lines

That doesn't work as nicely with SELinux.

It's completely reasonable to have a user that can interact in a read only mode with a VM via libvirt but cannot read the guest's disk images or the guest's memory contents.

If a user cannot read the image file then the user has no access to its contents via other namespaces either. That is, of course, a basic security aspect.

( That is perfectly true with a non-SELinux Unix permission model as well, and
is true in the SELinux case as well. )

Quoted 8 lines
Quoted 8 lines

Secondly, regarding confidentiality, and this is guest security 101: whoever can access the image on the host _already_ has access to all the guest data!

A Linux image can generally be loopback mounted straight away:

losetup -o 32256 /dev/loop0 ./guest-image.img
mount -o ro /dev/loop0 /mnt-guest

Quoted 7 lines
Quoted 5 lines

(Or, if you are an unprivileged user who cannot mount, it can be read via ext2 tools.)

There's nothing the guest can do about that. The host is in total control of guest image data for heaven's sake!

It's not that simple in a MAC environment.

Erm. Please explain to me, what exactly is 'not that simple' in a MAC environment?

Also, i'd like to note that the 'restrictive SELinux setups' usecases are pretty secondary.

To demonstrate that, i'd like every KVM developer on this list who reads this mail and who has their home development system where they produce their patches set up in a restrictive MAC environment, in that you cannot even read the images you are using, to chime in with a "I'm doing that" reply.

If there's just a _single_ KVM developer amongst dozens and dozens of developers on this list who develops in an environment like that i'd be surprised. That result should pretty much tell you where the weight of instrumentation focus should lie - and it isnt on restrictive MAC environments
...

Ingo

#331 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way? Can we trust it? Is there some proper tooling available to do it, or do we have to push it through 2-3 packages to get such a useful feature done?

Since we want to implement a pmu usable for the guest anyway why we don't just use a guests perf to get all information we want? If we get a pmu-nmi from the guest we just re-inject it to the guest and perf in the guest gives us all information we wand including kernel and userspace symbols, stack traces, and so on.

In the previous thread we discussed about a direct trace channel between guest and host kernel (which can be used for ftrace events for example). This channel could be used to transport this information to the host kernel.

The only additional feature needed is a way for the host to start a perf instance in the guest.

Opinions?

Joerg

#332 lore raw
Quoted 7 lines · oerg Roedel
Quoted 5 lines · Ingo Molnar

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way? Can we trust it? Is there some proper tooling available to do it, or do we have to push it through 2-3 packages to get such a useful feature done?

Quoted 5 lines

Since we want to implement a pmu usable for the guest anyway why we don't just use a guests perf to get all information we want? If we get a pmu-nmi from the guest we just re-inject it to the guest and perf in the guest gives us all information we wand including kernel and userspace symbols, stack traces, and so on.

I guess this aims to get information from old environments running on kvm for life extension :)

Quoted 4 lines

In the previous thread we discussed about a direct trace channel between guest and host kernel (which can be used for ftrace events for example). This channel could be used to transport this information to the host kernel.

Interesting! I know the people who are trying to do that with systemtap. See, http://vesper.sourceforge.net/

Quoted 3 lines

The only additional feature needed is a way for the host to start a perf instance in the guest.

# ssh localguest perf record --host-chanel ... ? B-)

Thank you,

Quoted 11 lines

Opinions?

Joerg

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#26 lore raw
In reply to Ingo Molnar
Quoted 26 lines · Ingo Molnar
Quoted 23 lines · Anthony Liguori
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Anthony Liguori
Quoted 7 lines · Ingo Molnar

You are quite mistaken: KVM isnt really a 'random unprivileged application' in this context, it is clearly an extension of system/kernel services.

( Which can be seen from the simple fact that what started the discussion was
'how do we get /proc/kallsyms from the guest'. I.e. an extension of the existing host-space /proc/kallsyms was desired. )

Quoted 6 lines
Quoted 3 lines

Random tools (like perf) should not be able to do what you describe. It's a security nightmare.

A security nightmare exactly how? Mind to go into details as i dont understand your point.

Assume you're using SELinux to implement mandatory access control. How do you label this file system?

Quoted 9 lines
Quoted 6 lines

Generally speaking, we don't know the difference between /proc/kallsyms vs. /dev/mem if we do generic passthrough. While it might be safe to have a relaxed label of kallsyms (since it's read only), it's clearly not safe to do that for /dev/mem, /etc/shadow, or any file containing sensitive information.

What's your _point_? Please outline a threat model, a vector of attack, _anything_ that substantiates your "it's a security nightmare" claim.

You suggested "to have a (read only) mount of all guest filesystems".

As I described earlier, not all of the information within the guest filesystem has the same level of sensitivity. If you exposed a generic interface like this, it makes it very difficult to delegate privileges.

Delegating privileges is important because from in a higher security environment, you may want to prevent a management tool from accessing the VM's disk directly, but still allow it to do basic operations (in particular, to view performance statistics).

Quoted 10 lines
Quoted 4 lines

Rather, we ought to expose a higher level interface that we have more confidence in with respect to understanding the ramifications of exposing that guest data.

Exactly, we want something that has a flexible namespace and works well with Linux tools in general. Preferably that namespace should be human readable, and it should be hierarchic, and it should have a well-known permission model.

This concept exists in Linux and is generally called a 'filesystem'.

If you want to use a synthetic filesystem as the management interface for qemu, that's one thing. But you suggested exposing the guest filesystem in its entirely and that's what I disagreed with.

Quoted 7 lines

If a user cannot read the image file then the user has no access to its contents via other namespaces either. That is, of course, a basic security aspect.

( That is perfectly true with a non-SELinux Unix permission model as well, and
is true in the SELinux case as well. )

I don't think that's reasonable at all. The guest may encrypt it's disk image. It still ought to be possible to run perf against that guest, no?

Quoted 11 lines

Erm. Please explain to me, what exactly is 'not that simple' in a MAC environment?

Also, i'd like to note that the 'restrictive SELinux setups' usecases are pretty secondary.

To demonstrate that, i'd like every KVM developer on this list who reads this mail and who has their home development system where they produce their patches set up in a restrictive MAC environment, in that you cannot even read the images you are using, to chime in with a "I'm doing that" reply.

My home system doesn't run SELinux but I work daily with systems that are using SELinux.

I want to be able to run tools like perf on these systems because ultimately, I need to debug these systems on a daily basis.

But that's missing the point. We want to have an interface that works for both cases so that we're not maintaining two separate interfaces.

We've rat holed a bit though. You want:

1) to run perf kvm list and be able to enumerate KVM guests

2) for this to Just Work with qemu guests launched from the command line

You could achieve (1) by tying perf to libvirt but that won't work for (2). There are a few practical problems with (2).

qemu does not require the user to associate any uniquely identifying information with a VM. We've also optimized the command line use case so that if all you want to do is run a disk image, you just execute "qemu foo.img". To satisfy your use case, we would either have to force a use to always specify unique information, which would be less convenient for our users or we would have to let the name be an optional parameter.

As it turns out, we already support "qemu -name Fedora foo.img". What we don't do today, but I've been suggesting we should, is automatically create a QMP management socket in a well known location based on the -name parameter when it's specified. That would let a tool like perf Just Work provided that a user specified -name.

No one uses -name today though and I'm sure you don't either.

The only way to really address this is to change the interaction. Instead of running perf externally to qemu, we should support a perf command in the qemu monitor that can then tie directly to the perf tooling. That gives us the best possible user experience.

We can't do that though unless perf is a library or is in some way more programmatic.

Regards,

Anthony Liguori

#37 lore raw
In reply to Ingo Molnar
Quoted 16 lines · Ingo Molnar
Quoted 4 lines

If we look at the use-case, it's going to be something like, a user is creating virtual machines and wants to get performance information about them.

Quoted 9 lines

Having to run a separate tool like perf is not going to be what they would expect they had to do. Instead, they would either use their existing GUI tool (like virt-manager) or they would use their management interface (either QMP or libvirt).

The complexity of interaction is due to the fact that perf shouldn't be a stand alone tool. It should be a library or something with a programmatic interface that another tool can make use of.

But ... a GUI interface/integration is of course possible too, and it's being worked on.

Quoted 9 lines

perf is mainly a kernel developer tool, and kernel developers generally dont use GUIs to do their stuff: which is the (sole) reason why its first ~850 commits of tools/perf/ were done without a GUI. We go where our developers are.

In any case it's not an excuse to have no proper command-line tooling. In fact if you cannot get simpler, more atomic command-line tooling right then you'll probably doubly suck at doing a GUI as well.

It's about who owns the user interface.

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Regards,

Anthony Liguori

Quoted 2 lines

Ingo

#27 lore raw
In reply to Anthony Liguori

Hi -

Quoted 5 lines · Anthony Liguori

[...]
The only way to really address this is to change the interaction. Instead of running perf externally to qemu, we should support a perf command in the qemu monitor that can then tie directly to the perf tooling. That gives us the best possible user experience.

To what extent could this be solved with less crossing of isolation/abstraction layers, if the perfctr facilities were properly virtualized? That way guests could run perf goo internally. Optionally virt tools on the host side could aggregate data from cooperating self-monitoring guests.

- FChE

#344 lore raw
In reply to Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Yanmin
Quoted 6 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

Quoted 7 lines
Quoted 4 lines

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

That certainly works, though automatic association of guest data with guest symbols is friendlier.

Thanks. Originally, I planed to add a -G parameter to perf. Such like
-G 8888:/XXX/XXX/guestkallsyms:/XXX/XXX/modules,8889:/XXX/XXX/guestkallsyms:/XXX/XXX/modules 8888 and 8889 are just qemu guest pid.

So we could define multiple guest os symbol files. But it seems ugly, and 'perf kvm report --sort pid" and 'perf kvm top --pid' could provide similar functionality.

Quoted 41 lines
Quoted 31 lines
Quoted 30 lines
Quoted 29 lines

diff -Nraup linux-2.6_tipmaster0315/arch/x86/kvm/vmx.c linux-2.6_tipmaster0315_perfkvm/arch/x86/kvm/vmx.c

arch/x86/kvm/vmx.c +12 -0
@@ -26,6 +26,7 @@
   #include<linux/sched.h>
   #include<linux/moduleparam.h>
   #include<linux/ftrace_event.h>
+#include<linux/perf_event.h>
   #include "kvm_cache_regs.h"
   #include "x86.h"
 
@@ -3632,6 +3633,43 @@ static void update_cr8_intercept(struct
   	vmcs_write32(TPR_THRESHOLD, irr);
   }
 
+DEFINE_PER_CPU(int, kvm_in_guest) = {0};
+
+static void kvm_set_in_guest(void)
+{
+	percpu_write(kvm_in_guest, 1);
+}
+
+static int kvm_is_in_guest(void)
+{
+	return percpu_read(kvm_in_guest);
+}
 
 
Quoted 6 lines
Quoted 2 lines

There is already PF_VCPU for this.

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Quoted 6 lines

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct

Quoted 9 lines
arch/x86/kvm/vmx.c +6 -0
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+	.is_in_guest 		= kvm_is_in_guest,
+	.is_user_mode		= kvm_is_user_mode,
+	.get_guest_ip		= kvm_get_guest_ip,
+	.reset_in_guest		= kvm_reset_in_guest,
+};
 

Should be in common code, not vmx specific.

Quoted 7 lines
Quoted 4 lines

Right. I discussed with Yangsheng. I will move above data structures and callbacks to file arch/x86/kvm/x86.c, and add get_ip, a new callback to kvm_x86_ops.

You will need access to the vcpu pointer (kvm_rip_read() needs it), you can put it in a percpu variable.

We do so now in a new patch.

Quoted 2 lines

I guess if it's not null, you know
you're in a guest, so no need for PF_VCPU.

Good suggestion.

Thanks.

#28 lore raw
In reply to Frank Ch. Eigler
Quoted 10 lines · Frank Ch. Eigler

Hi -

Quoted 6 lines · Anthony Liguori

[...]
The only way to really address this is to change the interaction. Instead of running perf externally to qemu, we should support a perf command in the qemu monitor that can then tie directly to the perf tooling. That gives us the best possible user experience.

Quoted 4 lines

To what extent could this be solved with less crossing of isolation/abstraction layers, if the perfctr facilities were properly virtualized?

That's the more interesting (by far) usage model. In general guest owners don't have access to the host, and host owners can't (and shouldn't) change guests.

Monitoring guests from the host is useful for kvm developers, but less so for users.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#333 lore raw
In reply to oerg Roedel
Quoted 9 lines · oerg Roedel
Quoted 5 lines · Ingo Molnar

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way? Can we trust it? Is there some proper tooling available to do it, or do we have to push it through 2-3 packages to get such a useful feature done?

Since we want to implement a pmu usable for the guest anyway why we don't just use a guests perf to get all information we want? [...]

Look at the previous posting of this patch, this is something new and rather unique. The main power in the 'perf kvm' kind of instrumentation is to profile _both_ the host and the guest on the host, using the same tool (often using the same kernel) and using similar workloads, and do profile comparisons using 'perf diff'.

Note that KVM's in-kernel design makes it easy to offer this kind of host/guest shared implementation that Yanmin has created. Other virtulization solutions with a poorer design (for example where the hypervisor code base is split away from the guest implementation) will have it much harder to create something similar.

That kind of integrated approach can result in very interesting finds straight away, see:

http://lkml.indiana.edu/hypermail/linux/kernel/1003.0/00613.html

( the profile there demoes the need for spinlock accelerators for example -
there's clearly assymetrically large overhead in guest spinlock code. Guess how much else we'll be able to find with a full 'perf kvm' implementation. )

One of the main goals of a virtualization implementation is to eliminate as many performance differences to the host kernel as possible. From the first day KVM was released the overriding question from users was always: 'how much slower is it than native, and which workloads are hit worst, and why, and could you pretty please speed up important workload XYZ'.

'perf kvm' helps exactly that kind of development workflow.

Note that with oprofile you can already do separate guest space and host space profiling (with the timer driven fallbackin the guest). One idea with 'perf kvm' is to change that paradigm of forced separation and forced duplication and to supprt the workflow that most developers employ: use the host space for development and unify instrumentation in an intuitive framework. Yanmin's 'perf kvm' patch is a very good step towards that goal.

Anyway ... look at the patches, try them and see it for yourself. Back in the days when i did KVM performance work i wish i had something like Yanmin's 'perf kvm' feature. I'd probably still be hacking KVM today ;-)

So, the code is there, it's useful and it's up to you guys whether you live with this opportunity - the perf developers are certainly eager to help out with the details. There's already tons of per kernel subsystem perf helper
tools: perf sched, perf kmem, perf lock, perf bench, perf timechart.

'perf kvm' is really a natural and good next step IMO that underlines the main design goodness KVM brought to the world of virtualization: proper guest/host code base integration.

Thanks,

Ingo

#38 lore raw

[RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Anthony Liguori
Quoted 25 lines · Anthony Liguori
Quoted 15 lines · Ingo Molnar
Quoted 4 lines

If we look at the use-case, it's going to be something like, a user is creating virtual machines and wants to get performance information about them.

Quoted 8 lines

Having to run a separate tool like perf is not going to be what they would expect they had to do. Instead, they would either use their existing GUI tool (like virt-manager) or they would use their management interface (either QMP or libvirt).

The complexity of interaction is due to the fact that perf shouldn't be a stand alone tool. It should be a library or something with a programmatic interface that another tool can make use of.

But ... a GUI interface/integration is of course possible too, and it's being worked on.

Quoted 8 lines

perf is mainly a kernel developer tool, and kernel developers generally dont use GUIs to do their stuff: which is the (sole) reason why its first ~850 commits of tools/perf/ were done without a GUI. We go where our developers are.

In any case it's not an excuse to have no proper command-line tooling. In fact if you cannot get simpler, more atomic command-line tooling right then you'll probably doubly suck at doing a GUI as well.

Quoted 5 lines

It's about who owns the user interface.

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Of course illogical modularization complicates things 'significantly'.

I wish both you and Avi looked back 3-4 years and realized what made KVM so successful back then and why the hearts and minds of virtualization developers were captured by KVM almost overnight.

KVM's main strength back then was that it was a surprisingly functional piece of code offered by a 10 KLOC patch - right on the very latest upstream kernel. Code was shared with upstream, there was version parity, and it all was in the same single repo which was (and is) a pleasure to develop on.

Unlike Xen, which was a 200+ KLOC patch on top of a forked 10 MLOC kernel a few upstream versions back. Xen had constant version friction due to that fork and due to that forced/false separation/modularization: Xen _itself_ was a fork of Linux to begin with. (for exampe Xen still had my copyrights last i checked, which it got from old Linux code i worked on)

That forced separation and version friction in Xen was a development and productization nightmare, and developing on KVM was a truly refreshing experience. (I'll go out on a limb to declare that you wont find a _single_ developer on this list who will tells us otherwise.)

Fast forward to 2010. The kernel side of KVM is maximum goodness - by far the worst-quality remaining aspects of KVM are precisely in areas that you
mention: 'if we have to support third party tools, then it significantly complicates things'. You kept Qemu as an external 'third party' entity to KVM, and KVM is clearly hurting from that - just see the recent KVM usability thread for examples about suckage.

So a similar 'complication' is the crux of the matter behind KVM quality
problems: you've not followed through with the original KVM vision and you have not applied that concept to Qemu!

And please realize that the user does not care that KVM's kernel bits are top notch, if the rest of the package has sucky aspects: it's always the weakest link of the chain that matters to the user.

Xen sucked because of such design shortsightedness on the kernel level, and now KVM suffers from it on the user space level.

If you want to jump to the next level of technological quality you need to fix this attitude and you need to go back to the design roots of KVM. Concentrate on Qemu (as that is the weakest link now), make it a first class member of the KVM repo and simplify your development model by having a single repo:

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

- co-develop new features within the same patch. Release new versions of kvm-qemu and the kvm bits at the same time (together with the upstream kernel), at well defined points in time.

- encourage kernel-space and user-space KVM developers to work on both user-space and kernel-space bits as a single unit. It's one project and a single experience to the user.

- [ and probably libvirt should go there too ]

If KVM's hypervisor and guest kernel code can enjoy the benefits of a single repository, why cannot the rest of KVM enjoy the same developer goodness? Only fixing that will bring the break-through in quality - not more manpower really.

Yes, i've read a thousand excuses for why this is an absolutely impossible and a bad thing to do, and none of them was really convincing to me - and you also have become rather emotional about all the arguments so it's hard to argue about it on a technical basis.

We made a similar (admittedly very difficult ...) design jump from oprofile to perf, and i can tell you from that experience that it's day and night, both in terms of development and in terms of the end result!

( We recently also made another, kernel/kernel unification that had a very
positive result: we unified the 32-bit and 64-bit x86 architectures. Even within the same repo the unification of technology is generally a good thing. The KVM/Qemu situation is different - it's more similar to the perf design. )

Not having to fight artificial package boundaries and forced package separation is very refreshing experience to a developer - and very rewarding and flexible to develop on. ABI compatibility is _easier_ to maintain in such a model. It's quite similar to the jump from Xen hacking to KVM hacking (i did both). It's a bit like the jump from CVS to Git. Trust me, you _cannot_ know the difference if you havent tried a similar jump with Qemu.

Anyway, you made your position about this rather clear and you are clearly uncompromising, so i just wanted to post this note to the list: you'll waste years of your life on a visibly crappy development model that has been unable to break through a magic usability barrier for the past 2-3 years - just like the Xen mis-design has wasted so many people's time and effort in kernel space.

Thanks,

Ingo

#33 lore raw
In reply to Frank Ch. Eigler
Quoted 9 lines · Frank Ch. Eigler

Hi -

Quoted 5 lines · Anthony Liguori

[...]
The only way to really address this is to change the interaction. Instead of running perf externally to qemu, we should support a perf command in the qemu monitor that can then tie directly to the perf tooling. That gives us the best possible user experience.

Quoted 3 lines

To what extent could this be solved with less crossing of isolation/abstraction layers, if the perfctr facilities were properly virtualized? [...]

Note, 'perfctr' is a different out-of-tree Linux kernel project run by someone
else: it offers the /dev/perfctr special-purpose device that allows raw, unabstracted, low-level access to the PMU.

I suspect the one you wanted to mention here is called 'perf' or 'perf events'. (and used to be called 'performance counters' or 'perfcounters' until it got renamed about a year ago)

Thanks,

Ingo

#29 lore raw
In reply to Avi Kivity
Quoted 2 lines · Avi Kivity

Monitoring guests from the host is useful for kvm developers, but less so for users.

Guest space profiling is easy, and 'perf kvm' is not about that. (plain 'perf' will work if a proper paravirt channel is opened to the host)

I think you might have misunderstood the purpose and role of the 'perf kvm' patch here? 'perf kvm' is aimed at KVM developers: it is them who improve KVM code, not guest kernel users.

Ingo

#30 lore raw
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · Avi Kivity

Monitoring guests from the host is useful for kvm developers, but less so for users.

Quoted 7 lines

Guest space profiling is easy, and 'perf kvm' is not about that. (plain 'perf' will work if a proper paravirt channel is opened to the host)

I think you might have misunderstood the purpose and role of the 'perf kvm' patch here? 'perf kvm' is aimed at KVM developers: it is them who improve KVM code, not guest kernel users.

Of course I understood it. My point was that 'perf kvm' serves a tiny minority of users. That doesn't mean it isn't useful, just that it doesn't satisfy all needs by itself.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#34 lore raw
In reply to Anthony Liguori
Quoted 3 lines · Anthony Liguori

If you want to use a synthetic filesystem as the management interface for qemu, that's one thing. But you suggested exposing the guest filesystem in its entirely and that's what I disagreed with.

What did you think, that it would be world-readable? Why would we do such a stupid thing? Any mounted content should at minimum match whatever policy covers the image file. The mounting of contents is not a privilege escallation and it is already possible today - just not integrated properly and not practical. (and apparently not implemented for all the wrong 'security' reasons)

Quoted 2 lines

The guest may encrypt it's disk image. It still ought to be possible to run perf against that guest, no?

_In_ the guest you can of course run it just fine. (once paravirt bits are in place)

That has no connection to 'perf kvm' though, which this patch submission is about ...

If you want unified profiling of both host and guest then you need access to both the guest and the host. This is what the 'perf kvm' patch is about. Please read the patch, i think you might be misunderstanding what it does ...

Regarding encrypted contents - that's really a distraction but the host has absolute, 100% control over the guest and there's nothing the guest can do about that - unless you are thinking about the sub-sub-case of Orwellian DRM-locked-down systems - in which case there's nothing for the host to mount and the guest can reject any requests for information on itself and impose additional policy that way. So it's a security non-issue.

Note that DRM is pretty much the worst place to look at when it comes to
usability: DRM lock-down is the anti-thesis of usability. Do you really want KVM to match the mind-set of the RIAA and MPAA? Why do you pretend that a developer cannot mount his own disk image? Pretty please, help Linux instead, where development is driven by usability and accessibility ...

Thanks,

Ingo

#31 lore raw
In reply to Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Ingo Molnar
Quoted 2 lines · Avi Kivity

Monitoring guests from the host is useful for kvm developers, but less so for users.

Guest space profiling is easy, and 'perf kvm' is not about that. (plain 'perf' will work if a proper paravirt channel is opened to the host)

Quoted 6 lines
Quoted 3 lines

I think you might have misunderstood the purpose and role of the 'perf kvm' patch here? 'perf kvm' is aimed at KVM developers: it is them who improve KVM code, not guest kernel users.

Of course I understood it. My point was that 'perf kvm' serves a tiny minority of users. [...]

I hope you wont be disappointed to learn that 100% of Linux, all 13+ million lines of it, was and is being developed by a tiny, tiny, tiny minority of users ;-)

Quoted 2 lines

[...] That doesn't mean it isn't useful, just that it doesn't satisfy all needs by itself.

Of course - and it doesnt bring world peace either. One step at a time.

Thanks,

Ingo

#338 lore raw
In reply to Ingo Molnar
Quoted 47 lines · Ingo Molnar
Quoted 45 lines · Zhang, Yanmin
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

Quoted 8 lines
Quoted 2 lines

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yeah. For maximum utility i'd suggest to extend --pid to include this, and introduce --tid for the previous, limited-to-a-single-task functionality.

Most users would expect --pid to work like a 'late attach' - i.e. to work like strace -f or like a gdb attach.

Thanks Ingo, Avi.

I worked out below patch against tip/master of March 15th.

Subject: [PATCH] Change perf's parameter --pid to process-wide collection
From: Zhang, Yanmin <[email protected]>

Change parameter -p (--pid) to real process pid and add -t (--tid) meaning thread id. Now, --pid means perf collects the statistics of all threads of the process, while --tid means perf just collect the statistics of that thread.

BTW, the patch fixes a bug of 'perf stat -p'. 'perf stat' always configures attr->disabled=1 if it isn't a system-wide collection. If there is a '-p' and no forks, 'perf stat -p' doesn't collect any data. In addition, the while(!done) in run_perf_stat consumes 100% single cpu time which has bad impact on running workload. I added a sleep(1) in the loop.

---

tools/perf/builtin-record.c +150 -96
diff -Nraup linux-2.6_tipmaster0315/tools/perf/builtin-record.c linux-2.6_tipmaster0315_perfpid/tools/perf/builtin-record.c
@@ -27,7 +27,7 @@
 #include <unistd.h>
 #include <sched.h>
 
-static int			fd[MAX_NR_CPUS][MAX_COUNTERS];
+static int			*fd[MAX_NR_CPUS][MAX_COUNTERS];
 
 static long			default_interval		=      0;
 
@@ -43,6 +43,9 @@ static int			raw_samples			=      0;
 static int			system_wide			=      0;
 static int			profile_cpu			=     -1;
 static pid_t			target_pid			=     -1;
+static pid_t			target_tid			=     -1;
+static int			*all_tids			=      NULL;
+static int			thread_num			=      0;
 static pid_t			child_pid			=     -1;
 static int			inherit				=      1;
 static int			force				=      0;
@@ -60,7 +63,7 @@ static struct timeval		this_read;
 
 static u64			bytes_written			=      0;
 
-static struct pollfd		event_array[MAX_NR_CPUS * MAX_COUNTERS];
+static struct pollfd		*event_array;
 
 static int			nr_poll				=      0;
 static int			nr_cpu				=      0;
@@ -77,7 +80,7 @@ struct mmap_data {
 	unsigned int		prev;
 };
 
-static struct mmap_data		mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
+static struct mmap_data		*mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
 
 static unsigned long mmap_read_head(struct mmap_data *md)
 {
@@ -225,11 +228,12 @@ static struct perf_header_attr *get_head
 	return h_attr;
 }
 
-static void create_counter(int counter, int cpu, pid_t pid, bool forks)
+static void create_counter(int counter, int cpu, bool forks)
 {
 	char *filter = filters[counter];
 	struct perf_event_attr *attr = attrs + counter;
 	struct perf_header_attr *h_attr;
+	int thread_index;
 	int track = !counter; /* only the first counter needs these */
 	int ret;
 	struct {
@@ -280,117 +284,124 @@ static void create_counter(int counter, 
 	if (forks)
 		attr->enable_on_exec = 1;
 
+	for (thread_index = 0; thread_index < thread_num; thread_index++) {
 try_again:
-	fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0);
+		fd[nr_cpu][counter][thread_index] = sys_perf_event_open(attr,
+				all_tids[thread_index], cpu, group_fd, 0);
 
-	if (fd[nr_cpu][counter] < 0) {
-		int err = errno;
+		if (fd[nr_cpu][counter][thread_index] < 0) {
+			int err = errno;
 
-		if (err == EPERM || err == EACCES)
-			die("Permission error - are you root?\n"
-			    "\t Consider tweaking /proc/sys/kernel/perf_event_paranoid.\n");
-		else if (err ==  ENODEV && profile_cpu != -1)
-			die("No such device - did you specify an out-of-range profile CPU?\n");
+			if (err == EPERM || err == EACCES)
+				die("Permission error - are you root?\n"
+						"\t Consider tweaking /proc/sys/kernel/perf_event_paranoid.\n");
+			else if (err ==  ENODEV && profile_cpu != -1)
+				die("No such device - did you specify an out-of-range profile CPU?\n");
 
-		/*
-		 * If it's cycles then fall back to hrtimer
-		 * based cpu-clock-tick sw counter, which
-		 * is always available even if no PMU support:
-		 */
-		if (attr->type == PERF_TYPE_HARDWARE
-			&& attr->config == PERF_COUNT_HW_CPU_CYCLES) {
+			/*
+			 * If it's cycles then fall back to hrtimer
+			 * based cpu-clock-tick sw counter, which
+			 * is always available even if no PMU support:
+			 */
+			if (attr->type == PERF_TYPE_HARDWARE
+					&& attr->config == PERF_COUNT_HW_CPU_CYCLES) {
 
-			if (verbose)
-				warning(" ... trying to fall back to cpu-clock-ticks\n");
-			attr->type = PERF_TYPE_SOFTWARE;
-			attr->config = PERF_COUNT_SW_CPU_CLOCK;
-			goto try_again;
-		}
-		printf("\n");
-		error("perfcounter syscall returned with %d (%s)\n",
-			fd[nr_cpu][counter], strerror(err));
+				if (verbose)
+					warning(" ... trying to fall back to cpu-clock-ticks\n");
+				attr->type = PERF_TYPE_SOFTWARE;
+				attr->config = PERF_COUNT_SW_CPU_CLOCK;
+				goto try_again;
+			}
+			printf("\n");
+			error("perfcounter syscall returned with %d (%s)\n",
+				fd[nr_cpu][counter][thread_index],
+				strerror(err));
 
 #if defined(__i386__) || defined(__x86_64__)
-		if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP)
-			die("No hardware sampling interrupt available. No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.\n");
+			if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP)
+				die("No hardware sampling interrupt available. No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.\n");
 #endif
 
-		die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
-		exit(-1);
-	}
+			die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
+			exit(-1);
+		}
 
-	h_attr = get_header_attr(attr, counter);
-	if (h_attr == NULL)
-		die("nomem\n");
+		h_attr = get_header_attr(attr, counter);
+		if (h_attr == NULL)
+			die("nomem\n");
+
+		if (!file_new) {
+			if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
+				fprintf(stderr, "incompatible append\n");
+				exit(-1);
+			}
+		}
 
-	if (!file_new) {
-		if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
-			fprintf(stderr, "incompatible append\n");
+		if (read(fd[nr_cpu][counter][thread_index], &read_data, sizeof(read_data)) == -1) {
+			perror("Unable to read perf file descriptor\n");
 			exit(-1);
 		}
-	}
-
-	if (read(fd[nr_cpu][counter], &read_data, sizeof(read_data)) == -1) {
-		perror("Unable to read perf file descriptor\n");
-		exit(-1);
-	}
 
-	if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
-		pr_warning("Not enough memory to add id\n");
-		exit(-1);
-	}
+		if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
+			pr_warning("Not enough memory to add id\n");
+			exit(-1);
+		}
 
-	assert(fd[nr_cpu][counter] >= 0);
-	fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK);
+		assert(fd[nr_cpu][counter][thread_index] >= 0);
+		fcntl(fd[nr_cpu][counter][thread_index], F_SETFL, O_NONBLOCK);
 
-	/*
-	 * First counter acts as the group leader:
-	 */
-	if (group && group_fd == -1)
-		group_fd = fd[nr_cpu][counter];
-	if (multiplex && multiplex_fd == -1)
-		multiplex_fd = fd[nr_cpu][counter];
+		/*
+		 * First counter acts as the group leader:
+		 */
+		if (group && group_fd == -1)
+			group_fd = fd[nr_cpu][counter][thread_index];
+		if (multiplex && multiplex_fd == -1)
+			multiplex_fd = fd[nr_cpu][counter][thread_index];
 
-	if (multiplex && fd[nr_cpu][counter] != multiplex_fd) {
+		if (multiplex && fd[nr_cpu][counter][thread_index] != multiplex_fd) {
 
-		ret = ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd);
-		assert(ret != -1);
-	} else {
-		event_array[nr_poll].fd = fd[nr_cpu][counter];
-		event_array[nr_poll].events = POLLIN;
-		nr_poll++;
-
-		mmap_array[nr_cpu][counter].counter = counter;
-		mmap_array[nr_cpu][counter].prev = 0;
-		mmap_array[nr_cpu][counter].mask = mmap_pages*page_size - 1;
-		mmap_array[nr_cpu][counter].base = mmap(NULL, (mmap_pages+1)*page_size,
-				PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter], 0);
-		if (mmap_array[nr_cpu][counter].base == MAP_FAILED) {
-			error("failed to mmap with %d (%s)\n", errno, strerror(errno));
-			exit(-1);
+			ret = ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd);
+			assert(ret != -1);
+		} else {
+			event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index];
+			event_array[nr_poll].events = POLLIN;
+			nr_poll++;
+
+			mmap_array[nr_cpu][counter][thread_index].counter = counter;
+			mmap_array[nr_cpu][counter][thread_index].prev = 0;
+			mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1;
+			mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL,
+							(mmap_pages+1)*page_size,
+							PROT_READ|PROT_WRITE, MAP_SHARED,
+							fd[nr_cpu][counter][thread_index],
+							0);
+			if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) {
+				error("failed to mmap with %d (%s)\n", errno, strerror(errno));
+				exit(-1);
+			}
 		}
-	}
 
-	if (filter != NULL) {
-		ret = ioctl(fd[nr_cpu][counter],
-			    PERF_EVENT_IOC_SET_FILTER, filter);
-		if (ret) {
-			error("failed to set filter with %d (%s)\n", errno,
-			      strerror(errno));
-			exit(-1);
+		if (filter != NULL) {
+			ret = ioctl(fd[nr_cpu][counter][thread_index],
+					PERF_EVENT_IOC_SET_FILTER, filter);
+			if (ret) {
+				error("failed to set filter with %d (%s)\n", errno,
+						strerror(errno));
+				exit(-1);
+			}
 		}
-	}
 
-	ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
+		ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_ENABLE);
+	}
 }
 
-static void open_counters(int cpu, pid_t pid, bool forks)
+static void open_counters(int cpu, bool forks)
 {
 	int counter;
 
 	group_fd = -1;
 	for (counter = 0; counter < nr_counters; counter++)
-		create_counter(counter, cpu, pid, forks);
+		create_counter(counter, cpu, forks);
 
 	nr_cpu++;
 }
@@ -425,7 +436,7 @@ static int __cmd_record(int argc, const 
 	int err;
 	unsigned long waking = 0;
 	int child_ready_pipe[2], go_pipe[2];
-	const bool forks = target_pid == -1 && argc > 0;
+	const bool forks = target_tid == -1 && argc > 0;
 	char buf;
 
 	page_size = sysconf(_SC_PAGE_SIZE);
@@ -534,7 +545,7 @@ static int __cmd_record(int argc, const 
 		child_pid = pid;
 
 		if (!system_wide)
-			target_pid = pid;
+			target_tid = pid;
 
 		close(child_ready_pipe[1]);
 		close(go_pipe[0]);
@@ -550,11 +561,11 @@ static int __cmd_record(int argc, const 
 
 
 	if ((!system_wide && !inherit) || profile_cpu != -1) {
-		open_counters(profile_cpu, target_pid, forks);
+		open_counters(profile_cpu, forks);
 	} else {
 		nr_cpus = read_cpu_map();
 		for (i = 0; i < nr_cpus; i++)
-			open_counters(cpumap[i], target_pid, forks);
+			open_counters(cpumap[i], forks);
 	}
 
 	if (file_new) {
@@ -579,7 +590,7 @@ static int __cmd_record(int argc, const 
 	}
 
 	if (!system_wide && profile_cpu == -1)
-		event__synthesize_thread(target_pid, process_synthesized_event,
+		event__synthesize_thread(target_tid, process_synthesized_event,
 					 session);
 	else
 		event__synthesize_threads(process_synthesized_event, session);
@@ -602,11 +613,15 @@ static int __cmd_record(int argc, const 
 
 	for (;;) {
 		int hits = samples;
+		int thread;
 
 		for (i = 0; i < nr_cpu; i++) {
 			for (counter = 0; counter < nr_counters; counter++) {
-				if (mmap_array[i][counter].base)
-					mmap_read(&mmap_array[i][counter]);
+				for (thread = 0;
+					thread < thread_num; thread++) {
+					if (mmap_array[i][counter][thread].base)
+						mmap_read(&mmap_array[i][counter][thread]);
+				}
 			}
 		}
 
@@ -619,8 +634,13 @@ static int __cmd_record(int argc, const 
 
 		if (done) {
 			for (i = 0; i < nr_cpu; i++) {
-				for (counter = 0; counter < nr_counters; counter++)
-					ioctl(fd[i][counter], PERF_EVENT_IOC_DISABLE);
+				for (counter = 0; counter < nr_counters;
+					counter++) {
+					for (thread = 0;
+						thread < thread_num; thread++)
+						ioctl(fd[i][counter][thread],
+							PERF_EVENT_IOC_DISABLE);
+				}
 			}
 		}
 	}
@@ -653,6 +673,8 @@ static const struct option options[] = {
 		     "event filter", parse_filter),
 	OPT_INTEGER('p', "pid", &target_pid,
 		    "record events on existing pid"),
+	OPT_INTEGER('t', "tid", &target_tid,
+		    "record events on existing thread id"),
 	OPT_INTEGER('r', "realtime", &realtime_prio,
 		    "collect data with this RT SCHED_FIFO priority"),
 	OPT_BOOLEAN('R', "raw-samples", &raw_samples,
@@ -693,10 +715,11 @@ static const struct option options[] = {
 int cmd_record(int argc, const char **argv, const char *prefix __used)
 {
 	int counter;
+	int i,j;
 
 	argc = parse_options(argc, argv, options, record_usage,
 			    PARSE_OPT_STOP_AT_NON_OPTION);
-	if (!argc && target_pid == -1 && !system_wide && profile_cpu == -1)
+	if (!argc && target_tid == -1 && !system_wide && profile_cpu == -1)
 		usage_with_options(record_usage, options);
 
 	symbol__init();
@@ -707,6 +730,37 @@ int cmd_record(int argc, const char **ar
 		attrs[0].config = PERF_COUNT_HW_CPU_CYCLES;
 	}
 
+	if (target_pid != -1) {
+		target_tid = target_pid;
+		thread_num = find_all_tid(target_pid, &all_tids);
+		if (thread_num <= 0) {
+			fprintf(stderr, "Can't find all threads of pid %d\n",
+				target_pid);
+			usage_with_options(record_usage, options);
+		}
+	} else {
+		all_tids=malloc(sizeof(int));
+		if (!all_tids)
+			return -ENOMEM;
+
+		all_tids[0] = target_tid;
+		thread_num = 1;
+	}
+
+	for (i = 0; i < MAX_NR_CPUS; i++) {
+		for (j = 0; j < MAX_COUNTERS; j++) {
+			fd[i][j] = malloc(sizeof(int)*thread_num);
+			mmap_array[i][j] = malloc(
+				sizeof(struct mmap_data)*thread_num);
+			if (!fd[i][j] || !mmap_array[i][j])
+				return -ENOMEM;
+		}
+	}
+	event_array = malloc(
+		sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num);
+	if (!event_array)
+		return -ENOMEM;
+
 	/*
 	 * User specified count overrides default frequency.
 	 */
tools/perf/builtin-stat.c +78 -33

219 lines not on this page · raw message

tools/perf/builtin-top.c +102 -54

251 lines not on this page · raw message

tools/perf/util/thread.c +32 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/thread.c linux-2.6_tipmaster0315_perfpid/tools/perf/util/thread.c
@@ -7,6 +7,37 @@
 #include "util.h"
 #include "debug.h"
 
+int find_all_tid(int pid, int ** all_tid)
+{
+	char name[256];
+	int items;
+	struct dirent **namelist = NULL;
+	int ret = 0;
+	int i;
+
+	sprintf(name, "/proc/%d/task", pid);
+	items = scandir(name, &namelist, NULL, NULL);
+	if (items <= 0)
+                return -ENOENT;
+	*all_tid = malloc(sizeof(int) * items);
+	if (!*all_tid) {
+		ret = -ENOMEM;
+		goto failure;
+	}
+
+	for (i = 0; i < items; i++)
+		(*all_tid)[i] = atoi(namelist[i]->d_name);
+
+	ret = items;
+
+failure:
+	for (i=0; i<items; i++)
+		free(namelist[i]);
+	free(namelist);
+
+	return ret;
+}
+
 void map_groups__init(struct map_groups *self)
 {
 	int i;
@@ -348,3 +379,4 @@ struct symbol *map_groups__find_symbol(s
 
 	return NULL;
 }
+
tools/perf/util/thread.h +1 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/thread.h linux-2.6_tipmaster0315_perfpid/tools/perf/util/thread.h
@@ -23,6 +23,7 @@ struct thread {
 	int			comm_len;
 };
 
+int find_all_tid(int pid, int ** all_tid);
 void map_groups__init(struct map_groups *self);
 int thread__set_comm(struct thread *self, const char *comm);
 int thread__comm_len(struct thread *self);
#345 lore raw
In reply to Zhang, Yanmin
Quoted 13 lines · Yanmin
Quoted 12 lines · Avi Kivity
Quoted 3 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 5 lines
Quoted 2 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Signature · 2 lines
regards
Yang, Sheng
#346 lore raw
Quoted 4 lines · Sheng Yang
Quoted 4 lines

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

Quoted 9 lines

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

That's pretty bad, as NMI runs on a separate stack (via IST). So if another NMI happens while our int $2 is running, the stack will be corrupted.

Quoted 7 lines

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

I think you need DM_NMI for that to work correctly.

An alternative is to call the NMI handler directly.

Signature · 1 line
error compiling committee.c: too many arguments to function
#347 lore raw
Quoted 10 lines · On Wednesday 17 March 2010 17:41:58 Avi Kivity wrote:
Quoted 9 lines · Sheng Yang
Quoted 3 lines

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

Quoted 7 lines
Quoted 3 lines

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

That's pretty bad, as NMI runs on a separate stack (via IST). So if another NMI happens while our int $2 is running, the stack will be corrupted.

Though hardware didn't provide this kind of block, software at least would warn about it... nmi_enter() still would be executed by "int $2", and result in BUG() if we are already in NMI context(OK, it is a little better than mysterious crash due to corrupted stack).

Quoted 11 lines
Quoted 7 lines

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

I think you need DM_NMI for that to work correctly.

An alternative is to call the NMI handler directly.

apic_send_IPI_self() already took care of APIC_DM_NMI.

And NMI handler would block the following NMI?

Signature · 2 lines
regards
Yang, Sheng
#348 lore raw
Quoted 7 lines · Sheng Yang
Quoted 5 lines

I think you need DM_NMI for that to work correctly.

An alternative is to call the NMI handler directly.

apic_send_IPI_self() already took care of APIC_DM_NMI.

So it does (though not for x2apic?). I don't see why it doesn't work.

Quoted 3 lines

And NMI handler would block the following NMI?

It wouldn't - won't work without extensive changes.

Signature · 1 line
error compiling committee.c: too many arguments to function
#349 lore raw
In reply to Sheng Yang
Quoted 32 lines · Sheng Yang
Quoted 15 lines · Yanmin
Quoted 13 lines · Avi Kivity
Quoted 4 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 6 lines
Quoted 3 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

Quoted 7 lines

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Zach

#350 lore raw
Quoted 35 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 34 lines · Sheng Yang
Quoted 13 lines · Yanmin
Quoted 12 lines · Avi Kivity
Quoted 3 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 6 lines
Quoted 2 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

Quoted 5 lines
Quoted 2 lines

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

Signature · 2 lines
regards
Yang, Sheng
#339 lore raw
In reply to Zhang, Yanmin
Quoted 68 lines · Yanmin
Quoted 47 lines · Ingo Molnar
Quoted 45 lines · Zhang, Yanmin
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

Quoted 8 lines
Quoted 2 lines

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yeah. For maximum utility i'd suggest to extend --pid to include this, and introduce --tid for the previous, limited-to-a-single-task functionality.

Most users would expect --pid to work like a 'late attach' - i.e. to work like strace -f or like a gdb attach.

Thanks Ingo, Avi.

I worked out below patch against tip/master of March 15th.

Subject: [PATCH] Change perf's parameter --pid to process-wide collection
From: Zhang, Yanmin <[email protected]>

Change parameter -p (--pid) to real process pid and add -t (--tid) meaning thread id. Now, --pid means perf collects the statistics of all threads of the process, while --tid means perf just collect the statistics of that thread.

Quoted 7 lines

BTW, the patch fixes a bug of 'perf stat -p'. 'perf stat' always configures attr->disabled=1 if it isn't a system-wide collection. If there is a '-p' and no forks, 'perf stat -p' doesn't collect any data. In addition, the while(!done) in run_perf_stat consumes 100% single cpu time which has bad impact on running workload. I added a sleep(1) in the loop.

Ingo,

Sorry, the patch has bugs. I need do a better job and will work out 2 separate patches against the 2 issues.

Yanmin

#351 lore raw
In reply to Sheng Yang
Quoted 44 lines · Sheng Yang
Quoted 42 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 40 lines · Sheng Yang
Quoted 15 lines · Yanmin
Quoted 13 lines · Avi Kivity
Quoted 4 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 7 lines
Quoted 3 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Quoted 8 lines
Quoted 3 lines

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

That's the only defined case, and it is defined because the vector field is ignore for DM_NMI. Vol 3A (exact section numbers may vary depending on your version).

8.5.1 / 8.6.1

'100 (NMI) Delivers an NMI interrupt to the target processor or processors. The vector information is ignored'

8.5.2 Valid Interrupt Vectors

'Local and I/O APICs support 240 of these vectors (in the range of 16 to 255) as valid interrupts.'

8.8.4 Interrupt Acceptance for Fixed Interrupts

'...; vectors 0 through 15 are reserved by the APIC (see also: Section 8.5.2, "Valid Interrupt Vectors")'

So I misremembered, apparently you can deliver interrupts 0x10-0x1f, but vectors 0x00-0x0f are not valid to send via APIC or I/O APIC.

Zach

#352 lore raw
Quoted 62 lines · On Thursday 18 March 2010 12:50:58 Zachary Amsden wrote:
Quoted 40 lines · Sheng Yang
Quoted 39 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 37 lines · Sheng Yang
Quoted 13 lines · Yanmin
Quoted 12 lines · Avi Kivity
Quoted 3 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 6 lines
Quoted 2 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Quoted 6 lines
Quoted 2 lines

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

That's the only defined case, and it is defined because the vector field is ignore for DM_NMI. Vol 3A (exact section numbers may vary depending on your version).

8.5.1 / 8.6.1

'100 (NMI) Delivers an NMI interrupt to the target processor or processors. The vector information is ignored'

8.5.2 Valid Interrupt Vectors

'Local and I/O APICs support 240 of these vectors (in the range of 16 to
255) as valid interrupts.'

Quoted 7 lines

8.8.4 Interrupt Acceptance for Fixed Interrupts

'...; vectors 0 through 15 are reserved by the APIC (see also: Section 8.5.2, "Valid Interrupt Vectors")'

So I misremembered, apparently you can deliver interrupts 0x10-0x1f, but vectors 0x00-0x0f are not valid to send via APIC or I/O APIC.

As you pointed out, NMI is not "Fixed interrupt". If we want to send NMI, it would need a specific delivery mode rather than vector number.

And if you look at code, if we specific NMI_VECTOR, the delivery mode would be set to NMI.

So what's wrong here?

Signature · 2 lines
regards
Yang, Sheng
#32 lore raw
In reply to Avi Kivity

Hi Avi, Ingo,

I've been following through this long thread since the very first email.

I'm a performance engineer whose job is to tune workloads run on top of KVM (and Xen previously). As a performance engineer, I desperately want to have a tool that can monitor the host and guests at same time. Think about >100 guests mixed with Linux/Windows running together on single system, being able to know what's happening is critical to do performance analysis. Actually I am the person asked Yanmin to add feature for CPU utilization break down (into host_usr, host_krn, guest_usr, guest_krn) so that I can monitor dozens of running guests. I hasn't made this patch work on my system yet but I _do_ think this patch is a very good start.

And finally, monitoring guests from host is useful for users too (administrator and performance guy like me). I really appreciate you guys' work and would love to provide feedback from my point of view if needed.

Regards,

HUANG, Zhiteng

Intel SSG/SSD/SPA/PRC Scalability Lab

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Avi Kivity
Sent: Wednesday, March 17, 2010 11:55 AM
To: Frank Ch. Eigler
Cc: Anthony Liguori; Ingo Molnar; Zhang, Yanmin; Peter Zijlstra; Sheng Yang; [email protected]; [email protected]; Marcelo Tosatti; oerg Roedel; Jes Sorensen; Gleb Natapov; Zachary Amsden; [email protected]
Subject: Re: [PATCH] Enhance perf to collect KVM guest os statistics from host side

Quoted 10 lines · Frank Ch. Eigler

Hi -

Quoted 6 lines · Anthony Liguori

[...]
The only way to really address this is to change the interaction. Instead of running perf externally to qemu, we should support a perf command in the qemu monitor that can then tie directly to the perf tooling. That gives us the best possible user experience.

Quoted 4 lines

To what extent could this be solved with less crossing of isolation/abstraction layers, if the perfctr facilities were properly virtualized?

That's the more interesting (by far) usage model. In general guest owners don't have access to the host, and host owners can't (and shouldn't) change guests.

Monitoring guests from the host is useful for kvm developers, but less so for users.

Signature · 6 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#353 lore raw
In reply to Sheng Yang
Quoted 72 lines · On Thursday 18 March 2010 13:22:28 Sheng Yang wrote:
Quoted 63 lines · On Thursday 18 March 2010 12:50:58 Zachary Amsden wrote:
Quoted 41 lines · Sheng Yang
Quoted 40 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 38 lines · Sheng Yang
Quoted 14 lines · Yanmin
Quoted 13 lines · Avi Kivity
Quoted 3 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 6 lines
Quoted 2 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Quoted 6 lines
Quoted 2 lines

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

That's the only defined case, and it is defined because the vector field is ignore for DM_NMI. Vol 3A (exact section numbers may vary depending on your version).

8.5.1 / 8.6.1

'100 (NMI) Delivers an NMI interrupt to the target processor or processors. The vector information is ignored'

8.5.2 Valid Interrupt Vectors

'Local and I/O APICs support 240 of these vectors (in the range of 16 to
255) as valid interrupts.'

Quoted 7 lines

8.8.4 Interrupt Acceptance for Fixed Interrupts

'...; vectors 0 through 15 are reserved by the APIC (see also: Section 8.5.2, "Valid Interrupt Vectors")'

So I misremembered, apparently you can deliver interrupts 0x10-0x1f, but vectors 0x00-0x0f are not valid to send via APIC or I/O APIC.

Quoted 7 lines

As you pointed out, NMI is not "Fixed interrupt". If we want to send NMI,
it would need a specific delivery mode rather than vector number.

And if you look at code, if we specific NMI_VECTOR, the delivery mode would
be set to NMI.

So what's wrong here?

OK, I think I understand your points now. You meant that these vectors can't be filled in vector field directly, right? But NMI is a exception due to DM_NMI. Is that your point? I think we agree on this.

Signature · 2 lines
regards
Yang, Sheng
#340 lore raw
In reply to Zhang, Yanmin
Quoted 75 lines · Yanmin
Quoted 74 lines · Yanmin
Quoted 47 lines · Ingo Molnar
Quoted 45 lines · Zhang, Yanmin
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

Quoted 8 lines
Quoted 2 lines

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yeah. For maximum utility i'd suggest to extend --pid to include this, and introduce --tid for the previous, limited-to-a-single-task functionality.

Most users would expect --pid to work like a 'late attach' - i.e. to work like strace -f or like a gdb attach.

Thanks Ingo, Avi.

I worked out below patch against tip/master of March 15th.

Subject: [PATCH] Change perf's parameter --pid to process-wide collection
From: Zhang, Yanmin <[email protected]>

Change parameter -p (--pid) to real process pid and add -t (--tid) meaning thread id. Now, --pid means perf collects the statistics of all threads of the process, while --tid means perf just collect the statistics of that thread.

BTW, the patch fixes a bug of 'perf stat -p'. 'perf stat' always configures attr->disabled=1 if it isn't a system-wide collection. If there is a '-p' and no forks, 'perf stat -p' doesn't collect any data. In addition, the while(!done) in run_perf_stat consumes 100% single cpu time which has bad impact on running workload. I added a sleep(1) in the loop.

Quoted 5 lines
Quoted 1 line

Ingo,

Sorry, the patch has bugs. I need do a better job and will work out 2 separate patches against the 2 issues.

I worked out 3 new patches against tip/master tree of Mar. 17th.

1) Patch perf_stat: Fix the issue that perf doesn't enable counters when target_pid != -1. Change the condition to fork/exec subcommand. If there is a subcommand parameter, perf always fork/exec it. The usage example is:
#perf stat -a sleep 10
So this command could collect statistics for 10 seconds precisely. User still could stop it by CTRL+C.

2) Patch perf_record: Fix the issue that when perf forks/exec a subcommand, it should enable all counters after the new process is execing.Change the condition to fork/exec subcommand. If there is a subcommand parameter, perf always fork/exec it. The usage example is:
#perf record -f -a sleep 10
So this command could collect statistics for 10 seconds precisely. User still could stop it by CTRL+C.

3) perf_pid: Change parameter --pid to process-wide collection. Add --tid which means collecting thread-wide statistics. Usage example is:
#perf top -p 8888
#perf record -p 8888 -f sleep 10
#perf stat -p 8888 -f sleep 10

Arnaldo,

Pls. apply the 3 attached patches.

Yanmin

tools/perf/builtin-stat.c +14 -10
diff -Nraup linux-2.6_tipmaster0317/tools/perf/builtin-stat.c linux-2.6_tipmaster0317_fixstat/tools/perf/builtin-stat.c
@@ -159,8 +159,10 @@ static void create_perf_stat_counter(int
 		}
 	} else {
 		attr->inherit	     = inherit;
-		attr->disabled	     = 1;
-		attr->enable_on_exec = 1;
+		if (target_pid == -1) {
+			attr->disabled = 1;
+			attr->enable_on_exec = 1;
+		}
 
 		fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0);
 		if (fd[0][counter] < 0 && verbose)
@@ -251,9 +253,9 @@ static int run_perf_stat(int argc __used
 	unsigned long long t0, t1;
 	int status = 0;
 	int counter;
-	int pid = target_pid;
+	int pid;
 	int child_ready_pipe[2], go_pipe[2];
-	const bool forks = (target_pid == -1 && argc > 0);
+	const bool forks = (argc > 0);
 	char buf;
 
 	if (!system_wide)
@@ -265,10 +267,10 @@ static int run_perf_stat(int argc __used
 	}
 
 	if (forks) {
-		if ((pid = fork()) < 0)
+		if ((child_pid = fork()) < 0)
 			perror("failed to fork");
 
-		if (!pid) {
+		if (!child_pid) {
 			close(child_ready_pipe[0]);
 			close(go_pipe[1]);
 			fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
@@ -297,8 +299,6 @@ static int run_perf_stat(int argc __used
 			exit(-1);
 		}
 
-		child_pid = pid;
-
 		/*
 		 * Wait for the child to be ready to exec.
 		 */
@@ -309,6 +309,10 @@ static int run_perf_stat(int argc __used
 		close(child_ready_pipe[0]);
 	}
 
+	if (target_pid == -1)
+		pid = child_pid;
+	else
+		pid = target_pid;
 	for (counter = 0; counter < nr_counters; counter++)
 		create_perf_stat_counter(counter, pid);
 
@@ -321,7 +325,7 @@ static int run_perf_stat(int argc __used
 		close(go_pipe[1]);
 		wait(&status);
 	} else {
-		while(!done);
+		while(!done) sleep(1);
 	}
 
 	t1 = rdclock();
@@ -459,7 +463,7 @@ static volatile int signr = -1;
 
 static void skip_signal(int signo)
 {
-	if(target_pid != -1)
+	if(child_pid == -1)
 		done = 1;
 
 	signr = signo;
tools/perf/builtin-record.c +15 -18
diff -Nraup linux-2.6_tip0317/tools/perf/builtin-record.c linux-2.6_tip0317_fixrecord/tools/perf/builtin-record.c
@@ -225,7 +225,7 @@ static struct perf_header_attr *get_head
 	return h_attr;
 }
 
-static void create_counter(int counter, int cpu, pid_t pid, bool forks)
+static void create_counter(int counter, int cpu, pid_t pid)
 {
 	char *filter = filters[counter];
 	struct perf_event_attr *attr = attrs + counter;
@@ -275,10 +275,10 @@ static void create_counter(int counter, 
 	attr->mmap		= track;
 	attr->comm		= track;
 	attr->inherit		= inherit;
-	attr->disabled		= 1;
-
-	if (forks)
+	if (target_pid == -1 && !system_wide) {
+		attr->disabled = 1;
 		attr->enable_on_exec = 1;
+	}
 
 try_again:
 	fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0);
@@ -380,17 +380,15 @@ try_again:
 			exit(-1);
 		}
 	}
-
-	ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
 }
 
-static void open_counters(int cpu, pid_t pid, bool forks)
+static void open_counters(int cpu, pid_t pid)
 {
 	int counter;
 
 	group_fd = -1;
 	for (counter = 0; counter < nr_counters; counter++)
-		create_counter(counter, cpu, pid, forks);
+		create_counter(counter, cpu, pid);
 
 	nr_cpu++;
 }
@@ -425,7 +423,7 @@ static int __cmd_record(int argc, const 
 	int err;
 	unsigned long waking = 0;
 	int child_ready_pipe[2], go_pipe[2];
-	const bool forks = target_pid == -1 && argc > 0;
+	const bool forks = argc > 0;
 	char buf;
 
 	page_size = sysconf(_SC_PAGE_SIZE);
@@ -496,13 +494,13 @@ static int __cmd_record(int argc, const 
 	atexit(atexit_header);
 
 	if (forks) {
-		pid = fork();
+		child_pid = fork();
 		if (pid < 0) {
 			perror("failed to fork");
 			exit(-1);
 		}
 
-		if (!pid) {
+		if (!child_pid) {
 			close(child_ready_pipe[0]);
 			close(go_pipe[1]);
 			fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
@@ -531,11 +529,6 @@ static int __cmd_record(int argc, const 
 			exit(-1);
 		}
 
-		child_pid = pid;
-
-		if (!system_wide)
-			target_pid = pid;
-
 		close(child_ready_pipe[1]);
 		close(go_pipe[0]);
 		/*
@@ -548,13 +541,17 @@ static int __cmd_record(int argc, const 
 		close(child_ready_pipe[0]);
 	}
 
+	if (forks && target_pid == -1 && !system_wide)
+		pid = child_pid;
+	else
+		pid = target_pid;
 
 	if ((!system_wide && !inherit) || profile_cpu != -1) {
-		open_counters(profile_cpu, target_pid, forks);
+		open_counters(profile_cpu, pid);
 	} else {
 		nr_cpus = read_cpu_map();
 		for (i = 0; i < nr_cpus; i++)
-			open_counters(cpumap[i], target_pid, forks);
+			open_counters(cpumap[i], pid);
 	}
 
 	if (file_new) {
tools/perf/builtin-record.c +156 -98

382 lines not on this page · raw message

tools/perf/builtin-stat.c +75 -35

206 lines not on this page · raw message

tools/perf/builtin-top.c +103 -55

252 lines not on this page · raw message

tools/perf/util/thread.c +32 -0
diff -Nraup linux-2.6_tip0317_statrecord/tools/perf/util/thread.c linux-2.6_tip0317_statrecordpid/tools/perf/util/thread.c
@@ -7,6 +7,37 @@
 #include "util.h"
 #include "debug.h"
 
+int find_all_tid(int pid, pid_t ** all_tid)
+{
+	char name[256];
+	int items;
+	struct dirent **namelist = NULL;
+	int ret = 0;
+	int i;
+
+	sprintf(name, "/proc/%d/task", pid);
+	items = scandir(name, &namelist, NULL, NULL);
+	if (items <= 0)
+                return -ENOENT;
+	*all_tid = malloc(sizeof(pid_t) * items);
+	if (!*all_tid) {
+		ret = -ENOMEM;
+		goto failure;
+	}
+
+	for (i = 0; i < items; i++)
+		(*all_tid)[i] = atoi(namelist[i]->d_name);
+
+	ret = items;
+
+failure:
+	for (i=0; i<items; i++)
+		free(namelist[i]);
+	free(namelist);
+
+	return ret;
+}
+
 void map_groups__init(struct map_groups *self)
 {
 	int i;
@@ -348,3 +379,4 @@ struct symbol *map_groups__find_symbol(s
 
 	return NULL;
 }
+
tools/perf/util/thread.h +1 -0
diff -Nraup linux-2.6_tip0317_statrecord/tools/perf/util/thread.h linux-2.6_tip0317_statrecordpid/tools/perf/util/thread.h
@@ -23,6 +23,7 @@ struct thread {
 	int			comm_len;
 };
 
+int find_all_tid(int pid, pid_t ** all_tid);
 void map_groups__init(struct map_groups *self);
 int thread__set_comm(struct thread *self, const char *comm);
 int thread__comm_len(struct thread *self);
#341 lore raw
Quoted 1 line · Zhang, Yanmin

I worked out 3 new patches against tip/master tree of Mar. 17th.

Cool! Mind sending them as a series of patches instead of attachment? That makes it easier to review them. Also, the Signed-off-by lines seem to be missing plus we need a per patch changelog as well.

Thanks,

Ingo

#39 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 9 lines · Ingo Molnar
Quoted 7 lines

It's about who owns the user interface.

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Of course illogical modularization complicates things 'significantly'.

Who should own the user interface then?

Quoted 7 lines

Fast forward to 2010. The kernel side of KVM is maximum goodness - by far the worst-quality remaining aspects of KVM are precisely in areas that you
mention: 'if we have to support third party tools, then it significantly complicates things'. You kept Qemu as an external 'third party' entity to KVM, and KVM is clearly hurting from that - just see the recent KVM usability thread for examples about suckage.

Any qemu usability problems are because developers (or their employers) are not interested in fixing them, not because of the repository location. Most kvm developer interest is in server-side deployment (even for desktop guests), so there is limited effort in implementing a virtualbox-style GUI.

Quoted 3 lines

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

I'll ignore the repository location which should be immaterial to a serious developer and concentrate on the 'clean and minimal' aspect, since it has some merit. Qemu development does have a tension between the needs of kvm and tcg. For kvm we need fine-grained threading to improve performance and tons of RAS work. For tcg these are mostly meaningless, and the tcg code has sufficient inertia to reduce the rate at which we can develop.

Nevertheless, the majority of developers feel that we'll lose more by a fork (the community) than we gain by it (reduced constraints).

Quoted 4 lines

- co-develop new features within the same patch. Release new versions of kvm-qemu and the kvm bits at the same time (together with the upstream kernel), at well defined points in time.

The majority of patches to qemu don't require changes to kvm, and vice versa. The interface between qemu and kvm is fairly narrow, and most of the changes are related to save/restore and guest debugging, hardly areas of great interest to the causal user.

Quoted 4 lines

- encourage kernel-space and user-space KVM developers to work on both user-space and kernel-space bits as a single unit. It's one project and a single experience to the user.

When a feature is developed that requires both kernel and qemu changes, the same developer makes the changes in both projects. Having them in different repositories does not appear to be a problem.

Quoted 2 lines

- [ and probably libvirt should go there too ]

Let's make a list of projects who don't need to be in the kernel repository, it will probably be shorted.

Seriously, libvirt is a cross-platform cross-hypervisor library, it has no business near the Linux kernel.

Quoted 2 lines

If KVM's hypervisor and guest kernel code can enjoy the benefits of a single repository,

In fact I try hard not to rely too much on that. While both kvm guest and host code are in the same repo, there is an ABI barrier between them because we need to support any guest version on any host version. When designing, writing, or reading guest or host code that interacts across that barrier we need to keep forward and backward compatibility in mind. It's very different from normal kernel APIs that we can adapt whenever the need arises.

Quoted 4 lines

why cannot the rest of KVM enjoy the same developer goodness? Only fixing that will bring the break-through in quality - not more manpower really.

I really don't understand why you believe that. You seem to want a virtualbox-style GUI, and lkml is probably the last place in the world to develop something like that. The developers here are mostly uninterested in GUI and usability problems, remember these are people who thing emacs xor vi is a great editor.

Quoted 9 lines

Yes, i've read a thousand excuses for why this is an absolutely impossible and a bad thing to do, and none of them was really convincing to me - and you also have become rather emotional about all the arguments so it's hard to argue about it on a technical basis.

We made a similar (admittedly very difficult ...) design jump from oprofile to perf, and i can tell you from that experience that it's day and night, both in terms of development and in terms of the end result!

Maybe it was due to better design and implementation choices.

Quoted 6 lines

( We recently also made another, kernel/kernel unification that had a very
positive result: we unified the 32-bit and 64-bit x86 architectures. Even within the same repo the unification of technology is generally a good thing. The KVM/Qemu situation is different - it's more similar to the perf design. )

Quoted 7 lines

Not having to fight artificial package boundaries and forced package separation is very refreshing experience to a developer - and very rewarding and flexible to develop on. ABI compatibility is _easier_ to maintain in such a model. It's quite similar to the jump from Xen hacking to KVM hacking (i did both). It's a bit like the jump from CVS to Git. Trust me, you _cannot_ know the difference if you havent tried a similar jump with Qemu.

Why is ABI compatibility easier to maintain in a single repo?

Quoted 7 lines

Anyway, you made your position about this rather clear and you are clearly uncompromising, so i just wanted to post this note to the list: you'll waste years of your life on a visibly crappy development model that has been unable to break through a magic usability barrier for the past 2-3 years - just like the Xen mis-design has wasted so many people's time and effort in kernel space.

Do you really think the echo'n'cat school of usability wants to write a GUI? In linux-2.6.git?

Signature · 1 line
error compiling committee.c: too many arguments to function
#319 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 3 lines · Ingo Molnar

I wish both you and Avi looked back 3-4 years and realized what made KVM so successful back then and why the hearts and minds of virtualization developers were captured by KVM almost overnight.

Ingo,

What made KVM so successful was that the core kernel of the hypervisor was designed the right way, as a kernel module where it belonged. It was obvious to anyone who had been exposed to the main competition at the time, Xen, that this was the right approach. What has ended up killing Xen in the end is the not-invented-here approach of copying everything over, reformatting it, and rewriting half of it, which made it impossible to maintain and support as a single codebase. At my previous employer we ended up dropping all Xen efforts exactly because it was like maintaining two separate operating system kernels. The key to KVM is that once you have Linux, you practically have KVM as well.

Quoted 10 lines

Fast forward to 2010. The kernel side of KVM is maximum goodness - by far the worst-quality remaining aspects of KVM are precisely in areas that you
mention: 'if we have to support third party tools, then it significantly complicates things'. You kept Qemu as an external 'third party' entity to KVM, and KVM is clearly hurting from that - just see the recent KVM usability thread for examples about suckage.

So a similar 'complication' is the crux of the matter behind KVM quality
problems: you've not followed through with the original KVM vision and you have not applied that concept to Qemu!

Well there are two ways to go about this. Either you base the KVM userland on top of an existing project, like QEMU, _or_ you rewrite it all from scratch. However, there is far more to it than just a couple of ioctls, for example the stack of reverse device-drivers is a pretty significant code base, rewriting that and maintaining it is not a trivial task. It is certainly my belief that the benefit we get from sharing that with QEMU by far outweighs the cost of forking it and keeping our own fork in the kernel tree. In fact it would result in exactly the same problems I mentioned above wrt Xen.

Quoted 7 lines

If you want to jump to the next level of technological quality you need to fix this attitude and you need to go back to the design roots of KVM. Concentrate on Qemu (as that is the weakest link now), make it a first class member of the KVM repo and simplify your development model by having a single repo:

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

With this you have just thrown away all the benefits of having the QEMU repository shared with other developers who will actively fix bugs in components we do care about for KVM.

Quoted 3 lines

- encourage kernel-space and user-space KVM developers to work on both user-space and kernel-space bits as a single unit. It's one project and a single experience to the user.

This is already happening and a total non issue.

Quoted 1 line

- [ and probably libvirt should go there too ]

Now that would be interesting, next we'll have to include things like libxml in the kernel git tree as well, to make sure libvirt doesn't get out of sync with the version supplied by your distribution vendor.

Quoted 4 lines

Yes, i've read a thousand excuses for why this is an absolutely impossible and a bad thing to do, and none of them was really convincing to me - and you also have become rather emotional about all the arguments so it's hard to argue about it on a technical basis.

So far your argument would justify pulling all of gdb into the kernel git tree as well, to support the kgdb efforts, or gcc so we can get rid of the gcc version quirks in the kernel header files, e2fsprogs and equivalent for _all_ file systems included in the kernel so we can make sure our fs tools never get out of sync with whats supported in the kernel......

Quoted 3 lines

We made a similar (admittedly very difficult ...) design jump from oprofile to perf, and i can tell you from that experience that it's day and night, both in terms of development and in terms of the end result!

The user components for perf vs oprofile are _tiny_ projects compared to the portions of QEMU that are actually used by KVM.

Oh and you completely forgot SeaBIOS. KVM+QEMU rely on SeaBIOS too, so from what you're saying we should pull that into the kernel git repository as well. Never mind the fact that we share SeaBIOS with the coreboot project which is very actively adding features to it that benefit us as well.....

Sorry, but there are times when unification make sense, and there are times where having a reasonably well designed split makes sense. KVM had problems with QEMU in the past which resulted in the qemu-kvm branch of it, which proved to be a major pain to deal with, but that is fortunately improving and qemu-kvm should go away completely at some point.

Cheers,
Jes

#354 lore raw
In reply to Sheng Yang
Quoted 84 lines · Sheng Yang
Quoted 82 lines · On Thursday 18 March 2010 13:22:28 Sheng Yang wrote:
Quoted 69 lines · On Thursday 18 March 2010 12:50:58 Zachary Amsden wrote:
Quoted 46 lines · Sheng Yang
Quoted 44 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 42 lines · Sheng Yang
Quoted 16 lines · Yanmin
Quoted 14 lines · Avi Kivity
Quoted 4 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 7 lines
Quoted 3 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Quoted 7 lines
Quoted 3 lines

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

That's the only defined case, and it is defined because the vector field is ignore for DM_NMI. Vol 3A (exact section numbers may vary depending on your version).

8.5.1 / 8.6.1

'100 (NMI) Delivers an NMI interrupt to the target processor or processors. The vector information is ignored'

8.5.2 Valid Interrupt Vectors

'Local and I/O APICs support 240 of these vectors (in the range of 16 to
255) as valid interrupts.'

Quoted 8 lines

8.8.4 Interrupt Acceptance for Fixed Interrupts

'...; vectors 0 through 15 are reserved by the APIC (see also: Section 8.5.2, "Valid Interrupt Vectors")'

So I misremembered, apparently you can deliver interrupts 0x10-0x1f, but vectors 0x00-0x0f are not valid to send via APIC or I/O APIC.

As you pointed out, NMI is not "Fixed interrupt". If we want to send NMI,
it would need a specific delivery mode rather than vector number.

Quoted 9 lines
Quoted 5 lines

And if you look at code, if we specific NMI_VECTOR, the delivery mode would
be set to NMI.

So what's wrong here?

OK, I think I understand your points now. You meant that these vectors can't be filled in vector field directly, right? But NMI is a exception due to DM_NMI. Is that your point? I think we agree on this.

Yes, I think we agree. NMI is the only vector in 0x0-0xf which can be sent via self-IPI because the vector itself does not matter for NMI.

Zach

#40 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 11 lines · Avi Kivity
Quoted 8 lines · Ingo Molnar
Quoted 6 lines

It's about who owns the user interface.

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Of course illogical modularization complicates things 'significantly'.

Who should own the user interface then?

If qemu was in tools/kvm/ then we wouldnt have such issues. A single patch (or series of patches) could modify tools/kvm/, arch/x86/kvm/, virt/ and tools/perf/.

Numerous times did we have patches to kernel/perf_event.c that fixed some detail, also accompanied by a tools/perf/ patch fixing another detail. Having a single 'culture of contribution' is a powerful way to develop.

It turns out kernel developers can be pretty good user-space developers as well and user-space developers can be pretty good kernel developers as well. Some like to do both - as long as it's all within a single project.

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Also, there's the harmful process that people start categorizing themselves into 'I am a kernel developer' and 'I am a user space programmer' stereotypes, which limits the scope of contributions artificially.

Quoted 11 lines
Quoted 6 lines

Fast forward to 2010. The kernel side of KVM is maximum goodness - by far the worst-quality remaining aspects of KVM are precisely in areas that you
mention: 'if we have to support third party tools, then it significantly complicates things'. You kept Qemu as an external 'third party' entity to KVM, and KVM is clearly hurting from that - just see the recent KVM usability thread for examples about suckage.

Any qemu usability problems are because developers (or their employers) are not interested in fixing them, not because of the repository location. Most kvm developer interest is in server-side deployment (even for desktop guests), so there is limited effort in implementing a virtualbox-style GUI.

The same has been said of oprofile as well: 'it somewhat sucks because we are too server centric', 'nobody is interested in good usability and oprofile is fine for the enterprises'. Ironically, the same has been said of Xen usability as well, up to the point KVM came around.

What was the core of the problem was a bad design and a split kernel-side user-side tool landscape.

In fact i think saying that 'our developers only care about the server' is borderline dishonest, when at the same time you are making it doubly sure (by inaction) that it stays so: by leaving an artificial package wall between kernel-side KVM and user-side KVM and not integrating the two technologies.

You'll never know what heights you could achieve if you leave that wall there
...

Furthermore, what should be realized is that bad usability hurts "server features" just as much. Most of the day-to-day testing is done on the desktop by desktop oriented testers/developers. _Not_ by enterprise shops - they tend to see the code years down the line to begin with ...

Yes, a particular feature might be server oriented, but a good portion of our testing is on the desktop and everyone is hurting from bad usability and this puts limits on contribution efficiency.

As the patch posted in _this very thread demonstrates it_, it is doubly more difficult to contribute a joint KVM+Qemu feature, because it's two separate code bases, two contribution guidelines, two release schedules. While to the user it really is just one and the same thing. It should be so for the developer as well.

Put in another way: KVM's current split design is making it easy to contribute server features (because the kernel side is clean and cool), but also makes it artificially hard to contribute desktop features: because the tooling side (Qemu) is 'just another package', is separated by a package and maintenance wall and is made somewhat uncool by a (as some KVM developers have pointed out in this thread) quirky codebase.

(the rest of your points are really a function of this fundamental disagreement)

Thanks,

Ingo

#313 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 2 lines

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

I'll ignore the repository location which should be immaterial to a serious developer and concentrate on the 'clean and minimal' aspect, since it has some merit. [...]

To the contrary, experience shows that repository location, and in particular a shared repository for closely related bits is very much material!

It matters because when there are two separate projects, even a "serious developer" is finding it double and triple difficult to contribute even trivial changes.

It becomes literally a nightmare if you have to touch 3 packages: kernel, a library and an app codebase. It takes _forever_ to get anything useful done.

Also, 'focus on a single thing' is a very basic aspect of humans, especially those who do computer programming. Working on two code bases in two repositories at once can be very challenging physically and psychically.

So what i've seen is that OSS programmers tend to pick a side, pretty much randomly, and then rationalize it in hindsight why they prefer that side ;-)

Most of them become either a kernel developer or a user-space package developer - and then they specialize on that field and shy away from changes that involve both. It's a basic human thing to avoid the hassle that comes with multi-package changes. (One really has to be outright stupid, fanatic or desperate to even attempt such changes these days - such are the difficulties for a comparatively low return.)

The solution is to tear down such artificial walls of contribution where possible. And tearing down the wall between KVM and qemu-kvm seems very much possible and the advantages would be numerous.

Unless by "serious developer" you meant: "developer willing to [or forced to] waste time and effort on illogically structured technology".

Quoted 4 lines

[...]

Do you really think the echo'n'cat school of usability wants to write a GUI? In linux-2.6.git?

Then you'll be surprised to hear that it's happening as we speak and the commits are there in linux-2.6.git. Both a TUI and GUI is in the works.

Furthermore, the numbers show that half of the usability fixes to tools/perf/ came not from regular perf contributors but from random kernel developers and testers who when they build the latest kernel and try out perf at the same time (it's very easy because you already have it in the kernel repository - no separate download, no installation, etc. necessary).

I had literally zero such contributions when (the precursor to) 'perf' was still a separate user-space project.

You could have the same effect for Qemu: the latest bits in tools/kvm/ would be built by regular kernel testers and developers. The integration benefits dont just extend to developers, a unified project is vastly easier to test as well.

Thanks,

Ingo

#41 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Ingo Molnar
Quoted 6 lines

It's about who owns the user interface.

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Of course illogical modularization complicates things 'significantly'.

Who should own the user interface then?

If qemu was in tools/kvm/ then we wouldnt have such issues. A single patch (or series of patches) could modify tools/kvm/, arch/x86/kvm/, virt/ and tools/perf/.

It's not a 1:1 connection. There are more users of the KVM interface. To name a few I'm aware of:

- Mac-on-Linux (PPC)
- Dolphin (PPC)
- Xenner (x86)
- Kuli (s390)

Having a clear userspace interface is the only viable solution there. And if you're interested, look at my MOL enabling patch. It's less than 500 lines of code.

The kernel/userspace interface really isn't the difficult part. Getting device emulation working properly, easily and fast is.

Alex

#320 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Jes Sorensen
Quoted 8 lines · Jes Sorensen
Quoted 3 lines · Ingo Molnar

I wish both you and Avi looked back 3-4 years and realized what made KVM so successful back then and why the hearts and minds of virtualization developers were captured by KVM almost overnight.

Ingo,

Quoted 7 lines

What made KVM so successful was that the core kernel of the hypervisor was designed the right way, as a kernel module where it belonged. It was obvious to anyone who had been exposed to the main competition at the time, Xen, that this was the right approach. What has ended up killing Xen in the end is the not-invented-here approach of copying everything over, reformatting it, and rewriting half of it, which made it impossible to maintain and support as a single codebase. [...]

Yes, exactly.

I was part of that nightmare so i know.

Quoted 5 lines

[...]

At my previous employer we ended up dropping all Xen efforts exactly because it was like maintaining two separate operating system kernels. The key to KVM is that once you have Linux, you practically have KVM as well.

Yes. Please realize that what is behind it is a strikingly simple argument:

"Once you have a single project to develop and maintain all is much better."

Quoted 7 lines
Quoted 7 lines

Fast forward to 2010. The kernel side of KVM is maximum goodness - by far the worst-quality remaining aspects of KVM are precisely in areas that you
mention: 'if we have to support third party tools, then it significantly complicates things'. You kept Qemu as an external 'third party' entity to KVM, and KVM is clearly hurting from that - just see the recent KVM usability thread for examples about suckage.

Quoted 7 lines
Quoted 3 lines

So a similar 'complication' is the crux of the matter behind KVM quality
problems: you've not followed through with the original KVM vision and you have not applied that concept to Qemu!

Well there are two ways to go about this. Either you base the KVM userland on top of an existing project, like QEMU, _or_ you rewrite it all from scratch. [...]

Btw., i made similar arguments to Avi about 3 years ago when it was going upstream, that qemu should be unified with KVM. This is more true today than ever.

Quoted 7 lines

[...] However, there is far more to it than just a couple of ioctls, for example the stack of reverse device-drivers is a pretty significant code base, rewriting that and maintaining it is not a trivial task. It is certainly my belief that the benefit we get from sharing that with QEMU by far outweighs the cost of forking it and keeping our own fork in the kernel tree. In fact it would result in exactly the same problems I mentioned above wrt Xen.

I do not suggest forking Qemu at all, i suggest using the most natural development model for the KVM+Qemu shared project: a single repository.

Quoted 6 lines
Quoted 6 lines

If you want to jump to the next level of technological quality you need to fix this attitude and you need to go back to the design roots of KVM. Concentrate on Qemu (as that is the weakest link now), make it a first class member of the KVM repo and simplify your development model by having a single repo:

Quoted 6 lines
Quoted 2 lines

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

With this you have just thrown away all the benefits of having the QEMU repository shared with other developers who will actively fix bugs in components we do care about for KVM.

Not if it's a unified project.

Quoted 5 lines
Quoted 3 lines

- encourage kernel-space and user-space KVM developers to work on both user-space and kernel-space bits as a single unit. It's one project and a single experience to the user.

This is already happening and a total non issue.

My experience as an external observer of the end result contradicts this.

Seemingly trivial usability changes to the KVM+Qemu combo are not being done often because they involve cross-discipline changes.

( _In this very thread_ there has been a somewhat self-defeating argument by
Anthony that multi-package scenario would 'significantly complicate' matters. What more proof do we need to state the obvious? Keeping what has become one piece of technology over the years in two separate halves is obviously bad. )

Quoted 5 lines
Quoted 1 line

- [ and probably libvirt should go there too ]

Now that would be interesting, next we'll have to include things like libxml in the kernel git tree as well, to make sure libvirt doesn't get out of sync with the version supplied by your distribution vendor.

The way we have gone about this in tools/perf/ is similar to the route picked by Git: we only use very lowlevel libraries available everywhere, and we provide optional wrappers to the rest.

We are also using the kernel's libraries so we rarely need to go outside to get some functionality.

I.e. it's a non-issue in practice and despite perf having an (optional) dependency on xmlto and docbook we dont include those packages nor do we force users to install particular versions of them.

Quoted 10 lines
Quoted 4 lines

Yes, i've read a thousand excuses for why this is an absolutely impossible and a bad thing to do, and none of them was really convincing to me - and you also have become rather emotional about all the arguments so it's hard to argue about it on a technical basis.

So far your argument would justify pulling all of gdb into the kernel git tree as well, to support the kgdb efforts, or gcc so we can get rid of the gcc version quirks in the kernel header files, e2fsprogs and equivalent for _all_ file systems included in the kernel so we can make sure our fs tools never get out of sync with whats supported in the kernel......

gdb and gcc is clearly extrinsic to the kernel so why would we move them there?

I was talking about tools that are closely related to the kernel - where much of the development and actual use is in combination with the Linux kernel.

90%+ of the Qemu usecases are combined with Linux. (Yes, i know that you can run Qemu without KVM, and no, i dont think it matters in the grand scheme of things and most investment into Qemu comes from the KVM angle these days. In particular it for sure does not justify handicapping future KVM evolution so drastically.)

Quoted 6 lines
Quoted 3 lines

We made a similar (admittedly very difficult ...) design jump from oprofile to perf, and i can tell you from that experience that it's day and night, both in terms of development and in terms of the end result!

The user components for perf vs oprofile are _tiny_ projects compared to the portions of QEMU that are actually used by KVM.

I know the size and scope of Qemu, i even hacked it - still my points remain. (my arguments are influenced and strengthened by that past hacking experience)

Quoted 4 lines

Oh and you completely forgot SeaBIOS. KVM+QEMU rely on SeaBIOS too, so from what you're saying we should pull that into the kernel git repository as well. Never mind the fact that we share SeaBIOS with the coreboot project which is very actively adding features to it that benefit us as well.....

SeaBIOS is in essence a firmware, so it could either be loaded as such.

Just look at the qemu source code - the BIOSes are .bin images in qemu/pc-bios/ imported externally in essence.

Moving qemu to tools/kvm/ would not change that much. The firmware could become part of /lib/firmware/*.bin.

( That would probably be a more intelligent approach to the BIOS image import
problem as well. )

Quoted 5 lines

Sorry, but there are times when unification make sense, and there are times where having a reasonably well designed split makes sense. KVM had problems with QEMU in the past which resulted in the qemu-kvm branch of it, which proved to be a major pain to deal with, but that is fortunately improving and qemu-kvm should go away completely at some point.

qemu-kvm branch is not similar to my proposal at all: it made KVM _more_ fragmented, not more unified. I.e. it was a move in the exact opposite direction and i'd expect such a move to fail.

In fact the failure of qemu-kvm supports my point rather explicitly: it demonstrates that extra packages and split development are actively harmful.

I speak about this as a person who has done successful unifications of split codebases and in my judgement this move would be significantly beneficial to KVM.

You cannot really validly reject this proposal with "It wont work" as it clearly has worked in other, comparable cases. You could only reject this with "I have tried it and it didnt work".

Think about it: a clean and hackable user-space component in tools/kvm/. It's very tempting :-)

Ingo

#42 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Alexander Graf
Quoted 22 lines · Alexander Graf
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Ingo Molnar
Quoted 6 lines

It's about who owns the user interface.

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Of course illogical modularization complicates things 'significantly'.

Who should own the user interface then?

If qemu was in tools/kvm/ then we wouldnt have such issues. A single patch (or series of patches) could modify tools/kvm/, arch/x86/kvm/, virt/ and tools/perf/.

Quoted 7 lines

It's not a 1:1 connection. There are more users of the KVM interface. To name a few I'm aware of:

- Mac-on-Linux (PPC)
- Dolphin (PPC)
- Xenner (x86)
- Kuli (s390)

There must be a misunderstanding here: tools/perf/ still has a clear userspace interface and ABI. There's external projects making use of it: sysprof and libpfm (and probably more i dont know about it). Those projects are also contributing back.

Still it's _very_ useful to have a single reference implementation under tools/perf/ where we concentrate the best of the code. That is where we make sure that each new kernel feature is appropriately implemented in user-space as well, that the combination works well together and is releasable to users. That is what keeps us all honest: the latency of features is much lower, and there's no ping-pong of blame going on between the two components in case of bugs or in case of misfeatures.

Same goes for KVM+Qemu: it would be so much nicer to have a single, well-focused reference implementation under tools/kvm/ and have improvements flow into that code base.

That way KVM developers cannot just shrug "well, GUI suckage is a user-space problem" - like the answers i got in the KVM usability thread ...

The buck will stop here.

And if someone thinks he can do better an external project can be started anytime. (it may even replace the upstream thing if it's better)

Quoted 3 lines

Having a clear userspace interface is the only viable solution there. And if you're interested, look at my MOL enabling patch. It's less than 500 lines of code.

Why do you suppose that what i propose is an "either or" scenario?

It isnt. I just suggested that instead of letting core KVM fragment its limbs into an external entity, put your name behind one good all-around solution and focus the development model into a single project.

I.e. do what KVM has done originally in the kernel space to begin with - and where it was so much better than Xen: single focus.

Learn from what KVM has done so well in the initial years and use the concept on the user-space components as well. The very same arguments that caused KVM to integrate into the upstream kernel (instead of being a separate project) are a valid basis to integrate the user-space components into tools/kvm/. Dont forget your roots and dont assume all your design decisions were correct.

Quoted 2 lines

The kernel/userspace interface really isn't the difficult part. Getting device emulation working properly, easily and fast is.

The kernel/userspace ABI is not difficult at all. Getting device emulation working properly, easily and fast indeed is. And my experience is that it is not working properly nor quickly at the moment, at all. (see the 'KVM usability' thread)

Getting device emulation working properly often involves putting certain pieces that are currently done in Qemu into kernel-space. That kind of 'movement of emulation technology' from user-space component into the kernel-space component [or back] would very clearly be helped if those two components were in the same repository.

And i have first-hand experience there: we had (and have) similar scenarios with tools/perf routinely. We did some aspects in user-space, then decided to do it in kernel-space. Sometimes we moved kernel bits to user-space. It was very easy and there were no package and version complications as it's a single project. Sometimes we even moved bits back and forth until we found the right balance.

Thanks,

Ingo

#64 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Avi Kivity
Quoted 7 lines · Ingo Molnar
Quoted 7 lines

It's about who owns the user interface.

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Of course illogical modularization complicates things 'significantly'.

Who should own the user interface then?

If qemu was in tools/kvm/ then we wouldnt have such issues. A single patch (or series of patches) could modify tools/kvm/, arch/x86/kvm/, virt/ and tools/perf/.

We would have exactly the same issues, only they would be in a single repository. The only difference is that we could ignore potential alternatives to qemu, libvirt, and RHEV-M. But that's not how kernel ABIs are developed, we try to make them general, not suited to just one consumer that happens to be close to our heart.

Quoted 4 lines

Numerous times did we have patches to kernel/perf_event.c that fixed some detail, also accompanied by a tools/perf/ patch fixing another detail. Having a single 'culture of contribution' is a powerful way to develop.

In fact kvm started out in a single repo, and it certainly made it easy to bring it up in baby steps. But we've long outgrown that. Maybe the difference is that perf is still new and thus needs tight cooperation. If/when perf gains a real GUI, I doubt more than 1% of the patches will touch both kernel and userspace.

Quoted 4 lines

It turns out kernel developers can be pretty good user-space developers as well and user-space developers can be pretty good kernel developers as well. Some like to do both - as long as it's all within a single project.

Very childish of them. If someone wants to contribute to a userspace project, they can swallow their pride and send patches to a non-kernel mailing list and repository.

Quoted 4 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

I the maintainers of all packages are cooperative and responsive, then the patches will get accepted quickly. If they aren't, development will be slow. It isn't any different from contributing to two unrelated kernel subsystems (which are in fact in different repositories until the next merge window).

Quoted 4 lines

Also, there's the harmful process that people start categorizing themselves into 'I am a kernel developer' and 'I am a user space programmer' stereotypes, which limits the scope of contributions artificially.

You're encouraging this with your proposal. You're basically using the glory of kernel development to attract people to userspace.

Quoted 12 lines
Quoted 7 lines
Quoted 7 lines

Fast forward to 2010. The kernel side of KVM is maximum goodness - by far the worst-quality remaining aspects of KVM are precisely in areas that you
mention: 'if we have to support third party tools, then it significantly complicates things'. You kept Qemu as an external 'third party' entity to KVM, and KVM is clearly hurting from that - just see the recent KVM usability thread for examples about suckage.

Quoted 5 lines

Any qemu usability problems are because developers (or their employers) are not interested in fixing them, not because of the repository location. Most kvm developer interest is in server-side deployment (even for desktop guests), so there is limited effort in implementing a virtualbox-style GUI.

Quoted 8 lines

The same has been said of oprofile as well: 'it somewhat sucks because we are too server centric', 'nobody is interested in good usability and oprofile is fine for the enterprises'. Ironically, the same has been said of Xen usability as well, up to the point KVM came around.

What was the core of the problem was a bad design and a split kernel-side user-side tool landscape.

I can accept the bad design (not knowing any of the details), but how can the kernel/user split affect usability?

Quoted 5 lines

In fact i think saying that 'our developers only care about the server' is borderline dishonest, when at the same time you are making it doubly sure (by inaction) that it stays so: by leaving an artificial package wall between kernel-side KVM and user-side KVM and not integrating the two technologies.

The wall is maybe four nanometers high. Please be serious. If someone wants to work on qemu usability all they have to do is to clone the repository and start sending patches to qemu-devel@. What's gained by putting it in the kernel repository? You're saving a minute's worth of clone, and that only for people who already happen to be kernel developers.

Quoted 3 lines

You'll never know what heights you could achieve if you leave that wall there
...

I truly don't know. What highly usable GUIs were developed in the kernel?

Quoted 9 lines

Furthermore, what should be realized is that bad usability hurts "server features" just as much. Most of the day-to-day testing is done on the desktop by desktop oriented testers/developers. _Not_ by enterprise shops - they tend to see the code years down the line to begin with ...

Yes, a particular feature might be server oriented, but a good portion of our testing is on the desktop and everyone is hurting from bad usability and this puts limits on contribution efficiency.

I'm not saying that improved usability isn't a good thing, but time spent on improving the GUI is time not spent on the features that we really want.

Desktop oriented users also rarely test 16 vcpu guests with tons of RAM exercising 10Gb NICs and a SAN. Instead they care about graphics performance for 2vcpu/1GB guests.

Quoted 6 lines

As the patch posted in _this very thread demonstrates it_, it is doubly more difficult to contribute a joint KVM+Qemu feature, because it's two separate code bases, two contribution guidelines, two release schedules. While to the user it really is just one and the same thing. It should be so for the developer as well.

It's hard to contribute a patch that goes against the architecture of the system, where kvm deals with cpu virtualization, qemu (or theoretically another tool) manages a guest, and libvirt (or another tool) manages the host. You want a list of guests to be provided by qemu or the kernel, and that simply isn't how the system works.

Quoted 5 lines

Put in another way: KVM's current split design is making it easy to contribute server features (because the kernel side is clean and cool), but also makes it artificially hard to contribute desktop features: because the tooling side (Qemu) is 'just another package', is separated by a package and maintenance wall

Most server oriented patches in qemu/kvm have gone into qemu, not kvm (simply because it sees many more patches overall). It isn't hard to contribute to 'just another package', I have 1700 packages installed on my desktop and only one of them is a kernel.

Anyway your arguments apply equally well to gedit.

Quoted 3 lines

and is made somewhat uncool by a (as some KVM developers have pointed out in this thread) quirky codebase.

The qemu codebase is in fact quirky, but cp won't solve it. Only long patchsets to qemu-devel@.

Quoted 3 lines

(the rest of your points are really a function of this fundamental disagreement)

I disagree.

Signature · 1 line
error compiling committee.c: too many arguments to function
#43 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 9 lines · Ingo Molnar
Quoted 9 lines

It's not a 1:1 connection. There are more users of the KVM interface. To name a few I'm aware of:

- Mac-on-Linux (PPC)
- Dolphin (PPC)
- Xenner (x86)
- Kuli (s390)

Quoted 5 lines

There must be a misunderstanding here: tools/perf/ still has a clear userspace interface and ABI. There's external projects making use of it: sysprof and libpfm (and probably more i dont know about it). Those projects are also contributing back.

So it seems it is possible to scale the package wall.

Quoted 8 lines

Still it's _very_ useful to have a single reference implementation under tools/perf/ where we concentrate the best of the code. That is where we make sure that each new kernel feature is appropriately implemented in user-space as well, that the combination works well together and is releasable to users. That is what keeps us all honest: the latency of features is much lower, and there's no ping-pong of blame going on between the two components in case of bugs or in case of misfeatures.

That would make sense for a truly minimal userspace for kvm: we once had a tool called kvmctl which was used to run tests (since folded into qemu). It didn't contain a GUI and was unable to run a general purpose guest. It was a few hundred lines of code, and indeed patches to kvmctl had a much closer correspondence to patches with kvm (though still low, as most kvm patches don't modify the ABI).

Quoted 9 lines

Same goes for KVM+Qemu: it would be so much nicer to have a single, well-focused reference implementation under tools/kvm/ and have improvements flow into that code base.

That way KVM developers cannot just shrug "well, GUI suckage is a user-space problem" - like the answers i got in the KVM usability thread ...

The buck will stop here.

Suppose we copy qemu tomorrow into tools/. All the problems will be copied with it. Someone still has to write patches to fix them. Who will it be?

Quoted 8 lines
Quoted 3 lines

The kernel/userspace interface really isn't the difficult part. Getting device emulation working properly, easily and fast is.

The kernel/userspace ABI is not difficult at all. Getting device emulation working properly, easily and fast indeed is. And my experience is that it is not working properly nor quickly at the moment, at all. (see the 'KVM usability' thread)

Quoted 6 lines

Getting device emulation working properly often involves putting certain pieces that are currently done in Qemu into kernel-space. That kind of 'movement of emulation technology' from user-space component into the kernel-space component [or back] would very clearly be helped if those two components were in the same repository.

Moving emulation into the kernel is indeed a problem. Not because it's difficult, but because it indicates that the interfaces exposed to userspace are insufficient to obtain good performance. We had that with vhost-net and I'm afraid we'll have that with vhost-blk.

Quoted 7 lines

And i have first-hand experience there: we had (and have) similar scenarios with tools/perf routinely. We did some aspects in user-space, then decided to do it in kernel-space. Sometimes we moved kernel bits to user-space. It was very easy and there were no package and version complications as it's a single project. Sometimes we even moved bits back and forth until we found the right balance.

That's reasonable in the first iterations of a project.

Signature · 1 line
error compiling committee.c: too many arguments to function
#65 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 15 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar
Quoted 3 lines · Avi Kivity
Quoted 2 lines · Ingo Molnar
Quoted 2 lines

It's about who owns the user interface.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Of course illogical modularization complicates things 'significantly'.

Who should own the user interface then?

If qemu was in tools/kvm/ then we wouldnt have such issues. A single patch (or series of patches) could modify tools/kvm/, arch/x86/kvm/, virt/ and tools/perf/.

Quoted 5 lines

We would have exactly the same issues, only they would be in a single repository. The only difference is that we could ignore potential alternatives to qemu, libvirt, and RHEV-M. But that's not how kernel ABIs are developed, we try to make them general, not suited to just one consumer that happens to be close to our heart.

Not at all - as i replied to in a previous mail, tools/perf/ still has a clear userspace interface and ABI, and external projects are making use of it.

So there's no problem with the ABI at all.

In fact our experience has been the opposite: the perf ABI is markedly better _because_ there's an immediate consumer of it in the form of tools/perf/. It gets tested better and external projects can get their ABI tweaks in as well and can provide a reference implementation for tools/perf. This has happened a couple of times. It's a win-win scenario.

So the exact opposite of what you suggest is happening in practice.

Thanks,

Ingo

#314 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 13 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 3 lines

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

I'll ignore the repository location which should be immaterial to a serious developer and concentrate on the 'clean and minimal' aspect, since it has some merit. [...]

To the contrary, experience shows that repository location, and in particular a shared repository for closely related bits is very much material!

Quoted 7 lines

It matters because when there are two separate projects, even a "serious developer" is finding it double and triple difficult to contribute even trivial changes.

It becomes literally a nightmare if you have to touch 3 packages: kernel, a library and an app codebase. It takes _forever_ to get anything useful done.

You can't be serious. I find that the difficulty in contributing a patch has mostly to do with writing the patch, and less with figuring out which email address to send it to.

Quoted 4 lines

Also, 'focus on a single thing' is a very basic aspect of humans, especially those who do computer programming. Working on two code bases in two repositories at once can be very challenging physically and psychically.

Indeed, working simultaneously on two different projects is difficult. I usually work for a while on one, and then 'cd', physically and psychically, to the other. Then switch back. Sort of like the scheduler on a uniprocessor machine.

Quoted 10 lines

So what i've seen is that OSS programmers tend to pick a side, pretty much randomly, and then rationalize it in hindsight why they prefer that side ;-)

Most of them become either a kernel developer or a user-space package developer - and then they specialize on that field and shy away from changes that involve both. It's a basic human thing to avoid the hassle that comes with multi-package changes. (One really has to be outright stupid, fanatic or desperate to even attempt such changes these days - such are the difficulties for a comparatively low return.)

We have a large number of such stupid, fanatic, desperate developers in the qemu and kvm communities.

Quoted 7 lines

The solution is to tear down such artificial walls of contribution where possible. And tearing down the wall between KVM and qemu-kvm seems very much possible and the advantages would be numerous.

Unless by "serious developer" you meant: "developer willing to [or forced to] waste time and effort on illogically structured technology".

By "serious developer" I mean

- someone who is interested in contributing, not in getting their name
into the kernel commits list
- someone who is willing to read the wiki page and find out where the
repository and mailing list for a project is
- someone who will spend enough time on the project so that the time
to clone two repositories will not be a factor in their contributions
- someone who will work on the uncool stuff like fixing bugs and
providing interfaces to other tools

Quoted 14 lines
Quoted 5 lines

[...]

Do you really think the echo'n'cat school of usability wants to write a GUI? In linux-2.6.git?

Then you'll be surprised to hear that it's happening as we speak and the commits are there in linux-2.6.git. Both a TUI and GUI is in the works.

Furthermore, the numbers show that half of the usability fixes to tools/perf/ came not from regular perf contributors but from random kernel developers and testers who when they build the latest kernel and try out perf at the same time (it's very easy because you already have it in the kernel repository - no separate download, no installation, etc. necessary).

Quoted 9 lines

I had literally zero such contributions when (the precursor to) 'perf' was still a separate user-space project.

You could have the same effect for Qemu: the latest bits in tools/kvm/ would be built by regular kernel testers and developers. The integration benefits dont just extend to developers, a unified project is vastly easier to test as well.

Let's wait and see then. If the tools/perf/ experience has really good results, we can reconsider this at a later date.

Signature · 1 line
error compiling committee.c: too many arguments to function
#321 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 1 line · Ingo Molnar

* Jes Sorensen<[email protected]> wrote:

[...]

Quoted 8 lines
Quoted 4 lines

At my previous employer we ended up dropping all Xen efforts exactly because it was like maintaining two separate operating system kernels. The key to KVM is that once you have Linux, you practically have KVM as well.

Yes. Please realize that what is behind it is a strikingly simple argument:

"Once you have a single project to develop and maintain all is much better."

Thats a very glorified statement but it's not reality, sorry. You can do that with something like perf because it's so small and development of perf is limited to a very small group of developers.

Quoted 10 lines
Quoted 7 lines

[...] However, there is far more to it than just a couple of ioctls, for example the stack of reverse device-drivers is a pretty significant code base, rewriting that and maintaining it is not a trivial task. It is certainly my belief that the benefit we get from sharing that with QEMU by far outweighs the cost of forking it and keeping our own fork in the kernel tree. In fact it would result in exactly the same problems I mentioned above wrt Xen.

I do not suggest forking Qemu at all, i suggest using the most natural development model for the KVM+Qemu shared project: a single repository.

If you are not suggesting to fork QEMU, what are you suggesting then? You don't seriously expect that the KVM community will be able to mandate that the QEMU community switch to the Linux kernel repository? That would be like telling the openssl developers that they should merge with glibc and start working out of the glibc tree.

What you are suggesting is *only* going to happen if we fork QEMU, there is zero chance to move the main QEMU repository into the Linux kernel tree. And trust me, you don't want to have Linus having to deal with handling patches for tcg or embedded board emulation.

Quoted 5 lines
Quoted 3 lines

With this you have just thrown away all the benefits of having the QEMU repository shared with other developers who will actively fix bugs in components we do care about for KVM.

Not if it's a unified project.

You still haven't explained how you expect create a unified KVM+QEMU project, without forking from the existing QEMU.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

- encourage kernel-space and user-space KVM developers to work on both user-space and kernel-space bits as a single unit. It's one project and a single experience to the user.

This is already happening and a total non issue.

My experience as an external observer of the end result contradicts this.

What I have seen you complain about here is the lack of a good end user GUI for KVM. However that is a different thing. So far no vendor has put significant effort into it, but that is nothing new in Linux. We have a great kernel, but our user applications are still lacking. We have 217 CD players for GNOME, but we have no usable calendering application.

A good GUI for virtualization is a big task, and whoever designs it will base their design upon their preferences for whats important. A lot of spare time developers would clearly care most about a gui installation and fancy icons to click on, whereas server users would be much more interested in automation and remote access to the systems. For a good example of an incomplete solution, try installing Fedora over a serial line, you cannot do half the things without launching VNC :( Getting a comprehensive solution for this that would satisfy the bulk of the users would be a huge chunk of code in the kernel tree. Imagine the screaming that would result in? How often have we not had the moaning from x86 users who wanted to rip out all the non x86 code to reduce the size of the tarball?

Quoted 2 lines

Seemingly trivial usability changes to the KVM+Qemu combo are not being done often because they involve cross-discipline changes.

Which trivial usability changes?

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

- [ and probably libvirt should go there too ]

Now that would be interesting, next we'll have to include things like libxml in the kernel git tree as well, to make sure libvirt doesn't get out of sync with the version supplied by your distribution vendor.

The way we have gone about this in tools/perf/ is similar to the route picked by Git: we only use very lowlevel libraries available everywhere, and we provide optional wrappers to the rest.

Did you ever look at what libvirt actually does and what it offers? Or how about the various libraries used by QEMU to offer things like VNC support or X support?

Again this works fine for something like perf where the primary display is text mode.

Quoted 8 lines
Quoted 5 lines

So far your argument would justify pulling all of gdb into the kernel git tree as well, to support the kgdb efforts, or gcc so we can get rid of the gcc version quirks in the kernel header files, e2fsprogs and equivalent for _all_ file systems included in the kernel so we can make sure our fs tools never get out of sync with whats supported in the kernel......

gdb and gcc is clearly extrinsic to the kernel so why would we move them there?

gdb should go with kgdb which goes with the kernel to keep it in sync. If you want to be consistent in your argument, you have to go all the way.

Quoted 2 lines

I was talking about tools that are closely related to the kernel - where much of the development and actual use is in combination with the Linux kernel.

Well the file system tools would obviously have to go into the kernel then so appropriate binaries can be distributed to match the kernel.

Quoted 5 lines

90%+ of the Qemu usecases are combined with Linux. (Yes, i know that you can run Qemu without KVM, and no, i dont think it matters in the grand scheme of things and most investment into Qemu comes from the KVM angle these days. In particular it for sure does not justify handicapping future KVM evolution so drastically.)

90+%? You got to be kidding? You clearly have no idea just how much it's used for running embedded emulators on non Linux. You should have seen the noise it made when I added C99 initializers to certain structs, because it broke builds using very old GCC versions on BeOS. Linux only, not a chance. Try subscribing to qemu-devel and you'll see a list that is only overtaken by few lists like lkml in terms of daily traffic.

Quoted 9 lines
Quoted 4 lines

Oh and you completely forgot SeaBIOS. KVM+QEMU rely on SeaBIOS too, so from what you're saying we should pull that into the kernel git repository as well. Never mind the fact that we share SeaBIOS with the coreboot project which is very actively adding features to it that benefit us as well.....

SeaBIOS is in essence a firmware, so it could either be loaded as such.

Just look at the qemu source code - the BIOSes are .bin images in qemu/pc-bios/ imported externally in essence.

Ehm no, QEMU now pulls in SeaBIOS to build it. And there are a lot of changes that require modification in SeaBIOS to match changes to QEMU.

Quoted 6 lines

qemu-kvm branch is not similar to my proposal at all: it made KVM _more_ fragmented, not more unified. I.e. it was a move in the exact opposite direction and i'd expect such a move to fail.

In fact the failure of qemu-kvm supports my point rather explicitly: it demonstrates that extra packages and split development are actively harmful.

Ehm it showed what happens when you fork QEMU to modify it primarily for your own project, ie. KVM. You are suggesting we fork QEMU for the benefit of KVM, and it will be exactly the same thing that happens.

I know you state that you are not suggesting we fork it, but as I showed above, pulling QEMU into the kernel tree, can only happen as a fork. There is no point pretending otherwise.

Quoted 10 lines

I speak about this as a person who has done successful unifications of split codebases and in my judgement this move would be significantly beneficial to KVM.

You cannot really validly reject this proposal with "It wont work" as it clearly has worked in other, comparable cases. You could only reject this with "I have tried it and it didnt work".

Think about it: a clean and hackable user-space component in tools/kvm/. It's very tempting :-)

I say this based on my hacking experience, my experience with the kernel, the QEMU base, SeaBIOS and merging projects. Yes it can be done, but the cost is much higher than the gain.

Cheers,
Jes

#66 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 4 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Quoted 3 lines

I the maintainers of all packages are cooperative and responsive, then the patches will get accepted quickly. If they aren't, development will be slow. [...]

I'm afraid practice is different from the rosy ideal you paint there. Even with assumed 'perfect projects' there's always random differences between projects, causing doubled (tripled) overhead and compounded up overhead:

- random differences in release schedules

- random differences in contribution guidelines

- random differences in coding style

Quoted 3 lines

[...] It isn't any different from contributing to two unrelated kernel subsystems (which are in fact in different repositories until the next merge window).

You mention a perfect example: contributing to multipe kernel subsystems. Even _that_ is very noticeably harder than contributing to a single subsystem - due to the inevitable buerocratic overhead, due to different development trees, due to different merge criteria.

So you are underlining my point (perhaps without intending to): treating closely related bits of technology as a single project is much better.

Obviously arch/x86/kvm/, virt/ and tools/kvm/ should live in a single development repository (perhaps micro-differentiated by a few topical branches), for exactly those reasons you mention.

Just like tools/perf/ and kernel/perf_event.c and arch/*/kernel/perf*.c are treated as a single project.

[ Note: we actually started from a 'split' design [almost everyone picks that,
because of this false 'kernel space bits must be separate from user space bits' myth] where the user-space component was a separate code base and unified it later on as the project progressed.

Trust me, the practical benefits of the unified approach are enormous to developers and to users alike, and there was no looking back once we made the switch. ]

Also, i dont really try to 'convince' you here - you made your position very clear early on and despite many unopposed technical arguments i made, the positions seem to have hardened and i expect it wont change, no matter what arguments i bring. It's a pity but hey, i'm just an observer here really - it's the rest of _your_ life this all impacts.

I just wanted to point out the root cause of KVM's usability problems as i see it - just like i was pointing out the mortal Xen design deficiencies back when i was backing KVM strongly, four years ago. Back then everyone was saying that i'm crazy and we are stuck with Xen forever and while KVM is nice it has no chance.

Just because you got the kernel bits of KVM right a few years ago does not mean you cannot mess up other design aspects, and sometimes badly so ;-) Historically i messed up more than half of all first-gut-feeling technical design decisions i did, so i had to correct the course many, many times.

I hope you are still keeping an open mind about it all and dont think that because the project was split for 4 years (to no fault of your own, simply out of necessity) it should be split forever ...

arch/x86 was split for a much longer period than that.

Circumstances have changed. Most Qemu users/contributions are now coming from the KVM angle, so please simply start thinking about the next level of evolution.

Thanks,

Ingo

#322 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Jes Sorensen
Quoted 8 lines · Jes Sorensen
Quoted 1 line · Ingo Molnar

* Jes Sorensen<[email protected]> wrote:

[...]

Quoted 5 lines
Quoted 4 lines

At my previous employer we ended up dropping all Xen efforts exactly because it was like maintaining two separate operating system kernels. The key to KVM is that once you have Linux, you practically have KVM as well.

Quoted 7 lines
Quoted 3 lines

Yes. Please realize that what is behind it is a strikingly simple argument:

"Once you have a single project to develop and maintain all is much better."

Thats a very glorified statement but it's not reality, sorry. You can do that with something like perf because it's so small and development of perf is limited to a very small group of developers.

I was not talking about just perf: i am also talking about the arch/x86/ unification which is 200+ KLOC of highly non-trivial kernel code with hundreds of contributors and with 8000+ commits in the past two years.

Also, it applies to perf as well: people said exactly that a year ago: 'perf has it easy to be clean as it is small, once it gets as large as Oprofile tooling it will be in the same messy situation'.

Today perf has more features than Oprofile, has a larger and more complex code base, has more contributors, and no, it's not in the same messy situation at all.

So whatever you think of large, unified projects, you are quite clearly mistaken. I have done and maintained through two different types of unifications and the experience was very similar: both developers and users (and maintainers) are much better off.

Ingo

#315 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 17 lines · Avi Kivity
Quoted 16 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 2 lines

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

I'll ignore the repository location which should be immaterial to a serious developer and concentrate on the 'clean and minimal' aspect, since it has some merit. [...]

To the contrary, experience shows that repository location, and in particular a shared repository for closely related bits is very much material!

It matters because when there are two separate projects, even a "serious developer" is finding it double and triple difficult to contribute even trivial changes.

Quoted 7 lines
Quoted 3 lines

It becomes literally a nightmare if you have to touch 3 packages: kernel, a library and an app codebase. It takes _forever_ to get anything useful done.

You can't be serious. I find that the difficulty in contributing a patch has mostly to do with writing the patch, and less with figuring out which email address to send it to.

My own experience and everyone i've talked about such topics (developers and distro people) about feature contribution tells the exact opposite: it's much harder to contribute features to multiple packages than to a single project.

kernel+library+app features take forever to propagate, and there's constant fear of version friction, productization deadlines are uncertain and ABI messups are frequent as well due to disjoint testing. Also, each component has essential veto power: so if the proposed API or approach is opposed or changed in a later stage then that affects (sometimes already committed) changes. If you've ever done it you'll know how tedious it is.

This very thread and recent threads about KVM usability demonstrate the same complications.

Thanks,

Ingo

#67 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 5 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Quoted 5 lines
Quoted 2 lines

Why is that?

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

It's not inevitable, if the projects are badly run, you'll have high latencies, but projects don't have to be badly run.

Quoted 6 lines

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Try sending a patch to qemu-devel@, you may be pleasantly surprised.

Quoted 8 lines
Quoted 4 lines

I the maintainers of all packages are cooperative and responsive, then the patches will get accepted quickly. If they aren't, development will be slow. [...]

I'm afraid practice is different from the rosy ideal you paint there. Even with assumed 'perfect projects' there's always random differences between projects, causing doubled (tripled) overhead and compounded up overhead:

Quoted 6 lines

- random differences in release schedules

- random differences in contribution guidelines

- random differences in coding style

None of these matter for steady contributors.

Quoted 9 lines
Quoted 4 lines

[...] It isn't any different from contributing to two unrelated kernel subsystems (which are in fact in different repositories until the next merge window).

You mention a perfect example: contributing to multipe kernel subsystems. Even _that_ is very noticeably harder than contributing to a single subsystem - due to the inevitable buerocratic overhead, due to different development trees, due to different merge criteria.

Quoted 7 lines

So you are underlining my point (perhaps without intending to): treating closely related bits of technology as a single project is much better.

Obviously arch/x86/kvm/, virt/ and tools/kvm/ should live in a single development repository (perhaps micro-differentiated by a few topical branches), for exactly those reasons you mention.

How is a patch for the qemu GUI eject button and the kvm shadow mmu related? Should a single maintainer deal with both?

Signature · 1 line
error compiling committee.c: too many arguments to function
#44 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 7 lines

Still it's _very_ useful to have a single reference implementation under tools/perf/ where we concentrate the best of the code. That is where we make sure that each new kernel feature is appropriately implemented in user-space as well, that the combination works well together and is releasable to users. That is what keeps us all honest: the latency of features is much lower, and there's no ping-pong of blame going on between the two components in case of bugs or in case of misfeatures.

Quoted 6 lines

That would make sense for a truly minimal userspace for kvm: we once had a tool called kvmctl which was used to run tests (since folded into qemu). It didn't contain a GUI and was unable to run a general purpose guest. It was a few hundred lines of code, and indeed patches to kvmctl had a much closer correspondence to patches with kvm (though still low, as most kvm patches don't modify the ABI).

If it's functional to the extent of at least allowing say a serial console via the console (like the UML binary allows) i'd expect the minimal user-space to quickly grow out of this minimal state. The rest will be history.

Maybe this is a better, simpler (and much cleaner and less controversial) approach than moving a 'full' copy of qemu there.

There's certainly no risk: if qemu stays dominant then nothing is lost [tools/kvm/ can be removed after some time], and if this clean base works out fine then the useful qemu technologies will move over to it gradually and without much fuss, and the developers will move with it as well.

If it's just a token effort with near zero utility to begin with it certainly wont take off.

Once it's there in tools/kvm/ and bootable i'd certainly hack up some quick xlib based VGA output capability myself - it's not that hard ;-) It would also allow me to test whether latest-KVM still boots fine in a much simpler way. (most of my testboxes dont have qemu installed)

So you have one user signed up for that already ;-)

Quoted 4 lines
Quoted 4 lines

Same goes for KVM+Qemu: it would be so much nicer to have a single, well-focused reference implementation under tools/kvm/ and have improvements flow into that code base.

Quoted 8 lines
Quoted 5 lines

That way KVM developers cannot just shrug "well, GUI suckage is a user-space problem" - like the answers i got in the KVM usability thread
...

The buck will stop here.

Suppose we copy qemu tomorrow into tools/. All the problems will be copied with it. Someone still has to write patches to fix them. Who will it be?

What we saw with tools/perf/ was that pure proximity to actual kernel testers and kernel developers produces a steady influx of new developers. It didnt happen overnight, but it happened. A simple:

cd tools/perf/
make -j install

Gets them something to play with. That kind of proximity is very powerful.

The other benefit was that distros can package perf with the kernel package, so it's updated together with the kernel. This means a very efficient distribution of new technologies, together with new kernel releases.

Distributions are very eager to update kernels even in stable periods of the distro lifetime - they are much less willing to update user-space packages.

You can literally get full KVM+userspace features done _and deployed to users_ within the 3 months development cycle of upstream KVM.

All these create synergies that are very clear once you see the process in motion. It's a powerful positive feedback loop. Give it some thought please.

Ingo

#68 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Ingo Molnar
Quoted 4 lines · Avi Kivity
Quoted 4 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Why is that?

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

It's not inevitable, if the projects are badly run, you'll have high latencies, but projects don't have to be badly run.

So the 64K dollar question is, why does Qemu still suck?

Quoted 36 lines
Quoted 6 lines

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Try sending a patch to qemu-devel@, you may be pleasantly surprised.

Quoted 7 lines
Quoted 3 lines

I the maintainers of all packages are cooperative and responsive, then the patches will get accepted quickly. If they aren't, development will be slow. [...]

I'm afraid practice is different from the rosy ideal you paint there. Even with assumed 'perfect projects' there's always random differences between projects, causing doubled (tripled) overhead and compounded up overhead:

Quoted 5 lines

- random differences in release schedules

- random differences in contribution guidelines

- random differences in coding style

None of these matter for steady contributors.

Quoted 11 lines
Quoted 3 lines

[...] It isn't any different from contributing to two unrelated kernel subsystems (which are in fact in different repositories until the next merge window).

You mention a perfect example: contributing to multipe kernel subsystems. Even _that_ is very noticeably harder than contributing to a single subsystem - due to the inevitable buerocratic overhead, due to different development trees, due to different merge criteria.

So you are underlining my point (perhaps without intending to): treating closely related bits of technology as a single project is much better.

Quoted 6 lines
Quoted 3 lines

Obviously arch/x86/kvm/, virt/ and tools/kvm/ should live in a single development repository (perhaps micro-differentiated by a few topical branches), for exactly those reasons you mention.

How is a patch for the qemu GUI eject button and the kvm shadow mmu related? Should a single maintainer deal with both?

We have co-maintainers for perf that have a different focus. It works pretty well.

Look at git log tools/perf/ and how user-space and kernel-space components interact in practice. You'll patches that only impact one side, but you'll see very big overlap both in contributor identity and in patches as well.

Also, let me put similar questions in a bit different way:

- ' how is an in-kernel PIT emulation connected to Qemu's PIT emulation? '

- ' how is the in-kernel dynticks implementation related to Qemu's implementation of hardware timers? '

- ' how is an in-kernel event for a CD-ROM eject connected to an in-Qemu eject event? '

- ' how is a new hardware virtualization feature related to being able to configure and use it via Qemu? '

- ' how is the in-kernel x86 decoder/emulator related to the Qemu x86 emulator? '

- ' how is the performance of the qemu GUI related to the way VGA buffers are mapped and accelerated by KVM? '

They are obviously deeply related. The quality of a development process is not defined by the easy cases where no project unification is needed. The quality of a development process is defined by the _difficult_ cases.

Ingo

#45 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 34 lines · Ingo Molnar
Quoted 8 lines · Avi Kivity
Quoted 8 lines

Still it's _very_ useful to have a single reference implementation under tools/perf/ where we concentrate the best of the code. That is where we make sure that each new kernel feature is appropriately implemented in user-space as well, that the combination works well together and is releasable to users. That is what keeps us all honest: the latency of features is much lower, and there's no ping-pong of blame going on between the two components in case of bugs or in case of misfeatures.

Quoted 7 lines

That would make sense for a truly minimal userspace for kvm: we once had a tool called kvmctl which was used to run tests (since folded into qemu). It didn't contain a GUI and was unable to run a general purpose guest. It was a few hundred lines of code, and indeed patches to kvmctl had a much closer correspondence to patches with kvm (though still low, as most kvm patches don't modify the ABI).

If it's functional to the extent of at least allowing say a serial console via the console (like the UML binary allows) i'd expect the minimal user-space to quickly grow out of this minimal state. The rest will be history.

Maybe this is a better, simpler (and much cleaner and less controversial) approach than moving a 'full' copy of qemu there.

There's certainly no risk: if qemu stays dominant then nothing is lost [tools/kvm/ can be removed after some time], and if this clean base works out fine then the useful qemu technologies will move over to it gradually and without much fuss, and the developers will move with it as well.

If it's just a token effort with near zero utility to begin with it certainly wont take off.

Quoted 7 lines

Once it's there in tools/kvm/ and bootable i'd certainly hack up some quick xlib based VGA output capability myself - it's not that hard ;-) It would also allow me to test whether latest-KVM still boots fine in a much simpler way. (most of my testboxes dont have qemu installed)

So you have one user signed up for that already ;-)

Alright, you just volunteered. Just give it a go and try to implement the "oh so simple" KVM frontend while maintaining compatibility with at least a few older Linux guests. My guess is that you'll realize it's a dead end before committing anything to the kernel source tree. But really, just try it out.

Good Luck

Alex

#69 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar
Quoted 4 lines

It's not inevitable, if the projects are badly run, you'll have high latencies, but projects don't have to be badly run.

So the 64K dollar question is, why does Qemu still suck?

Where people sent patches, it doesn't suck (or sucks less). Where they don't, it still sucks. And it cost way more than $64K.

If moving things to tools/ helps, let's move Fedora to tools/.

Quoted 6 lines
Quoted 3 lines

How is a patch for the qemu GUI eject button and the kvm shadow mmu related? Should a single maintainer deal with both?

We have co-maintainers for perf that have a different focus. It works pretty well.

And it works well when I have patches that change x86 core and kvm. But that's no longer a single repository and we have to coordinate.

Quoted 8 lines

Look at git log tools/perf/ and how user-space and kernel-space components interact in practice. You'll patches that only impact one side, but you'll see very big overlap both in contributor identity and in patches as well.

Also, let me put similar questions in a bit different way:

- ' how is an in-kernel PIT emulation connected to Qemu's PIT emulation? '

Both implement the same spec. One is be a code derivative of the other (via Xen).

Quoted 3 lines

- ' how is the in-kernel dynticks implementation related to Qemu's implementation of hardware timers? '

The quality of host kernel timers directly determines the quality of qemu's timer emulation.

Quoted 3 lines

- ' how is an in-kernel event for a CD-ROM eject connected to an in-Qemu eject event? '

Both implement the same spec. The kernel of course needs to handle all implementation variants, while qemu only needs to implement it once.

Quoted 3 lines

- ' how is a new hardware virtualization feature related to being able to configure and use it via Qemu? '

Most features (example: npt) are transparent to userspace, some are not. When they are not, we introduce an ioctl() to kvm for controlling the feature, and a command-line switch to qemu for calling it.

Quoted 3 lines

- ' how is the in-kernel x86 decoder/emulator related to the Qemu x86 emulator? '

Both implement the same spec. Note qemu is not an emulator but a binary translator.

Quoted 3 lines

- ' how is the performance of the qemu GUI related to the way VGA buffers are mapped and accelerated by KVM? '

kvm needs to support direct mapping when possible and efficient data transfer when not. The latter will obviously be much slower. When direct mapping is possible, kvm needs to track pages touched by the guest to avoid full screen redraws. The rest (interfacing to X or vnc, implementing emulated hardware acceleration, full-screen mode, etc.) are unrelated.

Quoted 1 line

They are obviously deeply related.

Not at all. kvm in fact knows nothing about vga, to take your last example. To suggest that qemu needs to be close to the kernel to benefit from the kernel's timer implementation means we don't care about providing quality timing except to ourselves, which luckily isn't the case.

Some time ago the various desktops needed directory change notification, and people implemented inotify (or whatever it's called today). No one suggested tools/gnome/ and tools/kde/.

Quoted 4 lines

The quality of a development process is not
defined by the easy cases where no project unification is needed. The quality of a development process is defined by the _difficult_ cases.

That's true, but we don't have issues at the qemu/kvm boundary. Note we do have issues at the qemu/aio interfaces and qemu/net interfaces (out of which vhost-net was born) but these wouldn't be solved by tools/qemu/.

Signature · 1 line
error compiling committee.c: too many arguments to function
#46 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 4 lines · Ingo Molnar

[...]
Distributions are very eager to update kernels even in stable periods of the distro lifetime - they are much less willing to update user-space packages. [...]

Sorry, er, what? What distributions eagerly upgrade kernels in stable periods, were it not primarily motivated by security fixes? What users eagerly replace their kernels?

- FChE

#70 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 4 lines · Ingo Molnar
Quoted 2 lines

It's not inevitable, if the projects are badly run, you'll have high latencies, but projects don't have to be badly run.

So the 64K dollar question is, why does Qemu still suck?

Where people sent patches, it doesn't suck (or sucks less). Where they don't, it still sucks. [...]

So is your point that the development process and basic code structure does not matter at all, it's just a matter of people sending patches? I beg to differ ...

Quoted 3 lines

[...] And it cost way more than $64K.

If moving things to tools/ helps, let's move Fedora to tools/.

Those bits of Fedora which deeply relate to the kernel - yes. Those bits that are arguably separate - nope.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

How is a patch for the qemu GUI eject button and the kvm shadow mmu related? Should a single maintainer deal with both?

We have co-maintainers for perf that have a different focus. It works pretty well.

And it works well when I have patches that change x86 core and kvm. But that's no longer a single repository and we have to coordinate.

Actually, it works much better if, contrary to your proposal it ends up in a single repo. Last i checked both of us really worked on such a project, run by some guy. (Named Linus or so.)

Quoted 48 lines
Quoted 7 lines

Look at git log tools/perf/ and how user-space and kernel-space components interact in practice. You'll patches that only impact one side, but you'll see very big overlap both in contributor identity and in patches as well.

Also, let me put similar questions in a bit different way:

- ' how is an in-kernel PIT emulation connected to Qemu's PIT emulation? '

Both implement the same spec. One is be a code derivative of the other (via Xen).

Quoted 2 lines

- ' how is the in-kernel dynticks implementation related to Qemu's implementation of hardware timers? '

The quality of host kernel timers directly determines the quality of qemu's timer emulation.

Quoted 2 lines

- ' how is an in-kernel event for a CD-ROM eject connected to an in-Qemu eject event? '

Both implement the same spec. The kernel of course needs to handle all implementation variants, while qemu only needs to implement it once.

Quoted 2 lines

- ' how is a new hardware virtualization feature related to being able to configure and use it via Qemu? '

Most features (example: npt) are transparent to userspace, some are not. When they are not, we introduce an ioctl() to kvm for controlling the feature, and a command-line switch to qemu for calling it.

Quoted 2 lines

- ' how is the in-kernel x86 decoder/emulator related to the Qemu x86 emulator? '

Both implement the same spec. Note qemu is not an emulator but a binary translator.

Quoted 2 lines

- ' how is the performance of the qemu GUI related to the way VGA buffers are mapped and accelerated by KVM? '

kvm needs to support direct mapping when possible and efficient data transfer when not. The latter will obviously be much slower. When direct mapping is possible, kvm needs to track pages touched by the guest to avoid full screen redraws. The rest (interfacing to X or vnc, implementing emulated hardware acceleration, full-screen mode, etc.) are unrelated.

Quoted 3 lines
Quoted 1 line

They are obviously deeply related.

Not at all. [...]

You are obviously arguing for something like UML. Fortunately KVM is not that. Or i hope it isnt.

Quoted 2 lines

[...] kvm in fact knows nothing about vga, to take your last example. [...]

Look at the VGA dirty bitmap optimization a'ka the KVM_GET_DIRTY_LOG ioctl.

See qemu/kvm-all.c's kvm_physical_sync_dirty_bitmap().

It started out as a VGA optimization (also used by live migration) and even today it's mostly used by the VGA drivers - albeit a weak one.

I wish there were stronger VGA optimizations implemented, copying the dirty bitmap is not a particularly performant solution. (although it's certainly better than full emulation) Graphics performance is one of the more painful aspects of KVM usability today.

Quoted 3 lines

[...] To suggest that qemu needs to be close to the kernel to benefit from the kernel's timer implementation means we don't care about providing quality timing except to ourselves, which luckily isn't the case.

That is not what i said. I said they are closely related, and where technologies are closely related, project proximity turns into project unification at a certain stage.

Quoted 3 lines

Some time ago the various desktops needed directory change notification, and people implemented inotify (or whatever it's called today). No one suggested tools/gnome/ and tools/kde/.

You are misconstruing and misrepresenting my argument - i'd expect better. Gnome and KDE runs on other kernels as well and is generally not considered close to the kernel.

Do you seriously argue that Qemu has nothing to do with KVM these days?

Quoted 7 lines
Quoted 3 lines

The quality of a development process is not defined by the easy cases where no project unification is needed. The quality of a development process is defined by the _difficult_ cases.

That's true, but we don't have issues at the qemu/kvm boundary. Note we do have issues at the qemu/aio interfaces and qemu/net interfaces (out of which vhost-net was born) but these wouldn't be solved by tools/qemu/.

That was not what i suggested. They would be solved by what i proposed:
tools/kvm/, right?

Thanks,

Ingo

#47 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Frank Ch. Eigler
Quoted 11 lines · Frank Ch. Eigler
Quoted 4 lines · Ingo Molnar

[...]
Distributions are very eager to update kernels even in stable periods of the distro lifetime - they are much less willing to update user-space packages. [...]

Sorry, er, what?  What distributions eagerly upgrade kernels in stable periods, were it not primarily motivated by security fixes?  What users eagerly replace their kernels?

Us guys reading and participating on the list. ;)

#50 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Frank Ch. Eigler
Quoted 9 lines · Frank Ch. Eigler
Quoted 4 lines · Ingo Molnar

[...]
Distributions are very eager to update kernels even in stable periods of the distro lifetime - they are much less willing to update user-space packages. [...]

Sorry, er, what? What distributions eagerly upgrade kernels in stable periods, were it not primarily motivated by security fixes? [...]

Please check the popular distro called 'Fedora' for example, and its kernel upgrade policies.

Quoted 1 line

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

Ingo

#342 lore raw
In reply to Ingo Molnar

Em Thu, Mar 18, 2010 at 09:03:25AM +0100, Ingo Molnar escreveu:

Quoted 8 lines · Zhang, Yanmin
Quoted 2 lines

I worked out 3 new patches against tip/master tree of Mar. 17th.

Cool! Mind sending them as a series of patches instead of attachment? That makes it easier to review them. Also, the Signed-off-by lines seem to be missing plus we need a per patch changelog as well.

Yeah, please, and I hadn't merged them, so the resend was the best thing to do.

- Arnaldo

#51 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar
Quoted 3 lines

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

Of which 1 is the kernel, and 192 are userspace updates (of which one may be qemu).

Signature · 1 line
error compiling committee.c: too many arguments to function
#323 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 9 lines · Ingo Molnar
Quoted 3 lines · Jes Sorensen

Thats a very glorified statement but it's not reality, sorry. You can do that with something like perf because it's so small and development of perf is limited to a very small group of developers.

I was not talking about just perf: i am also talking about the arch/x86/ unification which is 200+ KLOC of highly non-trivial kernel code with hundreds of contributors and with 8000+ commits in the past two years.

Sorry but you cannot compare merging two chunks of kernel code that originated from the same base, with the efforts of mixing a large userland project with a kernel component. Apples and oranges.

Quoted 7 lines

Also, it applies to perf as well: people said exactly that a year ago: 'perf has it easy to be clean as it is small, once it gets as large as Oprofile tooling it will be in the same messy situation'.

Today perf has more features than Oprofile, has a larger and more complex code base, has more contributors, and no, it's not in the same messy situation at all.

Both perf and oprofile are still relatively small projects in comparison to QEMU.

Quoted 4 lines

So whatever you think of large, unified projects, you are quite clearly mistaken. I have done and maintained through two different types of unifications and the experience was very similar: both developers and users (and maintainers) are much better off.

You believe that I am wrong in my assessment of unified projects, and I obviously think you are mistaken and underestimating the cost and effects of trying to merge the two.

Well I think we are just going to agree to disagree on this one. I am not against merging projects where it makes sense, but in this particular case I am strongly convinced the loss would be much greater than the gain.

Cheers,
Jes

#62 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar

Hi -

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

[...]
Distributions are very eager to update kernels even in stable periods of the distro lifetime - they are much less willing to update user-space packages. [...]

Sorry, er, what? What distributions eagerly upgrade kernels in stable periods, were it not primarily motivated by security fixes? [...]

Please check the popular distro called 'Fedora' for example

I do believe I've heard of it. According to fedora bodhi, there have been 18 kernel updates issues for fedora 11 since its release, of which 12 were for purely security updates, and most of the other six also contain security fixes. None are described as 'enhancement' updates. Oh, what about fedora 12? 8 updates total, of which 5 are security only, one for drm showstoppers, others including security fixes, again 0 tagged as 'enhancement'.

So where is that "eagerness" again?? My sense is that most users are happy to leave a stable kernel running as long as possible, and distributions know this. You surely must understand that the lkml demographics are different.

Quoted 1 line

and its kernel upgrade policies.

[citation needed]

Quoted 3 lines
Quoted 1 line

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

That's not "eager". That's "I'm exasperated from guessing what's really important; let's not have so many updates; meh".

- FChE

#52 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar
Quoted 2 lines

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

Of which 1 is the kernel, and 192 are userspace updates (of which one may be qemu).

I think you didnt understand my (tersely explained) point - which is probably my fault. What i said is:

- distros update the kernel first. Often in stable releases as well if there's a new kernel released. (They must because it provides new hardware enablement and other critical changes they generally cannot skip.)

- Qemu on the other hand is not upgraded with (nearly) that level of urgency. Completely new versions will generally have to wait for the next distro release.

With in-kernel tools the kernel and the tooling that accompanies the kernel are upgraded in the same low-latency pathway. That is a big plus if you are offering things like instrumentation (which perf does), which relates closely to the kernel.

Furthermore, many distros package up the latest -git kernel as well. They almost never do that with user-space packages.

Let me give you a specific example:

I'm running Fedora Rawhide with 2.6.34-rc1 right now on my main desktop, and that comes with perf-2.6.34-0.10.rc1.git0.fc14.noarch.

My rawhide box has qemu-kvm-0.12.3-3.fc14.x86_64 installed. That's more than a 1000 Qemu commits older than the latest Qemu development branch.

So by being part of the kernel repo there's lower latency upgrades and earlier and better testing available on most distros.

You made it very clear that you dont want that, but please dont try to claim that those advantages do not exist - they are very much real and we are making good use of it.

Thanks,

Ingo

#71 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 9 lines · Ingo Molnar
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Ingo Molnar
Quoted 3 lines

It's not inevitable, if the projects are badly run, you'll have high latencies, but projects don't have to be badly run.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

So the 64K dollar question is, why does Qemu still suck?

Where people sent patches, it doesn't suck (or sucks less). Where they don't, it still sucks. [...]

So is your point that the development process and basic code structure does not matter at all, it's just a matter of people sending patches? I beg to differ ...

The development process of course matters, and we have worked hard to fix qemu's. Basic code structure also matters, but you don't fix that with cp.

Quoted 7 lines
Quoted 4 lines

[...] And it cost way more than $64K.

If moving things to tools/ helps, let's move Fedora to tools/.

Those bits of Fedora which deeply relate to the kernel - yes. Those bits that are arguably separate - nope.

A qemu GUI is not deeply related to the kernel. Or at all.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

How is a patch for the qemu GUI eject button and the kvm shadow mmu related? Should a single maintainer deal with both?

We have co-maintainers for perf that have a different focus. It works pretty well.

Quoted 7 lines
Quoted 3 lines

And it works well when I have patches that change x86 core and kvm. But that's no longer a single repository and we have to coordinate.

Actually, it works much better if, contrary to your proposal it ends up in a single repo. Last i checked both of us really worked on such a project, run by some guy. (Named Linus or so.)

Well, when last I sent x86 patches, they went to you and hpa, applied to tip, from which I had to merge them back. Two repositories. After several weeks they did end up in a third repository, Linus'. The process isn't trivial or fast, but it works.

Quoted 54 lines
Quoted 54 lines
Quoted 8 lines

Look at git log tools/perf/ and how user-space and kernel-space components interact in practice. You'll patches that only impact one side, but you'll see very big overlap both in contributor identity and in patches as well.

Also, let me put similar questions in a bit different way:

- ' how is an in-kernel PIT emulation connected to Qemu's PIT emulation? '

Both implement the same spec. One is be a code derivative of the other (via Xen).

Quoted 3 lines

- ' how is the in-kernel dynticks implementation related to Qemu's implementation of hardware timers? '

The quality of host kernel timers directly determines the quality of qemu's timer emulation.

Quoted 3 lines

- ' how is an in-kernel event for a CD-ROM eject connected to an in-Qemu eject event? '

Both implement the same spec. The kernel of course needs to handle all implementation variants, while qemu only needs to implement it once.

Quoted 3 lines

- ' how is a new hardware virtualization feature related to being able to configure and use it via Qemu? '

Most features (example: npt) are transparent to userspace, some are not. When they are not, we introduce an ioctl() to kvm for controlling the feature, and a command-line switch to qemu for calling it.

Quoted 3 lines

- ' how is the in-kernel x86 decoder/emulator related to the Qemu x86 emulator? '

Both implement the same spec. Note qemu is not an emulator but a binary translator.

Quoted 3 lines

- ' how is the performance of the qemu GUI related to the way VGA buffers are mapped and accelerated by KVM? '

kvm needs to support direct mapping when possible and efficient data transfer when not. The latter will obviously be much slower. When direct mapping is possible, kvm needs to track pages touched by the guest to avoid full screen redraws. The rest (interfacing to X or vnc, implementing emulated hardware acceleration, full-screen mode, etc.) are unrelated.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

They are obviously deeply related.

Not at all. [...]

You are obviously arguing for something like UML. Fortunately KVM is not that. Or i hope it isnt.

I am not arguing for UML and don't understand why you think so.

Quoted 5 lines
Quoted 3 lines

[...] kvm in fact knows nothing about vga, to take your last example. [...]

Look at the VGA dirty bitmap optimization a'ka the KVM_GET_DIRTY_LOG ioctl.

Quoted 7 lines

See qemu/kvm-all.c's kvm_physical_sync_dirty_bitmap().

It started out as a VGA optimization (also used by live migration) and even today it's mostly used by the VGA drivers - albeit a weak one.

I wish there were stronger VGA optimizations implemented, copying the dirty bitmap is not a particularly performant solution.

The VGA dirty bitmap is 256 bytes in length. Copying it doesn't take any time at all.

People are in fact working on a copy-less dirty bitmap solution, for live migration of very large memory guests. Expect set_bit_user() patches for tip.git.

Quoted 4 lines

(although it's certainly
better than full emulation) Graphics performance is one of the more painful aspects of KVM usability today.

If you have suggestions for further optimizations (or even patches) I'd love to hear them.

One solution we are working on is QXL, a framebuffer-less graphics card designed for spice. The use case is again server based (hosted desktops) but may be adapted for desktop-on-desktop use.

Quoted 8 lines
Quoted 4 lines

[...] To suggest that qemu needs to be close to the kernel to benefit from the kernel's timer implementation means we don't care about providing quality timing except to ourselves, which luckily isn't the case.

That is not what i said. I said they are closely related, and where technologies are closely related, project proximity turns into project unification at a certain stage.

I really don't see how. So what if both qemu and kvm implement an i8254? They can't share any code since the internal APIs are so different. Even worse for the x86 emulator as qemu and kvm are fundamentally different. Even more with the qemu timers and kernel dyntick code.

Quoted 8 lines
Quoted 4 lines

Some time ago the various desktops needed directory change notification, and people implemented inotify (or whatever it's called today). No one suggested tools/gnome/ and tools/kde/.

You are misconstruing and misrepresenting my argument - i'd expect better. Gnome and KDE runs on other kernels as well and is generally not considered close to the kernel.

qemu runs on other kernels (including Windows), just without kvm.

Quoted 2 lines

Do you seriously argue that Qemu has nothing to do with KVM these days?

The vast majority of qemu has nothing to do with kvm, all the kvm interface bits are in two files. Things like the GUI, the VNC server, IDE emulation, the management interface (the monitor), live migration, qcow2 and ~15 other file format drivers, chipset emulation, USB controller emulation, snapshot support, slirp, serial port emulation, and a zillion other details have nothing to do with kvm.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

The quality of a development process is not defined by the easy cases where no project unification is needed. The quality of a development process is defined by the _difficult_ cases.

That's true, but we don't have issues at the qemu/kvm boundary. Note we do have issues at the qemu/aio interfaces and qemu/net interfaces (out of which vhost-net was born) but these wouldn't be solved by tools/qemu/.

That was not what i suggested. They would be solved by what i proposed:
tools/kvm/, right?

If they were, it would be worth it.

Signature · 1 line
error compiling committee.c: too many arguments to function
#53 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 16 lines · Ingo Molnar
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar
Quoted 2 lines

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

Of which 1 is the kernel, and 192 are userspace updates (of which one may be qemu).

I think you didnt understand my (tersely explained) point - which is probably my fault. What i said is:

Quoted 7 lines

- distros update the kernel first. Often in stable releases as well if there's a new kernel released. (They must because it provides new hardware enablement and other critical changes they generally cannot skip.)

- Qemu on the other hand is not upgraded with (nearly) that level of urgency. Completely new versions will generally have to wait for the next distro release.

This has nothing todo with them being in separate source repos. We could update QEMU to new major feature releaes with the same frequency in a Fedora release, but we delibrately choose not to rebase the QEMU userspace because experiance has shown the downside from new bugs / regressions outweighs the benefit of any new features.

The QEMU updates in stable Fedora trees, now just follow the minor bugfix release stream provided by QEMU & those arrive in Fedora with little noticable delay.

Daniel

Signature · 4 lines
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#57 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 14 lines · Ingo Molnar
Quoted 11 lines · Avi Kivity
Quoted 6 lines · Ingo Molnar
Quoted 3 lines

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

Of which 1 is the kernel, and 192 are userspace updates (of which one may be qemu).

Quoted 7 lines

I think you didnt understand my (tersely explained) point - which is probably my fault. What i said is:

- distros update the kernel first. Often in stable releases as well if there's a new kernel released. (They must because it provides new hardware enablement and other critical changes they generally cannot skip.)

No, they don't. RHEL 5 is still on 2.6.18, for example. Users don't like their kernels updated unless absolutely necessary, with good reason.

Kernel updates = reboots.

Quoted 4 lines

- Qemu on the other hand is not upgraded with (nearly) that level of urgency. Completely new versions will generally have to wait for the next distro release.

F12 recently updated to 2.6.32. This is probably due to 2.6.31.stable dropping away, and no capacity at Fedora to maintain it on their own. So they are caught in a bind - stay on 2.6.31 and expose users to security vulnerabilities or move to 2.6.32 and cause regressions. Not a happy choice.

Quoted 8 lines

With in-kernel tools the kernel and the tooling that accompanies the kernel are upgraded in the same low-latency pathway. That is a big plus if you are offering things like instrumentation (which perf does), which relates closely to the kernel.

Furthermore, many distros package up the latest -git kernel as well. They almost never do that with user-space packages.

I'm sure if we ask the Fedora qemu maintainer to package qemu-kvm.git they'll consider it favourably. Isn't that what rawhide is for?

Quoted 8 lines

Let me give you a specific example:

I'm running Fedora Rawhide with 2.6.34-rc1 right now on my main desktop, and that comes with perf-2.6.34-0.10.rc1.git0.fc14.noarch.

My rawhide box has qemu-kvm-0.12.3-3.fc14.x86_64 installed. That's more than a 1000 Qemu commits older than the latest Qemu development branch.

Quoted 7 lines

So by being part of the kernel repo there's lower latency upgrades and earlier and better testing available on most distros.

You made it very clear that you dont want that, but please dont try to claim that those advantages do not exist - they are very much real and we are making good use of it.

I don't mind at all if rawhide users run on the latest and greatest, but release users deserve a little more stability.

Signature · 1 line
error compiling committee.c: too many arguments to function
#63 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Frank Ch. Eigler
Quoted 20 lines · Frank Ch. Eigler

Hi -

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

[...]
Distributions are very eager to update kernels even in stable periods of the distro lifetime - they are much less willing to update user-space packages. [...]

Sorry, er, what? What distributions eagerly upgrade kernels in stable periods, were it not primarily motivated by security fixes? [...]

Please check the popular distro called 'Fedora' for example

I do believe I've heard of it. According to fedora bodhi, there have been 18 kernel updates issues for fedora 11 since its release, of which 12 were for purely security updates, and most of the other six also contain security fixes. None are described as 'enhancement' updates. Oh, what about fedora 12? 8 updates total, of which 5 are security only, one for drm showstoppers, others including security fixes, again 0 tagged as 'enhancement'.

Quoted 8 lines

So where is that "eagerness" again?? My sense is that most users are happy to leave a stable kernel running as long as possible, and distributions know this. You surely must understand that the lkml demographics are different.

Quoted 1 line

and its kernel upgrade policies.

[citation needed]

You are quite wrong, despite the sarcastic tone you are attempting to use, and this is distro kernel policy 101.

For distros such as Fedora it's simpler to support the same kernel version across many older versions of the distro than having to support different kernel versions.

Check Fedora 12 for example. Four months ago it was released with kernel v2.6.31:

http://download.fedora.redhat.com/pub/fedora/linux/releases/12/Fedora/x86_64/os/Packages/kernel-2.6.31.5-127.fc12.x86_64.rpm

But if you update a Fedora 12 installation today you'll get kernel v2.6.32:

http://download.fedora.redhat.com/pub/fedora/linux/updates/12/SRPMS/kernel-2.6.32.9-70.fc12.src.rpm

As a result you'll get a new 2.6.32 kernel on Fedora 12.

The end result is what i said in the previous mail: that you'll get a newer kernel even on a stable distro - while user-space packages will only be updated if there's a security issue (and even then there's no version jump like for the kernel).

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

That's not "eager". That's "I'm exasperated from guessing what's really important; let's not have so many updates; meh".

Erm, fact is, 99% [WAG] of the users click on the update button and accept whatever kernel version the distro update offers them.

Ingo

#58 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Ingo Molnar
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Ingo Molnar
Quoted 1 line

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

Of which 1 is the kernel, and 192 are userspace updates (of which one may be qemu).

Quoted 8 lines
Quoted 6 lines

I think you didnt understand my (tersely explained) point - which is probably my fault. What i said is:

- distros update the kernel first. Often in stable releases as well if there's a new kernel released. (They must because it provides new hardware enablement and other critical changes they generally cannot skip.)

No, they don't. [...]

I just replied to Frank Ch. Eigler with a specific example that shows how this happens - and believe me, it happens.

Quoted 3 lines

[...] RHEL 5 is still on 2.6.18, for example. Users don't like their kernels updated unless absolutely necessary, with good reason.

Nope - RHEL 5 is on a 2.6.18 base for entirely different reasons.

Quoted 1 line

Kernel updates = reboots.

If you check the update frequency of RHEL 5 kernels you'll see that it's comparable to that of Fedora.

Quoted 9 lines
Quoted 3 lines

- Qemu on the other hand is not upgraded with (nearly) that level of urgency. Completely new versions will generally have to wait for the next distro release.

F12 recently updated to 2.6.32. This is probably due to 2.6.31.stable dropping away, and no capacity at Fedora to maintain it on their own. So they are caught in a bind - stay on 2.6.31 and expose users to security vulnerabilities or move to 2.6.32 and cause regressions. Not a happy choice.

Happy choice or not, this is what i said is the distro practice these days. (i dont know all the distros that well so i'm sure there's differences)

Quoted 10 lines
Quoted 7 lines

With in-kernel tools the kernel and the tooling that accompanies the kernel are upgraded in the same low-latency pathway. That is a big plus if you are offering things like instrumentation (which perf does), which relates closely to the kernel.

Furthermore, many distros package up the latest -git kernel as well. They almost never do that with user-space packages.

I'm sure if we ask the Fedora qemu maintainer to package qemu-kvm.git they'll consider it favourably. Isn't that what rawhide is for?

Rawhide is generally for latest released versions, to ready them for the next distro release - with special exception for the kernel, which has a special position due being a hardware-enabler and because it has an extremely predictable release schedule of every 90 days (+- 10 days).

Very rarely do distro people jump versions for things like GCC or Xorg or Gnome/KDE, but they've been burned enough times by unexpected delays in those projects to be really loathe to do it.

Qemu might get an exception - dunno, you could ask. My point still holds: by hosting KVM user-space bits in the kernel together with the rest of KVM you get version parity - which has clear advantages.

You also might have more luck with a bleeding-edge distro such as Gentoo.

Quoted 11 lines
Quoted 11 lines

Let me give you a specific example:

I'm running Fedora Rawhide with 2.6.34-rc1 right now on my main desktop, and that comes with perf-2.6.34-0.10.rc1.git0.fc14.noarch.

My rawhide box has qemu-kvm-0.12.3-3.fc14.x86_64 installed. That's more than a 1000 Qemu commits older than the latest Qemu development branch.

So by being part of the kernel repo there's lower latency upgrades and earlier and better testing available on most distros.

Quoted 6 lines
Quoted 3 lines

You made it very clear that you dont want that, but please dont try to claim that those advantages do not exist - they are very much real and we are making good use of it.

I don't mind at all if rawhide users run on the latest and greatest, but release users deserve a little more stability.

What are you suggesting, that released versions of KVM are not reliable? Of course any tools/ bits are release engineered just as much as the rest of KVM
...

Ingo

#54 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Daniel P. Berrange
Quoted 31 lines · Daniel P. Berrange
Quoted 16 lines · Ingo Molnar
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar
Quoted 2 lines

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

Of which 1 is the kernel, and 192 are userspace updates (of which one may be qemu).

I think you didnt understand my (tersely explained) point - which is probably my fault. What i said is:

Quoted 7 lines

- distros update the kernel first. Often in stable releases as well if there's a new kernel released. (They must because it provides new hardware enablement and other critical changes they generally cannot skip.)

- Qemu on the other hand is not upgraded with (nearly) that level of urgency. Completely new versions will generally have to wait for the next distro release.

This has nothing todo with them being in separate source repos. We could update QEMU to new major feature releaes with the same frequency in a Fedora release, but we delibrately choose not to rebase the QEMU userspace because experiance has shown the downside from new bugs / regressions outweighs the benefit of any new features.

Quoted 3 lines

The QEMU updates in stable Fedora trees, now just follow the minor bugfix release stream provided by QEMU & those arrive in Fedora with little noticable delay.

That is exactly what i said: Qemu and most user-space packages are on a 'slower' update track than the kernel: generally updated for minor releases.

My further point was that the kernel on the other hand gets updated more frequently and as such, any user-space tool bits hosted in the kernel repo get updated more frequently as well.

Thanks,

Ingo

#55 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 41 lines · Ingo Molnar
Quoted 31 lines · Daniel P. Berrange
Quoted 16 lines · Ingo Molnar
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar
Quoted 2 lines

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

Of which 1 is the kernel, and 192 are userspace updates (of which one may be qemu).

I think you didnt understand my (tersely explained) point - which is probably my fault. What i said is:

Quoted 7 lines

 - distros update the kernel first. Often in stable releases as well if there's a new kernel released. (They must because it provides new hardware enablement and other critical changes they generally cannot skip.)

 - Qemu on the other hand is not upgraded with (nearly) that level of urgency. Completely new versions will generally have to wait for the next distro release.

This has nothing todo with them being in separate source repos. We could update QEMU to new major feature releaes with the same frequency in a Fedora release, but we delibrately choose not to rebase the QEMU userspace because experiance has shown the downside from new bugs / regressions outweighs the benefit of any new features.

Quoted 3 lines

The QEMU updates in stable Fedora trees, now just follow the minor bugfix release stream provided by QEMU & those arrive in Fedora with little noticable delay.

That is exactly what i said: Qemu and most user-space packages are on a 'slower' update track than the kernel: generally updated for minor releases.

Quoted 7 lines

My further point was that the kernel on the other hand gets updated more frequently and as such, any user-space tool bits hosted in the kernel repo get updated more frequently as well.

Thanks,

       Ingo

Just to play devil's advocate, let's not mix up the development model with the distribution model. There is nothing to stop packagers and distributors from providing separate kernel "proper" packages and perf tools packages.

It might even make good sense assuming backwards compatibility for distros that have conservative policies about new kernel versions to provide newer perf tools packages with older kernels.

John

#72 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 3 lines

That is not what i said. I said they are closely related, and where technologies are closely related, project proximity turns into project unification at a certain stage.

I really don't see how. So what if both qemu and kvm implement an i8254? They can't share any code since the internal APIs are so different. [...]

I wouldnt jump to assumptions there. perf shares some facilities with the kernel on the source code level - they can be built both in the kernel and in user-space.

But my main thought wasnt even to actually share the implementation - but to actually synchronize when a piece of device emulation moves into the kernel. It is arguably bad for performance in most cases when Qemu handles a given device - so all the common devices should be kernel accelerated.

The version and testing matrix would be simplified significantly as well: as kernel and qemu goes hand in hand, they are always on the same version.

Quoted 2 lines

[...] Even worse for the x86 emulator as qemu and kvm are fundamentally different.

So is it your argument that the difference and the duplication in x86 instruction emulation is a good thing? You said it some time ago that the kvm x86 emulator was very messy and you wish it was cleaner.

While qemu's is indeed rather different (it's partly a translator/JIT), i'm sure the decoder logic could be shared - and qemu has a slow-path full-emulation fallback in any case, which is similar to what in-kernel emulator does (IIRC ...).

That might have changed meanwhile.

Ingo

#56 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to John Kacur
Quoted 50 lines · John Kacur
Quoted 41 lines · Ingo Molnar
Quoted 31 lines · Daniel P. Berrange
Quoted 16 lines · Ingo Molnar
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar
Quoted 2 lines

[...] What users eagerly replace their kernels?

Those 99% who click on the 'install 193 updates' popup.

Of which 1 is the kernel, and 192 are userspace updates (of which one may be qemu).

I think you didnt understand my (tersely explained) point - which is probably my fault. What i said is:

Quoted 7 lines

?- distros update the kernel first. Often in stable releases as well if ? ?there's a new kernel released. (They must because it provides new hardware ? ?enablement and other critical changes they generally cannot skip.)

?- Qemu on the other hand is not upgraded with (nearly) that level of urgency. ? ?Completely new versions will generally have to wait for the next distro ? ?release.

This has nothing todo with them being in separate source repos. We could update QEMU to new major feature releaes with the same frequency in a Fedora release, but we delibrately choose not to rebase the QEMU userspace because experiance has shown the downside from new bugs / regressions outweighs the benefit of any new features.

Quoted 3 lines

The QEMU updates in stable Fedora trees, now just follow the minor bugfix release stream provided by QEMU & those arrive in Fedora with little noticable delay.

That is exactly what i said: Qemu and most user-space packages are on a 'slower' update track than the kernel: generally updated for minor releases.

Quoted 7 lines

My further point was that the kernel on the other hand gets updated more frequently and as such, any user-space tool bits hosted in the kernel repo get updated more frequently as well.

Thanks,

? ? ? ?Ingo

Quoted 7 lines

Just to play devil's advocate, let's not mix up the development model with the distribution model. There is nothing to stop packagers and distributors from providing separate kernel "proper" packages and perf tools packages.

It might even make good sense assuming backwards compatibility for distros that have conservative policies about new kernel versions to provide newer perf tools packages with older kernels.

Of course. Some distros are also very conservative about updating the kernel at all.

I'm mostly talking about the distros that are at the frontier of kernel
development: those with fresh packages, those which provide eager bleeding-edge testers and developers.

Ingo

#324 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Jes Sorensen
Quoted 7 lines · Jes Sorensen
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · Jes Sorensen

Thats a very glorified statement but it's not reality, sorry. You can do that with something like perf because it's so small and development of perf is limited to a very small group of developers.

Quoted 7 lines
Quoted 3 lines

I was not talking about just perf: i am also talking about the arch/x86/ unification which is 200+ KLOC of highly non-trivial kernel code with hundreds of contributors and with 8000+ commits in the past two years.

Sorry but you cannot compare merging two chunks of kernel code that originated from the same base, with the efforts of mixing a large userland project with a kernel component. Apples and oranges.

That's true to a certain degree, but combined with the perf experience it's all rather clear.

Similar arguments were made against the x86 unification and against perf. Similar arguments were made against KVM and in favor of Xen years ago - back when few of you knew about it ;-)

These are all repeating patterns in my experience.

You could fairly contrast that with a _failed_ unification perhaps - but i'm not aware of any such failed unification. (please educate me if you are)

The thing is, unifications are rare in the OSS space not because they dont make sense technically (to the contrary), they are rare due to blind inertia (why change if we managed to muddle through with the current scheme?) and to a certain degree due to the egos involved ;-)

As such we have a proliferation of packages in Linux, and we'd be much better off in a more focused fashion. And whenever i see that in the kernel's context i'll mention it - as it happened here too.

Quoted 10 lines
Quoted 7 lines

Also, it applies to perf as well: people said exactly that a year ago:
'perf has it easy to be clean as it is small, once it gets as large as Oprofile tooling it will be in the same messy situation'.

Today perf has more features than Oprofile, has a larger and more complex code base, has more contributors, and no, it's not in the same messy situation at all.

Both perf and oprofile are still relatively small projects in comparison to QEMU.

So is your argument that the unification does not make sense due to size? Would a smaller Qemu be more appropriate for this purpose?

Quoted 5 lines
Quoted 4 lines

So whatever you think of large, unified projects, you are quite clearly mistaken. I have done and maintained through two different types of unifications and the experience was very similar: both developers and users (and maintainers) are much better off.

Quoted 7 lines

You believe that I am wrong in my assessment of unified projects, and I obviously think you are mistaken and underestimating the cost and effects of trying to merge the two.

Well I think we are just going to agree to disagree on this one. I am not against merging projects where it makes sense, but in this particular case I am strongly convinced the loss would be much greater than the gain.

I wish you said that based on first hand negative experience with unifications, not based on just pure speculation.

(and yes, i speculate too, but at least with some basis)

Ingo

#48 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to John Kacur
Quoted 8 lines · John Kacur
Quoted 7 lines · Frank Ch. Eigler
Quoted 4 lines · Ingo Molnar

[...]
Distributions are very eager to update kernels even in stable periods of the distro lifetime - they are much less willing to update user-space packages. [...]

Quoted 6 lines
Quoted 4 lines

Sorry, er, what? ?What distributions eagerly upgrade kernels in stable periods, were it not primarily motivated by security fixes? ?What users eagerly replace their kernels?

Us guys reading and participating on the list. ;)

I'd like to second that - i'm actually quite happy to update the distro kernel. Also, i have rarely any problems even with bleeding edge kernels in rawhide - they are working pretty smoothly.

A large xorg update showing up in yum update gives me the cringe though ;-)

Ingo

#59 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar
Quoted 5 lines

[...] RHEL 5 is still on 2.6.18, for example. Users don't like their kernels updated unless absolutely necessary, with good reason.

Nope - RHEL 5 is on a 2.6.18 base for entirely different reasons.

All the reasons have 'stability' in them.

Quoted 5 lines
Quoted 2 lines

Kernel updates = reboots.

If you check the update frequency of RHEL 5 kernels you'll see that it's comparable to that of Fedora.

I'm sorry to say that's pretty bad. Users don't want to update their kernels.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

- Qemu on the other hand is not upgraded with (nearly) that level of urgency. Completely new versions will generally have to wait for the next distro release.

Quoted 9 lines
Quoted 6 lines

F12 recently updated to 2.6.32. This is probably due to 2.6.31.stable dropping away, and no capacity at Fedora to maintain it on their own. So they are caught in a bind - stay on 2.6.31 and expose users to security vulnerabilities or move to 2.6.32 and cause regressions. Not a happy choice.

Happy choice or not, this is what i said is the distro practice these days. (i dont know all the distros that well so i'm sure there's differences)

So in addition to all the normal kernel regressions, you want to force tools/kvm/ regressions on users.

Quoted 7 lines
Quoted 3 lines

I don't mind at all if rawhide users run on the latest and greatest, but release users deserve a little more stability.

What are you suggesting, that released versions of KVM are not reliable? Of course any tools/ bits are release engineered just as much as the rest of KVM
...

No, I am suggesting qemu-kvm.git is not as stable as released versions (and won't get fixed backported). Keep in mind that unlike many userspace applications, qemu exposes an ABI to guests which we must keep compatible.

Signature · 1 line
error compiling committee.c: too many arguments to function
#60 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 6 lines · Avi Kivity
Quoted 3 lines

Happy choice or not, this is what i said is the distro practice these days. (i dont know all the distros that well so i'm sure there's differences)

So in addition to all the normal kernel regressions, you want to force tools/kvm/ regressions on users.

So instead you force a NxN compatibility matrix [all versions of qemu combined with all versions of the kernel] instead of a linear N versions matrix with a clear focus on the last version. Brilliant engineering i have to say ;-)

Also, by your argument the kernel should be split up into a micro-kernel, with different packages for KVM, scheduler, drivers, upgradeable separately.

That would be a nightmare. (i can detail many facets of that nightmare if you insist but i'll spare the electrons for now) Fortunately few kernel developers share your views about this.

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

I don't mind at all if rawhide users run on the latest and greatest, but release users deserve a little more stability.

What are you suggesting, that released versions of KVM are not reliable? Of course any tools/ bits are release engineered just as much as the rest of KVM ...

No, I am suggesting qemu-kvm.git is not as stable as released versions (and won't get fixed backported). Keep in mind that unlike many userspace applications, qemu exposes an ABI to guests which we must keep compatible.

I think you still dont understand it: if a tool moves to the kernel repo, then it is _released stable_ together with the next stable kernel.

I.e. you'd get a stable qemu-2.6.34 in essence, when v2.6.34 is released. You get minor updates with 2.6.34.1, 2.6.34.2, 2.6.34.3, etc - while development continues.

I.e. you get _more_ stability, because a matching kernel is released with a matching Qemu.

Qemu might have a different release schedule. Which, i argue, is not a good thing for exactly that reason :-) If it moved to tools/kvm/ it would get the same 90 days release frequency, merge window and stabilization window treatment as the upstream kernel.

Furthermore, users can also run experimental versions of qemu together with experimental versions of the kernel, by running something like 2.6.34-rc1 on Rawhide. Even if they dont download the latest qemu git and build it.

I.e. clearly _more_ is possible in such a scheme.

Ingo

#73 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 14 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 4 lines

That is not what i said. I said they are closely related, and where technologies are closely related, project proximity turns into project unification at a certain stage.

I really don't see how. So what if both qemu and kvm implement an i8254? They can't share any code since the internal APIs are so different. [...]

I wouldnt jump to assumptions there. perf shares some facilities with the kernel on the source code level - they can be built both in the kernel and in user-space.

Quoted 8 lines

But my main thought wasnt even to actually share the implementation - but to actually synchronize when a piece of device emulation moves into the kernel. It is arguably bad for performance in most cases when Qemu handles a given device - so all the common devices should be kernel accelerated.

The version and testing matrix would be simplified significantly as well: as kernel and qemu goes hand in hand, they are always on the same version.

So, you propose to allow running tools/kvm/ only on the kernel it was shipped with?

Otherwise the testing matrix isn't simplified.

Quoted 5 lines
Quoted 3 lines

[...] Even worse for the x86 emulator as qemu and kvm are fundamentally different.

So is it your argument that the difference and the duplication in x86 instruction emulation is a good thing?

Of course it isn't a good thing, but it is unavoidable. Qemu compiles code just-in-time to avoid interpretation overhead, while kvm emulates one instruction at a time. No caching is possible, especially with ept/npt, since the guest is free to manipulate memory with no notification to the host. Qemu also supports the full instruction set while kvm only implements what is necessary. Qemu is a multi-source/multi-target translator while kvm's emulator is x86 specific.

Quoted 3 lines

You said it some time ago that
the kvm x86 emulator was very messy and you wish it was cleaner.

It's still messy but is being cleaned up.

Quoted 7 lines

While qemu's is indeed rather different (it's partly a translator/JIT), i'm sure the decoder logic could be shared - and qemu has a slow-path full-emulation fallback in any case, which is similar to what in-kernel emulator does (IIRC ...).

That might have changed meanwhile.

IIUC it only ever translates.

Signature · 1 line
error compiling committee.c: too many arguments to function
#329 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 30 lines · Ingo Molnar
Quoted 27 lines · Anthony Liguori
Quoted 25 lines · Ingo Molnar
Quoted 4 lines

If we look at the use-case, it's going to be something like, a user is creating virtual machines and wants to get performance information about them.

Quoted 9 lines

Having to run a separate tool like perf is not going to be what they would expect they had to do. Instead, they would either use their existing GUI tool (like virt-manager) or they would use their management interface (either QMP or libvirt).

The complexity of interaction is due to the fact that perf shouldn't be a stand alone tool. It should be a library or something with a programmatic interface that another tool can make use of.

But ... a GUI interface/integration is of course possible too, and it's being worked on.

perf is mainly a kernel developer tool, and kernel developers generally dont use GUIs to do their stuff: which is the (sole) reason why its first ~850 commits of tools/perf/ were done without a GUI. We go where our developers are.

In any case it's not an excuse to have no proper command-line tooling. In fact if you cannot get simpler, more atomic command-line tooling right then you'll probably doubly suck at doing a GUI as well.

Quoted 8 lines
Quoted 6 lines

It's about who owns the user interface.

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Of course illogical modularization complicates things 'significantly'.

Ok. Then apply this to the kernel. I'm then happy to take patches.

Regards,

Anthony Liguori

commit 84b84db054e83e7686b80fad9f8d2aa87aade1a1

Author: Anthony Liguori <[email protected]>
Date:   Thu Mar 18 09:35:29 2010 -0500

Bring QEMU into the Linux kernel tree

Ingo is under the impression that this will result in a massive improvement in the usability of QEMU.

.gitmodules new file +3 -0
new file mode 100644
index 0000000..76cdb68
@@ -0,0 +1,3 @@
+[submodule "tools/qemu"]
+	path = tools/qemu
+	url = git://git.qemu.org/qemu.git
MAINTAINERS +6 -0
index 03f38c1..6275796 100644
@@ -4427,6 +4427,12 @@ M:	Robert Jarzmik <[email protected]>
 L:	[email protected]
 S:	Maintained
 
+QEMU
+M:      Anthony Liguori <[email protected]>
+L:      [email protected]
+S:      Maintained
+F:      tools/qemu
+
 QLOGIC QLA2XXX FC-SCSI DRIVER
 M:	Andrew Vasquez <[email protected]>
 M:	[email protected]
tools/qemu new file +1 -0
new file mode 160000
index 0000000..e5322f7
@@ -0,0 +1 @@
+Subproject commit e5322f76a72352eea8eb511390c27726b64e5a87
#49 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar

Hi -

Quoted 10 lines · Ingo Molnar

[...]

Quoted 1 line

Us guys reading and participating on the list. ;)

I'd like to second that - i'm actually quite happy to update the distro kernel. Also, i have rarely any problems even with bleeding edge kernels in rawhide - they are working pretty smoothly.

A large xorg update showing up in yum update gives me the cringe though ;-)

From a parochial point of view, that makes perfect sense: someone

else's large software changes are a source of concern. The same thing applies to non-LKML people -- ordinary users -- when *your* large software changes are proposed.

Perhaps this change in perspective would help you see the absurdity of proposing kernel-2.6.git as a hosting repository for all kinds of stuff, on the theory that kernel updates get pushed to "eager" users more frequently than other kinds of updates. (Never mind that data shows otherwise.)

- FChE

#330 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 3 lines · Ingo Molnar

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

QEMU is about 600k LOC. We have a mechanism to compile out portions of the code but a lot things are tied together in an intimate way. In the long run, we're working on adding stronger interfaces such that we can split components out into libraries that are consumable by other applications.

Simplying forking the device model won't work. Well more than half of our contributors are not coming from KVM developers/users. If you just fork the device models, you start to lose a ton of fixes (look at Xen and VirtualBox).

So feel free to either 1) apply my previous patch and then start working on a "clean (and minimal)" QEMU or 2) wait to commit my previous patch and start sending patches to clean up QEMU.

Absolute none of this is going to give you a VirtualBox like GUI for QEMU.

Regards,

Anthony Liguori

#325 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar
Quoted 2 lines · Jes Sorensen

Both perf and oprofile are still relatively small projects in comparison to QEMU.

So is your argument that the unification does not make sense due to size? Would a smaller Qemu be more appropriate for this purpose?

As I have stated repeatedly in this discussion, a unification would hurt the QEMU development process because it would alienate a large number of QEMU developers who are *not* Linux kernel users.

QEMU is a lot more complex than you let on.

Quoted 8 lines
Quoted 3 lines

Well I think we are just going to agree to disagree on this one. I am not against merging projects where it makes sense, but in this particular case I am strongly convinced the loss would be much greater than the gain.

I wish you said that based on first hand negative experience with unifications, not based on just pure speculation.

(and yes, i speculate too, but at least with some basis)

You still haven't given us a *single* example of unification of something that wasn't purely linked to the Linux kernel. perf/ oprofile is 100% linked to the Linux kernel, QEMU is not. I wish you would actually look at what users use QEMU for. As long as you continue to purely speculate on this, to use your own words, your arguments are not holding up.

And you are not being consistent either. You have conveniently continue to ignore my questions about why the file system tools are not to be merged into the Linux kernel source tree?

Jes

#61 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar
Quoted 4 lines · Avi Kivity
Quoted 4 lines

Happy choice or not, this is what i said is the distro practice these days. (i dont know all the distros that well so i'm sure there's differences)

Quoted 7 lines
Quoted 3 lines

So in addition to all the normal kernel regressions, you want to force tools/kvm/ regressions on users.

So instead you force a NxN compatibility matrix [all versions of qemu combined with all versions of the kernel] instead of a linear N versions matrix with a clear focus on the last version. Brilliant engineering i have to say ;-)

Thanks. In fact with have an QxKxGxT compatibility matrix since we need to keep compatibility with guests and with tools. Since the easiest interface to keep compatible is the qemu/kernel interface, allowing the kernel and qemu to change independently allows reducing the compatibility matrix while still providing some improvements.

Regardless of that I'd keep binary compatibility anyway. Not everyone is on the update treadmill with everything updating every three months and those people appreciate stability. I intend to keep providing it.

Quoted 3 lines

Also, by your argument the kernel should be split up into a micro-kernel, with different packages for KVM, scheduler, drivers, upgradeable separately.

Some kernels do provide some of that facility (without being microkernels), for example the Windows and RHEL kernels. So it seems people want it.

Quoted 4 lines

That would be a nightmare. (i can detail many facets of that nightmare if you insist but i'll spare the electrons for now) Fortunately few kernel developers share your views about this.

I'm not sure you know my views about this.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

I don't mind at all if rawhide users run on the latest and greatest, but release users deserve a little more stability.

What are you suggesting, that released versions of KVM are not reliable? Of course any tools/ bits are release engineered just as much as the rest of KVM ...

Quoted 7 lines
Quoted 4 lines

No, I am suggesting qemu-kvm.git is not as stable as released versions (and won't get fixed backported). Keep in mind that unlike many userspace applications, qemu exposes an ABI to guests which we must keep compatible.

I think you still dont understand it: if a tool moves to the kernel repo, then it is _released stable_ together with the next stable kernel.

I was confused by the talk about 2.6.34-rc1, which isn't stable.

Signature · 1 line
error compiling committee.c: too many arguments to function
#291 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 15 lines · Ingo Molnar
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 5 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

It's not inevitable, if the projects are badly run, you'll have high latencies, but projects don't have to be badly run.

So the 64K dollar question is, why does Qemu still suck?

Why does Linux AIO still suck? Why do we not have a proper interface in userspace for doing asynchronous file system operations?

Why don't we have an interface in userspace to do zero-copy transmit and receive of raw network packets?

The lack of a decent userspace API for asynchronous file system operations is a huge usability problem for us. Take a look at the complexity of our -drive option. It's all because the kernel gives us sucky interfaces.

Regards,

Anthony Liguori

#75 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar
Quoted 3 lines

[...] kvm in fact knows nothing about vga, to take your last example. [...]

Look at the VGA dirty bitmap optimization a'ka the KVM_GET_DIRTY_LOG ioctl.

See qemu/kvm-all.c's kvm_physical_sync_dirty_bitmap().

Quoted 8 lines

It started out as a VGA optimization (also used by live migration) and even today it's mostly used by the VGA drivers - albeit a weak one.

I wish there were stronger VGA optimizations implemented, copying the dirty bitmap is not a particularly performant solution. (although it's certainly better than full emulation) Graphics performance is one of the more painful aspects of KVM usability today.

We have to maintain a dirty bitmap because we don't have a paravirtual graphics driver. IOW, someone needs to write an Xorg driver.

Ideally, we could just implement a Linux framebuffer device, right? Well, we took that approach in Xen and that sucks even worse because the Xorg framebuffer driver doesn't implement any of the optimizations that the Linux framebuffer supports and the Xorg driver does not provide use the kernel's interfaces for providing update regions.

Of course, we need to pull in X into the kernel to fix this, right?

Any sufficiently complicated piece of software is going to interact with a lot of other projects. The solution is not to pull it all into one massive repository. It's to build relationships and to find ways to efficiently work with the various communities.

And we're working on this with X. We'll have a paravirtual graphics driver very soon. There are no magic solutions. We need more developers working on the hard problems.

Regards,

Anthony Liguori

#76 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 18 lines · Anthony Liguori
Quoted 9 lines · Ingo Molnar
Quoted 3 lines

[...] kvm in fact knows nothing about vga, to take your last example. [...]

Look at the VGA dirty bitmap optimization a'ka the KVM_GET_DIRTY_LOG ioctl.

See qemu/kvm-all.c's kvm_physical_sync_dirty_bitmap().

Quoted 7 lines

It started out as a VGA optimization (also used by live migration) and even today it's mostly used by the VGA drivers - albeit a weak one.

I wish there were stronger VGA optimizations implemented, copying the dirty bitmap is not a particularly performant solution. (although it's certainly better than full emulation) Graphics performance is one of the more painful aspects of KVM usability today.

Quoted 4 lines

We have to maintain a dirty bitmap because we don't have a paravirtual graphics driver. IOW, someone needs to write an Xorg driver.

Ideally, we could just implement a Linux framebuffer device, right?

No, you'd want to interact with DRM.

( Especially as you want to write guest accelerators passing guest-space
OpenGL requests straight to the kernel DRM level. )

Especially if you want to do things like graphics card virtualization, with aspects of the graphics driver passed through to the guest OS.

There are all kernel space projects, going through Xorg would be a horrible waste of performance for full-screen virtualization. It's fine for the windowed or networked case (and good as a compatibility fallback), but very much not fine for local desktop use.

Quoted 6 lines

Well, we took that approach in Xen and that sucks even worse because the Xorg framebuffer driver doesn't implement any of the optimizations that the Linux framebuffer supports and the Xorg driver does not provide use the kernel's interfaces for providing update regions.

Of course, we need to pull in X into the kernel to fix this, right?

FYI, this part of X has already been pulled into the kernel, it's called DRM. If then it's being expanded.

Quoted 4 lines

Any sufficiently complicated piece of software is going to interact with a lot of other projects. The solution is not to pull it all into one massive repository. It's to build relationships and to find ways to efficiently work with the various communities.

That's my whole point with this thread: the kernel side of KVM and qemu, but all practical purposes should not be two 'separate communities'. They should be one and the same thing.

Separation makes sense where the relationship is light or strictly hierarchical - here it's neither. KVM and Qemu is interconnected, quite fundamentally so.

Quoted 3 lines

And we're working on this with X. We'll have a paravirtual graphics driver very soon. There are no magic solutions. We need more developers working on the hard problems.

The thing is, writing up a DRM connector to a guest Linux OS could be done in no time. It could be deployed to users in no time as well, with the proper development model.

That after years and years of waiting proper GX support is _still_ not implemented in KVM is really telling of the efficiency of development based on such disjoint 'communities'. Maybe put up a committee as well to increase efficiency? ;-)

Ingo

#77 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Anthony Liguori
Quoted 16 lines · Ingo Molnar
Quoted 3 lines

[...] kvm in fact knows nothing about vga, to take your last example. [...]

Look at the VGA dirty bitmap optimization a'ka the KVM_GET_DIRTY_LOG ioctl.

See qemu/kvm-all.c's kvm_physical_sync_dirty_bitmap().

It started out as a VGA optimization (also used by live migration) and even today it's mostly used by the VGA drivers - albeit a weak one.

I wish there were stronger VGA optimizations implemented, copying the dirty bitmap is not a particularly performant solution. (although it's certainly better than full emulation) Graphics performance is one of the more painful aspects of KVM usability today.

Quoted 7 lines
Quoted 5 lines

We have to maintain a dirty bitmap because we don't have a paravirtual graphics driver. IOW, someone needs to write an Xorg driver.

Ideally, we could just implement a Linux framebuffer device, right?

No, you'd want to interact with DRM.

Using DRM doesn't help very much. You still need an X driver and most of the operations you care about (video rendering, window movement, etc) are not operations that need to go through DRM.

3D graphics virtualization is extremely difficult in the non-passthrough case. It really requires hardware support that isn't widely available today (outside a few NVIDIA chipsets).

Quoted 9 lines
Quoted 6 lines

Xorg framebuffer driver doesn't implement any of the optimizations that the Linux framebuffer supports and the Xorg driver does not provide use the kernel's interfaces for providing update regions.

Of course, we need to pull in X into the kernel to fix this, right?

FYI, this part of X has already been pulled into the kernel, it's called DRM. If then it's being expanded.

It doesn't provide the things we need to a good user experience. You need things like an absolute input device, host driven display resize, RGBA hardware cursors. None of these go through DRI and it's those things that really provide the graphics user experience.

Quoted 9 lines
Quoted 5 lines

Any sufficiently complicated piece of software is going to interact with a lot of other projects. The solution is not to pull it all into one massive repository. It's to build relationships and to find ways to efficiently work with the various communities.

That's my whole point with this thread: the kernel side of KVM and qemu, but all practical purposes should not be two 'separate communities'. They should be one and the same thing.

I don't know why you keep saying this. The people who are in these "separate communities" keep claiming that they don't feel this way.

I'm not just saying this to be argumentative. Many of the people in the community have thought this same thing, and tried it themselves, and we've all come to the same conclusion.

It's certainly possible that we just missed the obvious thing to do but we'll never know that unless someone shows us.

Quoted 4 lines

The thing is, writing up a DRM connector to a guest Linux OS could be done in no time. It could be deployed to users in no time as well, with the proper development model.

If this is true, please demonstrate it. Prove your point with patches and I'll happily turn around and do whatever I can to help out.

Quoted 5 lines

That after years and years of waiting proper GX support is _still_ not implemented in KVM is really telling of the efficiency of development based on such disjoint 'communities'. Maybe put up a committee as well to increase efficiency? ;-)

Nah, instead we can just have a few hundred mail thread on the list. Otherwise we'd have to write patches and do other kinds of productive work.

Regards,

Anthony Liguori

Quoted 2 lines

Ingo

#292 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Anthony Liguori
Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Ingo Molnar
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 4 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

It's not inevitable, if the projects are badly run, you'll have high latencies, but projects don't have to be badly run.

So the 64K dollar question is, why does Qemu still suck?

Why does Linux AIO still suck? Why do we not have a proper interface in userspace for doing asynchronous file system operations?

Good that you mention it, i think it's an excellent example.

The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc - and between the apps that would make use of it.

( With the separated libaio it was made worse: there were 3 libraries to
work with, and even less applications that could make use of it ... )

So IMO klibc is an arguably good idea - eventually hpa will get around posting it for upstream merging again. Then we could offer both new libraries much faster, and could offer things like comprehensive AIO used pervasively within existing APIs.

Quoted 6 lines

Why don't we have an interface in userspace to do zero-copy transmit and receive of raw network packets?

The lack of a decent userspace API for asynchronous file system operations is a huge usability problem for us. Take a look at the complexity of our -drive option. It's all because the kernel gives us sucky interfaces.

If you had your bits in tools/kvm/ you could make a strong case for a good kaio implementation - coupled with an actual, working use-case. ( You could use the raw syscall even without klibc. )

We could see the arguments on lkml turn from:

'do we want this and it will take years to propagate this into apps'

into something like:

' Exactly how much faster does kvm go? and I'd get is straight away with my
next kernel update tomorrow? Wow! '

Ok, i exaggerated a bit - but you get the idea. It's a much different picture when kernel developers and maintainers see an actual use-case, _right in the kernel repo they work with every day_.

Currently there's a wall between kernel developers and user-space developers, and there's somewhat of an element of fear and arrogance on both sides. For efficient technology such walls needs torn down and people need a bit more experience with each other's areas.

Ingo

#78 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Anthony Liguori
Quoted 21 lines · Anthony Liguori
Quoted 20 lines · Ingo Molnar
Quoted 18 lines · Anthony Liguori
Quoted 7 lines · Ingo Molnar
Quoted 2 lines

[...] kvm in fact knows nothing about vga, to take your last example. [...]

Look at the VGA dirty bitmap optimization a'ka the KVM_GET_DIRTY_LOG ioctl.

See qemu/kvm-all.c's kvm_physical_sync_dirty_bitmap().

Quoted 7 lines

It started out as a VGA optimization (also used by live migration) and even today it's mostly used by the VGA drivers - albeit a weak one.

I wish there were stronger VGA optimizations implemented, copying the dirty bitmap is not a particularly performant solution. (although it's certainly better than full emulation) Graphics performance is one of the more painful aspects of KVM usability today.

We have to maintain a dirty bitmap because we don't have a paravirtual graphics driver. IOW, someone needs to write an Xorg driver.

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Ideally, we could just implement a Linux framebuffer device, right?

No, you'd want to interact with DRM.

Using DRM doesn't help very much. You still need an X driver and most of the operations you care about (video rendering, window movement, etc) are not operations that need to go through DRM.

You stripped out this bit from my reply:

Quoted 4 lines
Quoted 4 lines

There are all kernel space projects, going through Xorg would be a horrible waste of performance for full-screen virtualization. It's fine for the windowed or networked case (and good as a compatibility fallback), but very much not fine for local desktop use.

For the full-screen case (which is a very common mode of using a guest OS on the desktop) there's not much of window management needed. You need to save/restore as you switch in/out.

Quoted 3 lines

3D graphics virtualization is extremely difficult in the non-passthrough case. It really requires hardware support that isn't widely available today (outside a few NVIDIA chipsets).

Granted it's difficult in the general case.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Xorg framebuffer driver doesn't implement any of the optimizations that the Linux framebuffer supports and the Xorg driver does not provide use the kernel's interfaces for providing update regions.

Of course, we need to pull in X into the kernel to fix this, right?

Quoted 7 lines
Quoted 2 lines

FYI, this part of X has already been pulled into the kernel, it's called DRM. If then it's being expanded.

It doesn't provide the things we need to a good user experience. You need things like an absolute input device, host driven display resize, RGBA hardware cursors. None of these go through DRI and it's those things that really provide the graphics user experience.

With KSM the display resize is in the kernel. Cursor management is not. Yet: i think it would be a nice feature as the cursor could move even if Xorg is blocked or busy with other things.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

Any sufficiently complicated piece of software is going to interact with a lot of other projects. The solution is not to pull it all into one massive repository. It's to build relationships and to find ways to efficiently work with the various communities.

That's my whole point with this thread: the kernel side of KVM and qemu, but all practical purposes should not be two 'separate communities'. They should be one and the same thing.

I don't know why you keep saying this. The people who are in these "separate communities" keep claiming that they don't feel this way.

If you are not two separate communities but one community, then why do you go through the (somewhat masochistic) self-punishing excercise of keeping the project in two different pieces?

In a distant past Qemu was a separate project and KVM was just a newcomer who used it for fancy stuff. Today as you say(?) the two communities are one and the same. Why not bring it to its logical conclusion?

Quoted 6 lines

I'm not just saying this to be argumentative. Many of the people in the community have thought this same thing, and tried it themselves, and we've all come to the same conclusion.

It's certainly possible that we just missed the obvious thing to do but we'll never know that unless someone shows us.

I'm not aware of anyone in the past having attempted to move qemu to tools/kvm/ in the uptream kernel repo, and having reported on the experiences with such a contribution setup. (obviously it's not possible at all without heavy cooperation and acceptance from you and Avi, so this will probably remain a thought experiment forever)

If then you must refer to previous attempts to 'strip down' Qemu, right? Those attempts didnt really solve the fundamental problem of project code base separation.

Ingo

#79 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Ingo Molnar
Quoted 5 lines
Quoted 5 lines

There are all kernel space projects, going through Xorg would be a horrible waste of performance for full-screen virtualization. It's fine for the windowed or networked case (and good as a compatibility fallback), but very much not fine for local desktop use.

For the full-screen case (which is a very common mode of using a guest OS on the desktop) there's not much of window management needed. You need to save/restore as you switch in/out.

I don't think I've ever used full-screen mode with my VMs and I use virtualization on a daily basis.

We hear very infrequently from users using full screen mode.

Quoted 16 lines
Quoted 4 lines

3D graphics virtualization is extremely difficult in the non-passthrough case. It really requires hardware support that isn't widely available today (outside a few NVIDIA chipsets).

Granted it's difficult in the general case.

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

Xorg framebuffer driver doesn't implement any of the optimizations that the Linux framebuffer supports and the Xorg driver does not provide use the kernel's interfaces for providing update regions.

Of course, we need to pull in X into the kernel to fix this, right?

FYI, this part of X has already been pulled into the kernel, it's called DRM. If then it's being expanded.

Quoted 6 lines
Quoted 5 lines

It doesn't provide the things we need to a good user experience. You need things like an absolute input device, host driven display resize, RGBA hardware cursors. None of these go through DRI and it's those things that really provide the graphics user experience.

With KSM the display resize is in the kernel.

KMS

Quoted 4 lines

Cursor management is not. Yet: i
think it would be a nice feature as the cursor could move even if Xorg is blocked or busy with other things.

If it was all in the kernel, we'd try to support it.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

Any sufficiently complicated piece of software is going to interact with a lot of other projects. The solution is not to pull it all into one massive repository. It's to build relationships and to find ways to efficiently work with the various communities.

That's my whole point with this thread: the kernel side of KVM and qemu, but all practical purposes should not be two 'separate communities'. They should be one and the same thing.

Quoted 7 lines
Quoted 3 lines

I don't know why you keep saying this. The people who are in these "separate communities" keep claiming that they don't feel this way.

If you are not two separate communities but one community, then why do you go through the (somewhat masochistic) self-punishing excercise of keeping the project in two different pieces?

I don't see any actual KVM developer complaining about this so I'm not sure why you're describing it like this.

Quoted 4 lines

In a distant past Qemu was a separate project and KVM was just a newcomer who used it for fancy stuff. Today as you say(?) the two communities are one and the same. Why not bring it to its logical conclusion?

We lose a huge amount of users and contributors if we put QEMU in the Linux kernel. As I said earlier, a huge number of our contributions come from people not using KVM.

Quoted 4 lines
Quoted 4 lines

I'm not just saying this to be argumentative. Many of the people in the community have thought this same thing, and tried it themselves, and we've all come to the same conclusion.

Quoted 9 lines
Quoted 3 lines

It's certainly possible that we just missed the obvious thing to do but we'll never know that unless someone shows us.

I'm not aware of anyone in the past having attempted to move qemu to tools/kvm/ in the uptream kernel repo, and having reported on the experiences with such a contribution setup. (obviously it's not possible at all without heavy cooperation and acceptance from you and Avi, so this will probably remain a thought experiment forever)

We've tried to create a "clean" version of QEMU specifically for KVM. Moving it into tools/kvm would be the second step. We've all failed on the firs step.

Quoted 4 lines

If then you must refer to previous attempts to 'strip down' Qemu, right? Those attempts didnt really solve the fundamental problem of project code base separation.

If the problem is combining the two, I've sent you a patch that you can put into tip.git if you're so inclined.

Regards,

Anthony Liguori

Quoted 2 lines

Ingo

#80 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 5 lines · Anthony Liguori
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

There are all kernel space projects, going through Xorg would be a horrible waste of performance for full-screen virtualization. It's fine for the windowed or networked case (and good as a compatibility fallback), but very much not fine for local desktop use.

Quoted 8 lines
Quoted 3 lines

For the full-screen case (which is a very common mode of using a guest OS on the desktop) there's not much of window management needed. You need to save/restore as you switch in/out.

I don't think I've ever used full-screen mode with my VMs and I use virtualization on a daily basis.

We hear very infrequently from users using full screen mode.

Sorry for getting slightly off-topic but I find the above statement interesting.

I don't use virtualization on daily basis but a working, fully integrated full-screen model with VirtualBox was the only reason I bothered to give VMs a second chance. From my point of view, the user experience of earlier versions (e.g. Parallels) was just too painful to live with.

/me crawls back to his hole now...

Pekka

#326 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Jes Sorensen
Quoted 6 lines · Jes Sorensen
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Jes Sorensen

Both perf and oprofile are still relatively small projects in comparison to QEMU.

Quoted 6 lines
Quoted 2 lines

So is your argument that the unification does not make sense due to size? Would a smaller Qemu be more appropriate for this purpose?

As I have stated repeatedly in this discussion, a unification would hurt the QEMU development process because it would alienate a large number of QEMU developers who are *not* Linux kernel users.

I took a quick look at the qemu.git log and more than half of all recent contributions came from Linux distributors.

So without KVM Qemu would be a much, much smaller project. It would be similar to how it was 5 years ago.

Quoted 1 line

QEMU is a lot more complex than you let on.

Please educate me then about the specifics.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Well I think we are just going to agree to disagree on this one. I am not against merging projects where it makes sense, but in this particular case I am strongly convinced the loss would be much greater than the gain.

I wish you said that based on first hand negative experience with unifications, not based on just pure speculation.

Quoted 7 lines
Quoted 1 line

(and yes, i speculate too, but at least with some basis)

You still haven't given us a *single* example of unification of something that wasn't purely linked to the Linux kernel. perf/ oprofile is 100% linked to the Linux kernel, QEMU is not. I wish you would actually look at what users use QEMU for. As long as you continue to purely speculate on this, to use your own words, your arguments are not holding up.

The stats show that the huge increase in Qemu contributions over the past few years was mainly due to KVM. Do you claim it wasnt? What other projects make use of it and pay developers to work on it?

Quoted 3 lines

And you are not being consistent either. You have conveniently continue to ignore my questions about why the file system tools are not to be merged into the Linux kernel source tree?

Sorry, i didnt comment on it because the answer is obvious: the file system tools and pretty much any Linux-exclusive tool (such as udev) should be moved there. The difference is that there's not much active development done in most of those tools so the benefits are probably marginal. Both Qemu and KVM is being developed very actively though, so development model inefficiencies show up.

Anyway, i didnt think i'd step into such a hornet's nest by explaining what i see as KVM's biggest weakness today and how i suggest it to be fixed :-)

If you dont agree with me, then dont do it - no need to get emotional about it.

Thanks,

Ingo

#293 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

Currently there's a wall between kernel developers and user-space developers, and there's somewhat of an element of fear and arrogance on both sides. For efficient technology such walls needs torn down and people need a bit more experience with each other's areas.

I think you're increasing the height of that wall by arguing that a userspace project cannot be successful because it's development process sucks and the only way to fix it is to put it into the kernel where people know so much better. Instead we kernel developers should listen to requirements from users, even if their code isn't in tools/.

Signature · 1 line
error compiling committee.c: too many arguments to function
#81 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Pekka Enberg
Quoted 15 lines · Pekka Enberg
Quoted 5 lines · Anthony Liguori
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

There are all kernel space projects, going through Xorg would be a horrible waste of performance for full-screen virtualization. It's fine for the windowed or networked case (and good as a compatibility fallback), but very much not fine for local desktop use.

Quoted 8 lines
Quoted 3 lines

For the full-screen case (which is a very common mode of using a guest OS on the desktop) there's not much of window management needed. You need to save/restore as you switch in/out.

I don't think I've ever used full-screen mode with my VMs and I use virtualization on a daily basis.

We hear very infrequently from users using full screen mode.

Quoted 7 lines

Sorry for getting slightly off-topic but I find the above statement interesting.

I don't use virtualization on daily basis but a working, fully integrated full-screen model with VirtualBox was the only reason I bothered to give VMs a second chance. From my point of view, the user experience of earlier versions (e.g. Parallels) was just too painful to live with.

That's the same i do, and that's what i'm hearing from other desktop users as well.

The moment you work seriously in a guest OS you often want to switch to it full-screen, to maximize screen real-estate and to reduce host GUI element distractions. If it's just casual use of a single app then windowed mode suffices (but in that case performance doesnt matter much to begin with).

I find the 'KVM mostly cares about the server, not about the desktop' attitude expressed in this thread troubling.

Quoted 1 line

/me crawls back to his hole now...

/me should do that too - this discussion is not resulting in any positive result so it has become rather pointless.

Ingo

#82 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 4 lines · Ingo Molnar

I find the 'KVM mostly cares about the server, not about the desktop' attitude expressed in this thread troubling.

It's not kvm, just it's developers (and their employers, where applicable). If you post desktop oriented patches I'm sure they'll be welcome.

Signature · 1 line
error compiling committee.c: too many arguments to function
#294 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Ingo Molnar

Currently there's a wall between kernel developers and user-space developers, and there's somewhat of an element of fear and arrogance on both sides. For efficient technology such walls needs torn down and people need a bit more experience with each other's areas.

Quoted 5 lines

I think you're increasing the height of that wall by arguing that a userspace project cannot be successful because it's development process sucks and the only way to fix it is to put it into the kernel where people know so much better. Instead we kernel developers should listen to requirements from users, even if their code isn't in tools/.

No, it's tearing down that wall because finally, instead of providing rather abstract system calls that are designed perfectly, the kernel can operate by providing useful libraries and apps.

At least on the context i've worked on it has torn down walls and has improved the efficiency of working on ABIs towards user-space. (sysprof is an example of that)

Kernel developers are finally faced with user-space development directly, in the same repository, using the same rules of contribution.

Non-kernel-hosted apps win from that process too, as even if they dont integrate (because they dont want to or cannot for license reasons) they can participate in a more direct (and more practical) exchange with kernel developers. They can contribute a new system call and create a library function for it straight away.

Ingo

#74 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Ingo Molnar
Quoted 6 lines · Avi Kivity
Quoted 3 lines

That is not what i said. I said they are closely related, and where technologies are closely related, project proximity turns into project unification at a certain stage.

I really don't see how. So what if both qemu and kvm implement an i8254? They can't share any code since the internal APIs are so different. [...]

I wouldnt jump to assumptions there. perf shares some facilities with the kernel on the source code level - they can be built both in the kernel and in user-space.

But my main thought wasnt even to actually share the implementation - but to actually synchronize when a piece of device emulation moves into the kernel. It is arguably bad for performance in most cases when Qemu handles a given device - so all the common devices should be kernel accelerated.

Quoted 5 lines
Quoted 2 lines

The version and testing matrix would be simplified significantly as well:
as kernel and qemu goes hand in hand, they are always on the same version.

So, you propose to allow running tools/kvm/ only on the kernel it was shipped with?

No, but i propose concentrating on that natural combination.

Quoted 1 line

Otherwise the testing matrix isn't simplified.

It is, because testing is more focused and more people are testing the combination that developers tested as well. (and not some random version combination picked by the distributor or the user)

Ingo

#83 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 3 lines · Ingo Molnar

I find the 'KVM mostly cares about the server, not about the desktop' attitude expressed in this thread troubling.

It's not kvm, just it's developers (and their employers, where applicable). If you post desktop oriented patches I'm sure they'll be welcome.

Just such a patch-set was posted in this very thread: 'perf kvm'.

There were two negative reactions immediately, both showed a fundamental server versus desktop bias:

- you did not accept that the most important usecase is when there is a single guest running.

- the reaction to the 'how do we get symbols out of the guest' sub-question was, paraphrased: 'we dont want that due to <unspecified> security threat to XYZ selinux usecase with lots of guests'.

Anyone being aware of how Linux and KVM is being used on the desktop will know how detached that attitude is from the typical desktop usecase ...

Usability _never_ sucks because of lack of patches or lack of suggestions. I bet if you made the next server feature contingent on essential usability fixes they'd happen overnight - for God's sake there's been 1000 commits in the last 3 months in the Qemu repository so there's plenty of manpower...

Usability suckage - and i'm not going to be popular for saying this out loud - almost always shows a basic maintainer disconnect with the real world. See your very first reactions to my 'KVM usability' observations. Read back your and Anthony's replies: total 'sure, patches welcome' kind of indifference. It is _your project_, not some other project down the road ...

So that is my first-hand experience about how you are welcoming these desktop issues, in this very thread. I suspect people try a few times with suggestions, then get shot down like our suggestions were shot down and then give up.

Ingo

#327 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 3 lines · Ingo Molnar

I took a quick look at the qemu.git log and more than half of all recent contributions came from Linux distributors.

I don't know what you're looking at, but in the past month, there's been 56 unique contributors, with 411 changesets. I count 16 people employed by distributions with 188 changesets.

Quoted 3 lines

So without KVM Qemu would be a much, much smaller project. It would be similar to how it was 5 years ago.

I'm not saying that KVM isn't significant. I'm employed to work on QEMU because of KVM.

I'm just saying that KVM users aren't 99% of the community and that we can't neglect the rest of the community.

Regards,

Anthony Liguori

#295 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

Good that you mention it, i think it's an excellent example.
The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc - and between the apps that would make use of it.

Quoted 8 lines

( With the separated libaio it was made worse: there were 3 libraries to
work with, and even less applications that could make use of it ... )

So IMO klibc is an arguably good idea - eventually hpa will get around posting it for upstream merging again. Then we could offer both new libraries much faster, and could offer things like comprehensive AIO used pervasively within existing APIs.

And why wouldn't the kernel developers produce posix-aio within klibc.

posix-aio is also a really terrible interface (although not as bad as linux-aio).

The reason boils down to the fact that these interfaces are designed without interacting with the consumers. Part of the reason for that is the attitude of the community.

You approached this discussion with, "QEMU/KVM sucks, you should move into the kernel because we're awesome and we'd fix everything in a heart beat". That attitude does not result in any useful collaboration.

Had you started trying to understand what the problems that we face are and whether there's anything that can be done in the kernel to improve it, it would have been an entirely different discussion.

The sad thing is, QEMU is probably one of the most demanding free software applications out there today with respect to performance. We consume interfaces IO interfaces and things like large pages in a deeper way than just about any application out there.

We've been trying for a long time to improve Linux interfaces for years but we've not had many people in the kernel community be receptive.

We've failed to improve the userspace networking interfaces. Compare Rusty's posting of vringfd to vhost-net. They are the same interface except we tried to do something more generally useful with vringfd and it was shot down because it was "yet another kernel/userspace data transfer interface". Unfortunately, we're learning that if we claim something is virtualization specific, we avoid a lot of the kernel bureaucracy. My concern is that over time, we'll have more things like vhost and that's bad for everyone.

Regards,

Anthony Liguori

#316 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity

By "serious developer" I mean

- someone who is interested in contributing, not in getting their name
into the kernel commits list
- someone who is willing to read the wiki page and find out where the
repository and mailing list for a project is
- someone who will spend enough time on the project so that the time to
clone two repositories will not be a factor in their contributions

I'm not going to argue about the Qemu merging here. But your above assessment is incomplete.

It is not because developers don't want to clone two different trees that tools/perf is a success. Or may be it's a factor but I suspect it to be very minimal. I can script git commands if needed. It is actually because both kernel and user side are sync in this scheme.

Quoted 2 lines

Let's wait and see then. If the tools/perf/ experience has really good results, we can reconsider this at a later date.

I think it has already really good results.

#296 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 2 lines · Ingo Molnar

The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc

Bollocks. glibc would use (and is using) everything the kernel provides. We even have an implementation using the current AIO code. It only works in some situations but that's what the few users are OK with.

Don't try to blame anyone but kernel people for the complete and utter failure of AIO in Linux. I don't know how often I've discussed design of a kernel interface with various kernel developers. Heck, whenever Zach Brown and I meet there never is a different topic. And following these meetings the ball is not and cannot be in my court. How could it?

#297 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 6 lines · * [email protected] <[email protected]> wrote:
Quoted 2 lines · Ingo Molnar

The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc

Bollocks. glibc would use (and is using) everything the kernel provides.

I didnt say it's glibc's fault - if then it's more of the kernel's fault as most of the complexity is on that side. I said it's due to the fundamental distance between the app that makes use of it, the library and the kernel, and the resulting difficulties in getting a combined solution out.

None of the parties really feels it to be their own thing.

Ingo

#298 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 4 lines · Ingo Molnar

I didnt say it's glibc's fault - if then it's more of the kernel's fault as most of the complexity is on that side. I said it's due to the fundamental distance between the app that makes use of it, the library and the kernel, and the resulting difficulties in getting a combined solution out.

This is wrong, too. Once there is a kernel patch that has a reasonable syscall interface it's easy enough to hack up the glibc side. Don't try to artificially find an argument to support your thesis. If kernel developers always need an immediate itch which lives inside the kernel walls to make a change this is a failure of the kernel model and mustn't be "solved" by dragging ever more code into the kernel.

Aside, you don't need a full-fledged glibc implementation for testing. Especially for AIO it should be usable in much lighter-weight contexts than POSIX AIO. These wrappers are even more easy to hack up (and have been in the few cases where some code has been produced).

For AIO the situation isn't that the people interested in working on it don't know or care about the use. Zach (through Oracle's products) is very much interested in the code and knows how it should look like.

Face it, AIO is an example of a complete failure of the kernel developers to provide something usable. This was the argument and where you started the misdirection of including other projects in the reasoning.

#317 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Frederic Weisbecker
Quoted 2 lines · Frederic Weisbecker

[...] It is actually because both kernel and user side are sync in this scheme. [...]

This argues that co-evolution of an interface is easiest on the developers if they own both sides of that interface. No quarrel.

This does not argue that that the preservation of a stable ABI is best done this way. If anything, it makes it too easy to change both the provider and the preferred user of the interface without noticing unintentional breakage to forlorn out-of-your-tree clients.

- FChE

#299 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to [email protected]
Quoted 10 lines · * [email protected] <[email protected]> wrote:
Quoted 5 lines · Ingo Molnar

I didnt say it's glibc's fault - if then it's more of the kernel's fault as most of the complexity is on that side. I said it's due to the fundamental distance between the app that makes use of it, the library and the kernel, and the resulting difficulties in getting a combined solution out.

This is wrong, too. Once there is a kernel patch that has a reasonable syscall interface it's easy enough to hack up the glibc side. [...]

Where 'reasonable' is defined by you, right?

As i said, the KAIO situation is mostly the kernel's fault, but you are a pretty passive and unhelpful entity in this matter too, arent you?

For example, just to state the obvious: libaio has been written 8 years ago in 2002 and has been used in apps early on. Why arent those kernel APIs, while not being a full/complete solution, supported by glibc, and wrapped to pthreads based emulation on kernels that dont support it?

I'm not talking about a 100% full POSIX AIO implementation (the kernel side is not complete enough for that) - i'm just talking about the APIs that libaio and the kernel supports today.

Why isnt glibc itself making use of those AIO capabilities internally? (even if it's not possible to support full POSIX AIO)

I checked today's glibc repo, and there's no sign of any of that:

glibc> git grep io_submit
glibc> git grep aio_context_t
glibc>

Zero, nil, nada.

Getting _something_ into glibc would certainly help move the situation. Glibc itself using existing KAIO bits internally would help too and dont tell me it's 100% unusable: it's certainly capable enough to run DB servers. glibc using it would create further demand (and pressure, and incentives) for improvements.

There were even glibc patches created by Ben LaHaise for some of these bits, IIRC.

One can certainly make the argument that glibc not using _any_ of the current KAIO capabilities harms its further development.

Quoted 1 line

[...] Don't try to artificially find an argument to support your thesis.

Charming argumentation style, i really missed it.

Thanks,

Ingo

#300 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 1 line · Ingo Molnar

Where 'reasonable' is defined by you, right?

Not only by me. For some of the AIO approaches which happened there were also glibc patches other people wrote. It's pretty simple.

Quoted 2 lines

As i said, the KAIO situation is mostly the kernel's fault, but you are a pretty passive and unhelpful entity in this matter too, arent you?

How'd you guess? I've always been been willing to discuss interface requirements with whoever showed interest in implementing things. Again, ask Zach. I think Christoph Lameter also was involved as were various SGI people over the years.

Short of actually doing all the work myself I've done what can be expected.

Quoted 4 lines

For example, just to state the obvious: libaio has been written 8 years ago in 2002 and has been used in apps early on. Why arent those kernel APIs, while not being a full/complete solution, supported by glibc, and wrapped to pthreads based emulation on kernels that dont support it?

You never looked at the glibc code in use and didn't read what I wrote before. We do have an implementation of libaio using those interfaces. They exist in the Fedora/RHEL glibc and are probably copied elsewhere, too. The code is not upstream because it is not general enough. It simply doesn't work in all situations.

The problem with using it (among others) is that certain operations cannot be implemented. And that's not a kernel interface problem. I cannot just switch to using the pthread-based code when coming across something that's not implementable because then the requests have already been sent to the kernel. Only code that knows about the limitations ahead of time can use the KAIO code.

Quoted 2 lines

Why isnt glibc itself making use of those AIO capabilities internally? (even if it's not possible to support full POSIX AIO)

For what? glibc doesn't implement anything requiring AIO. The only non-trivial file handling is in nscd and nscd uses memory mapped files.

Quoted 1 line

I checked today's glibc repo, and there's no sign of any of that:

Check the Fedora/RHEL/... source files.

Quoted 1 line

Getting _something_ into glibc would certainly help move the situation.

No it won't as the 7+ since Jakub wrote the code nothing came out of it. And before you again make groundless claims, there was plenty of discussions with kernel people at the time when the code was written.

Quoted 3 lines

it's certainly capable enough to run DB servers. glibc
using it would create further demand (and pressure, and incentives) for improvements.

There simply is no need for AIO in glibc internally. Well, there might be, if it could be used on sockets. But that's not the case.

Quoted 1 line

Charming argumentation style, i really missed it.

Well, then this last mail should show you. Without knowing the subject matter, just based on flawed lookups you try to spread the blame to make sure that no mud ever sticks to development process you are so fond of. Sorry to disappoint you.

#318 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Frank Ch. Eigler
Quoted 7 lines · Frank Ch. Eigler
Quoted 2 lines · Frederic Weisbecker

[...] It is actually because both kernel and user side are sync in this scheme. [...]

This argues that co-evolution of an interface is easiest on the developers if they own both sides of that interface. No quarrel.

Correct, that's a big advantage.

Quoted 4 lines

This does not argue that that the preservation of a stable ABI is best done this way. If anything, it makes it too easy to change both the provider and the preferred user of the interface without noticing unintentional breakage to forlorn out-of-your-tree clients.

Your concern is valid, and this issue has been raised in the past as one of the main counter-arguments against tools/perf/. (there was a big flamewar about it on lkml when it was introduced)

Our roughly 1 year experience with perf is that, somewhat pradoxially, this scheme not only works as well as classic ABI schemes but actually brings a _better_ ABI than the classic "let the kernel define an ABI" single-sided solution.

I know the difference first hand, i've written various syscalls ABIs in the past 10+ years before perf and know how they interact with their user space counterparts.

Why did it work out better with tools/perf/? It turns out that there's an immediate, direct, actionable test feedback effect on the ABI, and much closer relation to the ABI. Typically the same developer implements the kernel bits and the user-space bits (because it's so easy to do co-development), so the ABI aspects are ingrained in the developer much more deeply. Once you see the kind of havoc ABI breakage can cause during development you avoid it in the future.

So developers find that a good, stable ABI helps development. It turns out that developers dont actually _want_ to break the ABI and are careful about it
- and having the app next to the kernel ABI and co-developing it makes it sure there's never any true mismatch.

Also, we can do ABI improvements at a far higher rate than any other kernel subsystem. I checked the git logs, we've done over three dozen ABI extensions since the first version, and all were forwards _and_ backwards compatible.

A higher rate of change gives developers more experience and lets them do a better ABI, and makes them more ABI-conscious. I think if all kernel ABIs had such a healthy rate of change we'd fill in all the missing kernel features very quickly.

With detached packages ABI features are often done by a kernel developer (who is familar with the kernel subsystem in question) and a separate user-space developer (who is familar with the user-space project in question), and the ABI consciousness is less strong.

So you are right that there's a danger of accidental ABI breakage, but it's not an issue in practice. There are external apps making use of the ABI as well, not just tools/perf/.

In a more abstract sense this is kind of a classic case of game theory: that a assume-trust strategy pays off in the long run.

Thanks,

Ingo

#301 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to [email protected]
Quoted 10 lines · * [email protected] <[email protected]> wrote:
Quoted 4 lines

For example, just to state the obvious: libaio has been written 8 years ago in 2002 and has been used in apps early on. Why arent those kernel APIs, while not being a full/complete solution, supported by glibc, and wrapped to pthreads based emulation on kernels that dont support it?

You never looked at the glibc code in use and didn't read what I wrote before. We do have an implementation of libaio using those interfaces. They exist in the Fedora/RHEL glibc and are probably copied elsewhere, too. The code is not upstream because it is not general enough. It simply doesn't work in all situations.

So it's good enough to be in Fedora/RHEL but not good enough to be in upstream glibc? How is that possible? Isnt that a double standard?

Upstream libc presence is really what is needed for an API to be ubiquitous to apps. That is what 'closes the loop' in the the positive feedback cycle loop and creates real back pressure and demand on the kernel to get its act together.

Again, i state it for the third time, the KAIO situation is mostly the kernel's fault. But glibc is certainly not being helpful in that situation either and your earlier claim that you are only waiting for the patches is rather dishonest.

Thanks,

Ingo

#306 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 5 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

Quoted 9 lines

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Ingo, what you miss is that this is not a bad thing. Fact of the matter is, it's not just painful, it downright sucks.

This is actually a Good Thing (tm). It means you have to get your feature and its interfaces well defined and able to version forwards and backwards independently from each other. And that introduces some complexity and time and testing, but in the end it's what you want. You don't introduce a requirement to have the feature, but take advantage of it if it is there.

It may take everyone else a couple years to upgrade the compilers, tools, libraries and kernel, and by that time any bugs introduced by interacting with this feature will have been ironed out and their patterns well known.

If you haven't well defined and carefully thought out the feature ahead of time, you end up creating a giant mess, possibly the need for nasty backwards compatibility (case in point: COMPAT_VDSO). But in the end, you would have made those same mistakes on your internal tree anyway, and then you (or likely, some other hapless project maintainer for the project you forked) would have to go add the features, fixes and workarounds back to the original project(s). However, since you developed in an insulated sheltered environment, those fixes and workarounds would not be robust and independently versionable from each other.

The result is you've kept your codebase version-neutral, forked in outside code, enhanced it, and left the hard work of backporting those changes and keeping them version-safe to the original package maintainers you forked from. What you've created is no longer a single project, it is called a distro, and you're being short-sighted and anti-social to think you can garner more support than all of those individual packages you forked. This is why most developers work upstream and let the goodness propagate down from the top like molten sugar of each granular package on a flan where it is collected from the rich custard channel sitting on a distribution plate below before the big hungry mouth of the consumer devours it and incorporates it into their infrastructure.

Or at least, something like that, until the last sentence. In short, if project A has Y active developers, you better have Z >> Y active developers to throw at project A when you fork it into project B.

Zach

#307 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Zachary Amsden
Quoted 10 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 4 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

Quoted 8 lines
Quoted 5 lines

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Ingo, what you miss is that this is not a bad thing. Fact of the matter is, it's not just painful, it downright sucks.

Our experience is the opposite, and we tried both variants and report about our experience with both models honestly.

You only have experience about one variant - the one you advocate.

See the assymetry?

Quoted 11 lines

This is actually a Good Thing (tm). It means you have to get your feature and its interfaces well defined and able to version forwards and backwards independently from each other. And that introduces some complexity and time and testing, but in the end it's what you want. You don't introduce a requirement to have the feature, but take advantage of it if it is there.

It may take everyone else a couple years to upgrade the compilers, tools, libraries and kernel, and by that time any bugs introduced by interacting with this feature will have been ironed out and their patterns well known.

Sorry, but this is pain not true. The 2.4->2.6 kernel cycle debacle has taught us that waiting long to 'iron out' the details has the following effects:

- developer pain
- user pain
- distro pain
- disconnect
- loss of developers, testers and users
- grave bugs discovered months (years ...) down the line
- untested features
- developer exhaustion

It didnt work, trust me - and i've been around long enough to have suffered through the whole 2.5.x misery. Some of our worst ABIs come from that cycle as well.

So we first created the 2.6.x process, then as we saw that it worked much better we _sped up_ the kernel development process some more, to what many claimed was an impossible, crazy pace: two weeks merge window, 2.5 months stabilization and a stable release every 3 months.

And you can also see the countless examples of carefully drafted, well thought out, committee written computer standards that were honed for years, which are not worth the paper they are written on.

'extra time' and 'extra buerocratic overhead to think things through' is about the worst thing you can inject into a development process.

You should think about the human brain as a cache - the 'closer' things are both in time and pyshically, the better they end up being. Also, the more gradual, the more concentrated a thing is, the better it works out in general. This is part of the basic human nature.

Sorry, but i really think you are really trying to rationalize a disadvantage here ...

Ingo

#302 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 2 lines

So it's good enough to be in Fedora/RHEL but not good enough to be in upstream glibc? How is that possible? Isnt that a double standard?

Yes its a double standard

Glibc has a higher standard than Fedora/RHEL.

Just like the Ubuntu kernel ships various ugly unfit for upstream kernel drivers.

Quoted 3 lines

kernel's fault. But glibc is certainly not being helpful in that situation either and your earlier claim that you are only waiting for the patches is rather dishonest.

I am sure Ulrich is being totally honest, but send him the patches and you'll find out. Plus you will learn what the API should look like when you try and create them ...

Alan

#303 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Alan Cox
Quoted 2 lines

So it's good enough to be in Fedora/RHEL but not good enough to be in upstream glibc? How is that possible? Isnt that a double standard?

Yes its a double standard

Glibc has a higher standard than Fedora/RHEL.

Just like the Ubuntu kernel ships various ugly unfit for upstream kernel drivers.

There's a world of a difference between a fugly driver and a glibc patch.

Also, we tend to upstream even fugly kernel drivers if they are important and are deployed by a major distro - see Noveau.

Quoted 7 lines
Quoted 3 lines

kernel's fault. But glibc is certainly not being helpful in that situation either and your earlier claim that you are only waiting for the patches is rather dishonest.

I am sure Ulrich is being totally honest, but send him the patches and you'll find out. Plus you will learn what the API should look like when you try and create them ...

I was there and extended/fixed bits of the kaio/libaio code when they were written so yes i already know something about it. To say that the glibc reaction was less than enthusiastic back then is a strong euphemism ;-)

So after 8 years some of the bits made its way into Fedora/RHEL.

I think this is a pretty good demonstration of the points i made ;-)

Thanks,

Ingo

#308 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 59 lines · Ingo Molnar
Quoted 15 lines · Zachary Amsden
Quoted 13 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 5 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

Quoted 9 lines
Quoted 6 lines

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Ingo, what you miss is that this is not a bad thing. Fact of the matter is, it's not just painful, it downright sucks.

Our experience is the opposite, and we tried both variants and report about our experience with both models honestly.

You only have experience about one variant - the one you advocate.

See the assymetry?

Quoted 7 lines

This is actually a Good Thing (tm). It means you have to get your feature and its interfaces well defined and able to version forwards and backwards independently from each other. And that introduces some complexity and time and testing, but in the end it's what you want. You don't introduce a requirement to have the feature, but take advantage of it if it is there.

Quoted 5 lines

It may take everyone else a couple years to upgrade the compilers, tools, libraries and kernel, and by that time any bugs introduced by interacting with this feature will have been ironed out and their patterns well known.

Sorry, but this is pain not true. The 2.4->2.6 kernel cycle debacle has taught us that waiting long to 'iron out' the details has the following effects:

- developer pain
- user pain
- distro pain
- disconnect
- loss of developers, testers and users
- grave bugs discovered months (years ...) down the line
- untested features
- developer exhaustion

Quoted 4 lines

It didnt work, trust me - and i've been around long enough to have suffered through the whole 2.5.x misery. Some of our worst ABIs come from that cycle as well.

You're talking about a single project and comparing it to my argument about multiple independent projects. In that case, I see no point in the discussion. If you want to win the argument by strawman, you are welcome to do so.

Quoted 3 lines

Sorry, but i really think you are really trying to rationalize a disadvantage here ...

This could very well be true, but until someone comes forward with compelling numbers (as in, developers committed to working on the project, number of patches and total amount of code contribution), there is no point in having an argument, there really isn't anything to discuss other than opinion. My opinion is you need a really strong justification to have a successful fork and I don't see that justification.

Zach

#309 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 51 lines · Zachary Amsden
Quoted 50 lines · Ingo Molnar
Quoted 11 lines · Zachary Amsden
Quoted 10 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 4 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

Quoted 7 lines
Quoted 5 lines

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Ingo, what you miss is that this is not a bad thing. Fact of the matter is, it's not just painful, it downright sucks.

Our experience is the opposite, and we tried both variants and report about our experience with both models honestly.

You only have experience about one variant - the one you advocate.

See the assymetry?

Quoted 11 lines

This is actually a Good Thing (tm). It means you have to get your feature and its interfaces well defined and able to version forwards and backwards independently from each other. And that introduces some complexity and time and testing, but in the end it's what you want. You don't introduce a requirement to have the feature, but take advantage of it if it is there.

It may take everyone else a couple years to upgrade the compilers, tools, libraries and kernel, and by that time any bugs introduced by interacting with this feature will have been ironed out and their patterns well known.

Sorry, but this is pain not true. The 2.4->2.6 kernel cycle debacle has taught us that waiting long to 'iron out' the details has the following effects:

- developer pain
- user pain
- distro pain
- disconnect
- loss of developers, testers and users
- grave bugs discovered months (years ...) down the line
- untested features
- developer exhaustion

Quoted 8 lines
Quoted 3 lines

It didnt work, trust me - and i've been around long enough to have suffered through the whole 2.5.x misery. Some of our worst ABIs come from that cycle as well.

You're talking about a single project and comparing it to my argument about multiple independent projects. In that case, I see no point in the discussion. If you want to win the argument by strawman, you are welcome to do so.

The kernel is a very complex project with many ABI issues, so all those arguments apply to it as well. The description you gave:

 | This is actually a Good Thing (tm).  It means you have to get your feature 
 | and its interfaces well defined and able to version forwards and backwards 
 | independently from each other.  And that introduces some complexity and 
 | time and testing, but in the end it's what you want.  You don't introduce a 
 | requirement to have the feature, but take advantage of it if it is there.

matches the kernel too. We have many such situations. (Furthermore, the tools/perf/ situation, which relates to ABIs and user-space/kernel-space interactions is similar as well.)

Do you still think i'm making a straw-man argument?

Quoted 9 lines
Quoted 2 lines

Sorry, but i really think you are really trying to rationalize a disadvantage here ...

This could very well be true, but until someone comes forward with compelling numbers (as in, developers committed to working on the project, number of patches and total amount of code contribution), there is no point in having an argument, there really isn't anything to discuss other than opinion. My opinion is you need a really strong justification to have a successful fork and I don't see that justification.

I can give you rough numbers for tools/perf - if that counts for you.

For the first four months of its existence, when it was a separate project, i had a single external contributor IIRC.

The moment it went into the kernel repo the number of contributors and contributions skyrocketed and basically all contributions were top-notch. We are at 60+ separate contributors now (after about 8 months upstream) - which is still small compared to the kernel or to Qemu, but huge for a relatively isolated project like instrumentation.

So in my estimation tools/kvm/ would certainly be popular. Whether it would be more popular than current Qemu is hard to tell - it would be pure speculation.

Any reliable numbers for the other aspect, whether a split project creates a more fragile and less developed ABI would be extremely hard to get. I believe it to be true, but that's my opinion based on my experience with other projects, extrapolated to KVM/Qemu.

Anyway, the issue is moot as there's clear opposition to the unification idea.

Too bad - there was heavy initial opposition to the arch/x86 unification as well [and heavy opposition to tools/perf/ as well], still both worked out extremely well :-)

Ingo

#355 lore raw

PATCH 1/1 Enhance perf to collect KVM guest os statistics from host side

In reply to Zhang, Yanmin
Quoted 2 lines · Yanmin

From: Zhang, Yanmin <[email protected]>

Here is the new patch of V2 against tip/master of March 17th if anyone wants to try it.

ChangeLog V2:
1) Based on Avi's suggestion, I moved callback functions to generic code area. So the kernel part of the patch is clearer.
2) Add 'perf kvm stat'.

From: Zhang, Yanmin <[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff
perf kvm stat

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

--------------------------------------------------------------------------------------------------------------------------
PerfTop: 16010 irqs/sec kernel:59.1% us: 1.5% guest kernel:31.9% guest us: 7.5% exact: 0.0% [1000Hz cycles], (all, 16 CPUs)
--------------------------------------------------------------------------------------------------------------------------

             samples  pcnt function                  DSO
             _______ _____ _________________________ _______________________

            38770.00 20.4% __ticket_spin_lock        [guest.kernel.kallsyms]
            22560.00 11.9% ftrace_likely_update      [kernel.kallsyms]
             9208.00  4.8% __lock_acquire            [kernel.kallsyms]
             5473.00  2.9% trace_hardirqs_off_caller [kernel.kallsyms]
             5222.00  2.7% copy_user_generic_string  [guest.kernel.kallsyms]
             4450.00  2.3% validate_chain            [kernel.kallsyms]
             4262.00  2.2% trace_hardirqs_on_caller  [kernel.kallsyms]
             4239.00  2.2% do_raw_spin_lock          [kernel.kallsyms]
             3548.00  1.9% do_raw_spin_unlock        [kernel.kallsyms]
             2487.00  1.3% lock_release              [kernel.kallsyms]
             2165.00  1.1% __local_bh_disable        [kernel.kallsyms]
             1905.00  1.0% check_chain_key           [kernel.kallsyms]
             1737.00  0.9% lock_acquire              [kernel.kallsyms]
             1604.00  0.8% tcp_recvmsg               [kernel.kallsyms]
             1524.00  0.8% mark_lock                 [kernel.kallsyms]
             1464.00  0.8% schedule                  [kernel.kallsyms]
             1423.00  0.7% __d_lookup                [guest.kernel.kallsyms]

If you want to just show host data, pls. don't use parameter --guest. The headline includes guest os kernel and userspace percentage.

2) perf kvm record
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules record -f -a sleep 60
[ perf record: Woken up 15 times to write data ]
[ perf record: Captured and wrote 29.385 MB perf.data.kvm (~1283837 samples) ]

3) perf kvm report

        3.1) [root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms

--guestmodules=/home/ymzhang/guest/modules report --sort pid --showcpuutilization>norm.host.guest.report.pid # Samples: 424719292247
#
# Overhead sys us guest sys guest us Command: Pid

# ........  .....................
#
    50.57%     1.02%     0.00%    39.97%     9.58%  qemu-system-x86: 3587
    49.32%     1.35%     0.01%    35.20%    12.76%  qemu-system-x86: 3347
     0.07%     0.07%     0.00%     0.00%     0.00%             perf: 5217

Some performance guys require perf to show sys/us/guest_sys/guest_us per KVM guest instance which is actually just a multi-threaded process. Above sub parameter --showcpuutilization does so.

        3.2) [root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms

--guestmodules=/home/ymzhang/guest/modules report >norm.host.guest.report # Samples: 2466991384118
#
# Overhead Command Shared Object Symbol

# ........  ...............  ........................................................................  ......
#
    29.11%  qemu-system-x86  [guest.kernel.kallsyms]                                                   [g] __ticket_spin_lock
     5.88%       tbench_srv  [kernel.kallsyms]                                                         [k] ftrace_likely_update
     5.76%           tbench  [kernel.kallsyms]                                                         [k] ftrace_likely_update
     3.88%  qemu-system-x86                                                                34c3255482  [u] 0x000034c3255482
     1.83%           tbench  [kernel.kallsyms]                                                         [k] __lock_acquire
     1.81%       tbench_srv  [kernel.kallsyms]                                                         [k] __lock_acquire
     1.38%       tbench_srv  [kernel.kallsyms]                                                         [k] trace_hardirqs_off_caller
     1.37%           tbench  [kernel.kallsyms]                                                         [k] trace_hardirqs_off_caller
     1.13%  qemu-system-x86  [guest.kernel.kallsyms]                                                   [g] copy_user_generic_string
     1.04%       tbench_srv  [kernel.kallsyms]                                                         [k] validate_chain
     1.00%           tbench  [kernel.kallsyms]                                                         [k] trace_hardirqs_on_caller
     1.00%       tbench_srv  [kernel.kallsyms]                                                         [k] trace_hardirqs_on_caller
     0.95%           tbench  [kernel.kallsyms]                                                         [k] do_raw_spin_lock

[u] means it's in guest os user space. [g] means in guest os kernel. Other info is very direct. If it shows a module such like [ext4], it means guest kernel module, because native host kernel's modules are start from something like /lib/modules/XXX.

Below is the patch against tip/master tree of 17th March.

---

arch/x86/include/asm/perf_event.h +4 -11
diff -Nraup linux-2.6_tip0317/arch/x86/include/asm/perf_event.h linux-2.6_tip0317_perfkvm/arch/x86/include/asm/perf_event.h
@@ -143,17 +143,10 @@ extern void perf_events_lapic_init(void)
  */
 #define PERF_EFLAGS_EXACT	(1UL << 3)
 
-#define perf_misc_flags(regs)				\
-({	int misc = 0;					\
-	if (user_mode(regs))				\
-		misc |= PERF_RECORD_MISC_USER;		\
-	else						\
-		misc |= PERF_RECORD_MISC_KERNEL;	\
-	if (regs->flags & PERF_EFLAGS_EXACT)		\
-		misc |= PERF_RECORD_MISC_EXACT;		\
-	misc; })
-
-#define perf_instruction_pointer(regs)	((regs)->ip)
+struct pt_regs;
+extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
+extern unsigned long perf_misc_flags(struct pt_regs *regs);
+#define perf_misc_flags(regs)	perf_misc_flags(regs)
 
 #else
 static inline void init_hw_perf_events(void)		{ }
arch/x86/kernel/cpu/perf_event.c +27 -0
diff -Nraup linux-2.6_tip0317/arch/x86/kernel/cpu/perf_event.c linux-2.6_tip0317_perfkvm/arch/x86/kernel/cpu/perf_event.c
@@ -1708,3 +1708,30 @@ void perf_arch_fetch_caller_regs(struct 
 	local_save_flags(regs->flags);
 }
 #endif
+
+unsigned long perf_instruction_pointer(struct pt_regs *regs)
+{
+	unsigned long ip;
+	if (perf_guest_cbs && perf_guest_cbs->is_in_guest())
+		ip = perf_guest_cbs->get_guest_ip();
+	else
+		ip = instruction_pointer(regs);
+	return ip;
+}
+
+unsigned long perf_misc_flags(struct pt_regs *regs)
+{
+	int misc = 0;
+	if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
+		misc |= perf_guest_cbs->is_user_mode() ?
+			PERF_RECORD_MISC_GUEST_USER :
+			PERF_RECORD_MISC_GUEST_KERNEL;
+	} else
+		misc |= user_mode(regs) ? PERF_RECORD_MISC_USER :
+			PERF_RECORD_MISC_KERNEL;
+	if (regs->flags & PERF_EFLAGS_EXACT)
+		misc |= PERF_RECORD_MISC_EXACT;
+
+	return misc;
+}
+
arch/x86/kvm/x86.c +36 -0
diff -Nraup linux-2.6_tip0317/arch/x86/kvm/x86.c linux-2.6_tip0317_perfkvm/arch/x86/kvm/x86.c
@@ -3764,6 +3764,35 @@ static void kvm_timer_init(void)
 	}
 }
 
+static DEFINE_PER_CPU(struct kvm_vcpu *, current_vcpu);
+
+static int kvm_is_in_guest(void)
+{
+	return percpu_read(current_vcpu) != NULL;
+}
+
+static int kvm_is_user_mode(void)
+{
+	int user_mode = 3;
+	if (percpu_read(current_vcpu))
+		user_mode = kvm_x86_ops->get_cpl(percpu_read(current_vcpu));
+	return user_mode != 0;
+}
+
+static unsigned long kvm_get_guest_ip(void)
+{
+	unsigned long ip = 0;
+	if (percpu_read(current_vcpu))
+		ip = kvm_rip_read(percpu_read(current_vcpu));
+	return ip;
+}
+
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+	.is_in_guest            = kvm_is_in_guest,
+	.is_user_mode           = kvm_is_user_mode,
+	.get_guest_ip           = kvm_get_guest_ip,
+};
+
 int kvm_arch_init(void *opaque)
 {
 	int r;
@@ -3800,6 +3829,8 @@ int kvm_arch_init(void *opaque)
 
 	kvm_timer_init();
 
+	perf_register_guest_info_callbacks(&kvm_guest_cbs);
+
 	return 0;
 
 out:
@@ -3808,6 +3839,8 @@ out:
 
 void kvm_arch_exit(void)
 {
+	perf_unregister_guest_info_callbacks(&kvm_guest_cbs);
+
 	if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
 		cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block,
 					    CPUFREQ_TRANSITION_NOTIFIER);
@@ -4338,7 +4371,10 @@ static int vcpu_enter_guest(struct kvm_v
 	}
 
 	trace_kvm_entry(vcpu->vcpu_id);
+
+	percpu_write(current_vcpu, vcpu);
 	kvm_x86_ops->run(vcpu);
+	percpu_write(current_vcpu, NULL);
 
 	/*
 	 * If the guest has used debug registers, at least dr7
include/linux/perf_event.h +20 -1
diff -Nraup linux-2.6_tip0317/include/linux/perf_event.h linux-2.6_tip0317_perfkvm/include/linux/perf_event.h
@@ -288,11 +288,13 @@ struct perf_event_mmap_page {
 	__u64	data_tail;		/* user-space written tail */
 };
 
-#define PERF_RECORD_MISC_CPUMODE_MASK		(3 << 0)
+#define PERF_RECORD_MISC_CPUMODE_MASK		(7 << 0)
 #define PERF_RECORD_MISC_CPUMODE_UNKNOWN	(0 << 0)
 #define PERF_RECORD_MISC_KERNEL			(1 << 0)
 #define PERF_RECORD_MISC_USER			(2 << 0)
 #define PERF_RECORD_MISC_HYPERVISOR		(3 << 0)
+#define PERF_RECORD_MISC_GUEST_KERNEL		(4 << 0)
+#define PERF_RECORD_MISC_GUEST_USER		(5 << 0)
 
 #define PERF_RECORD_MISC_EXACT			(1 << 14)
 /*
@@ -446,6 +448,12 @@ enum perf_callchain_context {
 # include <asm/perf_event.h>
 #endif
 
+struct perf_guest_info_callbacks {
+	int (*is_in_guest) (void);
+	int (*is_user_mode) (void);
+	unsigned long (*get_guest_ip) (void);
+};
+
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
 #include <asm/hw_breakpoint.h>
 #endif
@@ -913,6 +921,12 @@ static inline void perf_event_mmap(struc
 		__perf_event_mmap(vma);
 }
 
+extern struct perf_guest_info_callbacks *perf_guest_cbs;
+extern int perf_register_guest_info_callbacks(
+		struct perf_guest_info_callbacks *);
+extern int perf_unregister_guest_info_callbacks(
+		struct perf_guest_info_callbacks *);
+
 extern void perf_event_comm(struct task_struct *tsk);
 extern void perf_event_fork(struct task_struct *tsk);
 
@@ -982,6 +996,11 @@ perf_sw_event(u32 event_id, u64 nr, int 
 static inline void
 perf_bp_event(struct perf_event *event, void *data)			{ }
 
+static inline int perf_register_guest_info_callbacks
+(struct perf_guest_info_callbacks *)   {return 0; }
+static inline int perf_unregister_guest_info_callbacks
+(struct perf_guest_info_callbacks *)   {return 0; }
+
 static inline void perf_event_mmap(struct vm_area_struct *vma)		{ }
 static inline void perf_event_comm(struct task_struct *tsk)		{ }
 static inline void perf_event_fork(struct task_struct *tsk)		{ }
kernel/perf_event.c +22 -1
diff -Nraup linux-2.6_tip0317/kernel/perf_event.c linux-2.6_tip0317_perfkvm/kernel/perf_event.c
@@ -2798,6 +2798,27 @@ void perf_arch_fetch_caller_regs(struct 
 #endif
 
 /*
+ * We assume there is only KVM supporting the callbacks.
+ * Later on, we might change it to a list if there is
+ * another virtualization implementation supporting the callbacks.
+ */
+struct perf_guest_info_callbacks *perf_guest_cbs;
+
+int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
+{
+	perf_guest_cbs = cbs;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
+
+int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
+{
+	perf_guest_cbs = NULL;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks);
+
+/*
  * Output
  */
 static bool perf_output_space(struct perf_mmap_data *data, unsigned long tail,
@@ -3740,7 +3761,7 @@ void __perf_event_mmap(struct vm_area_st
 		.event_id  = {
 			.header = {
 				.type = PERF_RECORD_MMAP,
-				.misc = 0,
+				.misc = PERF_RECORD_MISC_USER,
 				/* .size */
 			},
 			/* .pid */
tools/perf/builtin-diff.c +4 -1
diff -Nraup linux-2.6_tip0317/tools/perf/builtin-diff.c linux-2.6_tip0317_perfkvm/tools/perf/builtin-diff.c
@@ -33,7 +33,7 @@ static int perf_session__add_hist_entry(
 		return -ENOMEM;
 
 	if (hit)
-		he->count += count;
+		__perf_session__add_count(he, al, count);
 
 	return 0;
 }
@@ -225,6 +225,9 @@ int cmd_diff(int argc, const char **argv
 			input_new = argv[1];
 		} else
 			input_new = argv[0];
+	} else if (symbol_conf.guest_vmlinux_name || symbol_conf.guest_kallsyms) {
+		input_old = "perf.data.host";
+		input_new = "perf.data.guest";
 	}
 
 	symbol_conf.exclude_other = false;
tools/perf/builtin.h +1 -0
diff -Nraup linux-2.6_tip0317/tools/perf/builtin.h linux-2.6_tip0317_perfkvm/tools/perf/builtin.h
@@ -32,5 +32,6 @@ extern int cmd_version(int argc, const c
 extern int cmd_probe(int argc, const char **argv, const char *prefix);
 extern int cmd_kmem(int argc, const char **argv, const char *prefix);
 extern int cmd_lock(int argc, const char **argv, const char *prefix);
+extern int cmd_kvm(int argc, const char **argv, const char *prefix);
 
 #endif
tools/perf/builtin-kvm.c +125 -0

125 lines not on this page · raw message

tools/perf/builtin-record.c +42 -2

60 lines not on this page · raw message

tools/perf/builtin-report.c +3 -1
diff -Nraup linux-2.6_tip0317/tools/perf/builtin-report.c linux-2.6_tip0317_perfkvm/tools/perf/builtin-report.c
@@ -104,7 +104,7 @@ static int perf_session__add_hist_entry(
 		return -ENOMEM;
 
 	if (hit)
-		he->count += data->period;
+		__perf_session__add_count(he, al,  data->period);
 
 	if (symbol_conf.use_callchain) {
 		if (!hit)
@@ -428,6 +428,8 @@ static const struct option options[] = {
 		   "sort by key(s): pid, comm, dso, symbol, parent"),
 	OPT_BOOLEAN('P', "full-paths", &symbol_conf.full_paths,
 		    "Don't shorten the pathnames taking into account the cwd"),
+	OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
+		    "Show sample percentage for different cpu modes"),
 	OPT_STRING('p', "parent", &parent_pattern, "regex",
 		   "regex filter to identify parent, see: '--sort parent'"),
 	OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
tools/perf/builtin-top.c +34 -7

75 lines not on this page · raw message

tools/perf/Makefile +1 -0
diff -Nraup linux-2.6_tip0317/tools/perf/Makefile linux-2.6_tip0317_perfkvm/tools/perf/Makefile
@@ -462,6 +462,7 @@ BUILTIN_OBJS += builtin-trace.o
 BUILTIN_OBJS += builtin-probe.o
 BUILTIN_OBJS += builtin-kmem.o
 BUILTIN_OBJS += builtin-lock.o
+BUILTIN_OBJS += builtin-kvm.o
 
 PERFLIBS = $(LIB_FILE)
 
tools/perf/perf.c +1 -0
diff -Nraup linux-2.6_tip0317/tools/perf/perf.c linux-2.6_tip0317_perfkvm/tools/perf/perf.c
@@ -308,6 +308,7 @@ static void handle_internal_command(int 
 		{ "probe",	cmd_probe,	0 },
 		{ "kmem",	cmd_kmem,	0 },
 		{ "lock",	cmd_lock,	0 },
+		{ "kvm",	cmd_kvm,	0 },
 	};
 	unsigned int i;
 	static const char ext[] = STRIP_EXTENSION;
tools/perf/perf.h +2 -0
diff -Nraup linux-2.6_tip0317/tools/perf/perf.h linux-2.6_tip0317_perfkvm/tools/perf/perf.h
@@ -133,4 +133,6 @@ struct ip_callchain {
 	u64 ips[0];
 };
 
+extern int perf_host, perf_guest;
+
 #endif
tools/perf/util/event.c +151 -40

293 lines not on this page · raw message

tools/perf/util/event.h +10 -3
diff -Nraup linux-2.6_tip0317/tools/perf/util/event.h linux-2.6_tip0317_perfkvm/tools/perf/util/event.h
@@ -119,10 +119,17 @@ int event__synthesize_thread(pid_t pid, 
 void event__synthesize_threads(event__handler_t process,
 			       struct perf_session *session);
 int event__synthesize_kernel_mmap(event__handler_t process,
-				  struct perf_session *session,
-				  const char *symbol_name);
+				struct perf_session *session,
+				const char *kallsyms_name,
+				const char *mmap_name,
+				struct map **maps,
+				const char *symbol_name,
+				unsigned int misc);
+
 int event__synthesize_modules(event__handler_t process,
-			      struct perf_session *session);
+			      struct perf_session *session,
+			      struct map_groups *kmaps,
+			      unsigned int misc);
 
 int event__process_comm(event_t *self, struct perf_session *session);
 int event__process_lost(event_t *self, struct perf_session *session);
tools/perf/util/hist.c +63 -4

110 lines not on this page · raw message

tools/perf/util/hist.h +3 -0
diff -Nraup linux-2.6_tip0317/tools/perf/util/hist.h linux-2.6_tip0317_perfkvm/tools/perf/util/hist.h
@@ -12,6 +12,9 @@ struct addr_location;
 struct symbol;
 struct rb_root;
 
+void __perf_session__add_count(struct hist_entry *he,
+			struct addr_location *al,
+			u64 count);
 struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
 						  struct addr_location *al,
 						  struct symbol *parent,
tools/perf/util/session.c +23 -9
diff -Nraup linux-2.6_tip0317/tools/perf/util/session.c linux-2.6_tip0317_perfkvm/tools/perf/util/session.c
@@ -54,7 +54,12 @@ out_close:
 
 static inline int perf_session__create_kernel_maps(struct perf_session *self)
 {
-	return map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps);
+	int ret;
+	ret = map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps);
+	if (ret >= 0)
+		ret = map_groups__create_guest_kernel_maps(&self->guest_kmaps,
+				self->guest_vmlinux_maps);
+	return ret;
 }
 
 struct perf_session *perf_session__new(const char *filename, int mode, bool force)
@@ -77,6 +82,7 @@ struct perf_session *perf_session__new(c
 	self->cwdlen = 0;
 	self->unknown_events = 0;
 	map_groups__init(&self->kmaps);
+	map_groups__init(&self->guest_kmaps);
 
 	if (mode == O_RDONLY) {
 		if (perf_session__open(self, force) < 0)
@@ -356,7 +362,8 @@ int perf_header__read_build_ids(struct p
 		if (read(input, filename, len) != len)
 			goto out;
 
-		if (bev.header.misc & PERF_RECORD_MISC_KERNEL)
+		if ((bev.header.misc & PERF_RECORD_MISC_CPUMODE_MASK)
+			==  PERF_RECORD_MISC_KERNEL)
 			head = &dsos__kernel;
 
 		dso = __dsos__findnew(head, filename);
@@ -519,26 +526,33 @@ bool perf_session__has_traces(struct per
 	return true;
 }
 
-int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self,
+int perf_session__set_kallsyms_ref_reloc_sym(struct map ** maps,
 					     const char *symbol_name,
 					     u64 addr)
 {
 	char *bracket;
 	enum map_type i;
+	struct ref_reloc_sym *ref;
 
-	self->ref_reloc_sym.name = strdup(symbol_name);
-	if (self->ref_reloc_sym.name == NULL)
+	ref = zalloc(sizeof(struct ref_reloc_sym));
+	if (ref == NULL)
 		return -ENOMEM;
 
-	bracket = strchr(self->ref_reloc_sym.name, ']');
+	ref->name = strdup(symbol_name);
+	if (ref->name == NULL) {
+		free(ref);
+		return -ENOMEM;
+	}
+
+	bracket = strchr(ref->name, ']');
 	if (bracket)
 		*bracket = '\0';
 
-	self->ref_reloc_sym.addr = addr;
+	ref->addr = addr;
 
 	for (i = 0; i < MAP__NR_TYPES; ++i) {
-		struct kmap *kmap = map__kmap(self->vmlinux_maps[i]);
-		kmap->ref_reloc_sym = &self->ref_reloc_sym;
+		struct kmap *kmap = map__kmap(maps[i]);
+		kmap->ref_reloc_sym = ref;
 	}
 
 	return 0;
tools/perf/util/session.h +3 -16
diff -Nraup linux-2.6_tip0317/tools/perf/util/session.h linux-2.6_tip0317_perfkvm/tools/perf/util/session.h
@@ -16,16 +16,17 @@ struct perf_session {
 	unsigned long		size;
 	unsigned long		mmap_window;
 	struct map_groups	kmaps;
+	struct map_groups	guest_kmaps;
 	struct rb_root		threads;
 	struct thread		*last_match;
 	struct map		*vmlinux_maps[MAP__NR_TYPES];
+	struct map		*guest_vmlinux_maps[MAP__NR_TYPES];
 	struct events_stats	events_stats;
 	struct rb_root		stats_by_id;
 	unsigned long		event_total[PERF_RECORD_MAX];
 	unsigned long		unknown_events;
 	struct rb_root		hists;
 	u64			sample_type;
-	struct ref_reloc_sym	ref_reloc_sym;
 	int			fd;
 	int			cwdlen;
 	char			*cwd;
@@ -67,26 +68,12 @@ bool perf_session__has_traces(struct per
 int perf_header__read_build_ids(struct perf_header *self, int input,
 				u64 offset, u64 file_size);
 
-int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self,
+int perf_session__set_kallsyms_ref_reloc_sym(struct map ** maps,
 					     const char *symbol_name,
 					     u64 addr);
 
 void mem_bswap_64(void *src, int byte_size);
 
-static inline int __perf_session__create_kernel_maps(struct perf_session *self,
-						struct dso *kernel)
-{
-	return __map_groups__create_kernel_maps(&self->kmaps,
-						self->vmlinux_maps, kernel);
-}
-
-static inline struct map *
-	perf_session__new_module_map(struct perf_session *self,
-				     u64 start, const char *filename)
-{
-	return map_groups__new_module(&self->kmaps, start, filename);
-}
-
 #ifdef NO_NEWT_SUPPORT
 static inline void perf_session__browse_hists(struct rb_root *hists __used,
 					      u64 session_total __used,
tools/perf/util/sort.h +4 -0
diff -Nraup linux-2.6_tip0317/tools/perf/util/sort.h linux-2.6_tip0317_perfkvm/tools/perf/util/sort.h
@@ -44,6 +44,10 @@ extern enum sort_type sort__first_dimens
 struct hist_entry {
 	struct rb_node		rb_node;
 	u64			count;
+	u64			count_sys;
+	u64			count_us;
+	u64			count_guest_sys;
+	u64			count_guest_us;
 	struct thread		*thread;
 	struct map		*map;
 	struct symbol		*sym;
tools/perf/util/symbol.c +157 -21

346 lines not on this page · raw message

tools/perf/util/symbol.h +18 -4
diff -Nraup linux-2.6_tip0317/tools/perf/util/symbol.h linux-2.6_tip0317_perfkvm/tools/perf/util/symbol.h
@@ -63,10 +63,14 @@ struct symbol_conf {
 			show_nr_samples,
 			use_callchain,
 			exclude_other,
-			full_paths;
+			full_paths,
+			show_cpu_utilization;
 	const char	*vmlinux_name,
 			*field_sep;
-	char            *dso_list_str,
+	const char	*guest_vmlinux_name,
+			*guest_kallsyms,
+			*guest_modules;
+	char		*dso_list_str,
 			*comm_list_str,
 			*sym_list_str,
 			*col_width_list_str;
@@ -95,6 +99,13 @@ struct addr_location {
 	u64	      addr;
 	char	      level;
 	bool	      filtered;
+	unsigned int  cpumode;
+};
+
+enum dso_kernel_type {
+	DSO_TYPE_USER = 0,
+	DSO_TYPE_KERNEL,
+	DSO_TYPE_GUEST_KERNEL
 };
 
 struct dso {
@@ -104,7 +115,7 @@ struct dso {
 	u8		 adjust_symbols:1;
 	u8		 slen_calculated:1;
 	u8		 has_build_id:1;
-	u8		 kernel:1;
+	enum dso_kernel_type	kernel;
 	u8		 hit:1;
 	u8		 annotate_warned:1;
 	unsigned char	 origin;
@@ -120,6 +131,7 @@ struct dso {
 
 struct dso *dso__new(const char *name);
 struct dso *dso__new_kernel(const char *name);
+struct dso *dso__new_guest_kernel(const char *name);
 void dso__delete(struct dso *self);
 
 bool dso__loaded(const struct dso *self, enum map_type type);
@@ -132,7 +144,7 @@ static inline void dso__set_loaded(struc
 
 void dso__sort_by_name(struct dso *self, enum map_type type);
 
-extern struct list_head dsos__user, dsos__kernel;
+extern struct list_head dsos__user, dsos__kernel, dsos__guest_user, dsos__guest_kernel;
 
 struct dso *__dsos__findnew(struct list_head *head, const char *name);
 
@@ -161,6 +173,8 @@ enum dso_origin {
 	DSO__ORIG_BUILDID,
 	DSO__ORIG_DSO,
 	DSO__ORIG_KMODULE,
+	DSO__ORIG_GUEST_KERNEL,
+	DSO__ORIG_GUEST_KMODULE,
 	DSO__ORIG_NOT_FOUND,
 };
 
tools/perf/util/thread.h +4 -1
diff -Nraup linux-2.6_tip0317/tools/perf/util/thread.h linux-2.6_tip0317_perfkvm/tools/perf/util/thread.h
@@ -82,6 +82,9 @@ int __map_groups__create_kernel_maps(str
 int map_groups__create_kernel_maps(struct map_groups *self,
 				   struct map *vmlinux_maps[MAP__NR_TYPES]);
 
+int map_groups__create_guest_kernel_maps(struct map_groups *self,
+				   struct map *vmlinux_maps[MAP__NR_TYPES]);
+
 struct map *map_groups__new_module(struct map_groups *self, u64 start,
-				   const char *filename);
+				   const char *filename, int guest);
 #endif	/* __PERF_THREAD_H */
#310 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

Too bad - there was heavy initial opposition to the arch/x86 unification as well [and heavy opposition to tools/perf/ as well], still both worked out extremely well :-)

Did you forget that arch/x86 was a merging of a code fork that happened several years previously? Maybe that fork shouldn't have been done to begin with.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#304 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar
Quoted 8 lines

Yes its a double standard

Glibc has a higher standard than Fedora/RHEL.

Just like the Ubuntu kernel ships various ugly unfit for upstream kernel drivers.

There's a world of a difference between a fugly driver and a glibc patch.

Yes, fugly drivers can be cleaned up, but glibc ABIs are forever.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#84 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Avi Kivity
Quoted 3 lines · Ingo Molnar

I find the 'KVM mostly cares about the server, not about the desktop' attitude expressed in this thread troubling.

It's not kvm, just it's developers (and their employers, where applicable). If you post desktop oriented patches I'm sure they'll be welcome.

Quoted 8 lines

Just such a patch-set was posted in this very thread: 'perf kvm'.

There were two negative reactions immediately, both showed a fundamental server versus desktop bias:

- you did not accept that the most important usecase is when there is a single guest running.

Well, it isn't.

Quoted 4 lines

- the reaction to the 'how do we get symbols out of the guest' sub-question was, paraphrased: 'we dont want that due to<unspecified> security threat to XYZ selinux usecase with lots of guests'.

When I review a patch, I try to think of the difficult cases, not just the easy case.

Quoted 8 lines

Anyone being aware of how Linux and KVM is being used on the desktop will know how detached that attitude is from the typical desktop usecase ...

Usability _never_ sucks because of lack of patches or lack of suggestions. I bet if you made the next server feature contingent on essential usability fixes they'd happen overnight - for God's sake there's been 1000 commits in the last 3 months in the Qemu repository so there's plenty of manpower...

First of all I am not a qemu maintainer. Second, from my point of view all contributors are volunteers (perhaps their employer volunteered them, but there's no difference from my perspective). Asking them to repaint my apartment as a condition to get a patch applied is abuse. If a patch is good, it gets applied.

Quoted 6 lines

Usability suckage - and i'm not going to be popular for saying this out loud - almost always shows a basic maintainer disconnect with the real world. See your very first reactions to my 'KVM usability' observations. Read back your and Anthony's replies: total 'sure, patches welcome' kind of indifference. It is _your project_, not some other project down the road ...

I could drop everything and write a gtk GUI for qemu. Is that what you want?

If someone is truly interested in a qemu usability, it's up to them to write the patches. Personally I've never missed the eject button.

As to disconnect from the real world, most products based on kvm and qemu (and Linux) are server based. Perhaps that's the reason people emphasise that? Maybe if Linux had 10-20% desktop market penetration, there would be more interest in a bells and whistles qemu GUI.

Quoted 5 lines

So that is my first-hand experience about how you are welcoming these desktop issues, in this very thread. I suspect people try a few times with suggestions, then get shot down like our suggestions were shot down and then give up.

I don't recall anyone trying this much less being shot down. Perhaps people are concentrating on virt-manager and the like and leaving qemu alone.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#356 lore raw
In reply to Zhang, Yanmin

Nice progress!

This bit:

Quoted 3 lines

1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Will be really be painful to developers - to enter that long line while we have these things called 'computers' that ought to reduce human work. Also, it's incomplete, we need access to the guest system's binaries to do ELF symbol resolution and dwarf decoding.

So we really need some good, automatic way to get to the guest symbol space, so that if a developer types:

perf kvm top

Then the obvious thing happens by default. (which is to show the guest overhead)

There's no technical barrier on the perf tooling side to implement all that:
perf supports build-ids extensively and can deal with multiple symbol spaces - as long as it has access to it. The guest kernel could be ID-ed based on its /sys/kernel/notes and /sys/module/*/notes/.note.gnu.build-id build-ids.

So some sort of --guestmount option would be the natural solution, which points to the guest system's root: and a Qemu enumeration of guest mounts (which would be off by default and configurable) from which perf can pick up the target guest all automatically. (obviously only under allowed permissions so that such access is secure)

This would allow not just kallsyms access via $guest/proc/kallsyms but also gives us the full space of symbol features: access to the guest binaries for annotation and general symbol resolution, command/binary name identification, etc.

Such a mount would obviously not broaden existing privileges - and as an additional control a guest would also have a way to indicate that it does not wish a guest mount at all.

Unfortunately, in a previous thread the Qemu maintainer has indicated that he will essentially NAK any attempt to enhance Qemu to provide an easily discoverable, self-contained, transparent guest mount on the host side.

No technical justification was given for that NAK, despite my repeated requests to particulate the exact security problems that such an approach would cause.

If that NAK does not stand in that form then i'd like to know about it - it makes no sense for us to try to code up a solution against a standing maintainer NAK ...

The other option is some sysadmin level hackery to NFS-mount the guest or so. This is a vastly inferior method that brings us back to the absymal usability levels of OProfile:

1) it wont be guest transparent
2) has to be re-done for every guest image.
3) even if packaged it has to be gotten into every. single. Linux. distro. separately.
4) old Linux guests wont work out of box

In other words: it's very inconvenient on multiple levels and wont ever happen on any reasonable enough scale to make a difference to Linux.

Which is an unfortunate situation - and the ball is on the KVM/Qemu side so i can do little about it.

Thanks,

Ingo

#85 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 5 lines

There were two negative reactions immediately, both showed a fundamental server versus desktop bias:

- you did not accept that the most important usecase is when there is a single guest running.

Well, it isn't.

Erm, my usability points are _doubly_ true when there are multiple guests ...

The inconvenience of having to type:

  perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms \
  --guestmodules=/home/ymzhang/guest/modules top

is very obvious even with a single guest. Now multiply that by more guests ...

The crux is: we are working on improving KVM instrumentation. There are working patches posted to this thread and we would like to have/implement an automatism to allow the discovery of all this information. The information should be available to the developer who wants it, and easily/transparently so
- in true Linux fashion.

Quoted 6 lines
Quoted 3 lines

- the reaction to the 'how do we get symbols out of the guest' sub-question was, paraphrased: 'we dont want that due to<unspecified> security threat to XYZ selinux usecase with lots of guests'.

When I review a patch, I try to think of the difficult cases, not just the easy case.

You havent articulated an actionable reason and you have suggested no solution either, you just passive-agressive backed the claim that giving developers access to the symbol space is some sort of vague 'security threat'.

If that is not so i'd be glad to be proven wrong.

Quoted 10 lines
Quoted 8 lines

Anyone being aware of how Linux and KVM is being used on the desktop will know how detached that attitude is from the typical desktop usecase ...

Usability _never_ sucks because of lack of patches or lack of suggestions. I bet if you made the next server feature contingent on essential usability fixes they'd happen overnight - for God's sake there's been 1000 commits in the last 3 months in the Qemu repository so there's plenty of manpower...

First of all I am not a qemu maintainer. [...]

That is the crux of the matter. My experience in these threads was that no-one really seems to feel in charge of the whole thing. Should we really wonder why KVM usability sucks?

Quoted 4 lines

[...] Second, from my point of view all contributors are volunteers (perhaps their employer volunteered them, but there's no difference from my perspective). Asking them to repaint my apartment as a condition to get a patch applied is abuse. If a patch is good, it gets applied.

This is one of the weirdest arguments i've seen in this thread. Almost all the time do we make contributions conditional on the general shape of the project. Developers dont get to do just the fun stuff.

This is a basic quid pro quo: new features introduce risks and create additional workload not just to the originating developer but on the rest of the community as well. You should check how Linus has pulled new features in the past 15 years: he very much requires the existing code to first be top-notch before he accepts new features for a given area of functionality.

Doing that and insisting on developers to see those imbalances as well is absolutely essential to code quality: otherwise everyone would be running around implementing just the features they are interested in, without regard for the general health of the project.

Of course, if you keep the project in two halves (KVM and Qemu), and pretend that they are separate and have little relation, imbalances of quality can mount up and you can throw your hands up and say that it's "too bad, I'm not maintaining that". It is your basic duty as a Linux maintainer to keep balances of quality. I do it all day, other maintainers do it all day.

Quoted 9 lines
Quoted 6 lines

Usability suckage - and i'm not going to be popular for saying this out loud - almost always shows a basic maintainer disconnect with the real world. See your very first reactions to my 'KVM usability' observations. Read back your and Anthony's replies: total 'sure, patches welcome' kind of indifference. It is _your project_, not some other project down the road ...

I could drop everything and write a gtk GUI for qemu. Is that what you want?

No, my suggestion to you (it's up to you whether you give my opinion any weight) is to accept your mistakes and improve, and to not stand in the way of people who'd like to improve the situation. You are happy with the server features and you also made it clear that you dont feel responsible for the rest of the package - which is a big mistake IMO.

Also, you have demonstrated it in this thread that you have near zero technical clue about basic desktop and development usability matters - for example your stance on symbol space access and your stance on how to enumerate guests symbolically are outright bizarre.

Thanks,

Ingo

#288 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Anthony Liguori
Quoted 26 lines · Anthony Liguori
Quoted 18 lines · Ingo Molnar
Quoted 17 lines · Anthony Liguori
Quoted 16 lines · Ingo Molnar
Quoted 3 lines

[...] kvm in fact knows nothing about vga, to take your last example. [...]

Look at the VGA dirty bitmap optimization a'ka the KVM_GET_DIRTY_LOG ioctl.

See qemu/kvm-all.c's kvm_physical_sync_dirty_bitmap().

It started out as a VGA optimization (also used by live migration) and even today it's mostly used by the VGA drivers - albeit a weak one.

I wish there were stronger VGA optimizations implemented, copying the dirty bitmap is not a particularly performant solution. (although it's certainly better than full emulation) Graphics performance is one of the more painful aspects of KVM usability today.

Quoted 6 lines
Quoted 5 lines

We have to maintain a dirty bitmap because we don't have a paravirtual graphics driver. IOW, someone needs to write an Xorg driver.

Ideally, we could just implement a Linux framebuffer device, right?

No, you'd want to interact with DRM.

Quoted 8 lines

Using DRM doesn't help very much. You still need an X driver and most of the operations you care about (video rendering, window movement, etc) are not operations that need to go through DRM.

3D graphics virtualization is extremely difficult in the non-passthrough case. It really requires hardware support that isn't widely available today (outside a few NVIDIA chipsets).

Implementing a virtualized DRM/KMS driver would at least get you the framebuffer interface more or less for free, while allowing you to deal with the userspace side of things incrementally (ie, running a dummy xorg on top of the virtualized fbdev until the DRI side catches up). It would also enable you to focus on the 2D and 3D parts independently.

Quoted 5 lines

It doesn't provide the things we need to a good user experience. You need things like an absolute input device, host driven display resize, RGBA hardware cursors. None of these go through DRI and it's those things that really provide the graphics user experience.

None of these things negate the benefit one would get from a virtualized DRM/KMS driver either. There are multiple problems that need solving in this area, and it's a bit disingenuous to discount a valid suggestion out of hand due to the fact it doesn't solve all of the outstanding issues.

#289 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 5 lines · Paul Mundt

Implementing a virtualized DRM/KMS driver would at least get you the framebuffer interface more or less for free, while allowing you to deal with the userspace side of things incrementally (ie, running a dummy xorg on top of the virtualized fbdev until the DRI side catches up). It would also enable you to focus on the 2D and 3D parts independently.

Guys, have a look at Gallium. In many ways it's a pile of crap, but at least it's a pile of crap designed by vmware for *exactly* your problem space.

OG.

#86 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Avi Kivity
Quoted 6 lines

There were two negative reactions immediately, both showed a fundamental server versus desktop bias:

- you did not accept that the most important usecase is when there is a single guest running.

Well, it isn't.

Quoted 9 lines

Erm, my usability points are _doubly_ true when there are multiple guests ...

The inconvenience of having to type:

   perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms \
   --guestmodules=/home/ymzhang/guest/modules top

is very obvious even with a single guest. Now multiply that by more guests ...

If you want to improve this, you need to do the following:

1) Add a userspace daemon that uses vmchannel that runs in the guest and can fetch kallsyms and arbitrary modules. If that daemon lives in tools/perf, that's fine.
2) Add a QMP interface in qemu to interact with such daemon
3) Add a default QMP port in a well known location[1]
4) Modify the perf tool to look for a default QMP port. In the case of a single guest, there's one port. If there are multiple guests, then you will have to connect to each port, find the name or any other identifying information, and let the user choose.

Patches are certainly welcome.

[1] I've written up this patch and will send it out some time today.

Regards,

Anthony Liguori

#290 lore raw

Re: [LKML] Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Olivier Galibert
Quoted 10 lines · Olivier Galibert
Quoted 5 lines · Paul Mundt

Implementing a virtualized DRM/KMS driver would at least get you the framebuffer interface more or less for free, while allowing you to deal with the userspace side of things incrementally (ie, running a dummy xorg on top of the virtualized fbdev until the DRI side catches up). It would also enable you to focus on the 2D and 3D parts independently.

Guys, have a look at Gallium. In many ways it's a pile of crap, but at least it's a pile of crap designed by vmware for *exactly* your problem space.

Or perhaps Chromium, which was designed years ago and can pass-through OpenGL commands via a pipe. VirtualBox uses it for their PV drivers. Naturally it is not a FB, just a OpenGL command pass-through interface.

#328 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Jes Sorensen

Hi there,

not really trying to get into the CC list of this discussion ;) but for what is worth I'd like to share my opinion on the matter.

Quoted 7 lines · Jes Sorensen

What made KVM so successful was that the core kernel of the hypervisor was designed the right way, as a kernel module where it belonged. It was obvious to anyone who had been exposed to the main competition at the time, Xen, that this was the right approach. What has ended up killing Xen in the end is the not-invented-here approach of copying everything over, reformatting it, and rewriting half of it, which made it impossible to maintain and support as a single codebase. At my previous

Full agreement with that. CVS/git/patches and development model is next to irrelevant compared to the basic design of the code.

qemu (and especially qemu-kvm) is surely much closer to perf, than a firefox or openoffice, because there is some tight interconnect with the kernel API. And the skills required to produce useful patches in qemu are similar to the skills requires to produce useful patches for the kernel, more often than not a new feature in kvm also requires some merging of a qemu-kvm side patch (it always happened to me so far ;). But clearly we've to draw a barrier somewhere and while I could see things like systemtap and util-linux included into the kernel and perf already is, I've an hard time to see userland code supporting kernels other than linux into the kernel.

I think that's probably where I'd draw the line. Let's say somebody creates a pure paravirt userland for kvm without full driver emulation that only runs on a linux kernel and no other OS, maybe that thing wouldn't be so controversial to include into the kernel as qemu is. qemu is clearly beyond the "only-running-on-a-linux-kernel" barrier...

I'd definitely start with systemtap, which I think is even more suitable than perf to be merged into the kernel. Things useful only for developers like perf/systemtap makes even more sense to fetch silently hidden in a single pull. Those projects are so ideal to fetch together because you run your own compiled userland binary and not an rpm, and you need very latest kernel and userland package and sometime new userland might not work so well with older kernel too and the other way around. they're tool for developers and no developer cares about API as they rebuild latest userland code anyway, they almost don't require backwards compatibility of kernel.

Quoted 6 lines

So far your argument would justify pulling all of gdb into the kernel git tree as well, to support the kgdb efforts, or gcc so we can get rid of the gcc version quirks in the kernel header files, e2fsprogs and equivalent for _all_ file systems included in the kernel so we can make sure our fs tools never get out of sync with whats supported in the kernel......

It also boils down to the maintainer, where the code is, defines the maintainer who pushes/commits it to the central repository that everyone pulls from. And having the code into Linus's tree doesn't make sense unless Linus is interested to follow and review qemu. So it'd only create blind pulls.

But I entirely see what Ingo is going after and I have no doubt that contribution increases if some code is merged into the kernel even if it's userland. The more people clones a project, the more people builds, uses, reads the code and has incentive to contribute... and there's nothing else like the linux git tree to give visibility to a project and get more contributions (well as long as the pulled code requires similar skills to the kernel code of course). Plus it's annoying to go on web, find url to clone, clone.. running make is faster. But this purely is a PR effect. It's like free ads, to get more people using and looking into the code because it's already on the harddisk and you've only to run make. After somebody gets familiar with the pulled userland code because it find it in the tree and it didn't need to search the web and cut-and-paste and stuff, clone a new repo, I think it wouldn't matter anymore to have it into the kernel or not. Like for perf, by now I doubt it'd get less contributions if it's moved out of the kernel tree. The only reason to leave it there is if Linus actively checks the code before pulling it.

So I think what would be nice maybe to get the PR/ads positive effect and get more _users_ (and later developers) involved without actually merging, is a command like:

git clone linux-2.6
cd linux-2.6
tools/clone-project qemu-kvm
tools/clone-project qemu
tools/clone-project systemtap
tools/clone-project seabios
tools/clone-project e2fsprogs
tools/clone-project perf
...

And then maybe a git-send-email or similar command that would do the right thing and send it to the right list or similar. Learning the process of other projects is time consuming and requires some effort.

But as far as qemu-kvm goes, the visibility is already there, and most people that could possibly contribute to the kernel side already has the userland cloned and pulls regularly from it so I doubt it'd generate anything remotely as beneficial like it did for perf. systemtap is really _identical_ to perf. You include it, lots more developers toys with it by just running "make", they find a bug and they fixes it, and they keep on contributing new features later after they got familiar with it. As usual ;).

Quoted 3 lines · In separate mail Ingo

Btw., i made similar arguments to Avi about 3 years ago when it was going upstream, that qemu should be unified with KVM. This is more true today than ever.

Well not sure if with KVM you mean qemu-kvm or KVM kernel code, but I would see an huge value and a win-win situation to see qemu-kvm and qemu unified. It's out of my reach how there can be still be a difference considering that nobody runs qemu with perhaps the exception of the maintainers themself. There's not even a qemu/kvm directory in qemu. These are the real problems that should be solved... Every time I've to send a patch I've to check if it also applies to qemu. I usually start with qemu-kvm to do my development there, and then I cross fingers and I hope the patch applies clean against qemu too, and send it there in that case. qemu and qemu-kvm are the same thing, it's the same people, it's the same community, it's the same skills, it's an absolute waste that a little amount of code isn't merged so we can all work on the same tree. And it's not an huge patch at all if compared to the size of qemu-kvm... so there can't be any technical explanation for qemu to take a tangent here.

So my suggestion is to start with what will give a _real_ tangible benefit to developers (i.e. to all work on the same branch), the PR effect of merging it into the kernel would be minor for qemu-kvm, it really doesn't matter which url we pull the code from as long as there is only 1 url and not 2.

#357 lore raw
In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar

Unfortunately, in a previous thread the Qemu maintainer has indicated that he will essentially NAK any attempt to enhance Qemu to provide an easily discoverable, self-contained, transparent guest mount on the host side.

No technical justification was given for that NAK, despite my repeated requests to particulate the exact security problems that such an approach would cause.

If that NAK does not stand in that form then i'd like to know about it - it makes no sense for us to try to code up a solution against a standing maintainer NAK ...

I still think it is the best and most generic way to let the guest do the symbol resolution. This has several advantages:

1. The guest knows best about its symbol space. So this would be extensible to other guest operating systems. A brave developer may even implement symbol passing for Windows or the BSDs ;-)

2. The guest can decide for its own if it want to pass this inforamtion to the host-perf. No security issues at all.

3. The guest can also pass us the call-chain and we don't need to care about complicated of fetching from the guest ourself.

4. This way extensible to nested virtualization too.

How we speak to the guest was already discussed in this thread. My personal opinion is that going through qemu is an unnecessary step and we can solve that more clever and transparent for perf.

Joerg

#163 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Avi Kivity
Quoted 6 lines

There were two negative reactions immediately, both showed a fundamental server versus desktop bias:

- you did not accept that the most important usecase is when there is a single guest running.

Well, it isn't.

Quoted 9 lines

Erm, my usability points are _doubly_ true when there are multiple guests ...

The inconvenience of having to type:

   perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms \
   --guestmodules=/home/ymzhang/guest/modules top

is very obvious even with a single guest. Now multiply that by more guests ...

Yes. That's why I asked how this is handled.

Quoted 11 lines

The crux is: we are working on improving KVM instrumentation. There are working patches posted to this thread and we would like to have/implement an automatism to allow the discovery of all this information. The information should be available to the developer who wants it, and easily/transparently so
- in true Linux fashion.

Quoted 4 lines
Quoted 4 lines

- the reaction to the 'how do we get symbols out of the guest' sub-question
was, paraphrased: 'we dont want that due to<unspecified> security threat
to XYZ selinux usecase with lots of guests'.

Quoted 5 lines
Quoted 3 lines

When I review a patch, I try to think of the difficult cases, not just the easy case.

You havent articulated an actionable reason and you have suggested no solution either,

I did suggest a symbol server, and using a well-known location, though I'm unhappy with it. Multiple guest management should be done by the appropriate tools, not qemu or implicitly.

Quoted 3 lines

you just passive-agressive backed the claim that giving developers access to the symbol space is some sort of vague 'security threat'.

Passive-aggressive? Should I see a doctor?

Quoted 12 lines

If that is not so i'd be glad to be proven wrong.

Quoted 9 lines
Quoted 9 lines

Anyone being aware of how Linux and KVM is being used on the desktop will know how detached that attitude is from the typical desktop usecase ...

Usability _never_ sucks because of lack of patches or lack of suggestions. I bet if you made the next server feature contingent on essential usability fixes they'd happen overnight - for God's sake there's been 1000 commits in the last 3 months in the Qemu repository so there's plenty of manpower...

Quoted 4 lines
Quoted 2 lines

First of all I am not a qemu maintainer. [...]

That is the crux of the matter. My experience in these threads was that no-one really seems to feel in charge of the whole thing.

I am comfortable with having someone I trust maintain qemu. While sometimes Anthony overrides me on issues where I know I'm right and he's wrong, still I prefer that to having to do everything myself, I would surely do a worse job due to overload.

I you actually look at qemu patches, the vast majority have little to do directly with kvm; and I (along with Marcelo) maintain the kvm integration in qemu.

Quoted 3 lines

Should we really wonder why
KVM usability sucks?

That wouldn't change at all if I were to maintain it, since I wouldn't start writing a GUI for it and wouldn't force other contributors to do so as a condition for accepting unrelated patches.

Quoted 9 lines
Quoted 5 lines

[...] Second, from my point of view all contributors are volunteers (perhaps their employer volunteered them, but there's no difference from my perspective). Asking them to repaint my apartment as a condition to get a patch applied is abuse. If a patch is good, it gets applied.

This is one of the weirdest arguments i've seen in this thread. Almost all the time do we make contributions conditional on the general shape of the project. Developers dont get to do just the fun stuff.

So, do you think a reply to a patch along the lines of

NAK. Improving scalability is pointless while we don't have a decent
GUI. I'll review you RCU patches
_after_ you've contributed a usable GUI.

?

Quoted 6 lines

This is a basic quid pro quo: new features introduce risks and create additional workload not just to the originating developer but on the rest of the community as well. You should check how Linus has pulled new features in the past 15 years: he very much requires the existing code to first be top-notch before he accepts new features for a given area of functionality.

For a given area, yes. It makes sense to clean up code before changing it, otherwise cruft accumulates rapidly. What you're describing is completely different and amounts to total disregard of contributors' time and effort.

Quoted 5 lines

Doing that and insisting on developers to see those imbalances as well is absolutely essential to code quality: otherwise everyone would be running around implementing just the features they are interested in, without regard for the general health of the project.

The general health of qemu in terms of code quality was indeed pretty bad and there was (and is) a massive effort to modernise it. If you're interested look at qdev and qmp. Both are efforts to improve the infrastructure rather than add features on rotten code, and very successful IMO. There was no effort to write a GUI since no one appears to be motivated to do it except you.

Quoted 6 lines

Of course, if you keep the project in two halves (KVM and Qemu), and pretend that they are separate and have little relation, imbalances of quality can mount up and you can throw your hands up and say that it's "too bad, I'm not maintaining that". It is your basic duty as a Linux maintainer to keep balances of quality. I do it all day, other maintainers do it all day.

IMO qemu quality has improved dramatically in the last year or two.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Usability suckage - and i'm not going to be popular for saying this out loud - almost always shows a basic maintainer disconnect with the real world. See your very first reactions to my 'KVM usability' observations. Read back your and Anthony's replies: total 'sure, patches welcome' kind of indifference. It is _your project_, not some other project down the road ...

Quoted 9 lines
Quoted 3 lines

I could drop everything and write a gtk GUI for qemu. Is that what you want?

No, my suggestion to you (it's up to you whether you give my opinion any weight) is to accept your mistakes and improve, and to not stand in the way of people who'd like to improve the situation. You are happy with the server features and you also made it clear that you dont feel responsible for the rest of the package - which is a big mistake IMO.

If there were no capable maintainer I would reluctantly step in. That is not the case. If I were to displace Anthony then qemu quality would suffer, or I would have to drop kvm maintainership, or, if some false modesty is allowed, perhaps both.

Quoted 3 lines

Also, you have demonstrated it in this thread that you have near zero technical clue about basic desktop and development usability matters

Neither do you. At least I have spent enough time among real usability people to know this. I don't have any pretences in this area and am happy to leave it to the experts. As infrastructure projects kvm and qemu should concentrate on providing flexible capabilities to consumers, which then expose it to users. These consumers can be server-oriented management applications, or end-user GUIs.

My preferred plan for GUIs, btw, is a plugin based approach where qemu exposes its internal objects (the same ones that are exposed to management applications) to the GUI which can then manipulate them, without being co-maintained in the same code base. This allows multiple GUIs (KDE and GNOME) and allows people with a clue to work on them.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#311 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 10 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar

Too bad - there was heavy initial opposition to the arch/x86 unification as well [and heavy opposition to tools/perf/ as well], still both worked out extremely well :-)

Did you forget that arch/x86 was a merging of a code fork that happened several years previously? Maybe that fork shouldn't have been done to begin with.

We discussed and probably timidly tried to share the sharable initially but we realized it was too time wasteful. In addition to having to adapt the code to 64bit we would also had to constantly solve another problem on top of it (see the various split on _32/_64, those takes time to achieve, maybe not huge time but still definitely some time and effort). Even in retrospect I am quite sure the way x86-64 happened was optimal and if we would go back we would do it again the exact same way even if the final object was to have a common arch/x86 (and thankfully Linus is flexible and smart enough to realize that code that isn't risking to destabilize anything shouldn't be forced out just because it's not to a totally theoretical-perfect-nitpicking-clean-state yet). It's still a lot of work do the unification later as a separate task, but it's not like if we did it immediately it would have been a lot less work. It's about the same amount of effort and we were able to defer it for later and decrease the time to market which surely has contributed to the success of x86-64.

Problem of qemu is not some lack of GUI or that it's not included in the linux kernel git tree, the definitive problem is how to merge qemu-kvm/kvm and qlx into it. If you (Avi) were the qemu maintainer I am sure there wouldn't two trees so as a developer I would totally love it, and I am sure that with you as maintainer it would have a chance to move forward with qlx on desktop virtualization without proposing to extend vnc instead to achieve a "similar" result (imagine if btrfs is published on a website and people starts to discuss if it should ever be merged ever because reinventing some part of btrfs inside ext5 might achieve ""similar"" results).

About a GUI for KVM to use on desktop distributions, that is an irrelevant concern compared to the lack of protocol more efficient than rdesktop/rdp/vnc for desktop virtualization. I've people asking me to migrate hundreds of desktops to desktop virtualization on KVM in their organizations and I tell them to use spice because I believe it's the most efficient option available (at least as far as we stick to open source open protocols), there are universities using spice on thousand of student desktops, and I think we need paravirt graphics to happen ASAP in the main qemu tree too.

In short: running KVM on the desktop is irrelevant compared to running the desktop on KVM so I suggest to focus on what is more important first ;).

Thanks,
Andrea

#312 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 22 lines · Andrea Arcangeli
Quoted 11 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar

Too bad - there was heavy initial opposition to the arch/x86 unification as well [and heavy opposition to tools/perf/ as well], still both worked out extremely well :-)

Did you forget that arch/x86 was a merging of a code fork that happened several years previously? Maybe that fork shouldn't have been done to begin with.

We discussed and probably timidly tried to share the sharable initially but we realized it was too time wasteful. In addition to having to adapt the code to 64bit we would also had to constantly solve another problem on top of it (see the various split on _32/_64, those takes time to achieve, maybe not huge time but still definitely some time and effort). Even in retrospect I am quite sure the way x86-64 happened was optimal and if we would go back we would do it again the exact same way even if the final object was to have a common arch/x86 (and thankfully Linus is flexible and smart enough to realize

Quoted 9 lines

that code that isn't risking to destabilize anything shouldn't be forced out just because it's not to a totally theoretical-perfect-nitpicking-clean-state yet). It's still a lot of work do the unification later as a separate task, but it's not like if we did it immediately it would have been a lot less work. It's about the same amount of effort and we were able to defer it for later and decrease the time to market which surely has contributed to the success of x86-64.

In hindsight decisions are much easier. I agree it was less risky to fork than to share. But if another instruction set forks out a 64-bit not-exactly-compatible variant, I'm sure we'll start out shared and not fork it, especially if the platform remains the same.

Quoted 11 lines

Problem of qemu is not some lack of GUI or that it's not included in the linux kernel git tree, the definitive problem is how to merge qemu-kvm/kvm and qlx into it. If you (Avi) were the qemu maintainer I am sure there wouldn't two trees so as a developer I would totally love it, and I am sure that with you as maintainer it would have a chance to move forward with qlx on desktop virtualization without proposing to extend vnc instead to achieve a "similar" result (imagine if btrfs is published on a website and people starts to discuss if it should ever be merged ever because reinventing some part of btrfs inside ext5 might achieve ""similar"" results).

The qemu/qemu-kvm fork is definitely hurting. Some history: when kvm started out I pulled qemu for fast hacking and, much like arch/x86_64, I couldn't destabilize qemu for something that was completely experimental (and closed source at the time). Moreover, it wasn't clear if the qemu community would be interested.

The qemu-kvm fork was designed for minimal intrusion so I could merge upstream qemu regularly. This resulted in kvm integration that was fairly ugly. Later Anthony merged a well-integrated alternative implementation (in retrospect this was a mistake IMO - we were left with a well tested high performing ugly implementation and a clean, slow, untested, and unfeatured implementation, and no one who wants to merge the two). So now it is pretty confusing to read the code which has the two alternate implementation sometimes sharing code and sometimes diverging.

Quoted 10 lines

About a GUI for KVM to use on desktop distributions, that is an irrelevant concern compared to the lack of protocol more efficient than rdesktop/rdp/vnc for desktop virtualization. I've people asking me to migrate hundreds of desktops to desktop virtualization on KVM in their organizations and I tell them to use spice because I believe it's the most efficient option available (at least as far as we stick to open source open protocols), there are universities using spice on thousand of student desktops, and I think we need paravirt graphics to happen ASAP in the main qemu tree too.

That effort will have to wait for the spice project to mature.

Quoted 4 lines

In short: running KVM on the desktop is irrelevant compared to running the desktop on KVM so I suggest to focus on what is more important first ;).

Anyone can focus on what interests them, if someone has an interest in a good desktop-on-desktop experience they should start hacking and sending patches.

Signature · 1 line
error compiling committee.c: too many arguments to function
#305 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar
Quoted 2 lines

Why does Linux AIO still suck? Why do we not have a proper interface in userspace for doing asynchronous file system operations?

Good that you mention it, i think it's an excellent example.

The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc - and between the apps that would make use of it.

No, kernel async IO sucks because it still does not play well with buffered I/O. Last time I checked (about a year ago or so), AIO syscall latencies were much worse when buffered I/O was used compared to direct I/O. Unfortunately, to achieve good performance with direct I/O, you need a HW RAID card with lots of on-board cache.

Gabor

#358 lore raw
In reply to oerg Roedel
Quoted 9 lines · oerg Roedel
Quoted 8 lines · Ingo Molnar

Unfortunately, in a previous thread the Qemu maintainer has indicated that he will essentially NAK any attempt to enhance Qemu to provide an easily discoverable, self-contained, transparent guest mount on the host side.

No technical justification was given for that NAK, despite my repeated requests to particulate the exact security problems that such an approach would cause.

Quoted 6 lines
Quoted 3 lines

If that NAK does not stand in that form then i'd like to know about it - it makes no sense for us to try to code up a solution against a standing maintainer NAK ...

I still think it is the best and most generic way to let the guest do the symbol resolution. [...]

Not really.

Quoted 6 lines

[...] This has several advantages:

1. The guest knows best about its symbol space. So this would be extensible to other guest operating systems. A brave developer may even implement symbol passing for Windows or the BSDs ;-)

Having access to the actual executable files that include the symbols achieves precisely that - with the additional robustness that all this functionality is concentrated into the host, while the guest side is kept minimal (and transparent).

Quoted 2 lines

2. The guest can decide for its own if it want to pass this inforamtion to the host-perf. No security issues at all.

It can decide whether it exposes the files. Nor are there any "security issues" to begin with.

Quoted 3 lines

3. The guest can also pass us the call-chain and we don't need to care about complicated of fetching from the guest ourself.

You need to be aware of the fact that symbol resolution is a separate step from call chain generation.

I.e. call-chains are a (entirely) separate issue, and could reasonably be done in the guest or in the host.

It has no bearing on this symbol resolution question.

Quoted 1 line

4. This way extensible to nested virtualization too.

Nested virtualization is actually already taken care of by the filesystem solution via an existing method called 'subdirectories'. If the guest offers sub-guests then those symbols will be exposed in a similar way via its own 'guest files' directory hierarchy.

I.e. if we have 'Guest-2' nested inside 'the 'Guest-Fedora-1' instance, we get:

/guests/
/guests/Guest-Fedora-1/etc/
/guests/Guest-Fedora-1/usr/

we'd also have:

/guests/Guest-Fedora-1/guests/Guest-2/

So this is taken care of automatically.

I.e. none of the four 'advantages' listed here are actually advantages over my proposed solution, so your conclusion is subsequently flawed as well.

Quoted 3 lines

How we speak to the guest was already discussed in this thread. My personal opinion is that going through qemu is an unnecessary step and we can solve that more clever and transparent for perf.

Meaning exactly what?

Thanks,

Ingo

#164 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 8 lines
Quoted 4 lines

[...] Second, from my point of view all contributors are volunteers (perhaps their employer volunteered them, but there's no difference from my perspective). Asking them to repaint my apartment as a condition to get a patch applied is abuse. If a patch is good, it gets applied.

This is one of the weirdest arguments i've seen in this thread. Almost all the time do we make contributions conditional on the general shape of the project. Developers dont get to do just the fun stuff.

Quoted 7 lines

So, do you think a reply to a patch along the lines of

NAK. Improving scalability is pointless while we don't have a decent GUI.
I'll review you RCU patches
_after_ you've contributed a usable GUI.

?

What does this have to do with RCU?

I'm talking about KVM, which is a Linux kernel feature that is useless without a proper, KVM-specific app making use of it.

RCU is a general kernel performance feature that works across the board. It helps KVM indirectly, and it helps many other kernel subsystems as well. It needs no user-space tool to be useful.

KVM on the other hand is useless without a user-space tool.

[ Theoretically you might have a fair point if it were a critical feature of
RCU for it to have a GUI, and if the main tool that made use of it sucked. But it isnt and you should know that. ]

Had you suggested the following 'NAK', applied to a different, relevant subsystem:

  |   NAK.  Improving scalability is pointless while we don't have a usable 
  | tool.  I'll review you perf patches _after_ you've contributed a usable 
  | tool.

you would have a fair point. In fact, we are doing that we are living by that. It makes absolutely zero sense to improve the scalability of perf if its usability sucks.

So where you are trying to point out an inconsistency in my argument there is none.

Quoted 8 lines
Quoted 6 lines

This is a basic quid pro quo: new features introduce risks and create additional workload not just to the originating developer but on the rest of the community as well. You should check how Linus has pulled new features in the past 15 years: he very much requires the existing code to first be top-notch before he accepts new features for a given area of functionality.

For a given area, yes. [...]

That is my precise point.

KVM is a specific subsystem or "area" that makes no sense without the user-space tooling it relates to. You seem to argue that you have no 'right' to insist on good quality of that tooling - and IMO you are fundamentally wrong with that.

Thanks,

Ingo

#87 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Anthony Liguori
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Ingo Molnar
Quoted 6 lines · Avi Kivity
Quoted 5 lines

There were two negative reactions immediately, both showed a fundamental server versus desktop bias:

- you did not accept that the most important usecase is when there is a single guest running.

Well, it isn't.

Erm, my usability points are _doubly_ true when there are multiple guests ...

The inconvenience of having to type:

  perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms \
  --guestmodules=/home/ymzhang/guest/modules top
Quoted 7 lines
Quoted 1 line

is very obvious even with a single guest. Now multiply that by more guests ...

If you want to improve this, you need to do the following:

1) Add a userspace daemon that uses vmchannel that runs in the guest and can fetch kallsyms and arbitrary modules. If that daemon lives in tools/perf, that's fine.

Adding any new daemon to an existing guest is a deployment and usability nightmare.

The basic rule of good instrumentation is to be transparent. The moment we have to modify the user-space of a guest just to monitor it, the purpose of transparent instrumentation is defeated.

That was one of the fundamental usability mistakes of Oprofile.

There is no 'perf' daemon - all the perf functionality is _built in_, and for very good reasons. It is one of the main reasons for perf's success as well.

Now Qemu is trying to repeat that stupid mistake ...

So please either suggest a different transparent solution that is technically better than the one i suggested, or you should concede the point really.

Please try think with the heads of our users and developers and dont suggest some weird ivory-tower design that is totally impractical ...

And no, you have to code none of this, we'll do all the coding. The only thing we are asking is for you to not stand in the way of good usability ...

Thanks,

Ingo

#88 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 23 lines · Ingo Molnar
Quoted 21 lines · Anthony Liguori
Quoted 19 lines · Ingo Molnar
Quoted 8 lines · Avi Kivity
Quoted 6 lines

There were two negative reactions immediately, both showed a fundamental server versus desktop bias:

- you did not accept that the most important usecase is when there is a single guest running.

Well, it isn't.

Erm, my usability points are _doubly_ true when there are multiple guests ...

The inconvenience of having to type:

   perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms \
   --guestmodules=/home/ymzhang/guest/modules top

is very obvious even with a single guest. Now multiply that by more guests ...

Quoted 9 lines
Quoted 6 lines

If you want to improve this, you need to do the following:

1) Add a userspace daemon that uses vmchannel that runs in the guest and can fetch kallsyms and arbitrary modules. If that daemon lives in tools/perf, that's fine.

Adding any new daemon to an existing guest is a deployment and usability nightmare.

Absolutely. In most cases it is not desirable, and you'll find that in a lot of cases it is not even possible - for non-technical reasons. One of the main benefits of virtualization is the ability to manage and see things from the outside.

Quoted 4 lines

The basic rule of good instrumentation is to be transparent. The moment we have to modify the user-space of a guest just to monitor it, the purpose of transparent instrumentation is defeated.

Not to mention Heisenbugs and interference.

Cheers
Antoine

Quoted 24 lines

That was one of the fundamental usability mistakes of Oprofile.

There is no 'perf' daemon - all the perf functionality is _built in_, and for very good reasons. It is one of the main reasons for perf's success as well.

Now Qemu is trying to repeat that stupid mistake ...

So please either suggest a different transparent solution that is technically better than the one i suggested, or you should concede the point really.

Please try think with the heads of our users and developers and dont suggest some weird ivory-tower design that is totally impractical ...

And no, you have to code none of this, we'll do all the coding. The only thing we are asking is for you to not stand in the way of good usability ...

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#89 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 30 lines · Antoine Martin
Quoted 17 lines · Ingo Molnar
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Ingo Molnar
Quoted 6 lines · Avi Kivity
Quoted 5 lines

There were two negative reactions immediately, both showed a fundamental server versus desktop bias:

- you did not accept that the most important usecase is when there is a single guest running.

Well, it isn't.

Erm, my usability points are _doubly_ true when there are multiple guests ...

The inconvenience of having to type:

  perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms \
  --guestmodules=/home/ymzhang/guest/modules top

is very obvious even with a single guest. Now multiply that by more guests ...

Quoted 8 lines
Quoted 5 lines

If you want to improve this, you need to do the following:

1) Add a userspace daemon that uses vmchannel that runs in the guest and can fetch kallsyms and arbitrary modules. If that daemon lives in tools/perf, that's fine.

Adding any new daemon to an existing guest is a deployment and usability nightmare.

Absolutely. In most cases it is not desirable, and you'll find that in a lot of cases it is not even possible - for non-technical reasons.

Quoted 8 lines

One of the main benefits of virtualization is the ability to manage and see things from the outside.

Quoted 3 lines

The basic rule of good instrumentation is to be transparent. The moment we have to modify the user-space of a guest just to monitor it, the purpose of transparent instrumentation is defeated.

Not to mention Heisenbugs and interference.

Correct.

Frankly, i was surprised (and taken slightly off base) by both Avi and Anthony suggesting such a clearly inferior "add a demon to the guest space" solution. It's a usability and deployment non-starter.

Furthermore, allowing a guest to integrate/mount its files into the host VFS space (which was my suggestion) has many other uses and advantages as well, beyond the instrumentation/symbol-lookup purpose.

So can we please have some resolution here and move on: the KVM maintainers should either suggest a different transparent approach, or should retract the NAK for the solution we suggested.

We very much want to make progress and want to write code, but obviously we cannot code against a maintainer NAK, nor can we code up an inferior solution either.

Thanks,

Ingo

#94 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 4 lines · Ingo Molnar

Adding any new daemon to an existing guest is a deployment and usability nightmare.

The logical conclusion of that is that everything should be built into the kernel. Where a failure brings the system down or worse. Where you have to bear the memory footprint whether you ever use the functionality or not. Where to update the functionality you need to deploy a new kernel (possibly introducing unrelated bugs) and reboot.

If userspace daemons are such a deployment and usability nightmare, maybe we should fix that instead.

Quoted 4 lines

The basic rule of good instrumentation is to be transparent. The moment we have to modify the user-space of a guest just to monitor it, the purpose of transparent instrumentation is defeated.

You have to modify the guest anyway by deploying a new kernel.

Quoted 3 lines

Please try think with the heads of our users and developers and dont suggest some weird ivory-tower design that is totally impractical ...

inetd.d style 'drop a listener config here and it will be executed on connection' should work. The listener could come with the kernel package, though I don't think it's a good idea. module-init-tools doesn't and people have survived somehow.

Quoted 3 lines

And no, you have to code none of this, we'll do all the coding. The only thing we are asking is for you to not stand in the way of good usability ...

Thanks.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#95 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 6 lines · Avi Kivity
Quoted 4 lines · Ingo Molnar

Adding any new daemon to an existing guest is a deployment and usability nightmare.

Quoted 8 lines

The logical conclusion of that is that everything should be built into the kernel. Where a failure brings the system down or worse. Where you have to bear the memory footprint whether you ever use the functionality or not. Where to update the functionality you need to deploy a new kernel (possibly introducing unrelated bugs) and reboot.

If userspace daemons are such a deployment and usability nightmare, maybe we should fix that instead.

Which userspace? Deploying *anything* in the guest can be a nightmare, including paravirt drivers if you don't have a natively supported in the OS virtual hardware backoff. Deploying things in the host OTOH is business as usual.

And you're smart enough to know that.

OG.

#90 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

Frankly, i was surprised (and taken slightly off base) by both Avi and Anthony suggesting such a clearly inferior "add a demon to the guest space" solution. It's a usability and deployment non-starter.

It's only clearly inferior if you ignore every consideration against it. It's definitely not a deployment non-starter, see the tons of daemons that come with any Linux system. The basic ones are installed and enabled automatically during system installation.

Quoted 4 lines

Furthermore, allowing a guest to integrate/mount its files into the host VFS space (which was my suggestion) has many other uses and advantages as well, beyond the instrumentation/symbol-lookup purpose.

Yes. I'm just not sure about the auto-enabling part.

Quoted 4 lines

So can we please have some resolution here and move on: the KVM maintainers should either suggest a different transparent approach, or should retract the NAK for the solution we suggested.

So long as you define 'transparent' as in 'only the guest kernel is involved' or even 'only the guest and host kernels are involved' we aren't going to make a lot of progress. I oppose shoving random bits of functionality into the kernel, especially things that are in daily use. While us developers do and will use profiling extensively, it doesn't need sit in every guest's non-swappable .text.

Quoted 4 lines

We very much want to make progress and want to write code, but obviously we cannot code against a maintainer NAK, nor can we code up an inferior solution either.

You haven't heard any NAKs, only objections. If we discuss things perhaps we can achieve something that works for everyone. If we keep turning the flames higher that's unlikely.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#96 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Olivier Galibert
Quoted 14 lines · Olivier Galibert
Quoted 12 lines · Avi Kivity
Quoted 4 lines · Ingo Molnar

Adding any new daemon to an existing guest is a deployment and usability nightmare.

The logical conclusion of that is that everything should be built into the kernel. Where a failure brings the system down or worse. Where you have to bear the memory footprint whether you ever use the functionality or not. Where to update the functionality you need to deploy a new kernel (possibly introducing unrelated bugs) and reboot.

Quoted 6 lines
Quoted 3 lines

If userspace daemons are such a deployment and usability nightmare, maybe we should fix that instead.

Which userspace? Deploying *anything* in the guest can be a nightmare, including paravirt drivers if you don't have a natively supported in the OS virtual hardware backoff.

That includes the guest kernel. If you can deploy a new kernel in the guest, presumably you can deploy a userspace package.

Quoted 3 lines

Deploying things in the
host OTOH is business as usual.

True.

Quoted 2 lines

And you're smart enough to know that.

Thanks.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#97 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Olivier Galibert
Quoted 14 lines · Olivier Galibert
Quoted 12 lines · Avi Kivity
Quoted 4 lines · Ingo Molnar

Adding any new daemon to an existing guest is a deployment and usability nightmare.

The logical conclusion of that is that everything should be built into the kernel. Where a failure brings the system down or worse. Where you have to bear the memory footprint whether you ever use the functionality or not. Where to update the functionality you need to deploy a new kernel (possibly introducing unrelated bugs) and reboot.

Quoted 6 lines
Quoted 3 lines

If userspace daemons are such a deployment and usability nightmare, maybe we should fix that instead.

Which userspace? Deploying *anything* in the guest can be a nightmare, including paravirt drivers if you don't have a natively supported in the OS virtual hardware backoff.

That includes the guest kernel. If you can deploy a new kernel in the guest, presumably you can deploy a userspace package.

Quoted 3 lines

Deploying things in the
host OTOH is business as usual.

True.

Quoted 2 lines

And you're smart enough to know that.

Thanks.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#98 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 12 lines · Avi Kivity
Quoted 11 lines · Olivier Galibert
Quoted 10 lines · Avi Kivity
Quoted 3 lines · Ingo Molnar

Adding any new daemon to an existing guest is a deployment and usability nightmare.

The logical conclusion of that is that everything should be built into the kernel. Where a failure brings the system down or worse. Where you have to bear the memory footprint whether you ever use the functionality or not. Where to update the functionality you need to deploy a new kernel (possibly introducing unrelated bugs) and reboot.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

If userspace daemons are such a deployment and usability nightmare, maybe we should fix that instead.

Which userspace? Deploying *anything* in the guest can be a nightmare, including paravirt drivers if you don't have a natively supported in the OS virtual hardware backoff.

That includes the guest kernel. If you can deploy a new kernel in the guest, presumably you can deploy a userspace package.

That's not always true.
The host admin can control the guest kernel via "kvm -kernel" easily enough, but he may or may not have access to the disk that is used in the guest. (think encrypted disks, service agreements, etc)

Antoine

Quoted 9 lines
Quoted 2 lines

Deploying things in the
host OTOH is business as usual.

True.

Quoted 1 line

And you're smart enough to know that.

Thanks.

#165 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 14 lines · Ingo Molnar
Quoted 11 lines · Avi Kivity
Quoted 9 lines
Quoted 5 lines

[...] Second, from my point of view all contributors are volunteers (perhaps their employer volunteered them, but there's no difference from my perspective). Asking them to repaint my apartment as a condition to get a patch applied is abuse. If a patch is good, it gets applied.

This is one of the weirdest arguments i've seen in this thread. Almost all the time do we make contributions conditional on the general shape of the project. Developers dont get to do just the fun stuff.

So, do you think a reply to a patch along the lines of

Quoted 8 lines
Quoted 6 lines

NAK. Improving scalability is pointless while we don't have a decent GUI.
I'll review you RCU patches
_after_ you've contributed a usable GUI.

?

What does this have to do with RCU?

The example was rcuifying kvm which took place a bit ago. Sorry, it wasn't clear.

Quoted 7 lines

I'm talking about KVM, which is a Linux kernel feature that is useless without a proper, KVM-specific app making use of it.

RCU is a general kernel performance feature that works across the board. It helps KVM indirectly, and it helps many other kernel subsystems as well. It needs no user-space tool to be useful.

Correct. So should I tell someone that has sent a patch that rcu-ified kvm in order to scale it, that I won't accept the patch unless they do some usability userspace work? say, implementing an eject button. That's what I understood you to mean.

Quoted 6 lines

KVM on the other hand is useless without a user-space tool.

[ Theoretically you might have a fair point if it were a critical feature of
RCU for it to have a GUI, and if the main tool that made use of it sucked. But it isnt and you should know that. ]

Quoted 7 lines

Had you suggested the following 'NAK', applied to a different, relevant subsystem:

   |   NAK.  Improving scalability is pointless while we don't have a usable
   | tool.  I'll review you perf patches _after_ you've contributed a usable
   | tool.

That might hold, but the tool is usable at least for some people - it runs in production. The people running it won't benefit from an eject button or any usability improvement since they run it through a centralized management tool that hides everything. They will benefit from the scalability patches. Should I still make those patches conditional on scalability work that is of no interest to the submitter?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

This is a basic quid pro quo: new features introduce risks and create additional workload not just to the originating developer but on the rest of the community as well. You should check how Linus has pulled new features in the past 15 years: he very much requires the existing code to first be top-notch before he accepts new features for a given area of functionality.

Quoted 9 lines
Quoted 2 lines

For a given area, yes. [...]

That is my precise point.

KVM is a specific subsystem or "area" that makes no sense without the user-space tooling it relates to. You seem to argue that you have no 'right' to insist on good quality of that tooling - and IMO you are fundamentally wrong with that.

kvm contains many sub-areas. I'm not going to tie unrelated things together like the GUI and sclability, configuration file format and emulator correctness, nested virtualization and qcow2 asynchronity, or other crazy combinations. People either leave en mass or become frustrated if they can't. I do reject patches touching a sub-area that I think need to be done in userspace, for example.

That's not to say kvm development is random. We have a weekly conference call where regular contributors and maintainers of both qemu and kvm participate and where we decide where to focus. Sadly the issue of a qemu GUI is not raised often. Perhaps you can participate and voice your concerns.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#99 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Antoine Martin
Quoted 4 lines · Antoine Martin
Quoted 1 line

That includes the guest kernel. If you can deploy a new kernel in the guest, presumably you can deploy a userspace package.

That's not always true.
The host admin can control the guest kernel via "kvm -kernel" easily enough, but he may or may not have access to the disk that is used in the guest. (think encrypted disks, service agreements, etc)

There is a matching -initrd argument that you can use to launch a daemon. I believe that -kernel use will be rare, though. It's a lot easier to keep everything in one filesystem.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#127 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 3 lines · Ingo Molnar

Adding any new daemon to an existing guest is a deployment and usability nightmare.

The logical conclusion of that is that everything should be built into the kernel. [...]

Only if you apply it as a totalitarian rule.

Furthermore, the logical conclusion of _your_ line of argument (applied in a totalitarian manner) is that 'nothing should be built into the kernel'.

I.e. you are arguing for microkernel Linux, while you see me as arguing for a monolithic kernel.

Reality is that we are somewhere inbetween, we are neither black nor white:
it's shades of grey.

If we want to do a good job with all this then we observe subsystems, we see how they relate to the physical world and decide about how to shape them. We identify long-term changes and re-design modularization boundaries in hindsight - when we got them wrong initially. We dont try to rationalize the status-quo.

Lets see one example of that thought process in action: Oprofile.

We saw that the modularization of oprofile was a total nightmare: a separate kernel-space and a separate user-space component, which was in constant version friction. The ABI between them was stiffling: it was hard to change it (you needed to trickle that through the tool as well which was on a different release schedule, etc.e tc.)

The result was sucky usability that never went beyond some basic 'you can do profiling' threshold. The subsystem worked well within that design box, and it was worked on by highly competent people - but it was still far, far away from the potential it could have achieved.

So we observed those problems and decided to do something about it:

- We unified the two parts into a single maintenance domain. There's the kernel-side in kernel/perf_event.c and arch/*/*/perf_event.c, plus the user-side in tools/perf/. The two are connected by a very flexible, forwards and backwards compatible ABI.

- We moved much more code into the kernel, realizing that transparent and robust instrumentation should be offered instead of punting abstractions into user-space (which is in a disadvantaged position to implement system-wide abstractions).

- We created a no-bullsh*t approach to usability. perf is by no means perfect, but it's written by developers for developers and if you report a bug to us we'll act on it before anything else. Furthermore the kernel developers do the user-space coding as well, so there's no chinese wall separating them. Kernel-space becomes aware of the intricacies of user-space and user-space developers become aware of the difficulties of kernel-space as well. It's a good mix in our experience.

The thing is (and i doubt you are surprised that i say that), i see a similar situation with KVM. The basic parameters are comparable to Oprofile: it has a kernel-space component and a KVM-specific user-space. By all practical means the two are one and the same, but are maintained as different projects.

I have followed KVM since its inception with great interest. I saw its good initial design, i tried it early on and even wrote various patches for it. So i care more about KVM than a random observer would, but this preference and passion for KVM's good technical sides does not cloud my judgement when it comes to its weaknesses.

In fact the weaknesses are far more important to identify and express publicly, so i tend to concentrate on them. Dont take this as me blasting KVM, we both know the many good aspects of KVM.

So, as i explained it earlier in greater detail the modularization of KVM into a separate kernel-space and user-space component is one of its worst current weaknesses, and it has become the main stiffling force in the way of a better KVM experience to users.

That, IMO, is the 'weakest link' of KVM today and no matter how well the rest of KVM gets improved those nice bits all get unfairly ignored when the user cannot have a usable and good desktop experience and thinks that KVM is crappy.

I think you should think outside the initial design box you have created 4 years ago, you should consider iterating the model and you should consider the alternative i suggested: move (or create) KVM tooling to tools/kvm/ and treat it as a single project from there on.

Thanks,

Ingo

#100 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Antoine Martin
Quoted 1 line

That includes the guest kernel. If you can deploy a new kernel in the guest, presumably you can deploy a userspace package.

That's not always true.
The host admin can control the guest kernel via "kvm -kernel" easily enough, but he may or may not have access to the disk that is used in the guest. (think encrypted disks, service agreements, etc)

There is a matching -initrd argument that you can use to launch a daemon.

I thought this discussion was about making it easy to deploy... and generating a custom initrd isn't easy by any means, and it requires access to the guest filesystem (and its mkinitrd tools).

Quoted 2 lines

I believe that -kernel use will be rare, though. It's a lot easier
to keep everything in one filesystem.

Well, for what it's worth, I rarely ever use anything else. My virtual disks are raw so I can loop mount them easily, and I can also switch my guest kernels from outside... without ever needing to mount those disks.

#120 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 12 lines · Avi Kivity
Quoted 11 lines · Olivier Galibert
Quoted 10 lines · Avi Kivity
Quoted 3 lines · Ingo Molnar

Adding any new daemon to an existing guest is a deployment and usability nightmare.

The logical conclusion of that is that everything should be built into the kernel. Where a failure brings the system down or worse. Where you have to bear the memory footprint whether you ever use the functionality or not. Where to update the functionality you need to deploy a new kernel (possibly introducing unrelated bugs) and reboot.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If userspace daemons are such a deployment and usability nightmare, maybe we should fix that instead.

Which userspace? Deploying *anything* in the guest can be a nightmare, including paravirt drivers if you don't have a natively supported in the OS virtual hardware backoff.

That includes the guest kernel. If you can deploy a new kernel in the guest, presumably you can deploy a userspace package.

Note that with perf we can instrument the guest with zero guest-kernel modifications as well.

We try to reduce the guest impact to a bare minimum, as the difficulties in deployment are function of the cross section surface to the guest.

Also, note that the kernel is special with regards to instrumentation: since this is the kernel project, we are doing kernel space changes, as we are doing them _anyway_. So adding symbol resolution capabilities would be a minimal addition to that - while adding a while new guest package for the demon would significantly increase the cross section surface.

Ingo

#166 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 25 lines · Avi Kivity
Quoted 9 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 7 lines
Quoted 4 lines

[...] Second, from my point of view all contributors are volunteers (perhaps their employer volunteered them, but there's no difference from my perspective). Asking them to repaint my apartment as a condition to get a patch applied is abuse. If a patch is good, it gets applied.

This is one of the weirdest arguments i've seen in this thread. Almost all the time do we make contributions conditional on the general shape of the project. Developers dont get to do just the fun stuff.

Quoted 8 lines
Quoted 7 lines

So, do you think a reply to a patch along the lines of

NAK. Improving scalability is pointless while we don't have a decent GUI.
I'll review you RCU patches
_after_ you've contributed a usable GUI.

?

What does this have to do with RCU?

The example was rcuifying kvm which took place a bit ago. Sorry, it wasn't clear.

Quoted 3 lines

I'm talking about KVM, which is a Linux kernel feature that is useless without a proper, KVM-specific app making use of it.

Quoted 8 lines
Quoted 3 lines

RCU is a general kernel performance feature that works across the board. It helps KVM indirectly, and it helps many other kernel subsystems as well. It needs no user-space tool to be useful.

Correct. So should I tell someone that has sent a patch that rcu-ified kvm in order to scale it, that I won't accept the patch unless they do some usability userspace work? say, implementing an eject button. That's what I understood you to mean.

Of course you could say the following:

' Thanks, I'll mark this for v2.6.36 integration. Note that we are not
able to add this to the v2.6.35 kernel queue anymore as the ongoing usability work already takes up all of the project's maintainer and testing bandwidth. If you want the feature to be merged sooner than that then please help us cut down on the TODO and BUGS list that can be found at XYZ. There's quite a few low hanging fruits there. '

Although this RCU example is 'worst' possible example, as it's a pure speedup change with no functionality effect.

Consider the _other_ examples that are a lot more clear:

' If you expose paravirt spilocks via KVM please also make sure the KVM
tooling can make use of it, has an option for it to configure it, and that it has sufficient efficiency statistics displayed in the tool for admins to monitor.'

' If you create this new paravirt driver then please also make sure it can
be configured in the tooling. '

' Please also add a testcase for this bug to tools/kvm/testcases/ so we dont
repeat this same mistake in the future. '

I'd say most of the high-level feature work in KVM has tooling impact.

And note the important arguement that the 'eject button' thing would not occur naturally in a project that is well designed and has a good quality balance. It would only occur in the transitionary period if a big lump of lower-quality code is unified with higher-quality code. Then indeed a lot of pressure gets created on the people working on the high-quality portion to go over and fix the low-quality portion.

Which, btw., is an unconditonally good thing ...

But even an RCU speedup can be fairly linked/ordered to more pressing needs of a project.

Really, the unification of two tightly related pieces of code has numerous clear advantages. Please give it some thought before rejecting it.

Thanks,

Ingo

#91 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 4 lines · Ingo Molnar

Frankly, i was surprised (and taken slightly off base) by both Avi and Anthony suggesting such a clearly inferior "add a demon to the guest space" solution. It's a usability and deployment non-starter.

It's only clearly inferior if you ignore every consideration against it. It's definitely not a deployment non-starter, see the tons of daemons that come with any Linux system. [...]

Avi, please dont put arguments into my mouth that i never made.

My (clearly expressed) argument was that:

_a new guest-side demon is a transparent instrumentation non-starter_

What is so hard to understand about that simple concept? Instrumentation is good if it's as transparent as possible.

Of course lots of other features can be done via a new user-space package ...

Thanks,

Ingo

#101 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Antoine Martin
Quoted 9 lines · Antoine Martin
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Antoine Martin
Quoted 1 line

That includes the guest kernel. If you can deploy a new kernel in the guest, presumably you can deploy a userspace package.

That's not always true.
The host admin can control the guest kernel via "kvm -kernel" easily enough, but he may or may not have access to the disk that is used in the guest. (think encrypted disks, service agreements, etc)

There is a matching -initrd argument that you can use to launch a daemon.

I thought this discussion was about making it easy to deploy... and generating a custom initrd isn't easy by any means, and it requires access to the guest filesystem (and its mkinitrd tools).

That's true. You need to run mkinitrd anyway, though, unless your guest is non-modular and non-lvm.

Quoted 3 lines
Quoted 2 lines

I believe that -kernel use will be rare, though. It's a lot easier
to keep everything in one filesystem.

Well, for what it's worth, I rarely ever use anything else. My virtual disks are raw so I can loop mount them easily, and I can also switch my guest kernels from outside... without ever needing to mount those disks.

Curious, what do you use them for?

btw, if you build your kernel outside the guest, then you already have access to all its symbols, without needing anything further.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#102 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 8 lines · Avi Kivity
Quoted 3 lines

Well, for what it's worth, I rarely ever use anything else. My virtual disks are raw so I can loop mount them easily, and I can also switch my guest kernels from outside... without ever needing to mount those disks.

Curious, what do you use them for?

btw, if you build your kernel outside the guest, then you already have access to all its symbols, without needing anything further.

There's two errors with your argument:

1) you are assuming that it's only about kernel symbols

Look at this 'perf report' output:

# Samples: 7127509216
#
# Overhead Command Shared Object Symbol

# ........  ..........  .............................  ......
#
    19.14%         git  git                            [.] lookup_object
    15.16%        perf  git                            [.] lookup_object
     4.74%        perf  libz.so.1.2.3                  [.] inflate
     4.52%         git  libz.so.1.2.3                  [.] inflate
     4.21%        perf  libz.so.1.2.3                  [.] inflate_table
     3.94%         git  libz.so.1.2.3                  [.] inflate_table
     3.29%         git  git                            [.] find_pack_entry_one
     3.24%         git  libz.so.1.2.3                  [.] inflate_fast
     2.96%        perf  libz.so.1.2.3                  [.] inflate_fast
     2.96%         git  git                            [.] decode_tree_entry
     2.80%        perf  libc-2.11.90.so                [.] __strlen_sse42
     2.56%         git  libc-2.11.90.so                [.] __strlen_sse42
     1.98%        perf  libc-2.11.90.so                [.] __GI_memcpy
     1.71%        perf  git                            [.] decode_tree_entry
     1.53%         git  libc-2.11.90.so                [.] __GI_memcpy
     1.48%         git  git                            [.] lookup_blob
     1.30%         git  git                            [.] process_tree
     1.30%        perf  git                            [.] process_tree
     0.90%        perf  git                            [.] tree_entry
     0.82%        perf  git                            [.] lookup_blob
     0.78%         git  [kernel.kallsyms]              [k] kstat_irqs_cpu

kernel symbols are only a small portion of the symbols. (a single line in this case)

To get to those other symbols we have to read the ELF symbols of those binaries in the guest filesystem, in the post-processing/reporting phase. This is both complex to do and relatively slow so we dont want to (and cannot) do this at sample time from IRQ context or NMI context ...

Also, many aspects of reporting are interactive so it's done lazily or on-demand. So we need ready access to the guest filesystem - for those guests which decide to integrate with the host for this.

2) the 'SystemTap mistake'

You are assuming that the symbols of the kernel when it got built got saved properly and are discoverable easily. In reality those symbols can be erased by a make clean, can be modified by a new build, can be misplaced and can generally be hard to find because each distro puts them in a different installation path.

My 10+ years experience with kernel instrumentation solutions is that kernel-driven, self-sufficient, robust, trustable, well-enumerated sources of information work far better in practice.

The thing is, in this thread i'm forced to repeat the same basic facts again and again. Could you _PLEASE_, pretty please, when it comes to instrumentation details, at least _read the mails_ of the guys who actually ... write and maintain Linux instrumentation code? This is getting ridiculous really.

Thanks,

Ingo

#128 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Ingo Molnar

Adding any new daemon to an existing guest is a deployment and usability nightmare.

Quoted 8 lines
Quoted 3 lines

The logical conclusion of that is that everything should be built into the kernel. [...]

Only if you apply it as a totalitarian rule.

Furthermore, the logical conclusion of _your_ line of argument (applied in a totalitarian manner) is that 'nothing should be built into the kernel'.

I'm certainly a minimalist, but that doesn't follow. Things that require privileged access, or access to the page cache, or that can't be made to perform otherwise should certainly be in the kernel. That's why I submitted kvm for inclusion in the first place.

If it's something that can work just as well in userspace but we can't be bothered to fix any 'deployment nightmares', then they shouldn't be in the kernel. Examples include lvm2 and mdadm (which truly are 'deployment nightmares' - you need to start them before you have access to your filesystem - yet they work somehow).

Quoted 3 lines

I.e. you are arguing for microkernel Linux, while you see me as arguing for a monolithic kernel.

No. I'm arguing for reducing bloat wherever possible. Kernel code is more expensive than userspace code in every metric possible.

Quoted 9 lines

Reality is that we are somewhere inbetween, we are neither black nor white:
it's shades of grey.

If we want to do a good job with all this then we observe subsystems, we see how they relate to the physical world and decide about how to shape them. We identify long-term changes and re-design modularization boundaries in hindsight - when we got them wrong initially. We dont try to rationalize the status-quo.

I'm not for the status quo either - I'm for reducing the kernel code footprint whereever it doesn't impact performance or break clean interfaces.

Quoted 13 lines

Lets see one example of that thought process in action: Oprofile.

We saw that the modularization of oprofile was a total nightmare: a separate kernel-space and a separate user-space component, which was in constant version friction. The ABI between them was stiffling: it was hard to change it (you needed to trickle that through the tool as well which was on a different release schedule, etc.e tc.)

The result was sucky usability that never went beyond some basic 'you can do profiling' threshold. The subsystem worked well within that design box, and it was worked on by highly competent people - but it was still far, far away from the potential it could have achieved.

Quoted 7 lines

So we observed those problems and decided to do something about it:

- We unified the two parts into a single maintenance domain. There's the kernel-side in kernel/perf_event.c and arch/*/*/perf_event.c, plus the user-side in tools/perf/. The two are connected by a very flexible, forwards and backwards compatible ABI.

That's useful because perf is still small. If it were a full fledged 350KLOC GUI, then most of the development would concentrate on the GUI and very little (relatively) would have to do with the kernel.

Qemu is in that state today. Please, please look at the recent commits and check how many have actually anything to do with kvm, and how many with everything else.

Quoted 5 lines

- We moved much more code into the kernel, realizing that transparent and robust instrumentation should be offered instead of punting abstractions into user-space (which is in a disadvantaged position to implement system-wide abstractions).

No argument.

I have a similar experience with kvm. The user/kernel break is at the cpu virtualization level - that is kvm is solely responsible for emulating a cpu and userspace is responsible for emulating devices. An exception was made for the PIC/IOAPIC/PIT due to performance considerations - they are emulated in the kernel as well.

A common FAQ is why do we not emulate real-mode instructions in qemu. The answer is that it the interface to kvm would be insane - it would emulate a partial cpu. All other users of that interface would have to implement an emulator (there is also a practical argument - the qemu emulator does not implement atomics correctly wrt other threads).

Quoted 8 lines

- We created a no-bullsh*t approach to usability. perf is by no means perfect, but it's written by developers for developers and if you report a bug to us we'll act on it before anything else. Furthermore the kernel developers do the user-space coding as well, so there's no chinese wall separating them. Kernel-space becomes aware of the intricacies of user-space and user-space developers become aware of the difficulties of kernel-space as well. It's a good mix in our experience.

Excellent. However qemu is written by developers for their users, and their users are not worried about an eject button in the qemu SDL interface, or about running the qemu command line by hand. They have complicated management interfaces that do everything, so we concentrate, for example, on a robust RPC interface for qemu. That means nothing for command line users but is critical for our users.

I am not _against_ excellent support for command-line users, but I am not going to divert the resources I control (=me) into something that is not needed by my users. I encourage anyone who wants to improve usability to subscribe to qemu-devel and contribute, they will receive a warm welcome.

Quoted 5 lines

The thing is (and i doubt you are surprised that i say that), i see a similar situation with KVM. The basic parameters are comparable to Oprofile: it has a kernel-space component and a KVM-specific user-space. By all practical means the two are one and the same, but are maintained as different projects.

There is tight cooperation between the maintainers and developers of these two projects. Most developers are subscibed to both mailing lists and many have contributed to both repositories. There does not appear to be a problem with release schedules.

Quoted 15 lines

I have followed KVM since its inception with great interest. I saw its good initial design, i tried it early on and even wrote various patches for it. So i care more about KVM than a random observer would, but this preference and passion for KVM's good technical sides does not cloud my judgement when it comes to its weaknesses.

In fact the weaknesses are far more important to identify and express publicly, so i tend to concentrate on them. Dont take this as me blasting KVM, we both know the many good aspects of KVM.

So, as i explained it earlier in greater detail the modularization of KVM into a separate kernel-space and user-space component is one of its worst current weaknesses, and it has become the main stiffling force in the way of a better KVM experience to users.

Quoted 5 lines

That, IMO, is the 'weakest link' of KVM today and no matter how well the rest of KVM gets improved those nice bits all get unfairly ignored when the user cannot have a usable and good desktop experience and thinks that KVM is crappy.

Thanks. I agree the user experience when launching qemu from the command line is miles behind virtualbox and vmware workstation. What I disagree is that this is how a typical user will first experience kvm - most distributions now integrate virt-manager which allows you much better graphical interaction.

Unfortunately, virt-manager is still server-oriented (for example, it uses VNC instead of displaying directly to X), and is hardly polished to the same level as commercial tools. However, you cannot force someone to write good desktop integration for qemu, it has to come from someone with the itch, the experience, the capability, and the time.

Quoted 5 lines

I think you should think outside the initial design box you have created 4 years ago, you should consider iterating the model and you should consider the alternative i suggested: move (or create) KVM tooling to tools/kvm/ and treat it as a single project from there on.

Do you really think that tools/kvm/ would create a good GUI for kvm? lkml is hardly the place where GUI developers and designers congregate. Please, if any of you GUI experts are reading this, please consider contributing to qemu directly.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#167 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar

Of course you could say the following:

' Thanks, I'll mark this for v2.6.36 integration. Note that we are not
able to add this to the v2.6.35 kernel queue anymore as the ongoing usability work already takes up all of the project's maintainer and testing bandwidth. If you want the feature to be merged sooner than that then please help us cut down on the TODO and BUGS list that can be found at XYZ. There's quite a few low hanging fruits there. '

That would be shooting at my own foot as well as the contributor's since I badly want that RCU stuff, and while a GUI would be nice, that itch isn't on my back.

You're asking a developer and a maintainer to put off the work they're interested in, in order to work on something someone else is interested in, but not contributing the work.

Quoted 10 lines

Although this RCU example is 'worst' possible example, as it's a pure speedup change with no functionality effect.

Consider the _other_ examples that are a lot more clear:

' If you expose paravirt spilocks via KVM please also make sure the KVM
tooling can make use of it, has an option for it to configure it, and that it has sufficient efficiency statistics displayed in the tool for admins to monitor.'

Quoted 6 lines

' If you create this new paravirt driver then please also make sure it can
be configured in the tooling. '

' Please also add a testcase for this bug to tools/kvm/testcases/ so we dont
repeat this same mistake in the future. '

All three happen quite commonly in qemu/kvm development. Of course someone who develops a feature also develops a patch that exposes it in qemu. There are several test cases in qemu-kvm.git/kvm/user/test.

Quoted 2 lines

I'd say most of the high-level feature work in KVM has tooling impact.

Usually, pretty low. Plumbing down a feature is usually trivial. There are exceptions, of course - smp is only supported in qemu-kvm.git, not in upstream qemu.git, for example. In any case of course the work is done in both qemu and kvm - do you think people develop features to see them bitrot?

Quoted 7 lines

And note the important arguement that the 'eject button' thing would not occur naturally in a project that is well designed and has a good quality balance. It would only occur in the transitionary period if a big lump of lower-quality code is unified with higher-quality code. Then indeed a lot of pressure gets created on the people working on the high-quality portion to go over and fix the low-quality portion.

It's a matter of priorities.

Quoted 5 lines

Which, btw., is an unconditonally good thing ...

But even an RCU speedup can be fairly linked/ordered to more pressing needs of a project.

Pressing to whom?

Quoted 3 lines

Really, the unification of two tightly related pieces of code has numerous clear advantages. Please give it some thought before rejecting it.

I'm not blind to the advantages. Dropping tcg would be the biggest of them by far (much more than moving the repository, IMO). But there are disadvantages as well.

Around two years ago I seriously considered forking qemu, at this time I do not think it is a good idea.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.