diff --git a/include/trick/Executive.hh b/include/trick/Executive.hh index 1f49c140..c2613826 100644 --- a/include/trick/Executive.hh +++ b/include/trick/Executive.hh @@ -1114,15 +1114,6 @@ namespace Trick { */ virtual int set_thread_cpu_affinity(unsigned int thread_id , int cpu_num) ; - /** - @userdesc Commmand to lock all of the process's memory into RAM, preventing it from being swapped out. - @par Python Usage: - @code trick.exec_set_lock_memory(<yes_no>) @endcode - @param yes_no - boolean (C integer 0/1) indicating if we lock memory - @return the return code of system lock call - */ - virtual int set_lock_memory(bool yes_no) ; - /** @userdesc Command to run the simulation (after a freeze). Set exec_command to RunCmd. @par Python Usage: diff --git a/include/trick/exec_proto.h b/include/trick/exec_proto.h index 4bf12b60..4ca1f2bb 100644 --- a/include/trick/exec_proto.h +++ b/include/trick/exec_proto.h @@ -48,7 +48,6 @@ extern "C" { int exec_set_enable_freeze( int on_off ) ; int exec_set_job_cycle(const char * job_name, int instance_num, double in_cycle) ; int exec_set_job_onoff(const char * job_name , int instance_num, int on) ; - int exec_set_lock_memory(int yes_no) ; int exec_set_rt_nap(int on_off) ; int exec_set_sim_object_onoff(const char * sim_object_name , int on) ; int exec_set_software_frame(double) ; diff --git a/include/trick/realtimesync_proto.h b/include/trick/realtimesync_proto.h index 4ef3fed4..f61b14ff 100644 --- a/include/trick/realtimesync_proto.h +++ b/include/trick/realtimesync_proto.h @@ -19,7 +19,10 @@ int real_time_restart(long long ref_time ) ; int is_real_time() ; const char * real_time_clock_get_name() ; int real_time_set_rt_clock_ratio(double in_clock_ratio) ; +int real_time_lock_memory(int yes_no) ; +// Deprecated +int exec_set_lock_memory(int yes_no) ; #ifdef __cplusplus } diff --git a/trick_source/sim_services/Executive/Executive_c_intf.cpp b/trick_source/sim_services/Executive/Executive_c_intf.cpp index 3bc8bd00..fa5dd551 100644 --- a/trick_source/sim_services/Executive/Executive_c_intf.cpp +++ b/trick_source/sim_services/Executive/Executive_c_intf.cpp @@ -887,18 +887,6 @@ extern "C" int exec_set_job_cycle(const char * job_name, int instance, double in return -1 ; } -/** - * @relates Trick::Executive - * @copydoc Trick::Executive::set_lock_memory - * C wrapper for Trick::Executive::set_lock_memory - */ -extern "C" int exec_set_lock_memory(int yes_no) { - if ( the_exec != NULL ) { - return the_exec->set_lock_memory((bool)yes_no) ; - } - return -1 ; -} - /** * @relates Trick::Executive * @copydoc Trick::Executive::add_depends_on_job diff --git a/trick_source/sim_services/Executive/Executive_set_lock_memory.cpp b/trick_source/sim_services/Executive/Executive_set_lock_memory.cpp deleted file mode 100644 index 3206223e..00000000 --- a/trick_source/sim_services/Executive/Executive_set_lock_memory.cpp +++ /dev/null @@ -1,52 +0,0 @@ - -#include "trick/Executive.hh" -#include "trick/message_proto.h" -#include "trick/message_type.h" - -#if __linux - -#include <sys/mman.h> -#include <errno.h> - -int Trick::Executive::set_lock_memory(bool yes_no) { - - /** @par Detailed Design */ - int ret = 0 ; - - /** @li lock or unlock memory based on yes_no parameter */ - if ( yes_no ) { - if ((ret = mlockall(MCL_CURRENT | MCL_FUTURE)) != 0 ) { - perror("Error locking memory."); - message_publish(MSG_ERROR, "Error %d when requesting memory lock.\n", errno); - } else { - message_publish(MSG_INFO, "Sim locked memory\n"); - } - } else { - if ( (ret = munlockall()) != 0 ) { - perror("Error unlocking memory."); - message_publish(MSG_ERROR, "Error %d when requesting memory unlock.\n", errno); - } else { - message_publish(MSG_INFO, "Sim unlocked memory\n"); - } - - } - - /** @li return result of mlockall or munlockall */ - return(ret) ; - -} - -#endif - -#if __APPLE__ - -int Trick::Executive::set_lock_memory(bool yes_no __attribute__((unused)) ) { - - message_publish(MSG_WARNING, "Warning: Trick on Darwin does not yet support memory locking.\n"); - - return(0) ; - -} - -#endif - diff --git a/trick_source/sim_services/Executive/Makefile_deps b/trick_source/sim_services/Executive/Makefile_deps index c9075b9a..3695c3e5 100644 --- a/trick_source/sim_services/Executive/Makefile_deps +++ b/trick_source/sim_services/Executive/Makefile_deps @@ -785,20 +785,6 @@ object_${TRICK_HOST_CPU}/Executive_set_thread_rt_semaphore.o: \ ${TRICK_HOME}/include/trick/Threads.hh \ ${TRICK_HOME}/include/trick/ThreadBase.hh \ ${TRICK_HOME}/include/trick/sim_mode.h -object_${TRICK_HOST_CPU}/Executive_set_lock_memory.o: Executive_set_lock_memory.cpp \ - ${TRICK_HOME}/include/trick/Executive.hh \ - ${TRICK_HOME}/include/trick/Scheduler.hh \ - ${TRICK_HOME}/include/trick/ScheduledJobQueue.hh \ - ${TRICK_HOME}/include/trick/JobData.hh \ - ${TRICK_HOME}/include/trick/InstrumentBase.hh \ - ${TRICK_HOME}/include/trick/SimObject.hh \ - ${TRICK_HOME}/include/trick/ScheduledJobQueue.hh \ - ${TRICK_HOME}/include/trick/SimObject.hh \ - ${TRICK_HOME}/include/trick/Threads.hh \ - ${TRICK_HOME}/include/trick/ThreadBase.hh \ - ${TRICK_HOME}/include/trick/sim_mode.h \ - ${TRICK_HOME}/include/trick/message_proto.h \ - ${TRICK_HOME}/include/trick/message_type.h object_${TRICK_HOST_CPU}/Executive_shutdown.o: Executive_shutdown.cpp \ ${TRICK_HOME}/include/trick/Executive.hh \ ${TRICK_HOME}/include/trick/Scheduler.hh \ diff --git a/trick_source/sim_services/RealtimeSync/Makefile_deps b/trick_source/sim_services/RealtimeSync/Makefile_deps index 5ec673e3..879b8197 100644 --- a/trick_source/sim_services/RealtimeSync/Makefile_deps +++ b/trick_source/sim_services/RealtimeSync/Makefile_deps @@ -13,4 +13,6 @@ object_${TRICK_HOST_CPU}/RealtimeSync_c_intf.o: RealtimeSync_c_intf.cpp \ ${TRICK_HOME}/include/trick/Timer.hh \ ${TRICK_HOME}/include/trick/realtimesync_proto.h \ ${TRICK_HOME}/include/trick/exec_proto.h \ - ${TRICK_HOME}/include/trick/sim_mode.h + ${TRICK_HOME}/include/trick/sim_mode.h \ + ${TRICK_HOME}/include/trick/message_proto.h \ + ${TRICK_HOME}/include/trick/message_type.h diff --git a/trick_source/sim_services/RealtimeSync/RealtimeSync_c_intf.cpp b/trick_source/sim_services/RealtimeSync/RealtimeSync_c_intf.cpp index 0887a003..9d343075 100644 --- a/trick_source/sim_services/RealtimeSync/RealtimeSync_c_intf.cpp +++ b/trick_source/sim_services/RealtimeSync/RealtimeSync_c_intf.cpp @@ -3,6 +3,9 @@ #include "trick/RealtimeSync.hh" #include "trick/realtimesync_proto.h" #include "trick/exec_proto.h" +#include "trick/message_proto.h" +#include "trick/message_type.h" + /* Global singleton pointer to the real-time synchronization */ extern Trick::RealtimeSync * the_rts ; @@ -85,3 +88,47 @@ int real_time_change_timer(Trick::Timer * in_sleep_timer ) { extern "C" int real_time_set_rt_clock_ratio(double in_clock_ratio) { return the_rts->set_rt_clock_ratio(in_clock_ratio) ; } + +// The lock memory functions are most closely related to real-time but are +// not required for syncing. Therefore keep the routines as stand +// alone C functions. + +#if __linux +#include <sys/mman.h> +#include <errno.h> +#endif + +extern "C" int real_time_lock_memory(int yes_no) { + /* lock or unlock memory based on yes_no parameter */ + int ret = 0 ; +#if __linux + if ( yes_no ) { + if ((ret = mlockall(MCL_CURRENT | MCL_FUTURE)) != 0 ) { + perror("Error locking memory."); + message_publish(MSG_ERROR, "Error %d when requesting memory lock.\n", errno); + } else { + message_publish(MSG_INFO, "Sim locked memory\n"); + } + } else { + if ( (ret = munlockall()) != 0 ) { + perror("Error unlocking memory."); + message_publish(MSG_ERROR, "Error %d when requesting memory unlock.\n", errno); + } else { + message_publish(MSG_INFO, "Sim unlocked memory\n"); + } + + } +#endif +#if __APPLE__ + (void)yes_no ; + message_publish(MSG_WARNING, "Warning: Trick on Darwin does not yet support memory locking.\n"); +#endif + return ret ; +} + + +extern "C" int exec_set_lock_memory(int yes_no) { + message_publish(MSG_WARNING, "Warning: exec_set_lock_memory deprecated. Use real_time_lock_memory (auto-called)\n"); + return real_time_lock_memory(yes_no) ; +} +