HPCToolkit
ibsop.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-2017, 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 <stdio.h>
48 
49 #include "event_info.h"
54 
55 #include "datacentric.h"
56 
57 #define IBS_OP_TYPE_FILE "/sys/bus/event_source/devices/ibs_op/type"
58 
59 #define PERF_IBS_CONFIG (1ULL<<19)
60 
61 
62 void
64  cct_node_t *datacentric_node,
65  cct_node_t *sample_node)
66 {}
67 
68 
69 int
71  struct event_threshold_s *period)
72 {
73  // get the type of ibs op
74 
75  FILE *ibs_file = fopen(IBS_OP_TYPE_FILE, "r");
76  u32 type = 0;
77 
78  if (!ibs_file) {
79  EMSG("Cannot open file: %s", IBS_OP_TYPE_FILE);
80  return 0;
81  }
82  fscanf(ibs_file, "%d", &type);
84  memset(einfo, 0, sizeof(event_info_t));
85 
86  einfo->attr.config = PERF_IBS_CONFIG;
87  einfo->attr.type = type;
88  einfo->attr.freq = period->threshold_type == FREQUENCY ? 1 : 0;
89 
90  einfo->attr.sample_period = period->threshold_num;
91 
92  u64 sample_type = PERF_SAMPLE_RAW
93  | PERF_SAMPLE_PERIOD | PERF_SAMPLE_TIME
94  | PERF_SAMPLE_IP | PERF_SAMPLE_ADDR
95  | PERF_SAMPLE_CPU | PERF_SAMPLE_TID;
96 
97  bool is_period = period->threshold_type == PERIOD;
98  perf_util_attr_init(NULL, &einfo->attr, is_period, period->threshold_num, sample_type);
100 
101  // testing the feasibility;
102  int ret = perf_event_open( &einfo->attr,
104 
105  if (ret >= 0) {
106  close(ret);
107  } else {
108  EMSG("Cannot initialize event %x, type: %d", einfo->attr.config, einfo->attr.type);
109  }
110 
111  einfo->metric_custom = event;
112 
113  // ------------------------------------------
114  // create metric data centric
115  // ------------------------------------------
116  int metric = hpcrun_new_metric();
118  metric, "IBS-OP",
120 
121  // ------------------------------------------
122  // Register the event to the global list
123  // ------------------------------------------
124  METHOD_CALL(self, store_event_and_info,
125  einfo->attr.config, 1, metric, einfo );
126 
127  return 1;
128 }
129 
#define GROUP_FD
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
#define PERF_IBS_CONFIG
Definition: ibsop.c:59
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 EMSG
Definition: messages.h:70
#define THREAD_SELF
__u32 u32
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
void datacentric_hw_handler(perf_mmap_data_t *mmap_data, cct_node_t *datacentric_node, cct_node_t *sample_node)
Definition: ibsop.c:63
__u64 u64
int datacentric_hw_register(sample_source_t *self, event_custom_t *event, struct event_threshold_s *period)
Definition: ibsop.c:70
#define METHOD_CALL(obj, meth,...)
Definition: simple_oo.h:87
#define IBS_OP_TYPE_FILE
Definition: ibsop.c:57
#define NULL
Definition: ElfHelper.cpp:85
Definition: cct.c:96
int hpcrun_new_metric(void)
Definition: metrics.c:333
static long period
Definition: itimer.c:194
#define metric_property_none
Definition: hpcrun-fmt.h:202