Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TLB resource management #43

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

joelsmithTT
Copy link
Contributor

Introduce TLB resource management to KMD.

https://tenstorrent.atlassian.net/wiki/spaces/syseng/pages/537100642/Inbound+PCIe+TLBs

Key features:

  • TLB window allocation: ioctl interface for allocating windows of specific sizes
  • TLB window configuration: ioctl interface for configuring TLB windows with NOC routing parameters
  • TLB window mapping: mmap interface for mapping windows to userspace with either UC or WC caching attributes

Implementation details:

  • Core management interfaces in tlb.h / tlb.c
  • Extended device class structure with TLB specific capabilities
  • Extended memory mapping logic to support TLB windows
  • Added support for Blackhole (Wormhole/Grayskull are not implemented)

Future work:

  • Wormhole support
  • Check NOC window parameters for validity

Copy link

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

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

Looks good to me - I defer to @alewycky-tenstorrent for approval, but am looking forward to using this.

This is the first part of moving TLB window management into the driver.
Add the necessary interfaces and data structures for TLB window
allocation, configuration, and ownership tracking:

- Add bitmap and refcount tracking in chardev_private for per-fd TLB
  ownership
- Define new IOCTLs for TLB allocation, freeing, and configuration
- Add TLB management callback interfaces to device class
- Add tlb.h
Implement the TLB management interfaces introduced in the previous
commit:

- Add TLB allocation logic using bitmap tracking at the device level
- Add TLB allocation, freeing, and configuration IOCTL handlers
- Add cleanup of TLBs on file descriptor close
- Extend mmap offset space to accommodate TLB windows
- Add tlb.c implementing core TLB management functions

The allocation strategy supports multiple TLB kinds of different sizes,
selecting the smallest TLB that can accommodate the requested size.  The
actual TLB configuration is delegated to device-specific implementations
via the device class callbacks.
Implement memory mapping support for TLB windows:

- Add map_tlb_window function to handle TLB-specific mmap requests
- Add vma_close() handler to track TLB mapping reference counts
- Wire up TLB window mapping in tenstorrent_mmap()

The implementation uses reference counting to track active mappings of
each TLB window, ensuring we don't free TLBs that are still mapped into
user address spaces.  Window mappings are backed by PCI BAR regions.
- Support both 2M and 4G window sizes
- Add separate configuration handlers for each size
- Add TLB descriptor implementation
- Convert kernel TLB window usage to new interface

The Blackhole chip provides 202 2M windows and 8 4G windows, mapped
through BAR0 and BAR4 respectively.
@joelsmithTT joelsmithTT force-pushed the joelsmith/tlb-resource-admin branch from 12c9241 to 24902be Compare February 28, 2025 21:42
@joelsmithTT joelsmithTT force-pushed the joelsmith/tlb-resource-admin branch 2 times, most recently from 0709e42 to 3b3fc9d Compare March 4, 2025 02:07
- Support 1M, 2M, and 16M window sizes
- Constructs register config for all TLB kinds into a u64
- Sanity check for address alignment and width

Wormhole supports 156 1M windows, 10 2M windows, and 20 16M windows, all
in BAR0.
@joelsmithTT joelsmithTT force-pushed the joelsmith/tlb-resource-admin branch from 3b3fc9d to 420f2d9 Compare March 4, 2025 02:08
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.

2 participants