-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os/kernel/sched: Add structure to save dead task info #6661
base: master
Are you sure you want to change the base?
Conversation
0abba02
to
8202c69
Compare
os/kernel/sched/sched_addDeadtask.c
Outdated
* Description: | ||
* This function removes a task's pid and name info from dead list | ||
* if present. This should be called after creating a task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wont this create confusion if we are only printing the most recent name of that pid,
at time1, pid1 is task1, it reserved some memory and terminated, but didnt free it.
at time2, pid1 is reassigned to task2, now according to the above logic, when dead threads list is printed, the memory allocated by task1 will be wrongly shown as allocated by task2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is ok. The max pid count in our system is 65535 (16 bit pid_t). If this is exhausted, then our counter will roll over and start checking from zero. It will allocate a pid of a previously dead task for the new task. If we want to completely avoid the situation that you mentioned, then we need to keep storing all previous task names also, I think it might be an overkill.
@sunghan-chang Please let us know your opinion.
os/kernel/sched/sched_addDeadtask.c
Outdated
|
||
leave_critical_section(flags); | ||
|
||
return "NA"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"NA" looks too general, maybe @sunghan-chang can suggest a better one.
39a932a
to
51db4ea
Compare
os/kernel/sched/sched_addDeadtask.c
Outdated
} else { | ||
dead_pid_t *pid_prev; | ||
while (pid_head) { | ||
if (pid_head->pid == pid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to check this?
Since we will add when task dies and remove when new task is created, I think this check is an overhead.
If we remove this check, then we can directly insert the new node at the beginning of the list.
os/kernel/sched/sched_addDeadtask.c
Outdated
* Description: | ||
* This function removes a task's pid and name info from dead list | ||
* if present. This should be called after creating a task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is ok. The max pid count in our system is 65535 (16 bit pid_t). If this is exhausted, then our counter will roll over and start checking from zero. It will allocate a pid of a previously dead task for the new task. If we want to completely avoid the situation that you mentioned, then we need to keep storing all previous task names also, I think it might be an overkill.
@sunghan-chang Please let us know your opinion.
f382bd6
to
8834581
Compare
os/kernel/sched/sched_deadtask.c
Outdated
|
||
dead_pid_t *allocate_pid_node(int pid) | ||
{ | ||
dead_pid_t *node = (dead_pid_t *)kmm_malloc(sizeof(dead_pid_t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us use zalloc so that the node data is set to zero at the time of creation.
os/kernel/sched/sched_deadtask.c
Outdated
* | ||
****************************************************************************/ | ||
|
||
void sched_addDeadtask(int pid, char *name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow naming convention. No capital letters.
os/kernel/sched/sched_deadtask.c
Outdated
* Note: whenever we create a task with pid no same as a pid no | ||
* that is already present in the dead pid list, we always remove | ||
* it from dead pid list. So when we add a dead pid node, we can | ||
* directly add it in the head of the dead pid list as there is no copy */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is not required here.
Or we can change as below:
NOTE: In order to make sure that same pid is not added twice to the dead task list, we will always call sched_removedeadtask at the time of task or thread creation.
os/kernel/sched/sched_releasetcb.c
Outdated
@@ -154,6 +154,10 @@ int sched_releasetcb(FAR struct tcb_s *tcb, uint8_t ttype) | |||
} | |||
#endif | |||
|
|||
#ifdef CONFIG_SCHED_SAVE_DEADTASK | |||
sched_addDeadtask(tcb->pid, tcb->name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us use LPWORK work queue for adding and removing data on the dead list.
519599d
to
f2aae2c
Compare
os/include/tinyara/sched.h
Outdated
* None | ||
* | ||
****************************************************************************/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to expose this API's ? can't this be static to scheduler itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we will always add and remove tasks from the list using work queue, we can make these apis static.
Let us keep only the sched_getdeadtaskname api here.
os/include/tinyara/sched.h
Outdated
* | ||
****************************************************************************/ | ||
|
||
void sched_deadtasklistinit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take care of coding guidelines for the declaration .
void sched_deadtasklistinit() -> void sched_deadtasklistinit(void)
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update the PR with the log where it can display all the dead task info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pr add new data structure to store info of dead task name , this change is good to merge .
|
||
/* point to newly created name node */ | ||
pid_node->name_ptr = name_node; | ||
name_node->ref_cnt++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is highly unlikely event but ref_cnt++ inside critical section would be safe.
25001ca
to
b465587
Compare
os/include/tinyara/sched.h
Outdated
* None | ||
* | ||
****************************************************************************/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we will always add and remove tasks from the list using work queue, we can make these apis static.
Let us keep only the sched_getdeadtaskname api here.
os/kernel/sched/sched_deadtask.c
Outdated
leave_critical_section(flags); | ||
} | ||
|
||
void work_removedeadtask(void *arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These apis should be made static.
* | ||
****************************************************************************/ | ||
|
||
void sched_savedeadtaskinfo(pid_t pid, const char *task_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to declare these apis in the header file.
- This commit implements code to save dead task pid and name value. It creates two list structure, one for pid list and another for name list that is used to store dead task info. This also adds api to get thread name of a dead task whenever required.
This commit adds code to show dead thread names along with dead thread pid, when showing heap info data.
b465587
to
53eef80
Compare
This commit implements code to save dead task pid and name value. It creates two list structure, one for pid list and another for name list that is used to store dead task info. This also adds api to get thread name of a dead task whenever required.