Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

per-task data structure in linux kernel module

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

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

It is also possible to maintain some sort of mapping from struct task_struct to my data in a hash table. But it seem to be a little too heavy-weight.

I've read the answer in Thread local data in linux kernel module. It mentioned using private_data in struct file. But it needs every thread to open it in order to get an struct file. And there's no way the query the per-task data with a struct task_struct. (As I need to use the data in a scheduler callback)

My question is: is there any simple and clean way that allows me registering per-task data-structure in Linux kernel without modifying struct task_struct?

Many thanks!

like image 943
Naruil Avatar asked Aug 28 '13 01:08

Naruil


1 Answers

The only simple and clean way that allows you to register a per-task data structure is to modify struct task_struct.

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

like image 161
CL. Avatar answered Oct 03 '22 18:10

CL.