Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/os/vxworks-rtp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ set(POSIX_BASE_SRCLIST
../posix/src/os-impl-idmap.c
../posix/src/os-impl-mutex.c
../posix/src/os-impl-queues.c
../posix/src/os-impl-tasks.c
../posix/src/os-impl-timebase.c
src/os-impl-filesys.c # VxWorks RTP specific implementation
src/os-impl-files.c # VxWorks RTP specific implementation
../portable/os-impl-pthread-no-affinity-np.c
src/os-impl-tasks.c # VxWorks RTP specific implementation
src/os-impl-filesys.c # VxWorks RTP specific implementation
src/os-impl-files.c # VxWorks RTP specific implementation
../portable/os-impl-posix-gettime-no-monotonic.c
)

# Use portable blocks for basic I/O
Expand Down Expand Up @@ -99,15 +99,25 @@ else()
)
endif ()

if (OSAL_CONFIG_MAX_CPUS GREATER 1)
list(APPEND POSIX_IMPL_SRCLIST
src/os-impl-pthread-affinity.c # use the real affinity code
)
else()
list(APPEND POSIX_IMPL_SRCLIST
../portable/os-impl-pthread-no-affinity-np.c
)
endif()

# Defines an OBJECT target named "osal_posix_impl" with selected source files
add_library(osal_vxworks-rtp_impl OBJECT
${POSIX_BASE_SRCLIST}
${POSIX_IMPL_SRCLIST}
)

target_include_directories(osal_vxworks-rtp_impl PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../posix/inc
${CMAKE_CURRENT_SOURCE_DIR}/inc
${CMAKE_CURRENT_SOURCE_DIR}/../posix/inc
)
target_compile_definitions(osal_public_api INTERFACE
_POSIX_OS_
Expand Down
44 changes: 44 additions & 0 deletions src/os/vxworks-rtp/inc/os-impl-taskaffinity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/************************************************************************
* NASA Docket No. GSC-19,200-1, and identified as "cFS Draco"
*
* Copyright (c) 2023 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* \file
*
* \ingroup vxworks
*
*/

#ifndef OS_IMPL_TASKAFFINITY_H
#define OS_IMPL_TASKAFFINITY_H

/* VxWorks Native Headers */
#include <vxWorks.h>
#include <taskLib.h>

#include "common_types.h"

/* Explicitly declare to avoid implicit declaration warnings */
extern unsigned int vxCpuConfiguredGet(void);

/* Define the function used by the OSAL initialization */
static inline uint32 OS_TaskAffinity_Proc_Conf(void)
{
return (uint32)vxCpuConfiguredGet();
}

#endif /* OS_IMPL_TASKAFFINITY_H */
54 changes: 54 additions & 0 deletions src/os/vxworks-rtp/inc/os-impl-tasks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/************************************************************************
* NASA Docket No. GSC-19,200-1, and identified as "cFS Draco"
*
* Copyright (c) 2023 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* \file
*
* \ingroup posix
*
*/

#ifndef OS_IMPL_TASKS_H
#define OS_IMPL_TASKS_H

#include "os-shared-task.h"

#include "osconfig.h"
#include <pthread.h>
#include <taskLib.h>

typedef void *(*PthreadFuncPtr_t)(void *entry_arg);

/*tasks */
typedef struct
{
pthread_t id;
TASK_ID vxid;
} OS_impl_task_internal_record_t;

/* Tables where the OS object information is stored */
extern OS_impl_task_internal_record_t OS_impl_task_table[OS_MAX_TASKS];

int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr,
osal_priority_t priority,
osal_stackptr_t stackptr,
size_t stacksz,
PthreadFuncPtr_t entry,
void *entry_arg);

#endif /* OS_IMPL_TASKS_H */
144 changes: 144 additions & 0 deletions src/os/vxworks-rtp/src/os-impl-pthread-affinity.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/************************************************************************
* NASA Docket No. GSC-19,200-1, and identified as "cFS Draco"
*
* Copyright (c) 2023 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* \file
*
* OSAL Task Affinity Implementation for VxWorks RTP
* This bridges the POSIX OSAL task structure with native VxWorks CPU Affinity APIs
*/

/****************************************************************************************
INCLUDE FILES
***************************************************************************************/

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <time.h>

/* POSIX thread support (needed for the OSAL internal records) */
#include <pthread.h>

/* Native VxWorks headers required for Task Affinity in RTP */
#include <vxWorks.h>
#include <cpuset.h>
#include <taskLib.h>
#include <vxCpuLib.h>
#include <errnoLib.h>

#include "os-impl-taskaffinity.h"
#include "osapi-task-affinity.h"
#include "os-impl-tasks.h"
#include "os-shared-file.h"
#include "os-shared-idmap.h"

/****************************************************************************************
Task Affinity API
***************************************************************************************/

/*
* ----------------------------------------------------------------------
* The OS_TaskAffinityGetCoresConfigured_Impl()
* Returns the number of configured cores
* ----------------------------------------------------------------------
*/
uint32 OS_TaskAffinityGetCoresConfigured_Impl(void)
{
return OS_TaskAffinity_Proc_Conf();
}

/*
* ----------------------------------------------------------------------
* The OS_TaskAffinitySetAffinity_Impl()
* Sets an affinity from cpuset to task with provided task_id
* ----------------------------------------------------------------------
*/
int32 OS_TaskAffinitySetAffinity_Impl(const OS_object_token_t *token, const OS_cpuset_t cpuset)
{
cpuset_t local_cpuset;
OS_impl_task_internal_record_t *impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token);
uint32 i;
int32 return_value;

/* Check if the thread has actually started and recorded its ID yet */
if (impl->vxid == 0 || impl->vxid == (TASK_ID)ERROR)
{
return OS_ERROR;
}

CPUSET_ZERO(local_cpuset);
for (i = 0; (i < OS_MAX_CPUS) && (i < OS_TaskAffinityGetCoresConfigured()); i++)
{
if (OS_CPUSET_ISSET(i, &cpuset))
{
CPUSET_SET(local_cpuset, i);
}
}

/* Pass the true native TASK_ID to VxWorks */
return_value = taskCpuAffinitySet(impl->vxid, local_cpuset);

if (return_value == 0)
{
return OS_SUCCESS;
}
else
{
return OS_ERROR;
}
}

/*
* ----------------------------------------------------------------------
* The OS_TaskAffinityGetAffinity_Impl() is an api call to get affinity from a task
* Writes affinity to cpuset from task with provided task_id
* ----------------------------------------------------------------------
*/
int32 OS_TaskAffinityGetAffinity_Impl(const OS_object_token_t *token, OS_cpuset_t *cpuset)
{
cpuset_t local_cpuset;
OS_impl_task_internal_record_t *impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token);
uint32 i;
int32 return_value;

/* Check if the thread has actually started and recorded its ID yet */
if (impl->vxid == 0 || impl->vxid == (TASK_ID)ERROR)
{
return OS_ERROR;
}

CPUSET_ZERO(local_cpuset);

/* Pass the true native TASK_ID to VxWorks */
return_value = taskCpuAffinityGet(impl->vxid, &local_cpuset);

if (return_value == 0)
{
OS_CPUSET_ZERO(cpuset);
for (i = 0; (i < OS_MAX_CPUS) && (i < OS_TaskAffinityGetCoresConfigured()); i++)
{
if (CPUSET_ISSET(local_cpuset, i))
{
OS_CPUSET_SET(i, cpuset);
}
}
return OS_SUCCESS;
}
return OS_ERROR;
}
Loading
Loading