[4a0e418] | 1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
| 2 | |
---|
[9278f3d] | 3 | /** |
---|
| 4 | * @file |
---|
| 5 | * |
---|
| 6 | * @ingroup RTEMSScoreScheduler |
---|
| 7 | * |
---|
| 8 | * @brief This source file contains the implementation of |
---|
| 9 | * _Scheduler_Set_affinity(). |
---|
| 10 | */ |
---|
| 11 | |
---|
[0712d17] | 12 | /* |
---|
[bcef89f2] | 13 | * Copyright (C) 2014, 2017 embedded brains GmbH & Co. KG |
---|
[0712d17] | 14 | * |
---|
[4a0e418] | 15 | * Redistribution and use in source and binary forms, with or without |
---|
| 16 | * modification, are permitted provided that the following conditions |
---|
| 17 | * are met: |
---|
| 18 | * 1. Redistributions of source code must retain the above copyright |
---|
| 19 | * notice, this list of conditions and the following disclaimer. |
---|
| 20 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 21 | * notice, this list of conditions and the following disclaimer in the |
---|
| 22 | * documentation and/or other materials provided with the distribution. |
---|
| 23 | * |
---|
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
| 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 34 | * POSSIBILITY OF SUCH DAMAGE. |
---|
[0712d17] | 35 | */ |
---|
| 36 | |
---|
[80cf60e] | 37 | #ifdef HAVE_CONFIG_H |
---|
| 38 | #include "config.h" |
---|
[0712d17] | 39 | #endif |
---|
| 40 | |
---|
| 41 | #include <rtems/score/schedulerimpl.h> |
---|
| 42 | |
---|
[9d82150] | 43 | Status_Control _Scheduler_Set_affinity( |
---|
[0232b28] | 44 | Thread_Control *the_thread, |
---|
| 45 | size_t cpusetsize, |
---|
| 46 | const cpu_set_t *cpuset |
---|
[0712d17] | 47 | ) |
---|
| 48 | { |
---|
[0232b28] | 49 | Processor_mask affinity; |
---|
[9d82150] | 50 | Processor_mask_Copy_status copy_status; |
---|
[0232b28] | 51 | const Scheduler_Control *scheduler; |
---|
[197a614] | 52 | Scheduler_Node *node; |
---|
[0232b28] | 53 | ISR_lock_Context lock_context; |
---|
[9d82150] | 54 | Status_Control status; |
---|
[0712d17] | 55 | |
---|
[9d82150] | 56 | copy_status = _Processor_mask_From_cpu_set_t( &affinity, cpusetsize, cpuset ); |
---|
| 57 | if ( !_Processor_mask_Is_at_most_partial_loss( copy_status ) ) { |
---|
| 58 | return STATUS_INVALID_NUMBER; |
---|
[25f5730f] | 59 | } |
---|
[c5831a3f] | 60 | |
---|
[8744498] | 61 | /* |
---|
| 62 | * Reduce affinity set to the online processors to be in line with |
---|
| 63 | * _Thread_Initialize() which sets the default affinity to the set of online |
---|
| 64 | * processors. |
---|
| 65 | */ |
---|
[9db3cc21] | 66 | _Processor_mask_And( &affinity, _SMP_Get_online_processors(), &affinity ); |
---|
[8744498] | 67 | |
---|
[2dd098a] | 68 | scheduler = _Thread_Scheduler_get_home( the_thread ); |
---|
[e135271] | 69 | _Scheduler_Acquire_critical( scheduler, &lock_context ); |
---|
| 70 | |
---|
[197a614] | 71 | node = _Thread_Scheduler_get_home_node( the_thread ); |
---|
[25f5730f] | 72 | #if defined(RTEMS_SMP) |
---|
[9d82150] | 73 | status = ( *scheduler->Operations.set_affinity )( |
---|
[25f5730f] | 74 | scheduler, |
---|
| 75 | the_thread, |
---|
[197a614] | 76 | node, |
---|
[0232b28] | 77 | &affinity |
---|
[25f5730f] | 78 | ); |
---|
[0232b28] | 79 | |
---|
[9d82150] | 80 | if ( status == STATUS_SUCCESSFUL ) { |
---|
[0232b28] | 81 | _Processor_mask_Assign( &the_thread->Scheduler.Affinity, &affinity ); |
---|
| 82 | } |
---|
[0712d17] | 83 | #else |
---|
[9d82150] | 84 | status = _Scheduler_default_Set_affinity_body( |
---|
[25f5730f] | 85 | scheduler, |
---|
| 86 | the_thread, |
---|
[197a614] | 87 | node, |
---|
[0232b28] | 88 | &affinity |
---|
[25f5730f] | 89 | ); |
---|
[0712d17] | 90 | #endif |
---|
[e135271] | 91 | |
---|
| 92 | _Scheduler_Release_critical( scheduler, &lock_context ); |
---|
[9d82150] | 93 | return status; |
---|
[0712d17] | 94 | } |
---|