walk_tg_tree_from的图解
在遍历task_group的时候,需要会调用到walk_tg_tree_from
函数,从函数注释看,这个函数的流程是:
以from
为根节点,当进入一个节点时调用down
回调函数,当离开一个节点时调用up
函数。这个函数
采用的是深度遍历。
下面用一张图来说明:
/*
* Iterate task_group tree rooted at *from, calling @down when first entering a
* node and @up when leaving it for the final time.
*
* Caller must hold rcu_lock or sufficient equivalent.
*/
int walk_tg_tree_from(struct task_group *from,
tg_visitor down, tg_visitor up, void *data)
{
struct task_group *parent, *child;
int ret;
parent = from;
down:
ret = (*down)(parent, data);
if (ret)
goto out;
list_for_each_entry_rcu(child, &parent->children, siblings) {
parent = child;
goto down;
up:
continue;
}
ret = (*up)(parent, data);
if (ret || parent == from)
goto out;
child = parent;
parent = parent->parent;
if (parent)
goto up;
out:
return ret;
}