-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/netinet/cc: Switch from deprecated random() to prng32() #1162
sys/netinet/cc: Switch from deprecated random() to prng32() #1162
Conversation
Hoping that someone with familiarity of these components can review this. I feel like it looks like an innocent enough set of changes, but I don't want to get something wrong here. |
CC @tuexen |
sys/netinet/cc/cc_cdg.c
Outdated
p = (UINT_MAX / (1 << EXP_PREC)) * probexp[idx]; | ||
backoff = (prng32() < p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why p is still int, not uint32_t or uint_t?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think that's a mistake. Should I do unit32_t
for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I'd say p should be unsigned for correct comparison, and it should have the same range for the probability to work. So there should be uint32_t
and UINT32_MAX
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the feedback! I've adjusted p
accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. But why did you leave UINT_MAX in its assignment instead of UINT32_MAX I proposed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad! I think I missed that.
@@ -161,7 +162,7 @@ should_backoff(int qdly, int maxqdly, struct chd *chd_data) | |||
{ | |||
unsigned long p, rand; | |||
|
|||
rand = random(); | |||
rand = prng32(); | |||
|
|||
if (qdly < V_chd_qthresh) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wonder whether should_backoff() arguments here and below should really be signed, whether they makes sense and if so, whether it is handled right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also am not sure why these were signed. I don't know hardly a thing about the code in question. Was just trying to take a stab at removing the deprecated random()
call where possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know this code either, so it was just a thought. What you should to though is use UINT32_MAX for RANDOM_MAX (or just inline it) and uint32_t for p. rand variable I would just remove, inlining the prng32() call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I did most of what you suggested, but I found that the rand variable was referenced twice, so it seemed necessary to keep it assigned. Is that alright?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, looks like RANDOM_MAX is still defined in the file. Should I remove it or reference it instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that alright?
Sure. I've just missed the other use. Sorry.
Either use RANDOM_MAX everywhere, or remove everywhere (in the two files for consistency). It is used only in the same small function as prng32(), so it is a bit obvious, but a bit confusing being declared many screens away.
I can update this but would prefer a little bit more guidance about how exactly it should be done, if that's possible. |
a3cc47d
to
bb3f867
Compare
sys/netinet/cc/cc_cdg.c
Outdated
@@ -308,7 +309,7 @@ cdg_cb_init(struct cc_var *ccv, void *ptr) | |||
cdg_data->queue_state = CDG_Q_UNKNOWN; | |||
cdg_data->maxrtt_in_rtt = 0; | |||
cdg_data->maxrtt_in_prevrtt = 0; | |||
cdg_data->minrtt_in_rtt = INT_MAX; | |||
cdg_data->minrtt_in_rtt = UINT_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minrtt_in_rtt is just int, this change makes no sense to me, same as one below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! I am not sure why I did that. Good catch.
sys/netinet/cc/cc_cdg.c
Outdated
p = (UINT_MAX / (1 << EXP_PREC)) * probexp[idx]; | ||
backoff = (prng32() < p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. But why did you leave UINT_MAX in its assignment instead of UINT32_MAX I proposed?
@@ -161,7 +162,7 @@ should_backoff(int qdly, int maxqdly, struct chd *chd_data) | |||
{ | |||
unsigned long p, rand; | |||
|
|||
rand = random(); | |||
rand = prng32(); | |||
|
|||
if (qdly < V_chd_qthresh) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that alright?
Sure. I've just missed the other use. Sorry.
Either use RANDOM_MAX everywhere, or remove everywhere (in the two files for consistency). It is used only in the same small function as prng32(), so it is a bit obvious, but a bit confusing being declared many screens away.
bb3f867
to
ba1e56d
Compare
sys/netinet/cc/cc_cdg.c
Outdated
@@ -637,7 +639,7 @@ cdg_ack_received(struct cc_var *ccv, ccsignal_t ack_type) | |||
} | |||
|
|||
cdg_data->minrtt_in_prevrtt = cdg_data->minrtt_in_rtt; | |||
cdg_data->minrtt_in_rtt = INT_MAX; | |||
cdg_data->minrtt_in_rtt = UINT_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The one below"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops!
sys/netinet/cc/cc_chd.c
Outdated
/* Largest possible number returned by random(). */ | ||
#define RANDOM_MAX INT_MAX | ||
/* Largest possible number returned by prng32(). */ | ||
#define RANDOM_MAX RANDOM_MAX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool define! ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today is not my day! Thank you for being patient with me.
ba1e56d
to
f521b30
Compare
Fix stdint.h file not found. Fixes: 4b75afe
Related: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277655 Signed-off-by: henrichhartzer@tuta.io Reviewed by: imp, mav Pull Request: freebsd#1162
f521b30
to
98b7bbf
Compare
Related: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277655 Signed-off-by: henrichhartzer@tuta.io Reviewed by: imp, mav Pull Request: freebsd#1162
98b7bbf
to
674956e
Compare
Related: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277655 Signed-off-by: henrichhartzer@tuta.io Reviewed by: imp, mav Pull Request: freebsd/freebsd-src#1162
Related: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277655 Signed-off-by: henrichhartzer@tuta.io Reviewed by: imp, mav Pull Request: freebsd/freebsd-src#1162
Related: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277655
Signed-off-by: henrichhartzer@tuta.io