I had reason to look at the linux timer code today and noticed what I
believe to be a subtle error.
This is in both 'master' and v1.8.5rc2

Since casts bind tighter than multiplication in C, I believe that the
1-line patch below is required to produce the desired result of conversion
to an integer *after* the multiplication.
While I don't see how to exercise the code, I can see that cpu_f=2692.841
will yield opal_timer_linux_freq=2,692,000,000 rather than 2,692,841,000.

-Paul


diff --git a/opal/mca/timer/linux/timer_linux_component.c
b/opal/mca/timer/linux/timer_linux_component.c
index b130826..7abe578 100644
--- a/opal/mca/timer/linux/timer_linux_component.c
+++ b/opal/mca/timer/linux/timer_linux_component.c
@@ -128,7 +128,7 @@ static int opal_timer_linux_find_freq(void)
             ret = sscanf(loc, "%f", &cpu_f);
             if (1 == ret) {
                 /* numer is in MHz - convert to Hz and make an integer */
-                opal_timer_linux_freq = (opal_timer_t) cpu_f * 1000000;
+                opal_timer_linux_freq = (opal_timer_t) (cpu_f * 1000000);
             }
         }
     }

-- 
Paul H. Hargrove                          phhargr...@lbl.gov
Computer Languages & Systems Software (CLaSS) Group
Computer Science Department               Tel: +1-510-495-2352
Lawrence Berkeley National Laboratory     Fax: +1-510-486-6900

Reply via email to