[SOLVED] L4T: Compiling simple Kernel Module fails!

Hi,

In my current project with the Jetson TK1 (Linux for Tegra (LT4) 21.1 R) I want to do some performance test. So I want to make use of the CPU’s PMU (Performance Monitor Unit)to read the “Cycle Counter”.
As the access from the user-mode is denied, I have to load a kernel module which sets a flag in the specific register:
cite:
Access permissions
Normally the Performance Monitors registers are accessible from all modes executing at PL1 or higher. However, the access permissions for PMU registers can be modified by:
• setting the PMUSERENR.EN bit to 1, to permit access from software executing in User mode, for example for instrumentation and profiling purposes

ref.: http://liris.cnrs.fr/~mmrissa/lib/exe/fetch.php?media=armv7-a-r-manual.pdf#E36.CIHHCBHC (page 2328)

Furthermore I found two interesting links, which already solved this:
1) User-mode performance counters for ARM/Linux:

So far so good, but when I try to compile one of these modules, I get a strange error:

ubuntu@tegra-ubuntu:~/Downloads/enable_arm_pmu-master$ sudo make runtests
[sudo] password for ubuntu:
KMOD ko/enable_arm_pmu.ko
/usr/src/linux-headers-3.10.40-ged4f697/scripts/recordmcount: 1: /usr/src/linux-headers-3.10.40-ged4f697/scripts/recordmcount: Syntax error: “(” unexpected
make[3]: *** [/home/ubuntu/Downloads/enable_arm_pmu-master/ko/enable_arm_pmu.o] Error 2
make[2]: *** [module/home/ubuntu/Downloads/enable_arm_pmu-master/ko] Error 2
make[1]: *** [all] Error 2
make: *** [ko/enable_arm_pmu.ko] Error 2

FYI:
$ uname -r
3.10.40-ged4f697

Then I thought, that the code might be incompatible and so I made the tutorial in the “The Linux Kernel Module Programming Guide” (simplest kernel module possible ;) ) :
-link: Hello, World (part 1): The Simplest Module

And I got the same error again.
Q1: So what the hell is going on?
Q2: Are the wrong Kernel headers installed? I didn’t change a thing, the system is almost freshly set up.
Q3: What has to be considered? (I am quite new to this topic…)

I hope some can help me.

Kind Regards,
Roland

HelloKernel.tar.gz (1.76 KB)

Hi,

I found the following page:

Which says in Step 2 to:
sudo apt-get install build-essential checkinstall

And in Step 4 to download the Kernel-Header:
sudo apt-get install kernel-headers-3.10.40 → Unable to loacate package.

But anyway, when I try to compile the “simplest Kernel Modul”:
sudo make

then I seems to pass the mysterious error… and ends in a new error:

--------------------------------------
ubuntu@tegra-ubuntu:~/Downloads/HelloKernel$ sudo make
[sudo] password for ubuntu: 
make -C /lib/modules/3.10.40-ged4f697/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-3.10.40-ged4f697'
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf --silentoldconfig Kconfig
make[1]: Leaving directory `/usr/src/linux-headers-3.10.40-ged4f697'
make[1]: Entering directory `/usr/src/linux-headers-3.10.40-ged4f697'
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  Generating include/generated/mach-types.h
  HOSTCC  scripts/dtc/checks.o
  HOSTCC  scripts/dtc/data.o
  HOSTCC  scripts/dtc/dtc-lexer.lex.o
  HOSTCC  scripts/dtc/dtc-parser.tab.o
  HOSTCC  scripts/dtc/dtc.o
  HOSTCC  scripts/dtc/flattree.o
  HOSTCC  scripts/dtc/fstree.o
  HOSTCC  scripts/dtc/livetree.o
  HOSTCC  scripts/dtc/srcpos.o
  HOSTCC  scripts/dtc/treesource.o
  HOSTCC  scripts/dtc/util.o
  HOSTLD  scripts/dtc/dtc
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  CC      scripts/mod/devicetable-offsets.s
  GEN     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/modpost.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/pnmtologo
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/bin2c
  HOSTCC  scripts/recordmcount
  HOSTCC  scripts/sortextable
make[3]: *** No rule to make target `fs/cifs/cifsfs.o', needed by `fs/cifs/cifs.o'.  Stop.
make[2]: *** [fs/cifs] Error 2
make[1]: *** [fs] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.10.40-ged4f697'
make: *** [all] Error 2
-----------------------------------------------------------

FYI:
I can remember to install a package for cifs some weeks ago, to mount a directory of our buildserver(jenkins)… Maybe this package is here the source of evil. What do you think?

Kind regards

A large number of errors are possible based simply on configuration. I have not read all of the links you gave as reference, but a few things will always remain as initial questions: Are you compiling from Jetson, or cross-compiling? Did you use /proc/config.gz for initial configuration? What changes were made to this configuration before building?

Hi linuxdev,

I am compiling from Jetson.

Ahhhh thank you for the hint with the: /proc/config.gz (As I already mentioned, I am quite new to this topic and it seems that I am suffering from some background knowledge.)

Here is a explanation for “Customizing a Kernel”: http://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/ch08.html

“What changes were made to this configuration before building?”
I made no changes at all and I did not unpack the /proc/config.gz to the ~/linux directory as described in the above link.

I thought it is sufficient to have the following dirs:
/lib/modules/3.10.40-ged4f697/build
/usr/src/linux-headers-3.10.40-ged4f697/

Q: Can you give an explanation why the /proc/config.gz is necessary?
Q: Do I have to unpack the /proc/config.gz to the ~/linux directory?

Thank you a lot!
KR

I don’t think there is a standard place for the kernel or it’s headers. And there’s no standard way to install just the kernel headers from a kernel build to a system. There are distro specific ways though.

I suggest that you compile the whole kernel on Jetson to get the proper kernel build tree, including the headers. Technically you should also then use the kernel but maybe that’s not needed.

Download the kernel sources matching the release you are running:
https://developer.nvidia.com/linux-tegra

gunzip the /proc/config.gz as “.config” to the kernel source tree and compile.

Change the enable_arm_pmu/ko/Makefile’s KDIR to point to your new kernel tree (or pass the KDIR as a parameter to the make command).

PS. related to your first post, what does the following say:

file /usr/src/linux-headers-3.10.40-ged4f697/scripts/recordmcount

Hi again,

Now it is working as desired. I just followed the instructions given in:
“/dev/hello_world: A Simple Introduction to Device Drivers under Linux”
link: http://www.linuxdevcenter.com/pub/a/linux/2007/07/05/devhelloworld-a-simple-introduction-to-device-drivers-under-linux.html?page=1

The most important thing was to install the package:
[i]"The module-assistant package for Debian installs packages and configures the system to build out-of-kernel modules. Install it with:

$ sudo apt-get install module-assistant

That’s it; you can now compile kernel modules…"[/i]

It seems that the content of the"The Linux Kernel Module Programming Guide" is deprecated.
So I changed the interface of the init and exit funtion, added the module_init and module_exit macro, and added the module information macros at the bottom of the file.

/*  
 *  hello-1.c - The simplest kernel module.
 */
#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_INFO */

static int __init Enter_module(void)
{
	printk(KERN_INFO "Hello world 1.\n");

	/* 
	 * A non 0 return means init_module failed; module can't be loaded. 
	 */
	return 0;
}

static void __exit Leave_module(void)
{
	printk(KERN_INFO "Goodbye world 1.\n");
}

module_init(Enter_module)
module_exit(Leave_module)

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Roland J...");
MODULE_DESCRIPTION("\"Hello, world 1!\" minimal module");
MODULE_VERSION("with_printk");

After calling make I could call sudo insmod ./hello-1.ko and sudo remmod ./hello-1.

Now I am quite happy and keep you posted if the thing with PMU for reading the Cycle Counter is working :)

Thank you all for your support!!!
KR,
Roland

I am getting the exact same error, even after following the OPs final fix:

sudo apt-get install module-assistant

I am running the following kernel on the TX2

4.4.38-tegra

I’m following the same tutorial that the OP linked to in the final post:
http://www.linuxdevcenter.com/pub/a/linux/2007/07/05/devhelloworld-a-simple-introduction-to-device-drivers-under-linux.html?page=1

Knowing what steps you took to set up for compile, and whether the compile was natively on the Jetson, versus cross compile on PC will change many things. Initial configuration as well will change many things. In the original posts the “no rule to make target” type error is very different from one build to the next even if that wording is exactly the same…the trick is seeing the output before the error hits along wiht the actual error so that it is known what failed prior to that output can be figured out.

@linuxdev, thank you for the response. As mentioned, I am following the exact same steps as the OP; that is, I am compiling on the TX2.

I was able to figure out how to fix this issue! It is frustrating… after searching “Google” for probably an hour, I finally decided to post a reply to this thread. Within 5 minutes of posting my response, I found this:

[url]https://github.com/thoughtpolice/enable_arm_pmu/issues/4[/url]

This may be helpful to others.