Lines Matching +full:non +full:- +full:pc
1 // SPDX-License-Identifier: GPL-2.0
23 map->fd = -1;
24 map->overwrite = overwrite;
25 map->unmap_cb = unmap_cb;
26 refcount_set(&map->refcnt, 0);
28 prev->next = map;
33 return map->mask + 1 + page_size;
39 map->prev = 0;
40 map->mask = mp->mask;
41 map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
43 if (map->base == MAP_FAILED) {
44 map->base = NULL;
45 return -1;
48 map->fd = fd;
49 map->cpu = cpu;
58 zfree(&map->event_copy);
59 map->event_copy_sz = 0;
60 if (map->base) {
61 munmap(map->base, perf_mmap__mmap_len(map));
62 map->base = NULL;
63 map->fd = -1;
64 refcount_set(&map->refcnt, 0);
66 if (map->unmap_cb)
67 map->unmap_cb(map);
72 refcount_inc(&map->refcnt);
77 BUG_ON(map->base && refcount_read(&map->refcnt) == 0);
79 if (refcount_dec_and_test(&map->refcnt))
85 ring_buffer_write_tail(md->base, tail);
90 return ring_buffer_read_head(map->base);
95 struct perf_event_mmap_page *pc = map->base;
97 return perf_mmap__read_head(map) == map->prev && !pc->aux_size;
102 if (!map->overwrite) {
103 u64 old = map->prev;
108 if (refcount_read(&map->refcnt) == 1 && perf_mmap__empty(map))
121 if (evt_head - *start >= (unsigned int)size) {
123 if (evt_head - *start > (unsigned int)size)
124 evt_head -= pheader->size;
131 if (pheader->size == 0) {
137 evt_head += pheader->size;
141 return -1;
150 u64 old = md->prev;
151 unsigned char *data = md->base + page_size;
154 md->start = md->overwrite ? head : old;
155 md->end = md->overwrite ? old : head;
157 if ((md->end - md->start) < md->flush)
158 return -EAGAIN;
160 size = md->end - md->start;
161 if (size > (unsigned long)(md->mask) + 1) {
162 if (!md->overwrite) {
165 md->prev = head;
167 return -EAGAIN;
174 if (overwrite_rb_find_range(data, md->mask, &md->start, &md->end))
175 return -EINVAL;
186 if (!refcount_read(&map->refcnt))
187 return -ENOENT;
195 * The last perf_mmap__read() will set tail to map->core.prev.
196 * Need to correct the map->core.prev to head which is the end of next read.
203 if (!refcount_read(&map->refcnt))
206 map->prev = perf_mmap__read_head(map);
213 unsigned char *data = map->base + page_size;
215 int diff = end - *startp;
217 if (diff >= (int)sizeof(event->header)) {
220 event = (union perf_event *)&data[*startp & map->mask];
221 size = event->header.size;
223 if (size < sizeof(event->header) || diff < (int)size)
227 * Event straddles the mmap boundary -- header should always
230 if ((*startp & map->mask) + size != ((*startp + size) & map->mask)) {
233 void *dst = map->event_copy;
235 if (size > map->event_copy_sz) {
236 dst = realloc(map->event_copy, size);
239 map->event_copy = dst;
240 map->event_copy_sz = size;
244 cpy = min(map->mask + 1 - (offset & map->mask), len);
245 memcpy(dst, &data[offset & map->mask], cpy);
248 len -= cpy;
251 event = (union perf_event *)map->event_copy;
279 if (!refcount_read(&map->refcnt))
282 /* non-overwrite doesn't pause the ringbuffer */
283 if (!map->overwrite)
284 map->end = perf_mmap__read_head(map);
286 event = perf_mmap__read(map, &map->start, map->end);
288 if (!map->overwrite)
289 map->prev = map->start;
409 /* __riscv_xlen contains the witdh of the native base integer, here 64-bit */
482 struct perf_event_mmap_page *pc = map->base;
486 if (!pc || !pc->cap_user_rdpmc)
487 return -1;
490 seq = READ_ONCE(pc->lock);
493 count->ena = READ_ONCE(pc->time_enabled);
494 count->run = READ_ONCE(pc->time_running);
496 if (pc->cap_user_time && count->ena != count->run) {
498 time_mult = READ_ONCE(pc->time_mult);
499 time_shift = READ_ONCE(pc->time_shift);
500 time_offset = READ_ONCE(pc->time_offset);
502 if (pc->cap_user_time_short) {
503 time_cycles = READ_ONCE(pc->time_cycles);
504 time_mask = READ_ONCE(pc->time_mask);
508 idx = READ_ONCE(pc->index);
509 cnt = READ_ONCE(pc->offset);
510 if (pc->cap_user_rdpmc && idx) {
511 s64 evcnt = read_perf_counter(idx - 1);
512 u16 width = READ_ONCE(pc->pmc_width);
514 evcnt <<= 64 - width;
515 evcnt >>= 64 - width;
518 return -1;
521 } while (READ_ONCE(pc->lock) != seq);
523 if (count->ena != count->run) {
527 cyc = time_cycles + ((cyc - time_cycles) & time_mask);
531 count->ena += delta;
533 count->run += delta;
536 count->val = cnt;