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. static int
  20. perf_evsel__apply_drv_configs(struct perf_evsel *evsel,
  21. struct perf_evsel_config_term **err_term)
  22. {
  23. bool found = false;
  24. int err = 0;
  25. struct perf_evsel_config_term *term;
  26. struct perf_pmu *pmu = NULL;
  27. while ((pmu = perf_pmu__scan(pmu)) != NULL)
  28. if (pmu->type == evsel->attr.type) {
  29. found = true;
  30. break;
  31. }
  32. list_for_each_entry(term, &evsel->config_terms, list) {
  33. if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG)
  34. continue;
  35. /*
  36. * We have a configuration term, report an error if we
  37. * can't find the PMU or if the PMU driver doesn't support
  38. * cmd line driver configuration.
  39. */
  40. if (!found || !pmu->set_drv_config) {
  41. err = -EINVAL;
  42. *err_term = term;
  43. break;
  44. }
  45. err = pmu->set_drv_config(term);
  46. if (err) {
  47. *err_term = term;
  48. break;
  49. }
  50. }
  51. return err;
  52. }
  53. int perf_evlist__apply_drv_configs(struct perf_evlist *evlist,
  54. struct perf_evsel **err_evsel,
  55. struct perf_evsel_config_term **err_term)
  56. {
  57. struct perf_evsel *evsel;
  58. int err = 0;
  59. evlist__for_each_entry(evlist, evsel) {
  60. err = perf_evsel__apply_drv_configs(evsel, err_term);
  61. if (err) {
  62. *err_evsel = evsel;
  63. break;
  64. }
  65. }
  66. return err;
  67. }