]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests/mm: fix unused variable warnings in hugetlb-madvise.c, migration.c
authorJohn Hubbard <jhubbard@nvidia.com>
Tue, 6 Jun 2023 07:16:28 +0000 (00:16 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 19 Jun 2023 23:19:01 +0000 (16:19 -0700)
Dummy variables are required in order to make these two (similar)
routines work, so in both cases, declare the variables as volatile in
order to avoid the clang compiler warning.

Furthermore, in order to ensure that each test actually does what is
intended, add an asm volatile invocation (thanks to David Hildenbrand
for the suggestion), with a clarifying comment so that it survives
future maintenance.

Link: https://lkml.kernel.org/r/20230606071637.267103-3-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/hugetlb-madvise.c
tools/testing/selftests/mm/migration.c

index 28426e30d9bc2fb40f1a780caefa0709d567cb05..d55322df4b7366c0cb3ad47a6de1092479230444 100644 (file)
@@ -65,11 +65,15 @@ void write_fault_pages(void *addr, unsigned long nr_pages)
 
 void read_fault_pages(void *addr, unsigned long nr_pages)
 {
-       unsigned long dummy = 0;
+       volatile unsigned long dummy = 0;
        unsigned long i;
 
-       for (i = 0; i < nr_pages; i++)
+       for (i = 0; i < nr_pages; i++) {
                dummy += *((unsigned long *)(addr + (i * huge_page_size)));
+
+               /* Prevent the compiler from optimizing out the entire loop: */
+               asm volatile("" : "+r" (dummy));
+       }
 }
 
 int main(int argc, char **argv)
index 1cec8425e3caac76727fa5d41551a74d8c83be99..379581567f272f58360608e1be51532d35d0f492 100644 (file)
@@ -95,12 +95,15 @@ int migrate(uint64_t *ptr, int n1, int n2)
 
 void *access_mem(void *ptr)
 {
-       uint64_t y = 0;
+       volatile uint64_t y = 0;
        volatile uint64_t *x = ptr;
 
        while (1) {
                pthread_testcancel();
                y += *x;
+
+               /* Prevent the compiler from optimizing out the writes to y: */
+               asm volatile("" : "+r" (y));
        }
 
        return NULL;