Skip to content

Comments

hwpmc: Initial support for AMD IBS#2022

Open
mashtizadeh wants to merge 1 commit intofreebsd:mainfrom
mashtizadeh:amdibs-new
Open

hwpmc: Initial support for AMD IBS#2022
mashtizadeh wants to merge 1 commit intofreebsd:mainfrom
mashtizadeh:amdibs-new

Conversation

@mashtizadeh
Copy link
Contributor

@mashtizadeh mashtizadeh commented Feb 14, 2026

This patch adds initial support for AMD IBS. It adds a new class of performance counter that cotains two events: ibs-fetch and ibs-op events. Unlike most existing sampled events, IBS events provide a number of values containing extra information regarding the sample. To support this we use the existing callchain event, and introduce a new flag for multipart payloads. The first 8 bytes of the pc_sample contains a header that defines up to four payloads.

Sponsored by: Netflix

@github-actions
Copy link

github-actions bot commented Feb 14, 2026

Thank you for taking the time to contribute to FreeBSD!

There is an issue that needs to be resolved:

  • Missing Signed-off-by lines (b9da553)

Note

Please review CONTRIBUTING.md, then update and push your branch again.

@mashtizadeh
Copy link
Contributor Author

mashtizadeh commented Feb 14, 2026

I tested that I didn't break the i386 and aarch64 builds. On AMD64 I tested the existing AMD counters and the new IBS events using pmcstat.

I've made this patch a draft until I get an external consumer of the API to give me their approval, but otherwise it's ready for review. In addition, I plan to use the multipart payload to implement LBR/BRS. In the meantime, I'll cleanup and push my other diffs including documentation.

@bsdimp @mhorne

@mashtizadeh mashtizadeh marked this pull request as draft February 14, 2026 05:39
@mashtizadeh mashtizadeh force-pushed the amdibs-new branch 4 times, most recently from 0680bd1 to 09a38f2 Compare February 15, 2026 23:01
@mhorne
Copy link
Contributor

mhorne commented Feb 16, 2026

Hi. I am unlikely to be able to review this in detail until next week.

I am not familiar with the AMD IBS feature. From a brief overview, it appears that it might be a better fit for the
hwt(4)/hwt(8) framework in FreeBSD. Have you looked into this? This tool is a divergence from hwpmc, added in the last few years to support tracing frameworks like ARM SPE and Intel PE.

Maybe or maybe it is not appropriate.

@mashtizadeh
Copy link
Contributor Author

Yes I originally thought similarly, but the problem with IBS is that it needs to be used with specific counters to provide a complete picture. IBS is also not the only exception, BRS and LBR both make more sense using this approach as they will trigger off counters. For these reasons it was an early requirement from our downstream consumer of the hwpmc module.

*/
#define PMC_MDEP_CLASS_INDEX_TSC 1
#define PMC_MDEP_CLASS_INDEX_K8 2
#define PMC_MDEP_CLASS_INDEX_IBS 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does 3 come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to not collide with other AMD counters, the Intel counters are separate.

@bsdimp
Copy link
Member

bsdimp commented Feb 19, 2026

Just a couple of questions, but overall I think it looks good. Note: I've not verified the details match the docs on this, however.

This patch adds support for AMD IBS.  It adds a new class of performance
counter that cotains two events: ibs-fetch and ibs-op events. Unlike
most existing sampled events, IBS events provide a number of values
containing extra information regarding the sample.  To support this we
use the existing callchain event, and introduce a new flag for multipart
payloads.  The first 8 bytes of the pc_sample contains a header that
defines up to four payloads.

Sponsored by: Netflix
@mashtizadeh mashtizadeh marked this pull request as ready for review February 20, 2026 17:14
@mashtizadeh
Copy link
Contributor Author

Diff is ready. Took a little longer than expected to fix the stop logic once I hit this spurious NMI on one machine. Now the PMC stop consumes several steps to clear the counter, clear the enable bit, then retry in a loop to clear the entire control register for 50us.

@mashtizadeh
Copy link
Contributor Author

Seems like someone broke kernel-toolchain so none of the builds are passing, nothing to do with hwpmc

@bsdimp
Copy link
Member

bsdimp commented Feb 20, 2026

So most of the failed builds are because monthly compute limit has been exceeded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants