Skip to contentSkip to conversation

drm/amd/display: Fix 64-bit division, yet again

PATCH In review Harry Wentland 2 participants 4 messages Feb 14, 2017 – Feb 15, 2017 3 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/display: Fix 64-bit division, yet again

Also make the code somewhat more readable.

---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +11 -4
index b00b1df71f3e..2026ef34b11b 100644
@@ -210,6 +210,8 @@ bool mod_freesync_add_stream(struct mod_freesync *mod_freesync,
 	struct core_freesync *core_freesync = NULL;
 	int persistent_freesync_enable = 0;
 	struct persistent_data_flag flag;
+	unsigned int nom_refresh_rate_micro_hz;
+	unsigned long long temp;
 
 	if (mod_freesync == NULL)
 		return false;
@@ -262,11 +264,16 @@ bool mod_freesync_add_stream(struct mod_freesync *mod_freesync,
 					enable_for_video = false;
 		}
 
-		unsigned int nom_refresh_rate_micro_hz = (unsigned int)
-				(((unsigned long long) core_stream->public.timing.pix_clk_khz) * 1000ULL * 1000ULL * 1000ULL
-				/ core_stream->public.timing.h_total / core_stream->public.timing.v_total);
+		temp = core_stream->public.timing.pix_clk_khz;
+		temp *= 1000ULL * 1000ULL * 1000ULL;
+		temp = div_u64(temp, core_stream->public.timing.h_total);
+		temp = div_u64(temp, core_stream->public.timing.v_total);
 
-		if (caps->supported && nom_refresh_rate_micro_hz >= caps->min_refresh_in_micro_hz && nom_refresh_rate_micro_hz <= caps->max_refresh_in_micro_hz)
+		nom_refresh_rate_micro_hz = (unsigned int) temp;
+
+		if (caps->supported &&
+		    nom_refresh_rate_micro_hz >= caps->min_refresh_in_micro_hz &&
+		    nom_refresh_rate_micro_hz <= caps->max_refresh_in_micro_hz)
 			core_stream->public.ignore_msa_timing_param = 1;
 
 		core_freesync->num_entities++;
Signature · 6 lines
2.9.3

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20170214203648.24212-1-harry.wentland-5C7GfCeVMHo@public.gmane.org

#2 lore raw
Quoted 2 lines · Harry Wentland

Also make the code somewhat more readable.

I'd suggest reaching to the team to integrate scripts/checkpatch.pl in the pre-commit hook.

It will help you improve the coding standard and, as you mentioned, it "make[s] the code somewhat more readable".

-Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CACvgo50e-sETxPcsHsn6HZu2_oaD2aSE9pFXcJK9wEH5eKS1MA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw
Quoted 9 lines · Emil Velikov
Quoted 2 lines · Harry Wentland

Also make the code somewhat more readable.

I'd suggest reaching to the team to integrate scripts/checkpatch.pl in the pre-commit hook.

It will help you improve the coding standard and, as you mentioned, it "make[s] the code somewhat more readable".

Thanks, Emil. We actually have that hooked up at pre-submission in our internal repo but don't block submission on warnings and allow a couple people to push anyways despite errors because we seem to get some unnecessary errors on complex macros that can't really be handled differently.

Need to think on how to improve that. It's a pain being the bad guy constantly and people don't always see the importance of good coding and commit msg style.

Harry

Quoted 2 lines

-Emil

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 2fa226e0-6765-404c-af71-3b0c9d146e90-5C7GfCeVMHo@public.gmane.org

#6 lore raw
Quoted 14 lines · Harry Wentland
Quoted 4 lines · Emil Velikov
Quoted 1 line · Harry Wentland
Quoted 8 lines
Quoted 2 lines

Also make the code somewhat more readable.

I'd suggest reaching to the team to integrate scripts/checkpatch.pl in the pre-commit hook.

It will help you improve the coding standard and, as you mentioned, it "make[s] the code somewhat more readable".

Quoted 6 lines

Thanks, Emil. We actually have that hooked up at pre-submission in our internal repo but don't block submission on warnings and allow a couple people to push anyways despite errors because we seem to get some unnecessary errors on complex macros that can't really be handled differently.

Some ideas:
- nobody is exempt - everyone has to go through the checks/hooks
- can not push if there are more than X warnings and Y errors
- whitelist patches that include changes to the problematic macros
Btw, do you recall which macros are responsible?

Quoted 4 lines

Need to think on how to improve that. It's a pain being the bad guy constantly and people don't always see the importance of good coding and commit msg style.

One possible solution is to check that the commit message is at least A% of the diffstat - refusing to commit + sending a bunch of links about why you want good commit messages.

Afaict all of the above can be automated, thus nobody will be an exception to the rule. With time all that can go away, but until then it will save you/Alex a) time and b) being the bad guys. It will take a few rounds to tweaking the X/Y/A numbers though ;-)

Thanks
Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx