~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/math/vmx_preempt.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Copyright 2015, Cyril Bur, IBM Corp.
  4  *
  5  * This test attempts to see if the VMX registers change across preemption.
  6  * Two things should be noted here a) The check_vmx function in asm only checks
  7  * the non volatile registers as it is reused from the syscall test b) There is
  8  * no way to be sure preemption happened so this test just uses many threads
  9  * and a long wait. As such, a successful test doesn't mean much but a failure
 10  * is bad.
 11  */
 12 
 13 #include <stdio.h>
 14 #include <unistd.h>
 15 #include <sys/syscall.h>
 16 #include <sys/time.h>
 17 #include <sys/types.h>
 18 #include <sys/wait.h>
 19 #include <stdlib.h>
 20 #include <pthread.h>
 21 
 22 #include "utils.h"
 23 
 24 /* Time to wait for workers to get preempted (seconds) */
 25 #define PREEMPT_TIME 20
 26 /*
 27  * Factor by which to multiply number of online CPUs for total number of
 28  * worker threads
 29  */
 30 #define THREAD_FACTOR 8
 31 
 32 __thread vector int varray[] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10,11,12},
 33         {13,14,15,16},{17,18,19,20},{21,22,23,24},
 34         {25,26,27,28},{29,30,31,32},{33,34,35,36},
 35         {37,38,39,40},{41,42,43,44},{45,46,47,48}};
 36 
 37 int threads_starting;
 38 int running;
 39 
 40 extern int preempt_vmx(vector int *varray, int *threads_starting, int *running);
 41 
 42 void *preempt_vmx_c(void *p)
 43 {
 44         int i, j;
 45         long rc;
 46 
 47         srand(pthread_self());
 48         for (i = 0; i < 12; i++)
 49                 for (j = 0; j < 4; j++)
 50                         varray[i][j] = rand();
 51 
 52         rc = preempt_vmx(varray, &threads_starting, &running);
 53 
 54         return (void *)rc;
 55 }
 56 
 57 int test_preempt_vmx(void)
 58 {
 59         int i, rc, threads;
 60         pthread_t *tids;
 61 
 62         // vcmpequd used in vmx_asm.S is v2.07
 63         SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
 64 
 65         threads = sysconf(_SC_NPROCESSORS_ONLN) * THREAD_FACTOR;
 66         tids = malloc(threads * sizeof(pthread_t));
 67         FAIL_IF(!tids);
 68 
 69         running = true;
 70         threads_starting = threads;
 71         for (i = 0; i < threads; i++) {
 72                 rc = pthread_create(&tids[i], NULL, preempt_vmx_c, NULL);
 73                 FAIL_IF(rc);
 74         }
 75 
 76         setbuf(stdout, NULL);
 77         /* Not really nessesary but nice to wait for every thread to start */
 78         printf("\tWaiting for all workers to start...");
 79         while(threads_starting)
 80                 asm volatile("": : :"memory");
 81         printf("done\n");
 82 
 83         printf("\tWaiting for %d seconds to let some workers get preempted...", PREEMPT_TIME);
 84         sleep(PREEMPT_TIME);
 85         printf("done\n");
 86 
 87         printf("\tStopping workers...");
 88         /*
 89          * Working are checking this value every loop. In preempt_vmx 'cmpwi r5,0; bne 2b'.
 90          * r5 will have loaded the value of running.
 91          */
 92         running = 0;
 93         for (i = 0; i < threads; i++) {
 94                 void *rc_p;
 95                 pthread_join(tids[i], &rc_p);
 96 
 97                 /*
 98                  * Harness will say the fail was here, look at why preempt_vmx
 99                  * returned
100                  */
101                 if ((long) rc_p)
102                         printf("oops\n");
103                 FAIL_IF((long) rc_p);
104         }
105         printf("done\n");
106 
107         return 0;
108 }
109 
110 int main(int argc, char *argv[])
111 {
112         return test_harness(test_preempt_vmx, "vmx_preempt");
113 }
114 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php