Skip to content

Commit

Permalink
lib: move time to exponent function out of context
Browse files Browse the repository at this point in the history
  • Loading branch information
llandwerlin-intel committed Apr 2, 2018
1 parent 706894a commit 6abf0ed
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
25 changes: 10 additions & 15 deletions lib/gputop-client-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,20 +1085,6 @@ register_platform_metrics(struct gputop_client_context *ctx,

/**/

uint32_t
gputop_period_to_oa_exponent(struct gputop_client_context *ctx, uint64_t period_ns)
{
for (int i = 0; i < 30; i++) {
uint64_t oa_period = gputop_oa_exponent_to_period_ns(&ctx->devinfo, i);

if (oa_period > period_ns)
return MAX2(0, i - 1);
}

unreachable("Period out of range");
return 0;
}

static void
close_i915_perf_stream(struct gputop_client_context *ctx)
{
Expand All @@ -1115,10 +1101,19 @@ open_i915_perf_stream(struct gputop_client_context *ctx)

i915_perf_empty_samples(ctx);

if (ctx->oa_sampling_period_ns > ctx->oa_aggregation_period_ns) {
ctx->oa_sampling_period_ns =
gputop_oa_exponent_to_period_ns(
&ctx->devinfo,
gputop_time_to_oa_exponent(
&ctx->devinfo,
ctx->oa_aggregation_period_ns));
}

Gputop__OAStreamInfo oa_stream = GPUTOP__OASTREAM_INFO__INIT;
oa_stream.uuid = (char *) ctx->metric_set->hw_config_guid;
oa_stream.period_exponent =
gputop_period_to_oa_exponent(ctx, ctx->oa_aggregation_period_ns);
gputop_time_to_oa_exponent(&ctx->devinfo, ctx->oa_sampling_period_ns);
oa_stream.per_ctx_mode = false;
oa_stream.cpu_timestamps = ctx->i915_perf_config.cpu_timestamps;
oa_stream.gpu_timestamps = ctx->i915_perf_config.gpu_timestamps;
Expand Down
3 changes: 0 additions & 3 deletions lib/gputop-client-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,6 @@ const struct gputop_metric_set *
gputop_client_context_symbol_to_metric_set(struct gputop_client_context *ctx,
const char *symbol_name);

uint32_t
gputop_period_to_oa_exponent(struct gputop_client_context *ctx, uint64_t period_ns);

struct gputop_perf_tracepoint *
gputop_client_context_add_tracepoint(struct gputop_client_context *ctx,
const char *name);
Expand Down
14 changes: 14 additions & 0 deletions lib/gputop-oa-counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
#include "gputop-log.h"
#endif

uint32_t
gputop_time_to_oa_exponent(struct gputop_devinfo *devinfo, uint64_t period_ns)
{
for (int i = 0; i < 30; i++) {
uint64_t oa_period = gputop_oa_exponent_to_period_ns(devinfo, i);

if (oa_period > period_ns)
return MAX2(0, i - 1);
}

unreachable("Period out of range");
return 0;
}

void
gputop_u32_clock_init(struct gputop_u32_clock *clock,
const struct gputop_devinfo *devinfo,
Expand Down
2 changes: 2 additions & 0 deletions lib/gputop-oa-counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ gputop_oa_exponent_to_period_ns(const struct gputop_devinfo *devinfo, uint32_t e
return ((2ULL << exponent) * 1000000000ULL) / devinfo->timestamp_frequency;
}

uint32_t gputop_time_to_oa_exponent(struct gputop_devinfo *devinfo, uint64_t period_ns);

static inline bool
gputop_cc_oa_report_ctx_is_valid(const struct gputop_devinfo *devinfo,
const uint8_t *_report)
Expand Down
10 changes: 5 additions & 5 deletions wrapper/gputop-wrapper-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,16 @@ static void print_system_info(void)

comment("OA info:\n");
comment("\tOA Hardware Sampling Exponent: %u\n",
gputop_period_to_oa_exponent(&context.ctx, context.ctx.oa_aggregation_period_ns));
gputop_time_to_oa_exponent(&context.ctx.devinfo, context.ctx.oa_aggregation_period_ns));
gputop_client_pretty_print_value(GPUTOP_PERFQUERY_COUNTER_UNITS_NS,
gputop_oa_exponent_to_period_ns(&context.ctx.devinfo,
gputop_period_to_oa_exponent(&context.ctx,
context.ctx.oa_aggregation_period_ns)),
gputop_time_to_oa_exponent(&context.ctx.devinfo,
context.ctx.oa_aggregation_period_ns)),
temp, sizeof(temp));
comment("\tOA Hardware Period: %u ns / %s\n",
gputop_oa_exponent_to_period_ns(&context.ctx.devinfo,
gputop_period_to_oa_exponent(&context.ctx,
context.ctx.oa_aggregation_period_ns)),
gputop_time_to_oa_exponent(&context.ctx.devinfo,
context.ctx.oa_aggregation_period_ns)),
temp);
}

Expand Down

0 comments on commit 6abf0ed

Please sign in to comment.