Skip to contentSkip to conversation

gauss.c: correct the stddev initializtion

RFC PATCH In review Feng Tang 2 participants 4 messages Mar 17, 2020 Library code

lore
Share & tools
lore

Feng Tang

author
#0 lore raw

RFC PATCH 1/1 gauss.c: correct the stddev initializtion

---
 lib/gauss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/gauss.c +1 -1
index 1d24e187..3f84dbc6 100644
@@ -51,7 +51,7 @@ void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
 	gs->nranges = nranges;
 
 	if (dev != 0.0) {
-		gs->stddev = ceil((double) (nranges * 100.0) / dev);
+		gs->stddev = ceil((double)(nranges * dev) / 100.0);
 		if (gs->stddev > nranges / 2)
 			gs->stddev = nranges / 2;
 	}
Signature · 1 line
2.20.1
#1 lore raw
Quoted 10 lines · Feng Tang
---
 lib/gauss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/gauss.c +0 -0
index 1d24e187..3f84dbc6 100644

lib/gauss.c void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev, · line 57

Quoted 8 lines
lib/gauss.c +1 -1
@@ -51,7 +51,7 @@ void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
 	gs->nranges = nranges;
 
 	if (dev != 0.0) {
-		gs->stddev = ceil((double) (nranges * 100.0) / dev);
+		gs->stddev = ceil((double)(nranges * dev) / 100.0);
 		if (gs->stddev > nranges / 2)
 			gs->stddev = nranges / 2;
 	}

Looks like I very helpfully did not include a reference to to where this is from... Can you expand on the need for the patch?

Signature · 1 line
Jens Axboe
author
#2 lore raw

Hi,

Quoted 13 lines · Jens Axboe
Quoted 12 lines · Feng Tang
---
 lib/gauss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/gauss.c +0 -0
index 1d24e187..3f84dbc6 100644
@@ -51,7 +51,7 @@ void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
 	gs->nranges = nranges;
 
Quoted 9 lines

lib/gauss.c void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev, · line 57

Quoted 6 lines
lib/gauss.c +1 -1
 	if (dev != 0.0) {
-		gs->stddev = ceil((double) (nranges * 100.0) / dev);
+		gs->stddev = ceil((double)(nranges * dev) / 100.0);
 		if (gs->stddev > nranges / 2)
 			gs->stddev = nranges / 2;
 	}

Looks like I very helpfully did not include a reference to to where this is from... Can you expand on the need for the patch?

Thanks for your prompt response!

I tried to run fio with "random_distribution=normal:20" as one parameter, and didn't notice it has difference with "normal:50", so I went to read the source code, as the man page says the deviation ranges from 0 to 100, so this gs->stddev will always be "nranges/2". Or I misunderstood the man page?

Thanks,
Feng

Quoted 3 lines
Signature · 2 lines
-- 
Jens Axboe
#3 lore raw
Quoted 26 lines · Feng Tang

Hi,

Quoted 13 lines · Jens Axboe
Quoted 12 lines · Feng Tang
---
 lib/gauss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/gauss.c +0 -0
index 1d24e187..3f84dbc6 100644
@@ -51,7 +51,7 @@ void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
 	gs->nranges = nranges;
 
Quoted 9 lines

lib/gauss.c void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev, · line 57

Quoted 6 lines
lib/gauss.c +1 -1
 	if (dev != 0.0) {
-		gs->stddev = ceil((double) (nranges * 100.0) / dev);
+		gs->stddev = ceil((double)(nranges * dev) / 100.0);
 		if (gs->stddev > nranges / 2)
 			gs->stddev = nranges / 2;
 	}

Looks like I very helpfully did not include a reference to to where this is from... Can you expand on the need for the patch?

Quoted 7 lines

Thanks for your prompt response!

I tried to run fio with "random_distribution=normal:20" as one parameter, and didn't notice it has difference with "normal:50", so I went to read the source code, as the man page says the deviation ranges from 0 to 100, so this gs->stddev will always be "nranges/2". Or I misunderstood the man page?

Nope I think you are right, I looked up the original change that made it a parameter:

https://git.kernel.dk/cgit/fio/commit/?id=3cdb8cf38198d5cea73074d427ae310320e1d65f

and that clearly indicates that your patch is correct. I'll apply it, thanks!

Signature · 1 line
Jens Axboe