diff options
author | arjan <arjan@arjan-desktop.localdomain> | 2010-09-10 05:27:09 -0700 |
---|---|---|
committer | arjan <arjan@arjan-desktop.localdomain> | 2010-09-10 05:27:09 -0700 |
commit | 92afb9be34cdbcc1a41be3d3c67bc0eb7d508225 (patch) | |
tree | ced8e1ab6a5477cf710670f7ec141bb1699c9b86 | |
parent | 4b4b3128b7eb4612599cd88cf28172bd51d07164 (diff) | |
download | powertop-92afb9be34cdbcc1a41be3d3c67bc0eb7d508225.tar.gz |
add i915 gpu operations parameter for catching games and such
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | calibrate/calibrate.cpp | 9 | ||||
-rw-r--r-- | devices/device.cpp | 3 | ||||
-rw-r--r-- | devices/i915-gpu.cpp | 67 | ||||
-rw-r--r-- | devices/i915-gpu.h | 27 | ||||
-rw-r--r-- | devices/usb.cpp | 2 | ||||
-rw-r--r-- | process/do_process.cpp | 25 | ||||
-rw-r--r-- | process/powerconsumer.cpp | 3 | ||||
-rw-r--r-- | process/powerconsumer.h | 3 | ||||
-rw-r--r-- | process/process.cpp | 4 |
10 files changed, 140 insertions, 5 deletions
@@ -7,7 +7,7 @@ OBJS := lib.o main.o OBJS += cpu/cpu.o cpu/abstract_cpu.o cpu/cpu_linux.o cpu/cpu_core.o cpu/cpu_package.o cpu/intel_cpus.o cpu/cpudevice.cpp OBJS += perf/perf.o perf/perf_bundle.o OBJS += process/process.o process/do_process.o process/interrupt.o process/timer.o process/work.o process/powerconsumer.o process/device.o -OBJS += devices/device.o devices/backlight.o devices/usb.o devices/ahci.o devices/alsa.o devices/rfkill.o +OBJS += devices/device.o devices/backlight.o devices/usb.o devices/ahci.o devices/alsa.o devices/rfkill.o devices/i915-gpu.o OBJS += measurement/measurement.o measurement/acpi.o OBJS += parameters/parameters.o parameters/learn.o parameters/persistent.o OBJS += calibrate/calibrate.o diff --git a/calibrate/calibrate.cpp b/calibrate/calibrate.cpp index 9344d7e..566791f 100644 --- a/calibrate/calibrate.cpp +++ b/calibrate/calibrate.cpp @@ -101,6 +101,15 @@ static void find_all_usb(void) if (access(filename, R_OK)!=0) continue; + sprintf(filename, "/sys/bus/usb/devices/%s/power/idVendor", entry->d_name); + file.open(filename, ios::in); + if (file) { + file.getline(filename, 4096); + file.close(); + if (strcmp(filename, "1d6b")==0) + continue; + } + sprintf(filename, "/sys/bus/usb/devices/%s/power/control", entry->d_name); save_sysfs(filename); diff --git a/devices/device.cpp b/devices/device.cpp index 6896a55..f87323a 100644 --- a/devices/device.cpp +++ b/devices/device.cpp @@ -9,6 +9,7 @@ using namespace std; #include "ahci.h" #include "alsa.h" #include "rfkill.h" +#include "i915-gpu.h" #include "../parameters/parameters.h" @@ -67,4 +68,6 @@ void create_all_devices(void) create_all_ahcis(); create_all_alsa(); create_all_rfkills(); + create_i915_gpu(); + } diff --git a/devices/i915-gpu.cpp b/devices/i915-gpu.cpp new file mode 100644 index 0000000..1ffe53d --- /dev/null +++ b/devices/i915-gpu.cpp @@ -0,0 +1,67 @@ +#include <iostream> +#include <fstream> + +#include <stdio.h> +#include <sys/types.h> +#include <dirent.h> + + +using namespace std; + +#include "device.h" +#include "i915-gpu.h" +#include "../parameters/parameters.h" +#include "../process/powerconsumer.h" + +#include <string.h> + + +i915gpu::i915gpu() +{ +} + +void i915gpu::start_measurement(void) +{ +} + +void i915gpu::end_measurement(void) +{ +} + + +double i915gpu::utilization(void) +{ + return 0; +} + +void create_i915_gpu(void) +{ + char filename[4096]; + class i915gpu *gpu; + + strcpy(filename, "/sys/kernel/debug/tracing/events/i915/i915_gem_request_submit/format"); + + if (access(filename, R_OK) !=0) + return; + + register_parameter("gpu-operations"); + + gpu = new class i915gpu(); + all_devices.push_back(gpu); +} + + + +double i915gpu::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) +{ + double power; + double factor; + double utilization; + + power = 0; + factor = get_parameter_value("gpu-operations", bundle); + utilization = get_result_value("gpu-operations", result); + + power += utilization * factor / 100.0; + return power; +}
\ No newline at end of file diff --git a/devices/i915-gpu.h b/devices/i915-gpu.h new file mode 100644 index 0000000..7794714 --- /dev/null +++ b/devices/i915-gpu.h @@ -0,0 +1,27 @@ +#ifndef _INCLUDE_GUARD_i915_GPU_H +#define _INCLUDE_GUARD_i915_GPU_H + + +#include "device.h" + +class i915gpu: public device { +public: + + i915gpu(); + + virtual void start_measurement(void); + virtual void end_measurement(void); + + virtual double utilization(void); /* percentage */ + + virtual const char * class_name(void) { return "GPU";}; + + virtual const char * device_name(void) { return "GPU";}; + virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); + virtual bool show_in_list(void) {return false;}; +}; + +extern void create_i915_gpu(void); + + +#endif
\ No newline at end of file diff --git a/devices/usb.cpp b/devices/usb.cpp index 81467e5..f187a98 100644 --- a/devices/usb.cpp +++ b/devices/usb.cpp @@ -76,6 +76,8 @@ double usbdevice::utilization(void) /* percentage */ { double d; d = 100.0 * (active_after - active_before) / (0.01 + connected_after - connected_before); + if (d < 0.0) + d = 0.0; return d; } diff --git a/process/do_process.cpp b/process/do_process.cpp index 7414c44..cc178ec 100644 --- a/process/do_process.cpp +++ b/process/do_process.cpp @@ -397,6 +397,13 @@ void perf_process_bundle::handle_trace_point(int type, void *trace, int cpu, uin if (strcmp(event_name, "power:power_end") == 0) { consume_blame(cpu); } + if (strcmp(event_name, "i915:i915_gem_request_submit") == 0) { + class power_consumer *consumer; + consumer = current_consumer(cpu); + if (consumer) { + consumer->gpu_ops++; + } + } } void start_process_measurement(void) @@ -417,6 +424,7 @@ void start_process_measurement(void) perf_events->add_event("power:power_end"); perf_events->add_event("workqueue:workqueue_execute_start"); perf_events->add_event("workqueue:workqueue_execute_end"); + perf_events->add_event("i915:i915_gem_request_submit"); } first_stamp = ~0ULL; @@ -484,7 +492,7 @@ void process_process_data(void) } -int total_wakeups(void) +double total_wakeups(void) { double total = 0; unsigned int i; @@ -497,6 +505,20 @@ int total_wakeups(void) return total; } +double total_gpu_ops(void) +{ + double total = 0; + unsigned int i; + for (i = 0; i < all_power.size() ; i++) + total += all_power[i]->gpu_ops; + + + total = total / measurement_time; + + + return total; +} + double total_cpu_time(void) { unsigned int i; @@ -521,6 +543,7 @@ void end_process_data(void) report_utilization("cpu-consumption", total_cpu_time()); report_utilization("cpu-wakeups", total_wakeups()); + report_utilization("gpu-operations", total_gpu_ops()); /* clean out old data */ for (i = 0; i < all_processes.size() ; i++) diff --git a/process/powerconsumer.cpp b/process/powerconsumer.cpp index 24bdf02..a93efef 100644 --- a/process/powerconsumer.cpp +++ b/process/powerconsumer.cpp @@ -8,15 +8,18 @@ double power_consumer::Witts(void) double cost; double timecost; double wakeupcost; + double gpucost; if (child_runtime > accumulated_runtime) child_runtime = 0; timecost = get_parameter_value("cpu-consumption"); wakeupcost = get_parameter_value("cpu-wakeups"); + gpucost = get_parameter_value("gpu-operations"); cost = wakeupcost * wake_ups / 10000.0; cost += ( (accumulated_runtime - child_runtime) / 1000000000.0 * timecost); + cost += gpucost * gpu_ops / 100.0; cost = cost / measurement_time; diff --git a/process/powerconsumer.h b/process/powerconsumer.h index 1fa2008..6e6176f 100644 --- a/process/powerconsumer.h +++ b/process/powerconsumer.h @@ -30,8 +30,9 @@ public: extern vector <class power_consumer *> all_power; -extern int total_wakeups(void); +extern double total_wakeups(void); extern double total_cpu_time(void); +extern double total_gpu_ops(void); diff --git a/process/process.cpp b/process/process.cpp index 6d4f5ac..c172b40 100644 --- a/process/process.cpp +++ b/process/process.cpp @@ -56,9 +56,9 @@ const char * process::description(void) if (child_runtime > accumulated_runtime) child_runtime = 0; - sprintf(desc, "Process %22s time %5.2fms wakeups %4.1f (child %5.1fms)", + sprintf(desc, "Process %22s time %5.2fms wakeups %4.1f gpu ops %4.1f (child %5.1fms)", comm, (accumulated_runtime - child_runtime) / 1000000.0 / measurement_time, wake_ups / measurement_time, - child_runtime / 1000000.0); + gpu_ops / measurement_time, child_runtime / 1000000.0); return desc; } |