Linux Perf
drv_configs.c
Go to the documentation of this file.
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 #include <errno.h>
21 
22 static int
24  struct perf_evsel_config_term **err_term)
25 {
26  bool found = false;
27  int err = 0;
29  struct perf_pmu *pmu = NULL;
30 
31  while ((pmu = perf_pmu__scan(pmu)) != NULL)
32  if (pmu->type == evsel->attr.type) {
33  found = true;
34  break;
35  }
36 
37  list_for_each_entry(term, &evsel->config_terms, list) {
39  continue;
40 
41  /*
42  * We have a configuration term, report an error if we
43  * can't find the PMU or if the PMU driver doesn't support
44  * cmd line driver configuration.
45  */
46  if (!found || !pmu->set_drv_config) {
47  err = -EINVAL;
48  *err_term = term;
49  break;
50  }
51 
52  err = pmu->set_drv_config(term);
53  if (err) {
54  *err_term = term;
55  break;
56  }
57  }
58 
59  return err;
60 }
61 
63  struct perf_evsel **err_evsel,
64  struct perf_evsel_config_term **err_term)
65 {
66  struct perf_evsel *evsel;
67  int err = 0;
68 
69  evlist__for_each_entry(evlist, evsel) {
70  err = perf_evsel__apply_drv_configs(evsel, err_term);
71  if (err) {
72  *err_evsel = evsel;
73  break;
74  }
75  }
76 
77  return err;
78 }
struct list_head list
Definition: pmu.h:31
int(* set_drv_config)(struct perf_evsel_config_term *term)
Definition: pmu.h:32
int int err
Definition: 5sec.c:44
static int term(yyscan_t scanner, int type)
Definition: pmu.h:22
struct perf_pmu * perf_pmu__scan(struct perf_pmu *pmu)
Definition: pmu.c:763
enum term_type type
Definition: evsel.h:56
#define evlist__for_each_entry(evlist, evsel)
Definition: evlist.h:247
static int perf_evsel__apply_drv_configs(struct perf_evsel *evsel, struct perf_evsel_config_term **err_term)
Definition: drv_configs.c:23
struct list_head config_terms
Definition: evsel.h:139
int perf_evlist__apply_drv_configs(struct perf_evlist *evlist, struct perf_evsel **err_evsel, struct perf_evsel_config_term **err_term)
Definition: drv_configs.c:62
__u32 type
Definition: pmu.h:24
struct perf_event_attr attr
Definition: evsel.h:93