Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:43

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 2014.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 /*
0030  * Test to walk the affinity of the init task across all the cores.
0031  */
0032 
0033 #ifdef HAVE_CONFIG_H
0034 #include "config.h"
0035 #endif
0036 
0037 #include <rtems.h>
0038 
0039 #include "tmacros.h"
0040 
0041 const char rtems_test_name[] = "SMPSCHEDAFFINITY 3";
0042 
0043 #define NUM_CPUS   4
0044 #define TASK_COUNT NUM_CPUS
0045 
0046 static void test_delay(int ticks)
0047 { 
0048   rtems_interval start, stop;
0049   start = rtems_clock_get_ticks_since_boot();
0050   do {
0051     stop = rtems_clock_get_ticks_since_boot();
0052   } while ( (stop - start) < ticks );
0053 }
0054 
0055 static void test(void)
0056 {
0057   rtems_status_code   sc;
0058   rtems_id            id;
0059   uint32_t            cpu_count;
0060   int                 cpu;
0061   int                 i;
0062   cpu_set_t           cpuset;
0063 
0064   /* Get the number of processors that we are using. */
0065   cpu_count = rtems_scheduler_get_processor_maximum();
0066  
0067   id = rtems_task_self();
0068 
0069   /* 
0070    * The Init task comes up on the maximum core so start at
0071    * that core and walk the affinity down to core 0.
0072    */
0073   for( i=cpu_count-1; i >= 0; i--) {
0074     
0075     /* Move the affinity to the current core - 1 */
0076     CPU_ZERO(&cpuset);
0077     CPU_SET(i, &cpuset);
0078     printf("Set Affinity for cpu %d\n", i);
0079     sc = rtems_task_set_affinity( id, sizeof(cpuset), &cpuset );
0080     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0081 
0082     /* Wait 100 clock ticks */
0083     test_delay(100);
0084 
0085     /* Check the cpu the Init task is running on */
0086     cpu = rtems_scheduler_get_processor();
0087     printf("On cpu %d\n", cpu);
0088     rtems_test_assert(cpu == i);
0089   }
0090 }
0091 
0092 static void Init(rtems_task_argument arg)
0093 {
0094   TEST_BEGIN();
0095 
0096   test();
0097 
0098   TEST_END();
0099   rtems_test_exit(0);
0100 }
0101 
0102 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0103 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0104 
0105 #define CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP
0106 
0107 #define CONFIGURE_MAXIMUM_PROCESSORS NUM_CPUS
0108 
0109 #define CONFIGURE_MAXIMUM_TASKS          TASK_COUNT
0110 
0111 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0112 
0113   #define CONFIGURE_INIT_TASK_PRIORITY      8
0114 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0115 
0116 #define CONFIGURE_INIT
0117 
0118 #include <rtems/confdefs.h>