turbostat.c (95aebc44e73b05d4e95774b983a63909de638808) turbostat.c (57a42a34d126f2fe5d1f2f120c5f7a31ec65cd31)
1/*
2 * turbostat -- show CPU frequency and C-state residency
3 * on modern Intel turbo-capable processors.
4 *
5 * Copyright (c) 2013 Intel Corporation.
6 * Len Brown <len.brown@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it

--- 1161 unchanged lines hidden (view full) ---

1170 package_odd = NULL;
1171
1172 free(output_buffer);
1173 output_buffer = NULL;
1174 outp = NULL;
1175}
1176
1177/*
1/*
2 * turbostat -- show CPU frequency and C-state residency
3 * on modern Intel turbo-capable processors.
4 *
5 * Copyright (c) 2013 Intel Corporation.
6 * Len Brown <len.brown@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it

--- 1161 unchanged lines hidden (view full) ---

1170 package_odd = NULL;
1171
1172 free(output_buffer);
1173 output_buffer = NULL;
1174 outp = NULL;
1175}
1176
1177/*
1178 * Open a file, and exit on failure
1179 */
1180FILE *fopen_or_die(const char *path, const char *mode)
1181{
1182 FILE *filep = fopen(path, "r");
1183 if (!filep) {
1184 perror(path);
1185 exit(1);
1186 }
1187 return filep;
1188}
1189
1190/*
1178 * Parse a file containing a single int.
1179 */
1180int parse_int_file(const char *fmt, ...)
1181{
1182 va_list args;
1183 char path[PATH_MAX];
1184 FILE *filep;
1185 int value;
1186
1187 va_start(args, fmt);
1188 vsnprintf(path, sizeof(path), fmt, args);
1189 va_end(args);
1191 * Parse a file containing a single int.
1192 */
1193int parse_int_file(const char *fmt, ...)
1194{
1195 va_list args;
1196 char path[PATH_MAX];
1197 FILE *filep;
1198 int value;
1199
1200 va_start(args, fmt);
1201 vsnprintf(path, sizeof(path), fmt, args);
1202 va_end(args);
1190 filep = fopen(path, "r");
1191 if (!filep) {
1192 perror(path);
1193 exit(1);
1194 }
1203 filep = fopen_or_die(path, "r");
1195 if (fscanf(filep, "%d", &value) != 1) {
1196 perror(path);
1197 exit(1);
1198 }
1199 fclose(filep);
1200 return value;
1201}
1202

--- 29 unchanged lines hidden (view full) ---

1232{
1233 char path[80];
1234 FILE *filep;
1235 int sib1, sib2;
1236 int matches;
1237 char character;
1238
1239 sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
1204 if (fscanf(filep, "%d", &value) != 1) {
1205 perror(path);
1206 exit(1);
1207 }
1208 fclose(filep);
1209 return value;
1210}
1211

--- 29 unchanged lines hidden (view full) ---

1241{
1242 char path[80];
1243 FILE *filep;
1244 int sib1, sib2;
1245 int matches;
1246 char character;
1247
1248 sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
1240 filep = fopen(path, "r");
1241 if (filep == NULL) {
1242 perror(path);
1243 exit(1);
1244 }
1249 filep = fopen_or_die(path, "r");
1245 /*
1246 * file format:
1247 * if a pair of number with a character between: 2 siblings (eg. 1-2, or 1,4)
1248 * otherwinse 1 sibling (self).
1249 */
1250 matches = fscanf(filep, "%d%c%d\n", &sib1, &character, &sib2);
1251
1252 fclose(filep);

--- 53 unchanged lines hidden (view full) ---

1306 * return max_cpu number
1307 */
1308int for_all_proc_cpus(int (func)(int))
1309{
1310 FILE *fp;
1311 int cpu_num;
1312 int retval;
1313
1250 /*
1251 * file format:
1252 * if a pair of number with a character between: 2 siblings (eg. 1-2, or 1,4)
1253 * otherwinse 1 sibling (self).
1254 */
1255 matches = fscanf(filep, "%d%c%d\n", &sib1, &character, &sib2);
1256
1257 fclose(filep);

--- 53 unchanged lines hidden (view full) ---

1311 * return max_cpu number
1312 */
1313int for_all_proc_cpus(int (func)(int))
1314{
1315 FILE *fp;
1316 int cpu_num;
1317 int retval;
1318
1314 fp = fopen(proc_stat, "r");
1315 if (fp == NULL) {
1316 perror(proc_stat);
1317 exit(1);
1318 }
1319 fp = fopen_or_die(proc_stat, "r");
1319
1320 retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n");
1321 if (retval != 0) {
1322 perror("/proc/stat format");
1323 exit(1);
1324 }
1325
1326 while (1) {

--- 1087 unchanged lines hidden ---
1320
1321 retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n");
1322 if (retval != 0) {
1323 perror("/proc/stat format");
1324 exit(1);
1325 }
1326
1327 while (1) {

--- 1087 unchanged lines hidden ---