Skip to contentSkip to conversation

cfq-iosched: Fix a gcc 4.5 warning and put some comments

PATCH In review Vivek Goyal 3 participants 5 messages Oct 21, 2010 – Oct 22, 2010 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cfq-iosched: Fix a gcc 4.5 warning and put some comments

- Andi encountedred following warning with gcc 4.5

linux/block/cfq-iosched.c: In function ‘cfq_dispatch_requests’:
linux/block/cfq-iosched.c:2156:3: warning: array subscript is above array bounds

- Warning happens due to following code.

slice = group_slice * count /

		max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_prio],
		cfq_group_busy_queues_wl(cfqd->serving_prio, cfqd, cfqg));

gcc is complaining about cfqg->busy_queues_avg[] being indexed by CFQ prio classes (RT, BE and IDLE) while the array size is only 2.

- At run time, we never access cfqg->busy_queues_avg[IDLE] and return from function before this code hits.

- To fix warning increase the array size though it will remain unused. This patch also puts some comments to clarify some of the confusions.

- I have taken Jens's patch and modified it a bit.

- Compile tested with gcc 4.4 and boot tested. I don't have gcc 4.5 running, Andi can you please test it with gcc 4.5 to make sure it worked.

---
 block/cfq-iosched.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
block/cfq-iosched.c +13 -3
Index: linux-2.6-block/block/cfq-iosched.c
===================================================================
@@ -160,6 +160,7 @@ enum wl_prio_t {
 	BE_WORKLOAD = 0,
 	RT_WORKLOAD = 1,
 	IDLE_WORKLOAD = 2,
+	CFQ_PRIO_NR,
 };
 
 /*
@@ -184,10 +185,19 @@ struct cfq_group {
 	/* number of cfqq currently on this group */
 	int nr_cfqq;
 
-	/* Per group busy queus average. Useful for workload slice calc. */
-	unsigned int busy_queues_avg[2];
 	/*
-	 * rr lists of queues with requests, onle rr for each priority class.
+	 * Per group busy queus average. Useful for workload slice calc. We
+	 * create the array for each prio class but at run time it is used
+	 * only for RT and BE class and slot for IDLE class remains unused.
+	 * This is primarily done to avoid confusion and a gcc warning.
+	 */
+	unsigned int busy_queues_avg[CFQ_PRIO_NR];
+	/*
+	 * rr lists of queues with requests. We maintain service trees for
+	 * RT and BE classes. These trees are subdivided in subclasses
+	 * of SYNC, SYNC_NOIDLE and ASYNC based on workload type. For IDLE
+	 * class there is no subclassification and all the cfq queues go on
+	 * a single tree service_tree_idle.
 	 * Counts are embedded in the cfq_rb_root
 	 */
 	struct cfq_rb_root service_trees[2][3];
Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · Vivek Goyal

- Andi encountedred following warning with gcc 4.5

linux/block/cfq-iosched.c: In function ‘cfq_dispatch_requests’:
linux/block/cfq-iosched.c:2156:3: warning: array subscript is above array bounds

- Warning happens due to following code.

slice = group_slice * count /

		max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_prio],
		cfq_group_busy_queues_wl(cfqd->serving_prio, cfqd, cfqg));

gcc is complaining about cfqg->busy_queues_avg[] being indexed by CFQ prio classes (RT, BE and IDLE) while the array size is only 2.

- At run time, we never access cfqg->busy_queues_avg[IDLE] and return from function before this code hits.

- To fix warning increase the array size though it will remain unused. This patch also puts some comments to clarify some of the confusions.

- I have taken Jens's patch and modified it a bit.

Quoted 7 lines

- Compile tested with gcc 4.4 and boot tested. I don't have gcc 4.5 running, Andi can you please test it with gcc 4.5 to make sure it worked.

#2 lore raw
In reply to Vivek Goyal
Quoted 23 lines · Vivek Goyal

- Andi encountedred following warning with gcc 4.5

linux/block/cfq-iosched.c: In function ‘cfq_dispatch_requests’:
linux/block/cfq-iosched.c:2156:3: warning: array subscript is above array bounds

- Warning happens due to following code.

slice = group_slice * count /

		max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_prio],
		cfq_group_busy_queues_wl(cfqd->serving_prio, cfqd, cfqg));

gcc is complaining about cfqg->busy_queues_avg[] being indexed by CFQ prio classes (RT, BE and IDLE) while the array size is only 2.

- At run time, we never access cfqg->busy_queues_avg[IDLE] and return from function before this code hits.

- To fix warning increase the array size though it will remain unused. This patch also puts some comments to clarify some of the confusions.

- I have taken Jens's patch and modified it a bit.

Quoted 7 lines

- Compile tested with gcc 4.4 and boot tested. I don't have gcc 4.5 running, Andi can you please test it with gcc 4.5 to make sure it worked.

Thanks, I'll put this one in. BTW, you can't just add a signed-off-by from me (or anyone else, for that matter), they have to be provided explicitly by each individual.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 28 lines · Jens Axboe
Quoted 27 lines · Vivek Goyal

- Andi encountedred following warning with gcc 4.5

linux/block/cfq-iosched.c: In function ‘cfq_dispatch_requests’:
linux/block/cfq-iosched.c:2156:3: warning: array subscript is above array bounds

- Warning happens due to following code.

slice = group_slice * count /

		max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_prio],
		cfq_group_busy_queues_wl(cfqd->serving_prio, cfqd, cfqg));

gcc is complaining about cfqg->busy_queues_avg[] being indexed by CFQ prio classes (RT, BE and IDLE) while the array size is only 2.

- At run time, we never access cfqg->busy_queues_avg[IDLE] and return from function before this code hits.

- To fix warning increase the array size though it will remain unused. This patch also puts some comments to clarify some of the confusions.

- I have taken Jens's patch and modified it a bit.

- Compile tested with gcc 4.4 and boot tested. I don't have gcc 4.5 running, Andi can you please test it with gcc 4.5 to make sure it worked.

Quoted 7 lines
Quoted 3 lines

Thanks, I'll put this one in. BTW, you can't just add a signed-off-by from me (or anyone else, for that matter), they have to be provided explicitly by each individual.

Ok, sorry about that.

So in general, if I happen to pick somebody's patch, modify it and repost it, how do I reflect the Signed-off-by of original author.

Thanks
Vivek

#4 lore raw
Quoted 33 lines · Vivek Goyal
Quoted 32 lines · Jens Axboe
Quoted 30 lines · Vivek Goyal

- Andi encountedred following warning with gcc 4.5

linux/block/cfq-iosched.c: In function ‘cfq_dispatch_requests’:
linux/block/cfq-iosched.c:2156:3: warning: array subscript is above array bounds

- Warning happens due to following code.

slice = group_slice * count /

		max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_prio],
		cfq_group_busy_queues_wl(cfqd->serving_prio, cfqd, cfqg));

gcc is complaining about cfqg->busy_queues_avg[] being indexed by CFQ prio classes (RT, BE and IDLE) while the array size is only 2.

- At run time, we never access cfqg->busy_queues_avg[IDLE] and return from function before this code hits.

- To fix warning increase the array size though it will remain unused. This patch also puts some comments to clarify some of the confusions.

- I have taken Jens's patch and modified it a bit.

- Compile tested with gcc 4.4 and boot tested. I don't have gcc 4.5 running, Andi can you please test it with gcc 4.5 to make sure it worked.

Quoted 8 lines
Quoted 3 lines

Thanks, I'll put this one in. BTW, you can't just add a signed-off-by from me (or anyone else, for that matter), they have to be provided explicitly by each individual.

Ok, sorry about that.

So in general, if I happen to pick somebody's patch, modify it and repost it, how do I reflect the Signed-off-by of original author.

What I usually do is leave the original signed-off-by, then describe my changes, then add my signed-off-by. I think that is acceptable behaviour. It's very different from adding a signed-off-by to something that hasn't been signed-off by the original author yet that's legally an issue. But hey, IANAL :-)

Signature · 1 line
Jens Axboe