void* recordEnergy(void *arg) { struct timeval t1, t2; double elapsedTime; gettimeofday(&t1, NULL); int retval = 0; long long counts[MICPOWER_MAX_COUNTERS]; // used for caching struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 50000000L; // 50 milliseconds double energy = 0.0; while (keepAlive) { retval = read_sysfs_file(counts); energy += counts[0]; nanosleep(&ts, NULL); } gettimeofday(&t2, NULL); keepAlive = 1; elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms passEnergy = energy; printf("#D,ENERGY_MIC,%lf\n", energy * 50.0 / 1000 / 1000 / 1000); printf("#D,TIME,%lf\n", elapsedTime); energy = 0.0; return arg; }
static int tc_acpi_str(void) { int res, ret = 0; char descr[4096], sysfs_path[4096]; int not_kver_3_7 = tst_kvercmp(3, 7, 0) < 0; while (1) { SAFE_FILE_PRINTF(cleanup, dev_tcase, "%d", ACPI_TRAVERSE); SAFE_FILE_SCANF(cleanup, dev_result, "%d", &res); if (res) return TFAIL; /* * if device has _STR object, we should get * a valid string from 'str' sysfs file and then can * find it in sysfs. */ if (read_sysfs_file(dev_str, descr, 4096)) { /* None of left devices has _STR */ break; } tst_resm(TINFO, "read description %s", descr); /* device's sysfs path */ strcpy(sysfs_path, "/sys"); if (read_sysfs_file(dev_path, sysfs_path + 4, 4092)) { /* * Device doesn't have sysfs entry * continue, because others might have it */ continue; } /* * Find device description in sysfs. * * New sysfs interface to export device description * implemented since Linux 3.7 */ if (not_kver_3_7) { tst_resm(TINFO, "sysfs _STR check required Linux 3.7+"); ret = TCONF; /* continue, we can still traverse ACPI devices */ continue; } strcat(sysfs_path, "/description"); if (access(sysfs_path, R_OK)) { tst_resm(TINFO, "can't find description file '%s'", sysfs_path); return TFAIL; } tst_resm(TINFO, "found description file '%s'", sysfs_path); char sysfs_descr[4096]; if (read_sysfs_file(sysfs_path, sysfs_descr, 4096)) return TFAIL; /* * Compare sysfs file and description from test driver */ int res = strncmp(descr, sysfs_descr, strlen(descr)); ret |= res ? TFAIL : TPASS; } return ret; }