Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for per-vGPU mode profiling #165

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion gputop-client-c/gputop-client-c-bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ gputop_cc_handle_i915_perf_message_binding(const v8::FunctionCallbackInfo<Value>
struct gputop_cc_stream *stream = (struct gputop_cc_stream *)ptr->ptr_;

unsigned int len = args[2]->NumberValue();
unsigned int ctx_hw_id = args[5]->NumberValue();
unsigned int idle_flag = args[6]->NumberValue();

if (!args[1]->IsArrayBufferView()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Expected 2nd argument to be an ArrayBufferView")));
Expand Down Expand Up @@ -167,7 +169,9 @@ gputop_cc_handle_i915_perf_message_binding(const v8::FunctionCallbackInfo<Value>
static_cast<uint8_t *>(data_contents.Data()) + offset,
len,
accumulators,
n_accumulators);
n_accumulators,
ctx_hw_id,
idle_flag);
}

void
Expand Down
10 changes: 10 additions & 0 deletions gputop-client-c/gputop-client-c-runtime-bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,15 @@ _gputop_cr_accumulator_end_update(void)
fn->Call(gputop, ARRAY_LENGTH(argv), argv);
}

void
_gputop_cr_send_idle_flag(int idle_flag)
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);

Local<Object> gputop = Local<Object>::New(isolate, gputop_cc_singleton);
Local<Function> fn = Local<Function>::Cast(gputop->Get(String::NewFromUtf8(isolate, "send_idle_flag")));

Local<Value> argv[] = {Number::New(isolate, idle_flag)};
fn->Call(gputop, ARRAY_LENGTH(argv), argv);
}
2 changes: 1 addition & 1 deletion gputop-client-c/gputop-client-c-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool _gputop_cr_accumulator_start_update(struct gputop_cc_stream *stream,
void _gputop_cr_accumulator_append_count(int counter,
double max, double value);
void _gputop_cr_accumulator_end_update(void);

void _gputop_cr_send_idle_flag(int idle_flag);
#ifdef __cplusplus
}
#endif
78 changes: 56 additions & 22 deletions gputop-client-c/gputop-client-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ gputop_cc_get_counter_id(const char *hw_config_guid, const char *counter_symbol_
return -1;
}

static void
reset_forward_oa_accumulator_events(struct gputop_cc_stream *stream,
struct gputop_cc_oa_accumulator *oa_accumulator,
uint32_t events)
{
struct gputop_metric_set *oa_metric_set = stream->oa_metric_set;

if (!_gputop_cr_accumulator_start_update(stream,
oa_accumulator,
events,
oa_accumulator->first_timestamp,
oa_accumulator->last_timestamp))
return;

for (int i = 0; i < oa_metric_set->n_counters; i++) {

double d_value = 0;
uint64_t max = 0;
_gputop_cr_accumulator_append_count(i, max, d_value);
}

_gputop_cr_accumulator_end_update();
}

static void
forward_oa_accumulator_events(struct gputop_cc_stream *stream,
struct gputop_cc_oa_accumulator *oa_accumulator,
Expand Down Expand Up @@ -204,14 +228,16 @@ void EMSCRIPTEN_KEEPALIVE
gputop_cc_handle_i915_perf_message(struct gputop_cc_stream *stream,
uint8_t *data, int data_len,
struct gputop_cc_oa_accumulator **accumulators,
int n_accumulators)
int n_accumulators,
int ctx_hw_id,
int idle_flag)
{
const struct drm_i915_perf_record_header *header;
uint8_t *last = NULL;

assert(stream);

if (stream->continuation_report)
if (stream->continuation_report && (idle_flag < 4))
last = stream->continuation_report;
else {
for (int i = 0; i < n_accumulators; i++) {
Expand All @@ -220,9 +246,14 @@ gputop_cc_handle_i915_perf_message(struct gputop_cc_stream *stream,

assert(oa_accumulator);
gputop_cc_oa_accumulator_clear(oa_accumulator);
reset_forward_oa_accumulator_events(stream, oa_accumulator, 1);
idle_flag = 4;
}
}

if (idle_flag < 4)
idle_flag++;

//int i = 0;
for (header = (void *)data;
(uint8_t *)header < (data + data_len);
Expand Down Expand Up @@ -250,34 +281,35 @@ gputop_cc_handle_i915_perf_message(struct gputop_cc_stream *stream,
case DRM_I915_PERF_RECORD_SAMPLE: {
struct oa_sample *sample = (struct oa_sample *)header;

if (last) {
for (int i = 0; i < n_accumulators; i++) {
struct gputop_cc_oa_accumulator *oa_accumulator =
accumulators[i];
if (sample->oa_report[8] == ctx_hw_id || ctx_hw_id == 0) {
idle_flag = 0;

if (last) {
for (int i = 0; i < n_accumulators; i++) {
struct gputop_cc_oa_accumulator *oa_accumulator =
accumulators[i];

assert(oa_accumulator);
assert(oa_accumulator);

if (gputop_cc_oa_accumulate_reports(oa_accumulator,
if (gputop_cc_oa_accumulate_reports(oa_accumulator,
last, sample->oa_report))
{
uint64_t elapsed = (oa_accumulator->last_timestamp -
{
uint64_t elapsed = (oa_accumulator->last_timestamp -
oa_accumulator->first_timestamp);
uint32_t events = 0;
//gputop_cr_console_log("i915_oa: accumulated reports\n");

if (elapsed > oa_accumulator->aggregation_period) {
//gputop_cr_console_log("i915_oa: PERIOD ELAPSED (%d)\n", (int)oa_accumulator->aggregation_period);
events |= ACCUMULATOR_EVENT_PERIOD_ELAPSED;
uint32_t events = 0;
//gputop_cr_console_log("i915_oa: accumulated reports\n");

if (elapsed > oa_accumulator->aggregation_period) {
//gputop_cr_console_log("i915_oa: PERIOD ELAPSED (%d)\n", (int)oa_accumulator->aggregation_period);
events |= ACCUMULATOR_EVENT_PERIOD_ELAPSED;
}
if (events)
forward_oa_accumulator_events(stream, oa_accumulator, events);
}

if (events)
forward_oa_accumulator_events(stream, oa_accumulator, events);
}
}
}

last = sample->oa_report;

}
break;
}

Expand All @@ -287,6 +319,8 @@ gputop_cc_handle_i915_perf_message(struct gputop_cc_stream *stream,
}
}

_gputop_cr_send_idle_flag(idle_flag);

if (last) {
int raw_size = stream->oa_metric_set->perf_raw_size;

Expand Down
4 changes: 3 additions & 1 deletion gputop-client-c/gputop-client-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ int gputop_cc_get_counter_id(const char *guid, const char *counter_symbol_name);
void gputop_cc_handle_i915_perf_message(struct gputop_cc_stream *stream,
uint8_t *data, int data_len,
struct gputop_cc_oa_accumulator **accumulators,
int n_accumulators);
int n_accumulators,
int ctx_hw_id,
int idle_flag);

void gputop_cc_reset_system_properties(void);
void gputop_cc_set_system_property(const char *name, double value);
Expand Down
7 changes: 7 additions & 0 deletions gputop-client-c/gputop-web-lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 38 additions & 5 deletions gputop-client/gputop.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
var is_nodejs = false;
var using_emscripten = true;

var ctx_hw_id_ = [];
var vgpu_id_ = [];
var ctx_mode=['Global'];
var map_vgpuID_hwID = [0];

if (typeof module !== 'undefined' && module.exports) {

var WebSocket = require('ws');
Expand Down Expand Up @@ -479,7 +484,7 @@ Gputop.prototype.clear_accumulated_metrics = function(metric) {
}
}

Gputop.prototype.replay_i915_perf_history = function(metric) {
Gputop.prototype.replay_i915_perf_history = function(metric, hw_id) {
this.clear_accumulated_metrics(metric);

var stream = metric.stream;
Expand Down Expand Up @@ -515,7 +520,9 @@ Gputop.prototype.replay_i915_perf_history = function(metric) {
stack_data,
data.length,
vec,
n_accumulators);
n_accumulators,
hw_id,
this.idle_flag);
} else {
var vec = [];
for (var j = 0; j < n_accumulators; j++) {
Expand All @@ -527,7 +534,9 @@ Gputop.prototype.replay_i915_perf_history = function(metric) {
stack_data,
data.length,
vec,
n_accumulators);
n_accumulators,
hw_id,
this.idle_flag);
}

cc.Runtime.stackRestore(sp);
Expand Down Expand Up @@ -664,6 +673,10 @@ Gputop.prototype.accumulator_end_update = function () {
update.events_mask);
}

Gputop.prototype.send_idle_flag = function (idle_flag) {
this.idle_flag = idle_flag;
}

Gputop.prototype.accumulator_clear = function (accumulator) {
cc._gputop_cc_oa_accumulator_clear(accumulator.cc_accumulator_ptr_);
}
Expand Down Expand Up @@ -737,6 +750,7 @@ Gputop.prototype.set_demo_architecture = function(architecture) {

this.demo_architecture = architecture;
this.is_connected_ = true;
this.request_hw_id_map();
this.request_features();
}

Expand Down Expand Up @@ -1383,6 +1397,16 @@ Gputop.prototype.rpc_request = function(method, value, closure) {
}
}

Gputop.prototype.request_hw_id_map = function() {
if (!this.is_demo()) {
if (this.socket_.readyState == is_nodejs ? 1 : WebSocket.OPEN) {
this.rpc_request('get_hw_id_map', true);
} else {
this.log("Can't request context hardware ID map while not connected", this.ERROR);
}
}
}

Gputop.prototype.request_features = function() {
if (!this.is_demo()) {
if (this.socket_.readyState == is_nodejs ? 1 : WebSocket.OPEN) {
Expand Down Expand Up @@ -1671,6 +1695,9 @@ function gputop_socket_on_message(evt) {
stream.dispatchEvent(ev);
}
break;
case 'hw_id':
this.update_vgpuID_hwID(msg.hw_id);
break;
}

if (msg.reply_uuid in this.rpc_closures_) {
Expand Down Expand Up @@ -1720,7 +1747,9 @@ function gputop_socket_on_message(evt) {
stack_data,
data.length,
vec,
n_accumulators);
n_accumulators,
this.current_hw_id,
this.idle_flag);
} else {
var vec = [];
for (var i = 0; i < n_accumulators; i++) {
Expand All @@ -1732,7 +1761,9 @@ function gputop_socket_on_message(evt) {
stack_data,
data.length,
vec,
n_accumulators);
n_accumulators,
this.current_hw_id,
this.idle_flag);
}

cc.Runtime.stackRestore(sp);
Expand Down Expand Up @@ -1824,6 +1855,7 @@ Gputop.prototype.connect = function(address, onopen, onclose, onerror) {
this.log('Connecting to ' + websocket_url);
this.socket_ = this.connect_web_socket(websocket_url, () => { //onopen
this.is_connected_ = true;
this.request_hw_id_map();
this.request_features();

var ev = { type: "open" };
Expand All @@ -1839,6 +1871,7 @@ Gputop.prototype.connect = function(address, onopen, onclose, onerror) {
});
} else {
this.is_connected_ = true;
this.request_hw_id_map();
this.request_features();

var ev = { type: "open" };
Expand Down
Loading