RayChromium
Not sure if here's the right place to ask but here's a question I have:
When we create a project in OpenPLC Editor, there's a button called "Start PLC simulation" on the top, from my understanding what it does is to generate a `plc.st` structural text file that contains all the variable, POU definition and the logic of the program; then this get's compiled by iec2c and generate the .c files and the VARIABLES.csv; finally the .c files gets compiled into a .so/.dll binary, also a lastBuildPLC.md5 is also created.
Now the question comes up when I write a python script ( contains some PLC binary loading logic from `PLCObject.py` ), and generate a functional mockup unit ( FMU ) for co-simulation. Is there any mechanism for reserving the computation resources and only using it for the PLC's binary execution? I mean when the .so/.dll binary that contains the PLC program is loaded, is there any guarantee that the processors are only dedicated in executing the logic of the binary, without any interruptions or context switching?
Thank you so much for your time.
( p.s. For example, in the attachment there is the FMU I created, and in the `resources` directory there's a `FMUWrapper.py` script which simply copied most of the logic in PLCObject.py, and I created FMU based on `FMUWrapper.py` )
Reply 0 0
thiagoralves
Those guarantees are made by the operating system, not the software. On linux, for example, you could isolate a CPU core with isolcpus= boot argument, and then set affinity of the task running the .so to the isolated core. This would guarantee that only the PLC simulation is running on that core, and nothing else. Even then, the real-time response is not absolutely great because Linux is not a real-time OS. In other words, this means that Linux can "delay" the beginning of a scan cycle because its scheduler is optimized to do more tasks in less time, instead of optimized to run tasks on time. The Linux PREEMPT_RT patch helps a lot if you need more precise timing for that.
 
With all that said, I'm wondering why you're doing this on the generated simulation .so/.dll instead of in the OpenPLC Runtime. The simulated PLC .so/.dll is much more limited.
Reply 1 0
RayChromium
Those guarantees are made by the operating system, not the software. On linux, for example, you could isolate a CPU core with isolcpus= boot argument, and then set affinity of the task running the .so to the isolated core. This would guarantee that only the PLC simulation is running on that core, and nothing else. Even then, the real-time response is not absolutely great because Linux is not a real-time OS. In other words, this means that Linux can "delay" the beginning of a scan cycle because its scheduler is optimized to do more tasks in less time, instead of optimized to run tasks on time. The Linux PREEMPT_RT patch helps a lot if you need more precise timing for that.
With all that said, I'm wondering why you're doing this on the generated simulation .so/.dll instead of in the OpenPLC Runtime. The simulated PLC .so/.dll is much more limited.
Hello Thiago, thank you for the clarification.
The reason I'm doing this is because I'm working on a project that attempts to figure out whether or not it's possible to create functional mock-up unites ( FMUs ) out of PLC programs, so that the FMUs can be used in co-simulation with other FMUs ( they could be generated out of any programs that has inputs and outputs though ), without downloading them to actual hardwares/micro controllers.
Therefore I thought it would be more straight forward if I just reuse some IDE's debug related functions that are built into the .so/.dll, so I modified the OpenPLC Editor's ProjectController.py a bit to generate these FMUs and did some testings.
Reply 0 0
Reply