Merge tag 'drm-msm-fixes-2021-05-09' of https://gitlab.freedesktop.org/drm/msm into...
[linux-2.6-microblaze.git] / tools / perf / util / sort.c
index 552b590..88ce47f 100644 (file)
@@ -25,6 +25,7 @@
 #include <traceevent/event-parse.h>
 #include "mem-events.h"
 #include "annotate.h"
+#include "event.h"
 #include "time-utils.h"
 #include "cgroup.h"
 #include "machine.h"
@@ -36,7 +37,7 @@ const char    default_parent_pattern[] = "^sys_|^do_page_fault";
 const char     *parent_pattern = default_parent_pattern;
 const char     *default_sort_order = "comm,dso,symbol";
 const char     default_branch_sort_order[] = "comm,dso_from,symbol_from,symbol_to,cycles";
-const char     default_mem_sort_order[] = "local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked,blocked,local_ins_lat";
+const char     default_mem_sort_order[] = "local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked,blocked,local_ins_lat,p_stage_cyc";
 const char     default_top_sort_order[] = "dso,symbol";
 const char     default_diff_sort_order[] = "dso,symbol";
 const char     default_tracepoint_sort_order[] = "trace";
@@ -45,6 +46,8 @@ const char    *field_order;
 regex_t                ignore_callees_regex;
 int            have_ignore_callees = 0;
 enum sort_mode sort__mode = SORT_MODE__NORMAL;
+const char     *dynamic_headers[] = {"local_ins_lat", "p_stage_cyc"};
+const char     *arch_specific_sort_keys[] = {"p_stage_cyc"};
 
 /*
  * Replaces all occurrences of a char used with the:
@@ -1408,6 +1411,25 @@ struct sort_entry sort_global_ins_lat = {
        .se_width_idx   = HISTC_GLOBAL_INS_LAT,
 };
 
+static int64_t
+sort__global_p_stage_cyc_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+       return left->stat.p_stage_cyc - right->stat.p_stage_cyc;
+}
+
+static int hist_entry__p_stage_cyc_snprintf(struct hist_entry *he, char *bf,
+                                       size_t size, unsigned int width)
+{
+       return repsep_snprintf(bf, size, "%-*u", width, he->stat.p_stage_cyc);
+}
+
+struct sort_entry sort_p_stage_cyc = {
+       .se_header      = "Pipeline Stage Cycle",
+       .se_cmp         = sort__global_p_stage_cyc_cmp,
+       .se_snprintf    = hist_entry__p_stage_cyc_snprintf,
+       .se_width_idx   = HISTC_P_STAGE_CYC,
+};
+
 struct sort_entry sort_mem_daddr_sym = {
        .se_header      = "Data Symbol",
        .se_cmp         = sort__daddr_cmp,
@@ -1816,6 +1838,21 @@ struct sort_dimension {
        int                     taken;
 };
 
+int __weak arch_support_sort_key(const char *sort_key __maybe_unused)
+{
+       return 0;
+}
+
+const char * __weak arch_perf_header_entry(const char *se_header)
+{
+       return se_header;
+}
+
+static void sort_dimension_add_dynamic_header(struct sort_dimension *sd)
+{
+       sd->entry->se_header = arch_perf_header_entry(sd->entry->se_header);
+}
+
 #define DIM(d, n, func) [d] = { .name = n, .entry = &(func) }
 
 static struct sort_dimension common_sort_dimensions[] = {
@@ -1841,6 +1878,7 @@ static struct sort_dimension common_sort_dimensions[] = {
        DIM(SORT_CODE_PAGE_SIZE, "code_page_size", sort_code_page_size),
        DIM(SORT_LOCAL_INS_LAT, "local_ins_lat", sort_local_ins_lat),
        DIM(SORT_GLOBAL_INS_LAT, "ins_lat", sort_global_ins_lat),
+       DIM(SORT_PIPELINE_STAGE_CYC, "p_stage_cyc", sort_p_stage_cyc),
 };
 
 #undef DIM
@@ -2739,7 +2777,20 @@ int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
                        struct evlist *evlist,
                        int level)
 {
-       unsigned int i;
+       unsigned int i, j;
+
+       /*
+        * Check to see if there are any arch specific
+        * sort dimensions not applicable for the current
+        * architecture. If so, Skip that sort key since
+        * we don't want to display it in the output fields.
+        */
+       for (j = 0; j < ARRAY_SIZE(arch_specific_sort_keys); j++) {
+               if (!strcmp(arch_specific_sort_keys[j], tok) &&
+                               !arch_support_sort_key(tok)) {
+                       return 0;
+               }
+       }
 
        for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) {
                struct sort_dimension *sd = &common_sort_dimensions[i];
@@ -2747,6 +2798,11 @@ int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
                if (strncasecmp(tok, sd->name, strlen(tok)))
                        continue;
 
+               for (j = 0; j < ARRAY_SIZE(dynamic_headers); j++) {
+                       if (!strcmp(dynamic_headers[j], sd->name))
+                               sort_dimension_add_dynamic_header(sd);
+               }
+
                if (sd->entry == &sort_parent) {
                        int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED);
                        if (ret) {