Issue in inserting a kernel module for performance counters on Jetson Nano

Hello All,

I am testing an kernel module which creates perf events on every core and count the total number of L2D_CACHE_REFILL.

System details are : NVIDIA Jetson nano, 
OS: Ubuntu  18.04.6 LTS,
Kernel: 4.9.255, L4T: 32.7.3, 
Jetpack: 4.6.3

insmod is inserting module in kernel space. But throws WARNING message in kernel log file. The screenshot of dmesg command is :

This warning states that at line no. 199, the function armpmu_start() is throwing an warning.

I tried checking the kernel source code. The kernel code snippet for armpmu_start function from drivers/perf/arm_pmu file is as below:

enter image description here

Also when I try to remove the module with rmmod command my jetson nano board is restarting.

Here are the few perf APIs the kernel module is using:

  1. Creating attributes structure of the perf event
 struct perf_event_attr sched_perf_hw_attr = {
        		.type		= PERF_TYPE_RAW,
        		.config		= 0x17,
        		.size		= sizeof (struct perf_event_attr),
        		.pinned		= 1,
        		.disabled	= 1,
        		.exclude_kernel	= 1,
        		.sample_period	= budget
        	};
  1. Creating perf event with event_overflow_callback function
     event = perf_event_create_kernel_counter (&sched_perf_hw_attr,
     						  cpu,
     						  NULL,
     						  event_overflow_callback,
     						  NULL
     						  );
  1. Code to start the counter
perf_event_enable (event);
event->pmu->add (event, PERF_EF_START);
  1. Code to stop the counter

event->pmu->stop (event, PERF_EF_UPDATE);
event->pmu->del(event,0);

  1. In the event_overflow_callback function following activities are performed.

Stopping counter

event->pmu->stop (event, PERF_EF_UPDATE);

Enable performance counter

event->pmu->start (event, PERF_EF_RELOAD);

The same kernel module is working fine on Jetson Nvidia Xavier NX without any warning messages.
Any help in diagnosing the issue is highly appreciated.
Also kindly suggest a methods of debugging Linux kernel modules on embedded devices like Nvidia jetson boards. That will help me in gaining more knowledge.
Thank in advance.

When I remove the module using rmmod command, I am getting following messages on kernel log file
image
and the system reboots…

Thanks

Does it the relative topic with below link?
Could you give more information how do you modify to reproduce it.

Thanks

Hi Shane,
Thank you for your reply.
The referred topic is not related to my issue.
The perf tool is installed by building from source code.

sudo perf list command produce following output (partial screenshot is taken)

For getting L2D_CACHE_REFILL events, i could run the command sudo perf stat -a -e armv8_pmuv3/l2d_cache_refill/ sleep 2 and get the event count as :
image

Also, I can extract per core statistics using the following command
sudo perf stat -a --per-core -e armv8_pmuv3/l2d_cache_refill/ sleep 2
image

pert tool in user-space is working perfectly fine.
I am trying to configure github repository with a kernel module which configures and counts the perf events. I have done necessary kernel patching and rebuilding of the kernel. In the kernel module, Linux perf APIs are used to create , to enable , to start, to stop etc. perf event counters, which are listed in my first post. As described in the first post, it throws the warning when I insert the kernel module and the nano board reboots when I remove the module.

Timely help in this aspect is highly appreciated.
Thank you.