diff mbox series

[-next,3/8] block, bfq: factor out code to update 'active_entities'

Message ID 20220514090522.1669270-4-yukuai3@huawei.com (mailing list archive)
State New, archived
Headers show
Series multiple cleanup patches for bfq | expand

Commit Message

Yu Kuai May 14, 2022, 9:05 a.m. UTC
Current code is a bit ugly and hard to read.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/bfq-wf2q.c | 61 +++++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 29 deletions(-)

Comments

Jan Kara May 19, 2022, 11:04 a.m. UTC | #1
On Sat 14-05-22 17:05:17, Yu Kuai wrote:
> Current code is a bit ugly and hard to read.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>

Yeah, looks a bit better. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  block/bfq-wf2q.c | 61 +++++++++++++++++++++++++-----------------------
>  1 file changed, 32 insertions(+), 29 deletions(-)
> 
> diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c
> index 2f3fb45a32c3..c58568a4b009 100644
> --- a/block/bfq-wf2q.c
> +++ b/block/bfq-wf2q.c
> @@ -230,6 +230,26 @@ static void bfq_dec_busy_queues(struct bfq_queue *bfqq)
>  		bfqq->bfqd->num_groups_with_busy_queues--;
>  }
>  
> +static void bfq_inc_active_entities(struct bfq_entity *entity)
> +{
> +	struct bfq_sched_data *sd = entity->sched_data;
> +	struct bfq_group *bfqg = container_of(sd, struct bfq_group, sched_data);
> +	struct bfq_data *bfqd = (struct bfq_data *)bfqg->bfqd;
> +
> +	if (bfqg != bfqd->root_group)
> +		bfqg->active_entities++;
> +}
> +
> +static void bfq_dec_active_entities(struct bfq_entity *entity)
> +{
> +	struct bfq_sched_data *sd = entity->sched_data;
> +	struct bfq_group *bfqg = container_of(sd, struct bfq_group, sched_data);
> +	struct bfq_data *bfqd = (struct bfq_data *)bfqg->bfqd;
> +
> +	if (bfqg != bfqd->root_group)
> +		bfqg->active_entities--;
> +}
> +
>  #else /* CONFIG_BFQ_GROUP_IOSCHED */
>  
>  static bool bfq_update_parent_budget(struct bfq_entity *next_in_service)
> @@ -250,6 +270,14 @@ static void bfq_dec_busy_queues(struct bfq_queue *bfqq)
>  {
>  }
>  
> +static void bfq_inc_active_entities(struct bfq_entity *entity)
> +{
> +}
> +
> +static void bfq_dec_active_entities(struct bfq_entity *entity)
> +{
> +}
> +
>  #endif /* CONFIG_BFQ_GROUP_IOSCHED */
>  
>  /*
> @@ -476,11 +504,6 @@ static void bfq_active_insert(struct bfq_service_tree *st,
>  {
>  	struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
>  	struct rb_node *node = &entity->rb_node;
> -#ifdef CONFIG_BFQ_GROUP_IOSCHED
> -	struct bfq_sched_data *sd = NULL;
> -	struct bfq_group *bfqg = NULL;
> -	struct bfq_data *bfqd = NULL;
> -#endif
>  
>  	bfq_insert(&st->active, entity);
>  
> @@ -491,17 +514,10 @@ static void bfq_active_insert(struct bfq_service_tree *st,
>  
>  	bfq_update_active_tree(node);
>  
> -#ifdef CONFIG_BFQ_GROUP_IOSCHED
> -	sd = entity->sched_data;
> -	bfqg = container_of(sd, struct bfq_group, sched_data);
> -	bfqd = (struct bfq_data *)bfqg->bfqd;
> -#endif
>  	if (bfqq)
>  		list_add(&bfqq->bfqq_list, &bfqq->bfqd->active_list);
> -#ifdef CONFIG_BFQ_GROUP_IOSCHED
> -	if (bfqg != bfqd->root_group)
> -		bfqg->active_entities++;
> -#endif
> +
> +	bfq_inc_active_entities(entity);
>  }
>  
>  /**
> @@ -578,29 +594,16 @@ static void bfq_active_extract(struct bfq_service_tree *st,
>  {
>  	struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
>  	struct rb_node *node;
> -#ifdef CONFIG_BFQ_GROUP_IOSCHED
> -	struct bfq_sched_data *sd = NULL;
> -	struct bfq_group *bfqg = NULL;
> -	struct bfq_data *bfqd = NULL;
> -#endif
>  
>  	node = bfq_find_deepest(&entity->rb_node);
>  	bfq_extract(&st->active, entity);
>  
>  	if (node)
>  		bfq_update_active_tree(node);
> -
> -#ifdef CONFIG_BFQ_GROUP_IOSCHED
> -	sd = entity->sched_data;
> -	bfqg = container_of(sd, struct bfq_group, sched_data);
> -	bfqd = (struct bfq_data *)bfqg->bfqd;
> -#endif
>  	if (bfqq)
>  		list_del(&bfqq->bfqq_list);
> -#ifdef CONFIG_BFQ_GROUP_IOSCHED
> -	if (bfqg != bfqd->root_group)
> -		bfqg->active_entities--;
> -#endif
> +
> +	bfq_dec_active_entities(entity);
>  }
>  
>  /**
> -- 
> 2.31.1
>
diff mbox series

Patch

diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c
index 2f3fb45a32c3..c58568a4b009 100644
--- a/block/bfq-wf2q.c
+++ b/block/bfq-wf2q.c
@@ -230,6 +230,26 @@  static void bfq_dec_busy_queues(struct bfq_queue *bfqq)
 		bfqq->bfqd->num_groups_with_busy_queues--;
 }
 
+static void bfq_inc_active_entities(struct bfq_entity *entity)
+{
+	struct bfq_sched_data *sd = entity->sched_data;
+	struct bfq_group *bfqg = container_of(sd, struct bfq_group, sched_data);
+	struct bfq_data *bfqd = (struct bfq_data *)bfqg->bfqd;
+
+	if (bfqg != bfqd->root_group)
+		bfqg->active_entities++;
+}
+
+static void bfq_dec_active_entities(struct bfq_entity *entity)
+{
+	struct bfq_sched_data *sd = entity->sched_data;
+	struct bfq_group *bfqg = container_of(sd, struct bfq_group, sched_data);
+	struct bfq_data *bfqd = (struct bfq_data *)bfqg->bfqd;
+
+	if (bfqg != bfqd->root_group)
+		bfqg->active_entities--;
+}
+
 #else /* CONFIG_BFQ_GROUP_IOSCHED */
 
 static bool bfq_update_parent_budget(struct bfq_entity *next_in_service)
@@ -250,6 +270,14 @@  static void bfq_dec_busy_queues(struct bfq_queue *bfqq)
 {
 }
 
+static void bfq_inc_active_entities(struct bfq_entity *entity)
+{
+}
+
+static void bfq_dec_active_entities(struct bfq_entity *entity)
+{
+}
+
 #endif /* CONFIG_BFQ_GROUP_IOSCHED */
 
 /*
@@ -476,11 +504,6 @@  static void bfq_active_insert(struct bfq_service_tree *st,
 {
 	struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
 	struct rb_node *node = &entity->rb_node;
-#ifdef CONFIG_BFQ_GROUP_IOSCHED
-	struct bfq_sched_data *sd = NULL;
-	struct bfq_group *bfqg = NULL;
-	struct bfq_data *bfqd = NULL;
-#endif
 
 	bfq_insert(&st->active, entity);
 
@@ -491,17 +514,10 @@  static void bfq_active_insert(struct bfq_service_tree *st,
 
 	bfq_update_active_tree(node);
 
-#ifdef CONFIG_BFQ_GROUP_IOSCHED
-	sd = entity->sched_data;
-	bfqg = container_of(sd, struct bfq_group, sched_data);
-	bfqd = (struct bfq_data *)bfqg->bfqd;
-#endif
 	if (bfqq)
 		list_add(&bfqq->bfqq_list, &bfqq->bfqd->active_list);
-#ifdef CONFIG_BFQ_GROUP_IOSCHED
-	if (bfqg != bfqd->root_group)
-		bfqg->active_entities++;
-#endif
+
+	bfq_inc_active_entities(entity);
 }
 
 /**
@@ -578,29 +594,16 @@  static void bfq_active_extract(struct bfq_service_tree *st,
 {
 	struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
 	struct rb_node *node;
-#ifdef CONFIG_BFQ_GROUP_IOSCHED
-	struct bfq_sched_data *sd = NULL;
-	struct bfq_group *bfqg = NULL;
-	struct bfq_data *bfqd = NULL;
-#endif
 
 	node = bfq_find_deepest(&entity->rb_node);
 	bfq_extract(&st->active, entity);
 
 	if (node)
 		bfq_update_active_tree(node);
-
-#ifdef CONFIG_BFQ_GROUP_IOSCHED
-	sd = entity->sched_data;
-	bfqg = container_of(sd, struct bfq_group, sched_data);
-	bfqd = (struct bfq_data *)bfqg->bfqd;
-#endif
 	if (bfqq)
 		list_del(&bfqq->bfqq_list);
-#ifdef CONFIG_BFQ_GROUP_IOSCHED
-	if (bfqg != bfqd->root_group)
-		bfqg->active_entities--;
-#endif
+
+	bfq_dec_active_entities(entity);
 }
 
 /**