drv_configs.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * drv_configs.h: Interface to apply PMU specific configuration
  3. * Copyright (c) 2016-2018, Linaro Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. */
  15. #include "drv_configs.h"
  16. #include "evlist.h"
  17. #include "evsel.h"
  18. #include "pmu.h"
  19. #include <errno.h>
  20. static int
  21. perf_evsel__apply_drv_configs(struct perf_evsel *evsel,
  22. struct perf_evsel_config_term **err_term)
  23. {
  24. bool found = false;
  25. int err = 0;
  26. struct perf_evsel_config_term *term;
  27. struct perf_pmu *pmu = NULL;
  28. while ((pmu = perf_pmu__scan(pmu)) != NULL)
  29. if (pmu->type == evsel->attr.type) {
  30. found = true;
  31. break;
  32. }
  33. list_for_each_entry(term, &evsel->config_terms, list) {
  34. if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG)
  35. continue;
  36. /*
  37. * We have a configuration term, report an error if we
  38. * can't find the PMU or if the PMU driver doesn't support
  39. * cmd line driver configuration.
  40. */
  41. if (!found || !pmu->set_drv_config) {
  42. err = -EINVAL;
  43. *err_term = term;
  44. break;
  45. }
  46. err = pmu->set_drv_config(term);
  47. if (err) {
  48. *err_term = term;
  49. break;
  50. }
  51. }
  52. return err;
  53. }
  54. int perf_evlist__apply_drv_configs(struct perf_evlist *evlist,
  55. struct perf_evsel **err_evsel,
  56. struct perf_evsel_config_term **err_term)
  57. {
  58. struct perf_evsel *evsel;
  59. int err = 0;
  60. evlist__for_each_entry(evlist, evsel) {
  61. err = perf_evsel__apply_drv_configs(evsel, err_term);
  62. if (err) {
  63. *err_evsel = evsel;
  64. break;
  65. }
  66. }
  67. return err;
  68. }