Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix #447, Add rtems_sysmon unit test #448

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
78 changes: 11 additions & 67 deletions fsw/modules/rtems_sysmon/rtems_sysmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
/************************************************************************
* Includes
************************************************************************/

#include "cfe_psp.h"

#include "iodriver_impl.h"
Expand All @@ -33,73 +32,12 @@
#include <rtems/cpuuse.h>
#include <rtems/score/threadimpl.h>
#include <rtems/rtems/tasks.h>

/********************************************************************
* Local Defines
********************************************************************/
#ifdef OS_MAXIMUM_PROCESSORS
#define RTEMS_SYSMON_MAX_CPUS OS_MAXIMUM_PROCESSORS
#else
#define RTEMS_SYSMON_MAX_CPUS 1
#endif

#define RTEMS_SYSMON_AGGREGATE_SUBSYS 0
#define RTEMS_SYSMON_CPULOAD_SUBSYS 1
#define RTEMS_SYSMON_AGGR_CPULOAD_SUBCH 0
#define RTEMS_SYSMON_SAMPLE_DELAY 1000
#define RTEMS_SYSMON_TASK_PRIORITY 100
#define RTEMS_SYSMON_STACK_SIZE 4096
#define RTEMS_SYSMON_MAX_SCALE 100000

#ifdef DEBUG_BUILD
#define RTEMS_SYSMON_DEBUG(...) OS_printf(__VA_ARGS__)
#else
#define RTEMS_SYSMON_DEBUG(...)
#endif

/********************************************************************
* Local Type Definitions
********************************************************************/
typedef struct rtems_sysmon_cpuload_core
{
CFE_PSP_IODriver_AdcCode_t avg_load;
Timestamp_Control last_run_time;
Timestamp_Control idle_last_uptime;

} rtems_sysmon_cpuload_core_t;

typedef struct rtems_sysmon_cpuload_state
{
volatile bool is_running;
volatile bool should_run;

rtems_id task_id;
rtems_name task_name;

uint8_t num_cpus;
rtems_sysmon_cpuload_core_t per_core[RTEMS_SYSMON_MAX_CPUS];

} rtems_sysmon_cpuload_state_t;

typedef struct rtems_sysmon_state
{
uint32_t local_module_id;
rtems_sysmon_cpuload_state_t cpu_load;
} rtems_sysmon_state_t;
#include "rtems_sysmon.h"

/********************************************************************
* Local Function Prototypes
********************************************************************/
static void rtems_sysmon_Init(uint32_t local_module_id);
static int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state);
static int32_t rtems_sysmon_Stop(rtems_sysmon_cpuload_state_t *state);

int32_t rtems_sysmon_aggregate_dispatch(uint32_t CommandCode, uint16_t Subchannel, CFE_PSP_IODriver_Arg_t Arg);
int32_t rtems_sysmon_calc_aggregate_cpu(rtems_sysmon_cpuload_state_t *state, CFE_PSP_IODriver_AdcCode_t *Val);

/* Function that starts up rtems_sysmon driver. */
static int32_t rtems_sysmon_DevCmd(uint32_t CommandCode, uint16_t SubsystemId, uint16_t SubchannelId,
CFE_PSP_IODriver_Arg_t Arg);

/********************************************************************
* Global Data
Expand All @@ -112,7 +50,7 @@ CFE_PSP_IODriver_API_t rtems_sysmon_DevApi = {.DeviceCommand = rtems_sysmon_DevC

CFE_PSP_MODULE_DECLARE_IODEVICEDRIVER(rtems_sysmon);

static rtems_sysmon_state_t rtems_sysmon_global;
rtems_sysmon_state_t rtems_sysmon_global;

static const char *rtems_sysmon_subsystem_names[] = {"aggregate", "per-cpu", NULL};
static const char *rtems_sysmon_subchannel_names[] = {"cpu-load", NULL};
Expand All @@ -127,7 +65,7 @@ void rtems_sysmon_Init(uint32_t local_module_id)
rtems_sysmon_global.local_module_id = local_module_id;
}

static bool rtems_cpu_usage_vistor(Thread_Control *the_thread, void *arg)
bool rtems_cpu_usage_visitor(Thread_Control *the_thread, void *arg)
{
rtems_sysmon_cpuload_state_t *state = (rtems_sysmon_cpuload_state_t *)arg;
rtems_sysmon_cpuload_core_t* core_p = &state->per_core[state->num_cpus];
Expand Down Expand Up @@ -213,7 +151,7 @@ static bool rtems_cpu_usage_vistor(Thread_Control *the_thread, void *arg)
void rtems_sysmon_update_stat(rtems_sysmon_cpuload_state_t *state)
{
state->num_cpus = 0;
rtems_task_iterate( rtems_cpu_usage_vistor, state);
rtems_task_iterate( rtems_cpu_usage_visitor, state);
}

rtems_task rtems_sysmon_Task(rtems_task_argument arg)
Expand Down Expand Up @@ -246,7 +184,7 @@ rtems_task rtems_sysmon_Task(rtems_task_argument arg)
* Starts the cpu load watcher function
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
static int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state)
int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state)
{
int32_t StatusCode;
rtems_status_code status;
Expand Down Expand Up @@ -453,6 +391,12 @@ int32_t rtems_sysmon_cpu_load_dispatch(uint32_t CommandCode, uint16_t Subchannel
{
RdWr->Samples[ch] = state->per_core[ch].avg_load;
}

StatusCode = CFE_PSP_SUCCESS;
}
else
{
StatusCode = CFE_PSP_ERROR;
}

break;
Expand Down
101 changes: 101 additions & 0 deletions fsw/modules/rtems_sysmon/rtems_sysmon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* 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
*
* Internal header for rtems_sysmon.c
*/

#ifndef RTEMS_SYSMON_H_
#define RTEMS_SYSMON_H_

/********************************************************************
* Local Defines
********************************************************************/
#ifdef OS_MAXIMUM_PROCESSORS
#define RTEMS_SYSMON_MAX_CPUS OS_MAXIMUM_PROCESSORS
#else
#define RTEMS_SYSMON_MAX_CPUS 1
#endif

#define RTEMS_SYSMON_AGGREGATE_SUBSYS 0
#define RTEMS_SYSMON_CPULOAD_SUBSYS 1
#define RTEMS_SYSMON_AGGR_CPULOAD_SUBCH 0
#define RTEMS_SYSMON_SAMPLE_DELAY 1000
#define RTEMS_SYSMON_TASK_PRIORITY 100
#define RTEMS_SYSMON_STACK_SIZE 4096
#define RTEMS_SYSMON_MAX_SCALE 100000

#ifdef DEBUG_BUILD
#define RTEMS_SYSMON_DEBUG(...) OS_printf(__VA_ARGS__)
#else
#define RTEMS_SYSMON_DEBUG(...)
#endif


/********************************************************************
* Local Type Definitions
********************************************************************/
typedef struct rtems_sysmon_cpuload_core
{
CFE_PSP_IODriver_AdcCode_t avg_load;
Timestamp_Control last_run_time;
Timestamp_Control idle_last_uptime;

} rtems_sysmon_cpuload_core_t;

typedef struct rtems_sysmon_cpuload_state
{
volatile bool is_running;
volatile bool should_run;

rtems_id task_id;
rtems_name task_name;

uint8_t num_cpus;
rtems_sysmon_cpuload_core_t per_core[RTEMS_SYSMON_MAX_CPUS];

} rtems_sysmon_cpuload_state_t;

typedef struct rtems_sysmon_state
{
uint32_t local_module_id;
rtems_sysmon_cpuload_state_t cpu_load;
} rtems_sysmon_state_t;


/********************************************************************
* Local Function Prototypes
********************************************************************/
rtems_task rtems_sysmon_Task(rtems_task_argument arg);
void rtems_sysmon_update_stat(rtems_sysmon_cpuload_state_t *state);
bool rtems_cpu_usage_visitor(Thread_Control *the_thread, void *arg);

int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state);
int32_t rtems_sysmon_Stop(rtems_sysmon_cpuload_state_t *state);

int32_t rtems_sysmon_aggregate_dispatch(uint32_t CommandCode, uint16_t Subchannel, CFE_PSP_IODriver_Arg_t Arg);
int32_t rtems_sysmon_calc_aggregate_cpu(rtems_sysmon_cpuload_state_t *state, CFE_PSP_IODriver_AdcCode_t *Val);

/* Function that starts up rtems_sysmon driver. */
int32_t rtems_sysmon_DevCmd(uint32_t CommandCode, uint16_t SubsystemId, uint16_t SubchannelId,
CFE_PSP_IODriver_Arg_t Arg);


#endif /* RTEMS_SYSMON_H_ */
1 change: 1 addition & 0 deletions unit-test-coverage/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ endfunction()
# a list of modules for which there is a coverage test implemented
add_subdirectory(timebase_vxworks)
add_subdirectory(vxworks_sysmon)
add_subdirectory(rtems_sysmon)
add_subdirectory(ram_notimpl)
add_subdirectory(ram_direct)
add_subdirectory(port_notimpl)
Expand Down
3 changes: 2 additions & 1 deletion unit-test-coverage/modules/rtems_sysmon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
######################################################################
#
# CMAKE build recipe for white-box coverage tests of VxWorks timebase module
# CMAKE build recipe for white-box coverage tests of rtems_sysmon
#
add_definitions(-D_CFE_PSP_MODULE_)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/inc")
include_directories("${CFEPSP_SOURCE_DIR}/fsw/modules/iodriver/inc")
include_directories("${CFEPSP_SOURCE_DIR}/fsw/modules/rtems_sysmon")

add_psp_covtest(rtems_sysmon src/coveragetest-rtems_sysmon.c
src/coveragetest-rtems_sysmon_utils.c
${CFEPSP_SOURCE_DIR}/fsw/modules/rtems_sysmon/rtems_sysmon.c
)
Loading
Loading