Data structure for each task in the Linux kernel module

I am writing a loadable kernel module for Linux. And I need to store some data for each task in the Linux kernel (this data will be used in the scheduler callback).

I know that I can modify the struct task_struct and insert my own fields. But since I am ready to write a relatively clean kernel module, I cannot change any code in the source Linux source tree.

It is also possible to save some mapping from struct task_struct to my data in a hash table. But that seems to be too hard.

I read the answer in Enter local data in the Linux kernel module . He mentioned the use of private_data in a struct file . But in order to get a struct file , each thread requires each thread. And there is no way to query data for each task using struct task_struct . (Since I need to use the data in the scheduler callback)

My question is: is there a simple and clean way that allows me to register the data structure for each task in the Linux kernel without changing the struct task_struct ?

Many thanks!

+7
c linux data-structures linux-kernel
source share
1 answer

The only simple and clean way that allows you to register the data structure for each task is to change the struct task_struct .

Modules are for optional parts of the kernel; they can only use functions that are explicitly exported from the underlying kernel. if you need to change the base kernel, you can no longer use modules.

+3
source share

All Articles