[igt-dev] [PATCH i-g-t 3/6] lib/i915: Add support for loading perf configurations

Chris Wilson chris at chris-wilson.co.uk
Tue Feb 18 18:52:02 UTC 2020


Quoting Lionel Landwerlin (2020-02-17 14:21:52)
> +void
> +intel_perf_load_perf_configs(struct intel_perf *perf, int drm_fd)
> +{
> +       int drm_card = get_card_for_fd(drm_fd);
> +       struct dirent *entry;
> +       char metrics_path[128];
> +       DIR *metrics_dir;
> +       struct intel_perf_metric_set *metric_set;
> +
> +       snprintf(metrics_path, sizeof(metrics_path),
> +                "/sys/class/drm/card%d/metrics", drm_card);

        if (fstat(i915, &st) || !S_ISCHR(st.st_mode))
                return NULL;

        snprintf(path, pathlen, "/sys/dev/char/%d:%d/metrics",
                 major(st.st_rdev), minor(st.st_rdev));


> +       metrics_dir = opendir(metrics_path);
> +       if (!metrics_dir)
> +               return;
> +
> +       while ((entry = readdir(metrics_dir))) {
> +               char *metric_id_path;
> +               uint64_t metric_id;
> +
> +               if (entry->d_type != DT_DIR)
> +                       continue;
> +
> +               asprintf(&metric_id_path, "%s/%s/id",
> +                        metrics_path, entry->d_name);

I'd suggest using openat.

> +
> +               if (!read_file_uint64(metric_id_path, &metric_id)) {
> +                       free(metric_id_path);
> +                       continue;
> +               }
> +
> +               free(metric_id_path);
> +
> +               igt_list_for_each_entry(metric_set, &perf->metric_sets, link) {
> +                       if (!strcmp(metric_set->hw_config_guid, entry->d_name)) {
> +                               metric_set->perf_oa_metrics_set = metric_id;
> +                               break;
> +                       }
> +               }
> +       }


More information about the igt-dev mailing list