Results 1 to 3 of 3
How do I add a field to the struct task_struct in the sched.h file, the field consists of a linked list with a special non primitive node?
say i have ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 05-01-2012 #1Just Joined!
- Join Date
- May 2012
- Posts
- 2
Add a complex list to task_struct in the linux kernel
How do I add a field to the struct task_struct in the sched.h file, the field consists of a linked list with a special non primitive node?
say i have this structure:
struct Node{
int counter;
char* buffer;
int sum;
}
and so on, and I want to add a list of such nodes? I don't want to re-implement the list with
struct Node{
int counter;
char* buffer;
int sum;
Node* next;
}
but I want to use struct list_head with the generic kernel list and not my implementation. But adding struct list_head to the task_struct just gives me another instance of task_struct while I want to add my special list with my specific fields.
In terms of C++, i want to add List to the struct_task so the file scehd.h will look something like
struct task_struct {
.
.
.
List<Node> myList;
.
.
}
How do i do that and how do I then how do initialize my node in the INIT_TASK macro?
What i'm trying to do is save a list of messages sent to each process, so i'm trying to make each process hold the string and the total number of messages the process received as my node. I have no idea how to implement it with the kernel list, and I don't want to add my own list.
- 05-02-2012 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,160
1. You cannot use C++ code such as templates like List<node> in kernel code.
2. Just add the Node* member to struct task_struct, and then recompile the entire kernel tree.
Do note, that none of the other kernel code that use task_struct will respect your link unless you modify them to do so. That means, if some kernel code were to zero out a task_struct item, if you had linked an active Node member to it in your code, it would be lost to that task_struct entity. So, before you do this, you need to do a thorough analysis of the entire kernel usage of task_struct. It may be limited to a few key modules, or it may be quite pervasive.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 05-02-2012 #3Just Joined!
- Join Date
- May 2012
- Posts
- 2
Well, that's the thing- I don't want to add my own Node and modify it, but i want to use the generic list in the kernel's list.h. My question is more syntactic than anything: how can I add a "struct list_head" (from list.h) to hold list elements of type "Node" (my complex structure) and add it to the task_struct, and then how to initialize it and add/remove to the list using generic list functions.
If i add to task_struct the field "struct list_head myList", if I undrestand correctly, it gives me just another instance of a linked list called myList who's element's are "struct task_struct". And I want to add a list of myNodes. Unsure how it's done syntactically and the usage of the list ADT.


Reply With Quote
