* [PATCH] Introduce callchains for guests
@ 2023-08-31 8:09 Tianyi Liu
2023-08-31 9:45 ` kernel test robot
0 siblings, 1 reply; 2+ messages in thread
From: Tianyi Liu @ 2023-08-31 8:09 UTC (permalink / raw)
To: peterz, acme, linux-perf-users, linux-kernel
Cc: mingo, mark.rutland, alexander.shishkin, jolsa, namhyung, irogers,
adrian.hunter, Tianyi Liu
This patch serves as the foundation for enabling callchains for guests,
(used by `perf kvm`). This functionality is useful for me, and I
noticed it holds the top spot on the perf wiki TODO list [1], so I'd like
to implement it. This patch introduces a `perf_callchain_guest` interface,
which different architectures can implement according to their own
specifications.
This is part of a series of patches. Since these patches are spread across
various modules like perf, kvm, arch/*, I plan to first submit some
foundational patches and gradually submit the complete implementation.
The full implementation can be found at [2], and it has been tested on
an x86_64 machine.
Since perf tools currently do not support callchain types with
PERF_CONTEXT_GUEST*, I temporarily used PERF_CONTEXT_KERNEL for ease of
testing and validation. This will be rectified once the perf tools patches
are applied.
Furthermore, do you think it's necessary to introduce a new guest filter
in the parameters of `get_perf_callchain`? Alternatively, should we add
two separate filters, `guest_user` and `guest_kernel`, to make these
filters entirely independent?
This is my first time submitting a patch for a new feature in the kernel,
and I would greatly appreciate any suggestions.
[1] https://perf.wiki.kernel.org/index.php/Todo
[2] https://github.com/i-Pear/linux/pull/2/files
Signed-off-by: Tianyi Liu <i.pear@outlook.com>
---
kernel/events/callchain.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index 1273be84392c..eacb6ccf7034 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -45,6 +45,10 @@ __weak void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
{
}
+__weak void perf_callchain_guest(struct perf_callchain_entry_ctx *entry)
+{
+}
+
static void release_callchain_buffers_rcu(struct rcu_head *head)
{
struct callchain_cpus_entries *entries;
@@ -183,6 +187,7 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
struct perf_callchain_entry *entry;
struct perf_callchain_entry_ctx ctx;
int rctx;
+ unsigned int guest_state;
entry = get_callchain_entry(&rctx);
if (!entry)
@@ -194,6 +199,26 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
ctx.contexts = 0;
ctx.contexts_maxed = false;
+ guest_state = perf_guest_state();
+ if (guest_state) {
+ if (add_mark) {
+ if (guest_state & PERF_GUEST_USER)
+ /*
+ * TODO: Change this to PERF_CONTEXT_GUEST_USER,
+ * which is currently not recognized by perf utils.
+ */
+ perf_callchain_store_context(&ctx, PERF_CONTEXT_KERNEL);
+ else
+ /*
+ * TODO: Change this to PERF_CONTEXT_GUEST_KERNEL,
+ * which is currently not recognized by perf utils.
+ */
+ perf_callchain_store_context(&ctx, PERF_CONTEXT_KERNEL);
+ }
+ perf_callchain_guest(&ctx);
+ goto exit_put;
+ }
+
if (kernel && !user_mode(regs)) {
if (add_mark)
perf_callchain_store_context(&ctx, PERF_CONTEXT_KERNEL);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Introduce callchains for guests
2023-08-31 8:09 [PATCH] Introduce callchains for guests Tianyi Liu
@ 2023-08-31 9:45 ` kernel test robot
0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2023-08-31 9:45 UTC (permalink / raw)
To: Tianyi Liu, acme, linux-perf-users, linux-kernel
Cc: oe-kbuild-all, mingo, mark.rutland, alexander.shishkin, jolsa,
namhyung, irogers, adrian.hunter, Tianyi Liu
Hi Tianyi,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tip/perf/core]
[also build test WARNING on acme/perf/core linus/master v6.5 next-20230831]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tianyi-Liu/Introduce-callchains-for-guests/20230831-161333
base: tip/perf/core
patch link: https://lore.kernel.org/r/SY4P282MB10848199D3F93AA47A845B8B9DE5A%40SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM
patch subject: [PATCH] Introduce callchains for guests
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230831/202308311743.uvv4Ras8-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230831/202308311743.uvv4Ras8-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308311743.uvv4Ras8-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> kernel/events/callchain.c:48:13: warning: no previous prototype for 'perf_callchain_guest' [-Wmissing-prototypes]
48 | __weak void perf_callchain_guest(struct perf_callchain_entry_ctx *entry)
| ^~~~~~~~~~~~~~~~~~~~
vim +/perf_callchain_guest +48 kernel/events/callchain.c
47
> 48 __weak void perf_callchain_guest(struct perf_callchain_entry_ctx *entry)
49 {
50 }
51
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-31 9:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-31 8:09 [PATCH] Introduce callchains for guests Tianyi Liu
2023-08-31 9:45 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).