evlist.c (351a1f5c8afa13ea5cfcdae543f6596ef8ebdbd9) evlist.c (a583053299c1e66e6202b494cbc3acd93cedc4cc)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
4 *
5 * Parts came from builtin-{top,stat,record}.c, see those files for further
6 * copyright notes.
7 */
8#include <api/fs/fs.h>

--- 409 unchanged lines hidden (view full) ---

418 if (fdarray__available_entries(&evlist->pollfd) < nfds &&
419 fdarray__grow(&evlist->pollfd, nfds) < 0)
420 return -ENOMEM;
421
422 return 0;
423}
424
425static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd,
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
4 *
5 * Parts came from builtin-{top,stat,record}.c, see those files for further
6 * copyright notes.
7 */
8#include <api/fs/fs.h>

--- 409 unchanged lines hidden (view full) ---

418 if (fdarray__available_entries(&evlist->pollfd) < nfds &&
419 fdarray__grow(&evlist->pollfd, nfds) < 0)
420 return -ENOMEM;
421
422 return 0;
423}
424
425static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd,
426 struct perf_mmap *map, short revent)
426 struct mmap *map, short revent)
427{
428 int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
429 /*
430 * Save the idx so that when we filter out fds POLLHUP'ed we can
431 * close the associated evlist->mmap[] entry.
432 */
433 if (pos >= 0) {
434 evlist->pollfd.priv[pos].ptr = map;

--- 7 unchanged lines hidden (view full) ---

442int perf_evlist__add_pollfd(struct evlist *evlist, int fd)
443{
444 return __perf_evlist__add_pollfd(evlist, fd, NULL, POLLIN);
445}
446
447static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
448 void *arg __maybe_unused)
449{
427{
428 int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
429 /*
430 * Save the idx so that when we filter out fds POLLHUP'ed we can
431 * close the associated evlist->mmap[] entry.
432 */
433 if (pos >= 0) {
434 evlist->pollfd.priv[pos].ptr = map;

--- 7 unchanged lines hidden (view full) ---

442int perf_evlist__add_pollfd(struct evlist *evlist, int fd)
443{
444 return __perf_evlist__add_pollfd(evlist, fd, NULL, POLLIN);
445}
446
447static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
448 void *arg __maybe_unused)
449{
450 struct perf_mmap *map = fda->priv[fd].ptr;
450 struct mmap *map = fda->priv[fd].ptr;
451
452 if (map)
453 perf_mmap__put(map);
454}
455
456int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
457{
458 return fdarray__filter(&evlist->pollfd, revents_and_mask,

--- 229 unchanged lines hidden (view full) ---

688
689void perf_evlist__munmap(struct evlist *evlist)
690{
691 perf_evlist__munmap_nofree(evlist);
692 zfree(&evlist->mmap);
693 zfree(&evlist->overwrite_mmap);
694}
695
451
452 if (map)
453 perf_mmap__put(map);
454}
455
456int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
457{
458 return fdarray__filter(&evlist->pollfd, revents_and_mask,

--- 229 unchanged lines hidden (view full) ---

688
689void perf_evlist__munmap(struct evlist *evlist)
690{
691 perf_evlist__munmap_nofree(evlist);
692 zfree(&evlist->mmap);
693 zfree(&evlist->overwrite_mmap);
694}
695
696static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
696static struct mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
697 bool overwrite)
698{
699 int i;
697 bool overwrite)
698{
699 int i;
700 struct perf_mmap *map;
700 struct mmap *map;
701
702 evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
703 if (perf_cpu_map__empty(evlist->core.cpus))
704 evlist->nr_mmaps = perf_thread_map__nr(evlist->core.threads);
701
702 evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
703 if (perf_cpu_map__empty(evlist->core.cpus))
704 evlist->nr_mmaps = perf_thread_map__nr(evlist->core.threads);
705 map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
705 map = zalloc(evlist->nr_mmaps * sizeof(struct mmap));
706 if (!map)
707 return NULL;
708
709 for (i = 0; i < evlist->nr_mmaps; i++) {
710 map[i].fd = -1;
711 map[i].overwrite = overwrite;
712 /*
713 * When the perf_mmap() call is made we grab one refcount, plus

--- 22 unchanged lines hidden (view full) ---

736 struct mmap_params *mp, int cpu_idx,
737 int thread, int *_output, int *_output_overwrite)
738{
739 struct evsel *evsel;
740 int revent;
741 int evlist_cpu = cpu_map__cpu(evlist->core.cpus, cpu_idx);
742
743 evlist__for_each_entry(evlist, evsel) {
706 if (!map)
707 return NULL;
708
709 for (i = 0; i < evlist->nr_mmaps; i++) {
710 map[i].fd = -1;
711 map[i].overwrite = overwrite;
712 /*
713 * When the perf_mmap() call is made we grab one refcount, plus

--- 22 unchanged lines hidden (view full) ---

736 struct mmap_params *mp, int cpu_idx,
737 int thread, int *_output, int *_output_overwrite)
738{
739 struct evsel *evsel;
740 int revent;
741 int evlist_cpu = cpu_map__cpu(evlist->core.cpus, cpu_idx);
742
743 evlist__for_each_entry(evlist, evsel) {
744 struct perf_mmap *maps = evlist->mmap;
744 struct mmap *maps = evlist->mmap;
745 int *output = _output;
746 int fd;
747 int cpu;
748
749 mp->prot = PROT_READ | PROT_WRITE;
750 if (evsel->core.attr.write_backward) {
751 output = _output_overwrite;
752 maps = evlist->overwrite_mmap;

--- 1089 unchanged lines hidden (view full) ---

1842
1843 if (evlist->thread.done)
1844 draining = true;
1845
1846 if (!draining)
1847 perf_evlist__poll(evlist, 1000);
1848
1849 for (i = 0; i < evlist->nr_mmaps; i++) {
745 int *output = _output;
746 int fd;
747 int cpu;
748
749 mp->prot = PROT_READ | PROT_WRITE;
750 if (evsel->core.attr.write_backward) {
751 output = _output_overwrite;
752 maps = evlist->overwrite_mmap;

--- 1089 unchanged lines hidden (view full) ---

1842
1843 if (evlist->thread.done)
1844 draining = true;
1845
1846 if (!draining)
1847 perf_evlist__poll(evlist, 1000);
1848
1849 for (i = 0; i < evlist->nr_mmaps; i++) {
1850 struct perf_mmap *map = &evlist->mmap[i];
1850 struct mmap *map = &evlist->mmap[i];
1851 union perf_event *event;
1852
1853 if (perf_mmap__read_init(map))
1854 continue;
1855 while ((event = perf_mmap__read_event(map)) != NULL) {
1856 struct evsel *evsel = perf_evlist__event2evsel(evlist, event);
1857
1858 if (evsel && evsel->side_band.cb)

--- 61 unchanged lines hidden ---
1851 union perf_event *event;
1852
1853 if (perf_mmap__read_init(map))
1854 continue;
1855 while ((event = perf_mmap__read_event(map)) != NULL) {
1856 struct evsel *evsel = perf_evlist__event2evsel(evlist, event);
1857
1858 if (evsel && evsel->side_band.cb)

--- 61 unchanged lines hidden ---