memstress.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * tools/testing/selftests/kvm/include/memstress.h
  4. *
  5. * Copyright (C) 2020, Google LLC.
  6. */
  7. #ifndef SELFTEST_KVM_MEMSTRESS_H
  8. #define SELFTEST_KVM_MEMSTRESS_H
  9. #include <pthread.h>
  10. #include "kvm_util.h"
  11. /* Default guest test virtual memory offset */
  12. #define DEFAULT_GUEST_TEST_MEM 0xc0000000
  13. #define DEFAULT_PER_VCPU_MEM_SIZE (1 << 30) /* 1G */
  14. #define MEMSTRESS_MEM_SLOT_INDEX 1
  15. struct memstress_vcpu_args {
  16. uint64_t gpa;
  17. uint64_t gva;
  18. uint64_t pages;
  19. /* Only used by the host userspace part of the vCPU thread */
  20. struct kvm_vcpu *vcpu;
  21. int vcpu_idx;
  22. };
  23. struct memstress_args {
  24. struct kvm_vm *vm;
  25. /* The starting address and size of the guest test region. */
  26. uint64_t gpa;
  27. uint64_t size;
  28. uint64_t guest_page_size;
  29. uint32_t random_seed;
  30. uint32_t write_percent;
  31. /* Run vCPUs in L2 instead of L1, if the architecture supports it. */
  32. bool nested;
  33. /* Randomize which pages are accessed by the guest. */
  34. bool random_access;
  35. /* True if all vCPUs are pinned to pCPUs */
  36. bool pin_vcpus;
  37. /* The vCPU=>pCPU pinning map. Only valid if pin_vcpus is true. */
  38. uint32_t vcpu_to_pcpu[KVM_MAX_VCPUS];
  39. /* Test is done, stop running vCPUs. */
  40. bool stop_vcpus;
  41. struct memstress_vcpu_args vcpu_args[KVM_MAX_VCPUS];
  42. };
  43. extern struct memstress_args memstress_args;
  44. struct kvm_vm *memstress_create_vm(enum vm_guest_mode mode, int nr_vcpus,
  45. uint64_t vcpu_memory_bytes, int slots,
  46. enum vm_mem_backing_src_type backing_src,
  47. bool partition_vcpu_memory_access);
  48. void memstress_destroy_vm(struct kvm_vm *vm);
  49. void memstress_set_write_percent(struct kvm_vm *vm, uint32_t write_percent);
  50. void memstress_set_random_access(struct kvm_vm *vm, bool random_access);
  51. void memstress_start_vcpu_threads(int vcpus, void (*vcpu_fn)(struct memstress_vcpu_args *));
  52. void memstress_join_vcpu_threads(int vcpus);
  53. void memstress_guest_code(uint32_t vcpu_id);
  54. uint64_t memstress_nested_pages(int nr_vcpus);
  55. void memstress_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_vcpu *vcpus[]);
  56. void memstress_enable_dirty_logging(struct kvm_vm *vm, int slots);
  57. void memstress_disable_dirty_logging(struct kvm_vm *vm, int slots);
  58. void memstress_get_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], int slots);
  59. void memstress_clear_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[],
  60. int slots, uint64_t pages_per_slot);
  61. unsigned long **memstress_alloc_bitmaps(int slots, uint64_t pages_per_slot);
  62. void memstress_free_bitmaps(unsigned long *bitmaps[], int slots);
  63. #endif /* SELFTEST_KVM_MEMSTRESS_H */