hal_parport: Do not write outputs, if not required#2513
hal_parport: Do not write outputs, if not required#2513rene-dev merged 1 commit intoLinuxCNC:masterfrom
Conversation
3a03863 to
067f3f8
Compare
| hal_u32_t debug1, debug2; | ||
| long long write_time; | ||
| unsigned char outdata; | ||
| unsigned short outdata; |
There was a problem hiding this comment.
What about fixed size types like uint8_t here?
There was a problem hiding this comment.
Yes, I would be fine with uint16_t. But the whole file uses variable size types, so I didn't want to deviate.
I changed it to be bigger than 8 bits to detect the first-write case.
|
This sounds really good. Do you have some numbers how much CPU load is saved with this? |
|
Yes, I had done measurements with halscope, but I can't currently find the results. :( The speedup was significant. The time it takes to access an I/O port is in the order of a couple of microseconds. That can quickly add up (depending on the setup and especially for small thread periods). I currently have a core load of less than 80 %, whereas I had a core load of >95 % (not safe to operate) before. But I'll get you better numbers... |
With halscope? I think measuring just the CPU load (with htop or similar) would be sufficient. |
|
I don't think that is sufficient, because what matters are the worst case execution times for single task cycles. This change does really only help, if at least one of the I/O ports is either never written or maybe only written once during init or at times where we can tolerate a task deadline miss. That said, this change does basically not increase the worst case latency. The time for the additional compare only takes nanoseconds and can be ignored. (If you were that close to deadline misses, the system was not really stable anyway). |
|
the linuxcnc norway meeting approves this PR. |




This optimizes hal_parport in that outputs are only written, if the output data actually changed.
The idea behind this is that the outb is a pretty expensive operation. It takes in the order of microseconds to execute. In contrast, the check if data has changed takes basically no time.
This saves a lot of runtime in case outputs on a port are written rarely (e.g. initialization only) or never. Either of outdata_ctrl or outdata may be unused. Especially in case of multiple parports chances are that not all outdata/ctrl "channels" are used. In that case these outbs only have to be performed once to give the port a known state.
That enables the use of older machines with fast(er) base thread periods.