Re: [RFC v2 5/5] ktest: sys_move_phys_pages ktest
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Date: 2023-10-02 14:09:33
Also in:
linux-arch, linux-cxl, lkml
On Tue, 19 Sep 2023 19:09:08 -0400 Gregory Price [off-list ref] wrote:
Implement simple ktest that looks up the physical address via /proc/self/pagemap and migrates the page based on that information. Signed-off-by: Gregory Price <redacted>
One trivial comment inline.
quoted hunk ↗ jump to hunk
--- tools/testing/selftests/mm/migration.c | 101 +++++++++++++++++++++++++ 1 file changed, 101 insertions(+)diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftests/mm/migration.c index 6908569ef406..67fbae243f94 100644 --- a/tools/testing/selftests/mm/migration.c +++ b/tools/testing/selftests/mm/migration.c@@ -5,6 +5,8 @@ */ #include "../kselftest_harness.h" +#include <stdint.h> +#include <stdio.h> #include <strings.h> #include <pthread.h> #include <numa.h>@@ -14,11 +16,17 @@ #include <sys/types.h> #include <signal.h> #include <time.h> +#include <unistd.h> #define TWOMEG (2<<20) #define RUNTIME (20) +#define GET_BIT(X, Y) ((X & ((uint64_t)1<<Y)) >> Y) +#define GET_PFN(X) (X & 0x7FFFFFFFFFFFFFull) #define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1))) +#define PAGEMAP_ENTRY 8 +const int __endian_bit = 1; +#define is_bigendian() ((*(char *)&__endian_bit) == 0) FIXTURE(migration) {@@ -94,6 +102,47 @@ int migrate(uint64_t *ptr, int n1, int n2) return 0; } +
Trivial, but 3 lines definitely more than needed.
+
+int migrate_phys(uint64_t paddr, int n1, int n2)
+{
+ int ret, tmp;
+ int status = 0;
+ struct timespec ts1, ts2;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts1))
+ return -1;
+
+ while (1) {
+ if (clock_gettime(CLOCK_MONOTONIC, &ts2))
+ return -1;
+
+ if (ts2.tv_sec - ts1.tv_sec >= RUNTIME)
+ return 0;
+
+ /*
+ * FIXME: move_phys_pages was syscall 454 during RFC.
+ * Update this when an official syscall number is adopted
+ * and the libnuma interface is implemented.
+ */
+ ret = syscall(454, 1, (void **) &paddr, &n2, &status,
+ MPOL_MF_MOVE_ALL);
+ if (ret) {
+ if (ret > 0)
+ printf("Didn't migrate %d pages\n", ret);
+ else
+ perror("Couldn't migrate pages");
+ return -2;
+ }
+
+ tmp = n2;
+ n2 = n1;
+ n1 = tmp;
+ }
+
+ return 0;
+}