tools/testing/selftests/mm/hmm-tests.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/hmm-tests.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/hmm-tests.c- Extension
.c- Size
- 72717 bytes
- Lines
- 2885
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kselftest_harness.herrno.hfcntl.hstdio.hstdlib.hstdint.hunistd.hstrings.htime.hpthread.hsys/types.hsys/stat.hsys/mman.hsys/ioctl.hsys/time.hlib/test_hmm_uapi.hmm/gup_test.hmm/vm_util.h
Detected Declarations
struct hmm_bufferstruct benchmark_resultsfunction hmm_openfunction hmm_is_coherent_typefunction hmm_dmirror_cmdfunction hmm_buffer_freefunction hmm_create_filefunction hmm_randomfunction hmm_nanosleepfunction hmm_migrate_sys_to_devfunction hmm_migrate_dev_to_sysfunction mprotectfunction mprotectfunction forkfunction hmm_range_faultfunction memoryfunction gup_test_execfunction pagefunction get_time_msfunction print_benchmark_resultsfunction run_migration_benchmark
Annotated Snippet
struct hmm_buffer {
void *ptr;
void *mirror;
unsigned long size;
int fd;
uint64_t cpages;
uint64_t faults;
};
enum {
HMM_PRIVATE_DEVICE_ONE,
HMM_PRIVATE_DEVICE_TWO,
HMM_COHERENCE_DEVICE_ONE,
HMM_COHERENCE_DEVICE_TWO,
};
#define ONEKB (1 << 10)
#define ONEMEG (1 << 20)
#define TWOMEG (1 << 21)
#define HMM_BUFFER_SIZE (1024 << 12)
#define HMM_PATH_MAX 64
#define NTIMES 10
#define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1)))
/* Just the flags we need, copied from mm.h: */
#ifndef FOLL_WRITE
#define FOLL_WRITE 0x01 /* check pte is writable */
#endif
#ifndef FOLL_LONGTERM
#define FOLL_LONGTERM 0x100 /* mapping lifetime is indefinite */
#endif
FIXTURE(hmm)
{
int fd;
unsigned int page_size;
unsigned int page_shift;
};
FIXTURE_VARIANT(hmm)
{
int device_number;
};
FIXTURE_VARIANT_ADD(hmm, hmm_device_private)
{
.device_number = HMM_PRIVATE_DEVICE_ONE,
};
FIXTURE_VARIANT_ADD(hmm, hmm_device_coherent)
{
.device_number = HMM_COHERENCE_DEVICE_ONE,
};
FIXTURE(hmm2)
{
int fd0;
int fd1;
unsigned int page_size;
unsigned int page_shift;
};
FIXTURE_VARIANT(hmm2)
{
int device_number0;
int device_number1;
};
FIXTURE_VARIANT_ADD(hmm2, hmm2_device_private)
{
.device_number0 = HMM_PRIVATE_DEVICE_ONE,
.device_number1 = HMM_PRIVATE_DEVICE_TWO,
};
FIXTURE_VARIANT_ADD(hmm2, hmm2_device_coherent)
{
.device_number0 = HMM_COHERENCE_DEVICE_ONE,
.device_number1 = HMM_COHERENCE_DEVICE_TWO,
};
static int hmm_open(int unit)
{
char pathname[HMM_PATH_MAX];
int fd;
snprintf(pathname, sizeof(pathname), "/dev/hmm_dmirror%d", unit);
fd = open(pathname, O_RDWR, 0);
if (fd < 0)
fprintf(stderr, "could not open hmm dmirror driver (%s)\n",
Annotation
- Immediate include surface: `kselftest_harness.h`, `errno.h`, `fcntl.h`, `stdio.h`, `stdlib.h`, `stdint.h`, `unistd.h`, `strings.h`.
- Detected declarations: `struct hmm_buffer`, `struct benchmark_results`, `function hmm_open`, `function hmm_is_coherent_type`, `function hmm_dmirror_cmd`, `function hmm_buffer_free`, `function hmm_create_file`, `function hmm_random`, `function hmm_nanosleep`, `function hmm_migrate_sys_to_dev`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.