Mathieu Poirier | 859442b | 2016-09-16 09:50:02 -0600 | [diff] [blame] | 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 | |
| 16 | #include "drv_configs.h" |
| 17 | #include "evlist.h" |
| 18 | #include "evsel.h" |
| 19 | #include "pmu.h" |
| 20 | |
| 21 | static int |
| 22 | perf_evsel__apply_drv_configs(struct perf_evsel *evsel, |
| 23 | struct perf_evsel_config_term **err_term) |
| 24 | { |
| 25 | bool found = false; |
| 26 | int err = 0; |
| 27 | struct perf_evsel_config_term *term; |
| 28 | struct perf_pmu *pmu = NULL; |
| 29 | |
| 30 | while ((pmu = perf_pmu__scan(pmu)) != NULL) |
| 31 | if (pmu->type == evsel->attr.type) { |
| 32 | found = true; |
| 33 | break; |
| 34 | } |
| 35 | |
| 36 | list_for_each_entry(term, &evsel->config_terms, list) { |
| 37 | if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG) |
| 38 | continue; |
| 39 | |
| 40 | /* |
| 41 | * We have a configuration term, report an error if we |
| 42 | * can't find the PMU or if the PMU driver doesn't support |
| 43 | * cmd line driver configuration. |
| 44 | */ |
| 45 | if (!found || !pmu->set_drv_config) { |
| 46 | err = -EINVAL; |
| 47 | *err_term = term; |
| 48 | break; |
| 49 | } |
| 50 | |
| 51 | err = pmu->set_drv_config(term); |
| 52 | if (err) { |
| 53 | *err_term = term; |
| 54 | break; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return err; |
| 59 | } |
| 60 | |
| 61 | int perf_evlist__apply_drv_configs(struct perf_evlist *evlist, |
| 62 | struct perf_evsel **err_evsel, |
| 63 | struct perf_evsel_config_term **err_term) |
| 64 | { |
| 65 | struct perf_evsel *evsel; |
| 66 | int err = 0; |
| 67 | |
| 68 | evlist__for_each_entry(evlist, evsel) { |
| 69 | err = perf_evsel__apply_drv_configs(evsel, err_term); |
| 70 | if (err) { |
| 71 | *err_evsel = evsel; |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return err; |
| 77 | } |