gpt4 book ai didi

linux - 我可以获得用户空间中断或有关 PMC 溢出的其他指示吗

转载 作者:行者123 更新时间:2023-12-01 22:10:38 25 4
gpt4 key购买 nike

我可以配置 perf 以便在 PMC 溢出时收到用户空间中断或其他通知吗?

也就是说,通常当 PMC 溢出时,内核会处理更新计数器、采样或其他需要完成的簿记工作,但我对在用户空间中接收这些内容并采取一些操作感兴趣。

最佳答案

根据man 2 perf_event_open ,“溢出处理”部分有perf_event_attr.watermark=0; perf_event_attr.wakeup_events=1 模式,可以在 fd 上生成事件,或者为添加到 perf_events 的 rind 缓冲区中的每个样本调用信号处理程序(在采样模式下,如 perf record)

 watermark    If set ...  Otherwise, overflow notifications happen 
after wakeup_events samples.
wakeup_events
This union sets how many samples (wakeup_events) happen
before an overflow notification happens.

wakeup_events counts only PERF_RECORD_SAMPLE record types. To
receive overflow notification for all PERF_RECORD types choose
watermark and set wakeup_watermark to 1.

Overflow handling

Events can be set to notify when a threshold is crossed, indicating
an overflow. Overflow conditions can be captured by monitoring the
event file descriptor with poll(2), select(2), or epoll(7). Alterna‐
tively, the overflow events can be captured via sa signal handler, by
enabling I/O signaling on the file descriptor; see the discussion of
the F_SETOWN and F_SETSIG operations in fcntl(2).

Overflows are generated only by sampling events (sample_period must
have a nonzero value).

There are two ways to generate overflow notifications.

The first is to set a wakeup_events or wakeup_watermark value that
will trigger if a certain number of samples or bytes have been writ‐
ten to the mmap ring buffer. In this case, POLL_IN is indicated.

The other way is by use of the PERF_EVENT_IOC_REFRESH ioctl. This
ioctl adds to a counter that decrements each time the event over‐
flows. When nonzero, POLL_IN is indicated, but once the counter
reaches 0 POLL_HUP is indicated and the underlying event is disabled.

有类似但不精确的限制环形缓冲区大小的方法,例如使用 perf record 的 -m 1 选项(工具将发出信号,表示大约每 100 个样本填充环形缓冲区,并使用 poll在FD上)。这对于查看实际的 perf_event_open 参数也很有用。

 $ strace -tttT -v perf record -m 1 -e cycles:u -F 20000 python -c 'print(1)' 2>&1 |less

另请查看示例 https://mirrors.edge.kernel.org/pub/linux/kernel/tools/perf/ - 任何最近的 perf tar.gz,然后是tests/bp_signal.c 或tests/bp_signal_overflow.c:

// SPDX-License-Identifier: GPL-2.0
...
pe.sample_period = THRESHOLD;
pe.sample_type = PERF_SAMPLE_IP;
pe.wakeup_events = 1;
...
ioctl(fd, PERF_EVENT_IOC_RESET, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);

for (i = 0; i < EXECUTIONS; i++)
test_function();

ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);

关于linux - 我可以获得用户空间中断或有关 PMC 溢出的其他指示吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60271735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com