Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 171638
Collapse All | Expand All

(-)a/libop/op_alloc_counter.c (-3 / +45 lines)
Lines 12-17 Link Here
12
 */
12
 */
13
13
14
#include <stdlib.h>
14
#include <stdlib.h>
15
#include <ctype.h>
16
#include <dirent.h>
15
17
16
#include "op_events.h"
18
#include "op_events.h"
17
#include "op_libiberty.h"
19
#include "op_libiberty.h"
Lines 130-136 Link Here
130
		counter_arc const * arc = list_entry(pos, counter_arc, next);
132
		counter_arc const * arc = list_entry(pos, counter_arc, next);
131
133
132
		if (allocated_mask & (1 << arc->counter))
134
		if (allocated_mask & (1 << arc->counter))
133
			return 0;
135
			continue;
134
136
135
		counter_map[depth] = arc->counter;
137
		counter_map[depth] = arc->counter;
136
138
Lines 143-148 Link Here
143
	return 0;
145
	return 0;
144
}
146
}
145
147
148
/* determine which directories are counter directories
149
 */
150
static int perfcounterdir(const struct dirent * entry)
151
{
152
	return (isdigit(entry->d_name[0]));
153
}
154
155
/**
156
 * @param mask pointer where to place bit mask of unavailable counters
157
 *
158
 * return >= 0 number of counters that are available
159
 *        < 0  could not determine number of counters
160
 *
161
 */
162
static int op_get_counter_mask(u32 * mask)
163
{
164
	struct dirent **counterlist;
165
	int count, i;
166
	/* assume nothing is available */
167
	u32 available=0;
168
169
	count = scandir("/dev/oprofile", &counterlist, perfcounterdir,
170
			alphasort);
171
	if (count < 0)
172
		/* unable to determine bit mask */
173
		return -1;
174
	/* convert to bit map (0 where counter exists) */
175
	for (i=0; i<count; ++i) {
176
		available |= 1 << atoi(counterlist[i]->d_name);
177
		free(counterlist[i]);
178
	}
179
	*mask=~available;
180
	free(counterlist);
181
	return count;
182
}
183
146
184
147
size_t * map_event_to_counter(struct op_event const * pev[], int nr_events,
185
size_t * map_event_to_counter(struct op_event const * pev[], int nr_events,
148
                              op_cpu cpu_type)
186
                              op_cpu cpu_type)
Lines 150-157 Link Here
150
	counter_arc_head * ctr_arc;
188
	counter_arc_head * ctr_arc;
151
	size_t * counter_map;
189
	size_t * counter_map;
152
	int nr_counters;
190
	int nr_counters;
191
	u32 unavailable_counters = 0;
153
192
154
	nr_counters = op_get_nr_counters(cpu_type);
193
	nr_counters = op_get_counter_mask(&unavailable_counters);
194
	if (nr_counters < 0) 
195
		nr_counters = op_get_nr_counters(cpu_type);
155
	if (nr_counters < nr_events)
196
	if (nr_counters < nr_events)
156
		return 0;
197
		return 0;
157
198
Lines 159-165 Link Here
159
200
160
	counter_map = xmalloc(nr_counters * sizeof(size_t));
201
	counter_map = xmalloc(nr_counters * sizeof(size_t));
161
202
162
	if (!allocate_counter(ctr_arc, nr_events, 0, 0, counter_map)) {
203
	if (!allocate_counter(ctr_arc, nr_events, 0, unavailable_counters,
204
			      counter_map)) {
163
		free(counter_map);
205
		free(counter_map);
164
		counter_map = 0;
206
		counter_map = 0;
165
	}
207
	}

Return to bug 171638