rajivnalawade / openpgm

Automatically exported from code.google.com/p/openpgm
0 stars 0 forks source link

Division by 0 in set_tsc_mul when /proc/cpuinfo reports 0.000 at cpu MHz #35

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Running a kernel under qemu where TSC fails to calibrate against PIT 
(https://bugs.launchpad.net/ubuntu/+source/linux-goldfish/+bug/1318070)
2. Call pgm_init (pgm_time_init)

What is the expected output? What do you see instead?

When /proc/cpuinfo contains a valid cpu MHz, it works fine. I know this is a 
kernel issue, but opening this bug here as well as the code shouldn't crash in 
case MHz is 0.

What version of the product are you using? On what operating system?

libpgm-5.1.118 - Ubuntu 14.10

Please provide any additional information below.

From the code:
pgm_time_init (
...
        FILE    *fp = fopen ("/proc/cpuinfo", "r");
        if (fp)
        {
            char buffer[1024];
            while (!feof(fp) && fgets (buffer, sizeof(buffer), fp))
            {
                if (strstr (buffer, "cpu MHz")) {
                    const char *p = strchr (buffer, ':');
                    if (p) tsc_mhz = atoi (p + 1) * 1000;
                    break;
                }
            }
            fclose (fp);
        }
...
#ifndef _WIN32
/* calibrate */
        if (0 >= tsc_mhz) {
            pgm_error_t* sub_error = NULL;
            if (!pgm_tsc_init (&sub_error)) {
                pgm_propagate_error (error, sub_error);
                goto err_cleanup;
            }
        }
#endif
        pgm_info (_("TSC frequency set to %u MHz"), (unsigned)(tsc_mhz / 1000));
        set_tsc_mul (tsc_mhz);
    }
...
}

It calls pgm_tsc_init when tsc_mhz is 0, but that function will not run the 
benchmark because it'll return before that gets executed (by checking the tsc 
and constant_tsc flags).

pgm_tsc_init (
...
     if (!flags || !strstr (flags, " tsc")) {
        pgm_warn (_("Linux kernel reports no Time Stamp Counter (TSC)."));
/* force both to stable clocks even though one might be OK */
        pgm_time_update_now = pgm_gettimeofday_update;
        ret = TRUE;
    } else if (!strstr (flags, " constant_tsc")) {
        pgm_warn (_("Linux kernel reports non-constant Time Stamp Counter (TSC)."));
/* force both to stable clocks even though one might be OK */
        pgm_time_update_now = pgm_gettimeofday_update;
        ret = TRUE;
    }
..
}

Original issue reported on code.google.com by rsalv...@gmail.com on 9 May 2014 at 10:27

GoogleCodeExporter commented 8 years ago
Simple patch to check if MHz is 0 so it can at least try to run the benchmark 
code.

I'm just not yet sure if you want to also update pgm_time_update_now in this 
case (pgm_gettimeofday_update).

Original comment by rsalv...@gmail.com on 9 May 2014 at 10:31

GoogleCodeExporter commented 8 years ago

Original comment by rsalv...@gmail.com on 9 May 2014 at 10:32

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks, I was wondering how reliable /proc would be.

Original comment by fnjo...@gmail.com on 10 May 2014 at 7:58