HPCToolkit
pmu_power.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2018, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 #include <linux/version.h>
48 
55 
56 #include "datacentric.h"
57 
58 // list of precise events
59 
60 #define EVNAME_POWER_RMRM "PM_MRK_DATA_FROM_RMEM"
61 #define EVNAME_POWER_DL4 "PM_MRK_DATA_FROM_DL4"
62 #define EVNAME_POWER_LMEM "PM_MRK_DATA_FROM_LMEM"
63 
64 
71 static const char *evnames[] = {
75 };
76 
77 
78 void
80  cct_node_t *datacentric_node,
81  cct_node_t *sample_node)
82 {}
83 
84 int
86  struct event_threshold_s *period)
87 {
88  int size = sizeof(evnames)/sizeof(const char*);
89  u64 sample_type = PERF_SAMPLE_CALLCHAIN
90  | PERF_SAMPLE_PERIOD | PERF_SAMPLE_TIME
91  | PERF_SAMPLE_IP | PERF_SAMPLE_ADDR
92  | PERF_SAMPLE_CPU | PERF_SAMPLE_TID
93 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
94  | PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_WEIGHT
95 #endif
96  ;
97 
98  int num_pmu = 0;
99 
100  for(int i=0; i<size ; i++) {
101  struct perf_event_attr event_attr;
102 
103  int isPMU = pfmu_getEventAttribute(evnames[i], &event_attr);
104  if (isPMU < 0) continue;
105 
106  //set_default_perf_event_attr(event_attr, period);
107  bool is_period = period->threshold_type == PERIOD;
108  perf_util_attr_init(evnames[i], &event_attr, is_period, period->threshold_num, sample_type);
109  perf_skid_set_max_precise_ip(&event_attr);
110 
111  // testing the feasibility;
112  int ret = perf_event_open(&event_attr,
114 
115  if (ret >= 0) {
116  close(ret);
117  num_pmu++;
118 
119  // ------------------------------------------
120  // create metric data centric
121  // ------------------------------------------
122  int metric = hpcrun_new_metric();
124  metric, evnames[i],
126 
127  // ------------------------------------------
128  // Register the event to the global list
129  // ------------------------------------------
131  einfo->metric_custom = event;
132  memcpy(&einfo->attr, &event_attr, sizeof(struct perf_event_attr));
133 
134  METHOD_CALL(self, store_event_and_info,
135  event_attr.config, /* event id */
136  1, /* threshold */
137  metric, /* metric id */
138  einfo /* info pointer */ );
139 
140  }
141  }
142  return num_pmu;
143 }
#define GROUP_FD
static const char * evnames[]
Definition: pmu_power.c:71
static struct perf_mem_metric metric
Definition: pmu_x86.c:114
int perf_skid_set_max_precise_ip(struct perf_event_attr *attr)
Definition: perf_skid.c:176
struct perf_event_attr attr
Definition: perf-util.h:138
struct event_custom_s * metric_custom
Definition: perf-util.h:139
metric_desc_t * hpcrun_set_metric_info_and_period(int metric_id, const char *name, MetricFlags_ValFmt_t valFmt, size_t period, metric_desc_properties_t prop)
Definition: metrics.c:411
#define PERF_FLAGS
long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags)
#define CPU_ANY
#define THREAD_SELF
enum threshold_e threshold_type
Definition: perf-util.h:75
void * hpcrun_malloc(size_t size)
Definition: mem.c:275
int perf_util_attr_init(const char *event_name, struct perf_event_attr *attr, bool usePeriod, u64 threshold, u64 sampletype)
Definition: perf-util.c:403
__u64 u64
#define METHOD_CALL(obj, meth,...)
Definition: simple_oo.h:87
int datacentric_hw_register(sample_source_t *self, event_custom_t *event, struct event_threshold_s *period)
Definition: pmu_power.c:85
#define EVNAME_POWER_RMRM
Definition: pmu_power.c:60
Definition: cct.c:96
#define EVNAME_POWER_LMEM
Definition: pmu_power.c:62
int hpcrun_new_metric(void)
Definition: metrics.c:333
void datacentric_hw_handler(perf_mmap_data_t *mmap_data, cct_node_t *datacentric_node, cct_node_t *sample_node)
Definition: pmu_power.c:79
static long period
Definition: itimer.c:194
int pfmu_getEventAttribute(const char *eventname, struct perf_event_attr *event_attr)
#define metric_property_none
Definition: hpcrun-fmt.h:202
#define EVNAME_POWER_DL4
Definition: pmu_power.c:61