Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ritesh55555
Copy link
Contributor

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.

@ritesh55555 ritesh55555 force-pushed the dead_task branch 2 times, most recently from 0abba02 to 8202c69 Compare February 10, 2025 05:35
Comment on lines 192 to 216
* Description:
* This function removes a task's pid and name info from dead list
* if present. This should be called after creating a task.
Copy link
Contributor

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.

Copy link
Contributor

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.


leave_critical_section(flags);

return "NA";
Copy link
Contributor

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.

@ritesh55555 ritesh55555 force-pushed the dead_task branch 3 times, most recently from 39a932a to 51db4ea Compare February 11, 2025 06:42
} else {
dead_pid_t *pid_prev;
while (pid_head) {
if (pid_head->pid == pid) {
Copy link
Contributor

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.

Comment on lines 192 to 216
* Description:
* This function removes a task's pid and name info from dead list
* if present. This should be called after creating a task.
Copy link
Contributor

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.

@ritesh55555 ritesh55555 force-pushed the dead_task branch 3 times, most recently from f382bd6 to 8834581 Compare February 11, 2025 08:01

dead_pid_t *allocate_pid_node(int pid)
{
dead_pid_t *node = (dead_pid_t *)kmm_malloc(sizeof(dead_pid_t));
Copy link
Contributor

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.

*
****************************************************************************/

void sched_addDeadtask(int pid, char *name)
Copy link
Contributor

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.

* 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 */
Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

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.

@ritesh55555 ritesh55555 force-pushed the dead_task branch 7 times, most recently from 519599d to f2aae2c Compare February 21, 2025 11:33
* None
*
****************************************************************************/

Copy link
Collaborator

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?

Copy link
Contributor

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.

*
****************************************************************************/

void sched_deadtasklistinit();
Copy link
Collaborator

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,
Copy link
Collaborator

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

Copy link
Contributor

@samsung-singh samsung-singh left a 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++;
Copy link
Contributor

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.

@ritesh55555 ritesh55555 force-pushed the dead_task branch 2 times, most recently from 25001ca to b465587 Compare February 24, 2025 10:52
* None
*
****************************************************************************/

Copy link
Contributor

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.

leave_critical_section(flags);
}

void work_removedeadtask(void *arg)
Copy link
Contributor

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)
Copy link
Contributor

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.

ritesh55555 added 2 commits February 25, 2025 14:20
	- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants