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!
task_structin kernel. And during scheduling these data might be accessed. Imagine that I am writing a module that counts #context-switch for each thread (I know this functionality exists in original kernel so it's just an example. It's difficult to explain what my module really doing here clearly in a few words.)