Piccolo OS: What is Context Switching?

  Рет қаралды 23,337

Gary Explains

Gary Explains

Күн бұрын

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.
How does a CPU work? • How does a CPU work?
Multitasking vs Multithreading vs Multiprocessing • Multitasking vs Multit...
Introduction to Android app development: www.dgitacademy.com
Let Me Explain T-shirt: teespring.com/gary-explains-l...
Twitter: / garyexplains
Instagram: / garyexplains
#garyexplains

Пікірлер: 96
@alflud
@alflud 3 жыл бұрын
An actual stack exchange. Cool.
@piiumlkj6497
@piiumlkj6497 3 жыл бұрын
Your ability to explain hard concepts is unique , thanks !
@halasimov1362
@halasimov1362 3 жыл бұрын
Ok I am going to play the Multitasking video in the background while I watch this one!
@GaryExplains
@GaryExplains 3 жыл бұрын
I see what you did there! 😂
@samaitcheson7057
@samaitcheson7057 3 жыл бұрын
Look forward to this series Gary and congrats on 200K subs.
@GaryExplains
@GaryExplains 3 жыл бұрын
Thanks 👍
@filker0
@filker0 3 жыл бұрын
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 "piccolo_create_task(task1_func)". 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.
@GaryExplains
@GaryExplains 3 жыл бұрын
I am not going to argue coding style with you, but without the & you are relying on an implicit conversion, which does have its merits, however for lesser known use cases, like function pointers, then I personally I like to use the &. The purpose of this video (and the following videos) is not for nit picking coding style. It is for teaching some OS fundamentals. Nit picking just makes me hesitant to publish the code because there is an army of pedants waiting to pounce on every & and *.
@mandelbro777
@mandelbro777 Жыл бұрын
awesome beginners explanation of concurrency.
@kayakMike1000
@kayakMike1000 Жыл бұрын
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.
@PATRIK67KALLBACK
@PATRIK67KALLBACK 3 жыл бұрын
Great little simple os Gary!
@virtualizeeverything
@virtualizeeverything 3 жыл бұрын
wow grate video you have me thicking about making an OS now if only i had time to do projects like this.
@mannhansen9337
@mannhansen9337 3 жыл бұрын
Thanks for sharing. Very cool stuff. Have you measured the time it takes to switch tasks ?
@SlyEcho
@SlyEcho 3 жыл бұрын
I thought it would be way harder with a lot of hacks, but this looks really nice!
@lemdixon01
@lemdixon01 3 жыл бұрын
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.
@sjenkinsnm
@sjenkinsnm 3 жыл бұрын
The Pico has a 2nd processing core that could be used for graphics.... 🤔
@eFeXuy
@eFeXuy 3 жыл бұрын
@@sjenkinsnm This. But also even using only one core, the Pico has this thing called PIOs that can handle the time critical part of outputing video, the core just need to write a frame buffer and then DMA and PIO can output it, leaving free the core to other stuff.
@sgodsell2
@sgodsell2 3 жыл бұрын
Nevermind the 80's. I remember single core processors in the 90's, and RAM speeds only got around 300 mhz at the end of the 90's. If you wanted a dual core back then you had to buy a motherboard with dual cpu sockets.
@sgodsell2
@sgodsell2 3 жыл бұрын
@@sjenkinsnm Gary never used the second core in his piccolo OS. I know why, because it would make piccolo OS that much harder to develop. Plus his examples didn't need another physical core.
@deterdamel7380
@deterdamel7380 3 жыл бұрын
@@sgodsell2 That's why the 2nd core can be used for graphics :) ZX80/81 powered the display by software in the beginning of the 80's.
@maheshkotal4214
@maheshkotal4214 3 жыл бұрын
i just wonder how do you even understand all these and then explain it nicely.... Appreaciated ;-)
@sgodsell2
@sgodsell2 3 жыл бұрын
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.
@GaryExplains
@GaryExplains 3 жыл бұрын
I show how to use the second core in my previous Pico video, but to be honest I doubt I will have time to add multitasking to the second core.
@DavidCabanis
@DavidCabanis 3 жыл бұрын
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?
@GaryExplains
@GaryExplains 3 жыл бұрын
I think I mention most of that (see 9:55 and 10:55 and note "if you desire") but not in so much detail as that is getting into the nitty gritty which we will when we start looking at the code.
@eafindme
@eafindme 3 жыл бұрын
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.
@TheTruth.K.J.V.
@TheTruth.K.J.V. 3 жыл бұрын
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!
@kayakMike1000
@kayakMike1000 Жыл бұрын
Wow. What do you think of the RISC-V stuff? The arm assembly to push and pop the stack is pretty convenient and RISC-V doesn't have this...
@TheTruth.K.J.V.
@TheTruth.K.J.V. Жыл бұрын
@@kayakMike1000 Each has its specialized use. The reason both are still in use today. I learned on the stacks but its sometimes very easy to get things lost. It is amazing that simple call programs and loops work better than complex ones. Especially now we have much faster CPUs and less latency in memories...about a wash either way you go.🤔
@LowLevelLearning
@LowLevelLearning 3 жыл бұрын
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!
@zetaconvex1987
@zetaconvex1987 3 жыл бұрын
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.
@destroyer2973
@destroyer2973 Жыл бұрын
Lets hope it is industrial tron compliant.
@iar1980
@iar1980 3 жыл бұрын
Congrats on 200k.
@muddyexport5639
@muddyexport5639 3 жыл бұрын
Good job and thanks for the Assembly memory jogger -- long time; no see. (need my IBM Green Card)
@nitrovenom991
@nitrovenom991 3 жыл бұрын
Please do a video on custom kernel
@TheRealFrankWizza
@TheRealFrankWizza 3 жыл бұрын
Cool. Subscribed.
@EvertvanKootwijk
@EvertvanKootwijk 3 жыл бұрын
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?
@IBITZEE
@IBITZEE 3 жыл бұрын
"Old chat... I'd say... you were astonished when that interrupt occurred!!!" ;-)
@neildarlow
@neildarlow 2 жыл бұрын
I understand that you're doing this as a teaching series but you might be interested to know (if you don't already) that FreeRTOS works with the Pico C SDK. If you install the "smp" branch of the FreeRTOS-Kernel submodule then it does multi-tasking across both cores too.
@stanleyyyyyyyyyyy
@stanleyyyyyyyyyyy 3 жыл бұрын
What about releasing sources, Garry? Nice job by the way!
@GaryExplains
@GaryExplains 3 жыл бұрын
What about it? I will upload the source with the next video.
@stanleyyyyyyyyyyy
@stanleyyyyyyyyyyy 3 жыл бұрын
@@GaryExplains great thanks!
@ativjoshi1049
@ativjoshi1049 3 жыл бұрын
Aptly explained.
@b.b4229
@b.b4229 3 жыл бұрын
Hey Gary, may you document your progress also on GitHub?
@GaryExplains
@GaryExplains 3 жыл бұрын
It is actually all done. Just making the video is all that is left to do.
@b.b4229
@b.b4229 3 жыл бұрын
@@GaryExplains Great, I will be checking it out! Many thanks for your efforts.
@casperes0912
@casperes0912 3 жыл бұрын
I'm working on an x86-64 OS for my bachelor project. Now either ARM is significantly simpler to deal with from a kernel perspective, or Gary simplified quite a bit, haha. If it's the former I'm jealous
@GaryExplains
@GaryExplains 3 жыл бұрын
If you watch the next video you can see my implementation and the source code is on GitHub. Why did you pick x86-64, don't you see the direction the market is going?
@spotterinc.engineering5207
@spotterinc.engineering5207 3 жыл бұрын
Hi - Great videos! I would love to explore your Piccolo OS on PiPico - however I can't seem to find the code in your github (yet?). I went to /examples/Raspberry Pi Pico/Piccolo_OS/ but there was only the design document there. Hopefully you will be uploading the companion code soon...
@GaryExplains
@GaryExplains 3 жыл бұрын
Yeah, no code up yet, still tweaking it, correcting spelling mistakes, double checking everything, etc. The code will go up soon, some time next week I guess.
@peterschets1380
@peterschets1380 3 жыл бұрын
But does this also mean that every process runs on different cores, or is the example you gave only running on 1 core?
@GaryExplains
@GaryExplains 3 жыл бұрын
1 core.
@rondamon4408
@rondamon4408 3 жыл бұрын
How do you use the debug pins? Do you b have a video for that?
@GaryExplains
@GaryExplains 3 жыл бұрын
No video, sorry, but there are very clear instructions in Chapter 5 of the Getting started with Raspberry Pi Pico document. See www.raspberrypi.org/documentation/rp2040/getting-started/
@rondamon4408
@rondamon4408 3 жыл бұрын
@@GaryExplains thanks
@Akshaytanotra
@Akshaytanotra 3 жыл бұрын
What is the link to GitHub can't find in description
@GaryExplains
@GaryExplains 3 жыл бұрын
Try github.com/garyexplains which incidentally is the first result on Google if you search for "Gary Explains GitHub"
@piccolosan19
@piccolosan19 3 жыл бұрын
Piccolosan!!
@Saif0412
@Saif0412 3 жыл бұрын
🤣
@bbq1423
@bbq1423 3 жыл бұрын
Any git repo one could take a look at?
@GaryExplains
@GaryExplains 3 жыл бұрын
Just a readme in my GitHub at the moment: github.com/garyexplains/examples/tree/master/Raspberry%20Pi%20Pico/Piccolo_OS
@apruszko
@apruszko 3 жыл бұрын
Program is set of instructions that all of them are making somethings on some registers - rather than "program is just set of registers"
@GaryExplains
@GaryExplains 3 жыл бұрын
Obviously that was a big typo, should be "CPU" not "program".
@peteradshead2383
@peteradshead2383 3 жыл бұрын
So it is just a simple version of RTOS ?
@GaryExplains
@GaryExplains 3 жыл бұрын
I don't know what you mean by "just", but yes this is a very simple RTOS with severe limitations and lots of missing functionality. However, as a teaching tool I hope it is useful. This is "Gary Explains", not "Gary Develops a Commercial RTOS" 😜
@youknowme2322
@youknowme2322 3 жыл бұрын
next: Gohan OS
@SkyRotionDan
@SkyRotionDan 3 жыл бұрын
i bet piccolo OS is made by Namekian 🤣🤣😂😂😂
@darkerm76
@darkerm76 3 жыл бұрын
But we can't understand their language 😂
@renechawy
@renechawy 3 жыл бұрын
Request a KZbin video, #Pico with ARM assembly programming, with GitHub code, compile-linking with debugger. Like the C/C++ posted (5 ✨ 🌟)
@sobertillnoon
@sobertillnoon 2 жыл бұрын
Should be named PiccolOS
@poweruser64
@poweruser64 3 жыл бұрын
Nice title! Very clickable!
@cornjulio4033
@cornjulio4033 3 жыл бұрын
This is definitely something I need, but don't want to understand.
@prabhatyadav8189
@prabhatyadav8189 2 жыл бұрын
No stack overflowing this time....🤣⛔
@myusernameislongerth
@myusernameislongerth 3 жыл бұрын
where's the source?
@GaryExplains
@GaryExplains 3 жыл бұрын
There is no source for a video about context switching. When I do the video about Piccolo OS itself there will be some source code.
@darkerm76
@darkerm76 3 жыл бұрын
So Where is the DragonBall?
@user-kv2dv1rf4i
@user-kv2dv1rf4i 3 жыл бұрын
Don't ever say that word "let me explain " it's disgusting 😡😡😡😡😡😡😤😤
@GaryExplains
@GaryExplains 3 жыл бұрын
Eh?
@paulpvhl1930
@paulpvhl1930 3 жыл бұрын
1:13 - 1:21 "Concurrent describes things that are occurring, or people who are doing something, at the same time, such as 'concurrent users' of a computer program. Consecutive refers to things that are arranged or happen in a sequential order." Parallel is equivalent to concurrent in this context. Concurrent computing uses multiple CPUs; the Pico has two. So now, part way in, I'm confused as to what you're addressing! Keep up the good work Gary. I'm sure the rest of the video will be up to your usual standards and I'll catch on -- or?
@GaryExplains
@GaryExplains 3 жыл бұрын
Concurrent and parallel are not technically the same in this context. Also, although the Pico has 2 CPUs, here I am ignoring the 2nd CPU core.
@paulpvhl1930
@paulpvhl1930 3 жыл бұрын
@@GaryExplains My point was it isn't concurrent or parallel, it is consecutive, one task after the other. Thanks for the reply.
@GaryExplains
@GaryExplains 3 жыл бұрын
@@paulpvhl1930 OK, well without watching the video again, I don't remember in what context I used the word consecutive. Let me look at the clip you noted.
@GaryExplains
@GaryExplains 3 жыл бұрын
@@paulpvhl1930 So I looked at the clip at the time code you mentioned and I don't use the word consecutive.
@GaryExplains
@GaryExplains 3 жыл бұрын
@@paulpvhl1930 Also it isn't one task after the other. That would mean you start task A, complete task A and then start task B, complete task B etc. In concurrent execution A and B don't complete and the start/stop of one task isn't dependent on the other. In consecutive executive task A must finish before task B starts.
@sahbibg9680
@sahbibg9680 3 жыл бұрын
2040 playing crisis in Piccolo OS
RAID   1 Configuration on Windows Server 2019
1:57
Prefe Tech
Рет қаралды 9 М.
Houdini Algorithmic Live #110 - Flying Spine
3:38:43
Junichiro Horikawa
Рет қаралды 154 М.
СҰЛТАН СҮЛЕЙМАНДАР | bayGUYS
24:46
bayGUYS
Рет қаралды 650 М.
Super sport🤯
00:15
Lexa_Merin
Рет қаралды 19 МЛН
Como ela fez isso? 😲
00:12
Los Wagners
Рет қаралды 23 МЛН
Context Switch
10:34
Neso Academy
Рет қаралды 327 М.
Write Your Own Emulator for Your Own CPU - Using a Raspberry Pi Pico
32:17
How does a CPU work?
7:51
Gary Explains
Рет қаралды 87 М.
CNC milling: how 3 axis, 4 axis, 5 axis working?
1:01
RAPID DIRECT
Рет қаралды 60 М.
What is VGA and How to Use it With a Raspberry Pi Pico
18:28
Gary Explains
Рет қаралды 50 М.
M4 Deep Dive - Apple's First Armv9 Processor
15:20
Gary Explains
Рет қаралды 89 М.
Raspberry Pi Pico - Review and Getting Started
18:32
Gary Explains
Рет қаралды 74 М.
СҰЛТАН СҮЛЕЙМАНДАР | bayGUYS
24:46
bayGUYS
Рет қаралды 650 М.