diff options
author | Eugeni Dodonov <eugeni.dodonov@intel.com> | 2011-11-09 11:37:38 -0200 |
---|---|---|
committer | Eugeni Dodonov <eugeni.dodonov@intel.com> | 2011-11-09 11:50:22 -0200 |
commit | f3c4c0499291cf484ecbef7154d42db4129a44f1 (patch) | |
tree | bcaa175ea4eb6ff36ae0e70015f7e1a8d748b132 | |
parent | df914160599e71af95f428c3cf59165fba92d102 (diff) |
intel_gpu_top: use system-specific defines instead of autoconf flag
As suggested by Konstantin Belousov, using __linux__ would be easier,
remove the --enable-linux-features compile flag, and also make porting
easier.
So we do it, and check for __linux__ during compilation, and only compile
linux-specific bits when we are on Linux. Other systems can extend the
proposed functions with system-specific value aquisition (for now, CPU and
GPU/ACPI power monitoring).
Signed-off-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
-rw-r--r-- | configure.ac | 10 | ||||
-rw-r--r-- | tools/intel_gpu_top.c | 65 |
2 files changed, 36 insertions, 39 deletions
diff --git a/configure.ac b/configure.ac index 65947f9..3e1218e 100644 --- a/configure.ac +++ b/configure.ac @@ -97,16 +97,6 @@ if test "x$SHADER_DEBUGGER" = xyes; then fi fi -AC_ARG_ENABLE(linux-features, - AS_HELP_STRING([--enable-linux-features], - [Enable additional Linux-specific features [default=no]]), - [LINUX_FEATURES="$enableval"], - [LINUX_FEATURES=no]) -AM_CONDITIONAL(HAVE_LINUX_FEATURES, [test "x$LINUX_FEATURES" = xyes]) -if test "x$LINUX_FEATURES" = xyes; then - AC_DEFINE(HAVE_LINUX_FEATURES, 1, [Have linux-specific features]) -fi - m4_ifndef([XORG_MACROS_VERSION], [AC_FATAL([must install xorg-macros 1.3 or later before running autoconf/autogen])]) XORG_MACROS_VERSION(1.3) XORG_DEFAULT_OPTIONS diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index 8fcd82d..8c771f3 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -117,11 +117,6 @@ uint64_t last_stats[STATS_COUNT]; * the tools usage on other systems. */ -#ifdef HAVE_LINUX_FEATURES - -#define BATTERY "BAT1" -#define DEBUGFS "/sys/kernel/debug/dri/0/" - struct cpudata { unsigned long user, system, idle, nice, total; @@ -140,9 +135,14 @@ struct powerdata float watts_gfx; }; + +#define BATTERY "BAT1" +#define DEBUGFS "/sys/kernel/debug/dri/0/" + static void get_cpu_stat(struct cpudata *cpu) { +#ifdef __linux__ FILE *file; char temp[10]; char line[255]; @@ -154,6 +154,11 @@ get_cpu_stat(struct cpudata *cpu) sscanf(line, "%s %lu %lu %lu %lu", temp, &cpu->user, &cpu->nice, &cpu->system, &cpu->idle); cpu->total = cpu->user + cpu->system + cpu->idle + cpu->nice; +#else + /* We are not on Linux, give a warning on compile */ +#warning Non-Linux OS detected, CPU statistics will not be collected! + cpu->total = cpu->user = cpu->system = cpu->idle = cpu->nice = 0; +#endif } @@ -169,15 +174,21 @@ get_cpu_stat(struct cpudata *cpu) static char* get_battery_file(char *battery) { +#ifdef __linux__ /* The format is /proc/acpi/battery/BAT?/state */ char *temp = (char *)malloc(sizeof(char) * (35 * strlen(battery))); sprintf(temp, "/proc/acpi/battery/%s/state", battery); return temp; +#else +#warning Non-Linux OS detected, skipping battery detection + return NULL; +#endif } static void get_power_stat(struct powerdata *power, const char *battery_file, char *debugfs, float elapsed_time) { +#ifdef __linux__ FILE *file; char line[255]; long rate, voltage; @@ -237,26 +248,30 @@ get_power_stat(struct powerdata *power, const char *battery_file, char *debugfs, sscanf(line, "GFX power: %lu\n", &tmp); power->watts_gfx = (float) tmp / 1000; } +#else + /* We are not on Linux, give a warning on compile */ +#warning Non-Linux OS detected, POWER statistics will not be collected! + power->watts = power->watts_gfx = power->watts_chipset = -1; +#endif } -static void linux_print_header(FILE *out) +static void system_print_header(FILE *out) { fprintf(out, "utime\tstime\tpower\tpower.chipset\tpower.gfx\t"); } -static void linux_print(FILE *out, struct cpudata *cpu, struct cpudata *oldcpu, +static void system_print(FILE *out, struct cpudata *cpu, struct cpudata *oldcpu, struct powerdata *power) { - float uload, sload; - uload = (float) ((cpu->user - oldcpu->user) * 100) / (cpu->total - oldcpu->total); - sload = (float) ((cpu->system - oldcpu->system) * 100) / (cpu->total - oldcpu->total); + float uload=-1, sload=-1; + if (cpu->total > 0) { + uload = (float) ((cpu->user - oldcpu->user) * 100) / (cpu->total - oldcpu->total); + sload = (float) ((cpu->system - oldcpu->system) * 100) / (cpu->total - oldcpu->total); + } fprintf(out, "%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t", uload, sload, power->watts, power->watts_chipset, power->watts_gfx); } -#endif - - static unsigned long gettime(void) { @@ -575,11 +590,11 @@ int main(int argc, char **argv) char *cmd=NULL; int interactive=1; -#ifdef HAVE_LINUX_FEATURES struct cpudata oldcpu, cpu; struct powerdata power; char *battery = BATTERY, *battery_file = NULL; char *debugfs = DEBUGFS; +#ifdef __linux__ int do_perf=0; char *perf_output=NULL; #endif @@ -603,7 +618,7 @@ int main(int argc, char **argv) } else { output = fopen(optarg, "w"); -#if HAVE_LINUX_FEATURES +#if __linux__ perf_output = (char *)malloc(strlen(optarg) + 5); sprintf(perf_output, "%s.perf", optarg); #endif @@ -615,8 +630,8 @@ int main(int argc, char **argv) } break; case 'p': -#ifndef HAVE_LINUX_FEATURES - fprintf(stderr, "Error: Linux-specific bits not enabled\n"); +#ifndef __linux__ + fprintf(stderr, "Error: perf tracing not available on non-Linux OS\n"); exit(1); #else do_perf=1; @@ -641,7 +656,7 @@ int main(int argc, char **argv) intel_get_mmio(pci_dev); init_instdone_definitions(devid); -#ifdef HAVE_LINUX_FEATURES +#ifdef __linux__ if (do_perf) { int perf_pid = fork(); if (perf_pid < 0) { @@ -713,13 +728,11 @@ int main(int argc, char **argv) ring_init(&blt_ring); } -#ifdef HAVE_LINUX_FEATURES /* Calculate initial stats */ /* Battery */ battery_file = get_battery_file(battery); /* CPU */ get_cpu_stat(&oldcpu); -#endif /* Initialize GPU stats */ if (HAS_STATS_REGS(devid)) { @@ -814,13 +827,11 @@ int main(int argc, char **argv) time_diff = (t2 - t1) / 1000000.0; elapsed_time += time_diff; -#ifdef HAVE_LINUX_FEATURES /* CPU */ get_cpu_stat(&cpu); /* Power */ get_power_stat(&power, battery_file, debugfs, time_diff); -#endif if (interactive) { printf("%s", clear_screen); @@ -861,9 +872,7 @@ int main(int argc, char **argv) /* Print headers for columns at first run */ if (print_headers) { fprintf(output, "# time\t"); -#ifdef HAVE_LINUX_FEATURES - linux_print_header(output); -#endif + system_print_header(output); ring_print_header(output, &render_ring); ring_print_header(output, &bsd_ring); ring_print_header(output, &bsd6_ring); @@ -883,10 +892,8 @@ int main(int argc, char **argv) /* Print statistics */ fprintf(output, "%.2f\t", elapsed_time); -#ifdef HAVE_LINUX_FEATURES - linux_print(output, &cpu, &oldcpu, &power); + system_print(output, &cpu, &oldcpu, &power); oldcpu = cpu; -#endif ring_log(&render_ring, last_samples_per_sec, output); ring_log(&bsd_ring, last_samples_per_sec, output); ring_log(&bsd6_ring, last_samples_per_sec, output); @@ -929,7 +936,7 @@ int main(int argc, char **argv) fclose(output); intel_register_access_fini(); -#if HAVE_LINUX_FEATURES +#if __linux__ if (perf_output != NULL) free(perf_output); #endif |