Piccolo OS: What is Context Switching?

preview_player
Показать описание
I am having fun with my Raspberry Pi Pico, and I thought I would put together a small multitasking OS for the Pico, which I have called Piccolo OS. This first video covers the idea of Context Switching, a key concept for any multitasking OS.




#garyexplains
Рекомендации по теме
Комментарии
Автор

Your ability to explain hard concepts is unique, thanks !

piiumlkj
Автор

Ok I am going to play the Multitasking video in the background while I watch this one!

halasimov
Автор

Look forward to this series Gary and congrats on 200K subs.

samaitcheson
Автор

Good video, nice explanation. I look forward to seeing what the code looks like.

Just one nit (at least for now); if "task1_func" is the entry point for the main function of task 1, then there is no need to take its address when passing it to the "piccolo_create_task()" function. The compiler does the right thing without complaint, I realize, but you can simply use If "task1_func" is a struct that contains task information, such as the actual entry point address, the address and size of the thread stack, and perhaps initial parameters, then the '&" is appropriate.

I have a small multi-tasking real-time executive that I wrote for ARM Cortex-M that does have thread priorities, timers, counting semaphores, gates, mutex, and events, and I'm attempting to implement signal handling in thread context as an option. It provides limited thread-local-storage to allow newlib nano that comes with the toolchain provided by the FPGA vendor (Microchip) to work in multiple threads without interference for the most part. I have my kernel working on M3, M4, M4F, and M7 (with double precision), and have put it on the embedded hard core in a SmartFusion2 FPGA as well as on several flavors of STM32.

What I would really like to see is something that explains how to write an os-aware plug-in or scripts for GCC/OCD, Eclipse, VS Code, or some other debugger or IDE.

filker
Автор

awesome beginners explanation of concurrency.

mandelbro
Автор

Great job Gary. Next you will have to add in more code to use the second core. I know that will be a lot harder to add in multiple cores. I wish the Pico's came with double the RAM and storage, but then we would be looking at a ESP32. I really hope the pi foundation looks at making some future Pico's with more RAM, storage, faster clock speeds, and even more cores. If they did that, then I would drop all the other micro controllers that I currently have in my arsenal.

sgodsell
Автор

As a Electrical Engineer that worked on early CPUs...I thank you for a better understanding of threading and multitasking. Keep up the good work!

TheTruth.K.J.V.
Автор

wow grate video you have me thicking about making an OS now if only i had time to do projects like this.

virtualizeeverything
Автор

I thought it would be way harder with a lot of hacks, but this looks really nice!

SlyEcho
Автор

i just wonder how do you even understand all these and then explain it nicely.... Appreaciated ;-)

maheshkotal
Автор

This is quite an advanced topic. I'm writing an exokernels, the bare minimum runs in kernel mode, like almost nothing. In fact I think the only thing that needs to run in kernel space is a process swap. I might even do a default kernel function for the ISR that can dispatch a signal to a process in user space.

kayakMike
Автор

Very educational.

I think the Pi Foundation is actually working on an RTOS for the Pico, so it will be interesting to see when and what they'll produce.

zetaconvex
Автор

Hey Gary! I'm trying to write some code similar to what you did with the piccolo_yield(...) function by running a svc interrupt. I'm getting an error from the assembler "SVC not supported on this architecture." Any tips? Thanks!

LowLevelLearning
Автор

Good job and thanks for the Assembly memory jogger -- long time; no see.
(need my IBM Green Card)

muddyexport
Автор

Thanks for sharing. Very cool stuff. Have you measured the time it takes to switch tasks ?

mannhansen
Автор

I realy enjoy your work Gary, Thank you for this video (and others). For the sake of completeness, I would like to clarify that at reset you are in thread mode using MSP. The choice of PSP has to be done manually via CONTROL and its configuration is also manual unlike the value of MSP that is automatically fetched from address 0x0 at reset. Additionally it might be worth mentioning the return address is automatically calculated by the core at the time of the exception and stacked along with the current value of LR during the context saving. I expect you are using the systick timer for your context switch signal. do you make use of pendsv too?

DavidCabanis
Автор

It looks like the pico has the processing power and memory of a micro computer from the 1980's so it might be quite good to see an OS embedded into the pico thats similar to a C64 or zx spectrum built in with a high level programming language, text editor, access to hardware and memory locations, but then there needs to be a graphics chip.

lemdixon
Автор

I programmed my Teensy 4 with thread handling built into the Arduino library. It is a very handy library, it even exploits software delay that CPU does nothing to switch context for other threads, achieving high performance multitasking.

eafindme
Автор

Hi Gary, looking at your video I began to think differently about a problem I'm having, which is a Windows application that shows UI freezing under Windows 10, but not under Windows 7. Instead of looing at the application-code, maybe I should look at how Windows deals with input from the keyboard and mouse to interrupt running application threads. Are you aware of any differences that might exists between Windows 7 and 10 in dealing with user input?

EvertvanKootwijk
Автор

"Old chat... I'd say... you were astonished when that interrupt occurred!!!" ;-)

IBITZEE
join shbcf.ru