diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/router1.cc | 2 | ||||
-rw-r--r-- | common/timing.cc | 34 | ||||
-rw-r--r-- | common/timing.h | 2 |
3 files changed, 33 insertions, 5 deletions
diff --git a/common/router1.cc b/common/router1.cc index 5f51b370..dd338b35 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -933,7 +933,7 @@ bool router1(Context *ctx, const Router1Cfg &cfg) #ifndef NDEBUG ctx->check(); #endif - timing_analysis(ctx, true /* print_path */); + timing_analysis(ctx, true /* slack_histogram */, true /* print_path */); ctx->unlock(); return true; } catch (log_execution_error_exception) { diff --git a/common/timing.cc b/common/timing.cc index 3b3c5da7..85683b75 100644 --- a/common/timing.cc +++ b/common/timing.cc @@ -27,6 +27,7 @@ NEXTPNR_NAMESPACE_BEGIN typedef std::vector<const PortRef*> PortRefVector; +typedef std::map<delay_t, unsigned> DelayFrequency; struct Timing { @@ -35,8 +36,10 @@ struct Timing delay_t min_slack; PortRefVector current_path; PortRefVector *crit_path; + DelayFrequency *slack_histogram; - Timing(Context *ctx, bool update, PortRefVector *crit_path = nullptr): ctx(ctx), update(update), min_slack(1.0e12 / ctx->target_freq), crit_path(crit_path) {} + Timing(Context *ctx, bool update, PortRefVector *crit_path = nullptr, DelayFrequency *slack_histogram = nullptr) + : ctx(ctx), update(update), min_slack(1.0e12 / ctx->target_freq), crit_path(crit_path), slack_histogram(slack_histogram) {} delay_t follow_net(NetInfo *net, int path_length, delay_t slack) { @@ -75,6 +78,8 @@ struct Timing if (crit_path) *crit_path = current_path; } + if (slack_histogram) + (*slack_histogram)[slack]++; } else { // Default to the path ending here, if no further paths found value = slack / path_length; @@ -178,11 +183,12 @@ void assign_budget(Context *ctx, bool quiet) log_info("Checksum: 0x%08x\n", ctx->checksum()); } -void timing_analysis(Context *ctx, bool print_path) +void timing_analysis(Context *ctx, bool print_histogram, bool print_path) { PortRefVector crit_path; + DelayFrequency slack_histogram; - Timing timing(ctx, false /* update */, &crit_path); + Timing timing(ctx, false /* update */, print_path ? &crit_path : nullptr, print_histogram ? &slack_histogram : nullptr); auto min_slack = timing.walk_paths(); if (print_path) { @@ -224,6 +230,28 @@ void timing_analysis(Context *ctx, bool print_path) delay_t default_slack = delay_t(1.0e12 / ctx->target_freq); log_info("estimated Fmax = %.2f MHz\n", 1e6 / (default_slack - min_slack)); + + if (print_histogram) { + constexpr unsigned num_bins = 20; + unsigned bar_width = 60; + auto min_slack = slack_histogram.begin()->first; + auto max_slack = slack_histogram.rbegin()->first; + auto bin_size = (max_slack - min_slack) / num_bins; + std::vector<unsigned> bins(num_bins+1); + unsigned max_freq = 0; + for (const auto& i : slack_histogram) { + auto& bin = bins[(i.first-min_slack) / bin_size]; + bin += i.second; + max_freq = std::max(max_freq, bin); + } + bar_width = std::min(bar_width, max_freq); + + log_break(); + log_info("Slack histogram:\n"); + log_info(" legend: * represents %d endpoint(s)\n", max_freq / bar_width); + for (unsigned i = 0; i < bins.size(); ++i) + log_info("%6d < ps < %6d |%s\n", min_slack + bin_size*i, min_slack + bin_size*(i+1), std::string(bins[i] * bar_width / max_freq, '*').c_str()); + } } NEXTPNR_NAMESPACE_END diff --git a/common/timing.h b/common/timing.h index 7073b899..cfb71ae0 100644 --- a/common/timing.h +++ b/common/timing.h @@ -29,7 +29,7 @@ void assign_budget(Context *ctx, bool quiet = false); // Perform timing analysis and print out the fmax, and optionally the // critical path -void timing_analysis(Context *ctx, bool print_path = false); +void timing_analysis(Context *ctx, bool slack_histogram = true, bool print_path = false); NEXTPNR_NAMESPACE_END |