gpu: nvgpu: utils: improve CCM for rbtree

This improves the code complexity of the rbtree function
nvgpu_rbtree_unlink() by creating helper functions swap_in_new_child()
and adopt_children().

This reduces the TCC metric to 9.

JIRA NVGPU-4097

Change-Id: I2eb9ddf9a74478600874c71dab2b1267b5148b7b
Signed-off-by: Philip Elcan <pelcan@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2205845
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com>
Reviewed-by: Nicolas Benech <nbenech@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Philip Elcan
2019-09-25 17:12:38 -04:00
committed by Alex Waterman
parent 5e0bf2bb7a
commit b5f1135ba8

View File

@@ -295,6 +295,35 @@ static void delete_fixup(struct nvgpu_rbtree_node **root,
} }
} }
static void swap_in_new_child(struct nvgpu_rbtree_node *old,
struct nvgpu_rbtree_node *new,
struct nvgpu_rbtree_node **root)
{
if (old->parent != NULL) {
if (old == old->parent->left) {
old->parent->left = new;
} else {
old->parent->right = new;
}
} else {
*root = new;
}
}
static void adopt_children(struct nvgpu_rbtree_node *old,
struct nvgpu_rbtree_node *new)
{
new->left = old->left;
if (old->left != NULL) {
old->left->parent = new;
}
new->right = old->right;
if (old->right != NULL) {
old->right->parent = new;
}
}
void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node, void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
struct nvgpu_rbtree_node **root) struct nvgpu_rbtree_node **root)
{ {
@@ -330,16 +359,8 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
if (x != NULL) { if (x != NULL) {
x->parent = parent_of_x; x->parent = parent_of_x;
} }
/* update the parent's links */
if (y->parent != NULL) { swap_in_new_child(y, x, root);
if (y == y->parent->left) {
y->parent->left = x;
} else {
y->parent->right = x;
}
} else {
*root = x;
}
y_was_black = !y->is_red; y_was_black = !y->is_red;
if (y != z) { if (y != z) {
@@ -347,27 +368,11 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
* the memory for z can be freed * the memory for z can be freed
*/ */
y->parent = z->parent; y->parent = z->parent;
if (z->parent != NULL) { swap_in_new_child(z, y, root);
if (z == z->parent->left) {
z->parent->left = y;
} else {
z->parent->right = y;
}
} else {
*root = y;
}
y->is_red = z->is_red; y->is_red = z->is_red;
y->left = z->left; adopt_children(z, y);
if (z->left != NULL) {
z->left->parent = y;
}
y->right = z->right;
if (z->right != NULL) {
z->right->parent = y;
}
if (parent_of_x == z) { if (parent_of_x == z) {
parent_of_x = y; parent_of_x = y;