Merge remote-tracking branch 'torvalds/master' into perf/core
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 22 Jun 2021 16:56:50 +0000 (13:56 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 22 Jun 2021 16:56:50 +0000 (13:56 -0300)
To pick up fixes, since perf/urgent is already upstream.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1  2 
tools/perf/Makefile.config
tools/perf/builtin-record.c
tools/perf/tests/shell/stat_bpf_counters.sh
tools/perf/util/env.c
tools/perf/util/evsel.c
tools/perf/util/session.c
tools/perf/util/stat-display.c

@@@ -90,7 -90,6 +90,6 @@@ endi
  ifeq ($(ARCH),mips)
    NO_PERF_REGS := 0
    CFLAGS += -I$(OUTPUT)arch/mips/include/generated
-   CFLAGS += -I../../arch/mips/include/uapi -I../../arch/mips/include/generated/uapi
    LIBUNWIND_LIBS = -lunwind -lunwind-mips
  endif
  
@@@ -202,12 -201,6 +201,12 @@@ ifeq ($(call get-executable,$(BISON)),
    dummy := $(error Error: $(BISON) is missing on this system, please install it)
  endif
  
 +ifneq ($(OUTPUT),)
 +  ifeq ($(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 371), 1)
 +    BISON_FILE_PREFIX_MAP := --file-prefix-map=$(OUTPUT)=
 +  endif
 +endif
 +
  # Treat warnings as errors unless directed not to
  ifneq ($(WERROR),0)
    CORE_CFLAGS += -Werror
@@@ -641,7 -634,7 +640,7 @@@ endi
  ifdef BUILD_BPF_SKEL
    $(call feature_check,clang-bpf-co-re)
    ifeq ($(feature-clang-bpf-co-re), 0)
 -    dummy := $(error Error: clang too old. Please install recent clang)
 +    dummy := $(error Error: clang too old/not installed. Please install recent clang to build with BUILD_BPF_SKEL)
    endif
    $(call detected,CONFIG_PERF_BPF_SKEL)
    CFLAGS += -DHAVE_BPF_SKEL
@@@ -1234,9 -1227,6 +1233,9 @@@ $(call detected_var,LIBDIR
  $(call detected_var,GTK_CFLAGS)
  $(call detected_var,PERL_EMBED_CCOPTS)
  $(call detected_var,PYTHON_EMBED_CCOPTS)
 +ifneq ($(BISON_FILE_PREFIX_MAP),)
 +$(call detected_var,BISON_FILE_PREFIX_MAP)
 +endif
  
  # re-generate FEATURE-DUMP as we may have called feature_check, found out
  # extra libraries to add to LDFLAGS of some other test and then redo those
@@@ -969,15 -969,6 +969,15 @@@ out
        return rc;
  }
  
 +static void set_timestamp_boundary(struct record *rec, u64 sample_time)
 +{
 +      if (rec->evlist->first_sample_time == 0)
 +              rec->evlist->first_sample_time = sample_time;
 +
 +      if (sample_time)
 +              rec->evlist->last_sample_time = sample_time;
 +}
 +
  static int process_sample_event(struct perf_tool *tool,
                                union perf_event *event,
                                struct perf_sample *sample,
  {
        struct record *rec = container_of(tool, struct record, tool);
  
 -      if (rec->evlist->first_sample_time == 0)
 -              rec->evlist->first_sample_time = sample->time;
 -
 -      rec->evlist->last_sample_time = sample->time;
 +      set_timestamp_boundary(rec, sample->time);
  
        if (rec->buildid_all)
                return 0;
@@@ -2408,17 -2402,6 +2408,17 @@@ static int build_id__process_mmap2(stru
        return perf_event__process_mmap2(tool, event, sample, machine);
  }
  
 +static int process_timestamp_boundary(struct perf_tool *tool,
 +                                    union perf_event *event __maybe_unused,
 +                                    struct perf_sample *sample,
 +                                    struct machine *machine __maybe_unused)
 +{
 +      struct record *rec = container_of(tool, struct record, tool);
 +
 +      set_timestamp_boundary(rec, sample->time);
 +      return 0;
 +}
 +
  /*
   * XXX Ideally would be local to cmd_record() and passed to a record__new
   * because we need to have access to it in record__exit, that is called
@@@ -2453,8 -2436,6 +2453,8 @@@ static struct record record = 
                .namespaces     = perf_event__process_namespaces,
                .mmap           = build_id__process_mmap,
                .mmap2          = build_id__process_mmap2,
 +              .itrace_start   = process_timestamp_boundary,
 +              .aux            = process_timestamp_boundary,
                .ordered_events = true,
        },
  };
@@@ -2733,6 -2714,12 +2733,12 @@@ int cmd_record(int argc, const char **a
                rec->no_buildid = true;
        }
  
+       if (rec->opts.record_cgroup && !perf_can_record_cgroup()) {
+               pr_err("Kernel has no cgroup sampling support.\n");
+               err = -EINVAL;
+               goto out_opts;
+       }
        if (rec->opts.kcore)
                rec->data.is_dir = true;
  
@@@ -11,9 -11,9 +11,9 @@@ compare_number(
         second_num=$2
  
         # upper bound is first_num * 110%
-        upper=$(( $first_num + $first_num / 10 ))
+        upper=$(expr $first_num + $first_num / 10 )
         # lower bound is first_num * 90%
-        lower=$(( $first_num - $first_num / 10 ))
+        lower=$(expr $first_num - $first_num / 10 )
  
         if [ $second_num -gt $upper ] || [ $second_num -lt $lower ]; then
                 echo "The difference between $first_num and $second_num are greater than 10%."
  }
  
  # skip if --bpf-counters is not supported
 -perf stat --bpf-counters true > /dev/null 2>&1 || exit 2
 +if ! perf stat --bpf-counters true > /dev/null 2>&1; then
 +      if [ "$1" == "-v" ]; then
 +              echo "Skipping: --bpf-counters not supported"
 +              perf --no-pager stat --bpf-counters true || true
 +      fi
 +      exit 2
 +fi
  
  base_cycles=$(perf stat --no-big-num -e cycles -- perf bench sched messaging -g 1 -l 100 -t 2>&1 | awk '/cycles/ {print $1}')
 +if [ "$base_cycles" == "<not" ]; then
 +      echo "Skipping: cycles event not counted"
 +      exit 2
 +fi
  bpf_cycles=$(perf stat --no-big-num --bpf-counters -e cycles -- perf bench sched messaging -g 1 -l 100 -t 2>&1 | awk '/cycles/ {print $1}')
 +if [ "$bpf_cycles" == "<not" ]; then
 +      echo "Failed: cycles not counted with --bpf-counters"
 +      exit 1
 +fi
  
  compare_number $base_cycles $bpf_cycles
  exit 0
diff --combined tools/perf/util/env.c
@@@ -144,6 -144,7 +144,7 @@@ static void perf_env__purge_bpf(struct 
                node = rb_entry(next, struct bpf_prog_info_node, rb_node);
                next = rb_next(&node->rb_node);
                rb_erase(&node->rb_node, root);
+               free(node->info_linear);
                free(node);
        }
  
@@@ -202,18 -203,6 +203,18 @@@ void perf_env__exit(struct perf_env *en
        for (i = 0; i < env->nr_memory_nodes; i++)
                zfree(&env->memory_nodes[i].set);
        zfree(&env->memory_nodes);
 +
 +      for (i = 0; i < env->nr_hybrid_nodes; i++) {
 +              zfree(&env->hybrid_nodes[i].pmu_name);
 +              zfree(&env->hybrid_nodes[i].cpus);
 +      }
 +      zfree(&env->hybrid_nodes);
 +
 +      for (i = 0; i < env->nr_hybrid_cpc_nodes; i++) {
 +              zfree(&env->hybrid_cpc_nodes[i].cpu_pmu_caps);
 +              zfree(&env->hybrid_cpc_nodes[i].pmu_name);
 +      }
 +      zfree(&env->hybrid_cpc_nodes);
  }
  
  void perf_env__init(struct perf_env *env __maybe_unused)
diff --combined tools/perf/util/evsel.c
@@@ -428,6 -428,7 +428,7 @@@ struct evsel *evsel__clone(struct evse
        evsel->auto_merge_stats = orig->auto_merge_stats;
        evsel->collect_stat = orig->collect_stat;
        evsel->weak_group = orig->weak_group;
+       evsel->use_config_name = orig->use_config_name;
  
        if (evsel__copy_config_terms(evsel, orig) < 0)
                goto out_err;
@@@ -1581,27 -1582,6 +1582,27 @@@ int __evsel__read_on_cpu(struct evsel *
        return 0;
  }
  
 +static int evsel__match_other_cpu(struct evsel *evsel, struct evsel *other,
 +                                int cpu)
 +{
 +      int cpuid;
 +
 +      cpuid = perf_cpu_map__cpu(evsel->core.cpus, cpu);
 +      return perf_cpu_map__idx(other->core.cpus, cpuid);
 +}
 +
 +static int evsel__hybrid_group_cpu(struct evsel *evsel, int cpu)
 +{
 +      struct evsel *leader = evsel->leader;
 +
 +      if ((evsel__is_hybrid(evsel) && !evsel__is_hybrid(leader)) ||
 +          (!evsel__is_hybrid(evsel) && evsel__is_hybrid(leader))) {
 +              return evsel__match_other_cpu(evsel, leader, cpu);
 +      }
 +
 +      return cpu;
 +}
 +
  static int get_group_fd(struct evsel *evsel, int cpu, int thread)
  {
        struct evsel *leader = evsel->leader;
         */
        BUG_ON(!leader->core.fd);
  
 +      cpu = evsel__hybrid_group_cpu(evsel, cpu);
 +      if (cpu == -1)
 +              return -1;
 +
        fd = FD(leader, cpu, thread);
        BUG_ON(fd == -1);
  
@@@ -1723,6 -1723,7 +1723,7 @@@ int perf_session__peek_event(struct per
        if (event->header.size < hdr_sz || event->header.size > buf_sz)
                return -1;
  
+       buf += hdr_sz;
        rest = event->header.size - hdr_sz;
  
        if (readn(fd, buf, rest) != (ssize_t)rest)
@@@ -2155,7 -2156,6 +2156,7 @@@ struct reader 
        u64              data_size;
        u64              data_offset;
        reader_cb_t      process;
 +      bool             in_place_update;
  };
  
  static int
@@@ -2189,9 -2189,7 +2190,9 @@@ reader__process_events(struct reader *r
        mmap_prot  = PROT_READ;
        mmap_flags = MAP_SHARED;
  
 -      if (session->header.needs_swap) {
 +      if (rd->in_place_update) {
 +              mmap_prot  |= PROT_WRITE;
 +      } else if (session->header.needs_swap) {
                mmap_prot  |= PROT_WRITE;
                mmap_flags = MAP_PRIVATE;
        }
@@@ -2277,7 -2275,6 +2278,7 @@@ static int __perf_session__process_even
                .data_size      = session->header.data_size,
                .data_offset    = session->header.data_offset,
                .process        = process_simple,
 +              .in_place_update = session->data->in_place_update,
        };
        struct ordered_events *oe = &session->ordered_events;
        struct perf_tool *tool = session->tool;
@@@ -541,7 -541,7 +541,7 @@@ static void uniquify_event_name(struct 
        char *config;
        int ret = 0;
  
-       if (counter->uniquified_name ||
+       if (counter->uniquified_name || counter->use_config_name ||
            !counter->pmu_name || !strncmp(counter->name, counter->pmu_name,
                                           strlen(counter->pmu_name)))
                return;
                }
        } else {
                if (perf_pmu__has_hybrid()) {
-                       if (!counter->use_config_name) {
-                               ret = asprintf(&new_name, "%s/%s/",
-                                              counter->pmu_name, counter->name);
-                       }
+                       ret = asprintf(&new_name, "%s/%s/",
+                                      counter->pmu_name, counter->name);
                } else {
                        ret = asprintf(&new_name, "%s [%s]",
                                       counter->name, counter->pmu_name);
@@@ -827,11 -825,11 +825,11 @@@ static void counter_aggr_cb(struct perf
                            bool first __maybe_unused)
  {
        struct caggr_data *cd = data;
 -      struct perf_stat_evsel *ps = counter->stats;
 +      struct perf_counts_values *aggr = &counter->counts->aggr;
  
 -      cd->avg += avg_stats(&ps->res_stats[0]);
 -      cd->avg_enabled += avg_stats(&ps->res_stats[1]);
 -      cd->avg_running += avg_stats(&ps->res_stats[2]);
 +      cd->avg += aggr->val;
 +      cd->avg_enabled += aggr->ena;
 +      cd->avg_running += aggr->run;
  }
  
  /*