ckormanyos / Osek_pi_spigot_metal

Use OSEK-like OS on RPI-Zero to calculate pi with a spigot algorithm
Boost Software License 1.0
2 stars 0 forks source link

Investigate client error or context switch weakness #1

Closed ckormanyos closed 1 year ago

ckormanyos commented 1 year ago

Hi Amine (@chalandi) here is the pi spigot benchmark project posted in its entirety, as we have discussed several times ni offline chats.

At the moment, I use your OSEK from Chalandi/OSEK_Raspberry_Pi_Zero. This is a very nice, clean, lighweight, elegant OS.

But I believe there might be either a client misunderstanding or perhaps a small weakness in context switch.

In the present form, I have configured for cooperative multitasking. And the pi-spigot algorithm obtains the correct answer. The correct answer is given by return value of zero (int value 0) as the return value from the subroutine pi_spigot_main() here.

The return value is queried in the Idle task which performs the calculatoin back-to-back, continuously and repeatedly.

If, however, I switch to preemptive multitasking in the configuration and simultaneously use the queried return value of zero in the idle task, then the correct numerical answer is not obtained.

Cc: @gdobato

ckormanyos commented 1 year ago

Hi Amine (@chalandi) the calculatoin at the moment performs $10,001$ decimal digits in the pi-spigot loop. This is a performance and memory intensive calculatoin. At the moment with chip running at full speed and caching active, the calculatoin requires about 12s.

If debug help needed, I could go down to $1,001$ digits, but then I would need to supply a new hash value which is used as the measure of numerical correctness of the calculation.

Chalandi commented 1 year ago

Hi Chris (@ckormanyos )

I found the issue, it was related to the banked SPSR_cpu_mode register of CPSR. a wrong CPSR was restored instead of the banked one.

ckormanyos commented 1 year ago

Thanks Amine (@Chalandi) I have re-synced my fork of your original OSEK repo and taken the changes in the assembly context switch from there. It works perfectly in the applicatoin with preemptive as well as cooperative multitasking now. Great catch! Great fix! Thenks Amine (@Chalandi) it's always great working with you.

ckormanyos commented 1 year ago

Fixed by 59e65a63c3dbe09866fafe21163cd562a9ed2866