Piccolo OS: What is Context Switching?

Поделиться
HTML-код
  • Опубликовано: 17 ноя 2024

Комментарии • 95

  • @piiumlkj6497
    @piiumlkj6497 3 года назад +12

    Your ability to explain hard concepts is unique , thanks !

  • @alflud
    @alflud 3 года назад +22

    An actual stack exchange. Cool.

  • @samaitcheson7057
    @samaitcheson7057 3 года назад +5

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

  • @halasimov1362
    @halasimov1362 3 года назад +4

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

    • @GaryExplains
      @GaryExplains  3 года назад +2

      I see what you did there! 😂

  • @filker0
    @filker0 3 года назад +2

    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 2 года назад +1

    awesome beginners explanation of concurrency.

  • @LowLevelTV
    @LowLevelTV 3 года назад +1

    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!

  • @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.🤔

  • @SlyEcho
    @SlyEcho 3 года назад +5

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

  • @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.

  • @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 года назад +1

      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.

  • @lemdixon01
    @lemdixon01 3 года назад +7

    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 года назад +2

      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.

  • @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.

  • @maheshkotal4214
    @maheshkotal4214 3 года назад

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

  • @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 2 года назад

      Lets hope it is industrial tron compliant.

  • @PATRIK67KALLBACK
    @PATRIK67KALLBACK 3 года назад

    Great little simple os Gary!

  • @IBITZEE
    @IBITZEE 3 года назад

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

  • @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.

  • @muddyexport5639
    @muddyexport5639 3 года назад +2

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

  • @nitrovenom991
    @nitrovenom991 3 года назад +2

    Please do a video on custom kernel

  • @neildarlow
    @neildarlow 3 года назад

    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.

  • @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.

  • @mannhansen9337
    @mannhansen9337 3 года назад

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

  • @stanleyyyyyyyyyyy
    @stanleyyyyyyyyyyy 3 года назад +1

    What about releasing sources, Garry? Nice job by the way!

    • @GaryExplains
      @GaryExplains  3 года назад +1

      What about it? I will upload the source with the next video.

    • @stanleyyyyyyyyyyy
      @stanleyyyyyyyyyyy 3 года назад +1

      @@GaryExplains great thanks!

  • @DavidCabanis
    @DavidCabanis 3 года назад +1

    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.

  • @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?

  • @b.b4229
    @b.b4229 3 года назад +6

    Hey Gary, may you document your progress also on GitHub?

    • @GaryExplains
      @GaryExplains  3 года назад +10

      It is actually all done. Just making the video is all that is left to do.

    • @b.b4229
      @b.b4229 3 года назад +3

      @@GaryExplains Great, I will be checking it out! Many thanks for your efforts.

  • @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?

  • @peterschets1380
    @peterschets1380 3 года назад +1

    But does this also mean that every process runs on different cores, or is the example you gave only running on 1 core?

  • @TheRealFrankWizza
    @TheRealFrankWizza 3 года назад

    Cool. Subscribed.

  • @ativjoshi1049
    @ativjoshi1049 3 года назад

    Aptly explained.

  • @spotterinc.engineering5207
    @spotterinc.engineering5207 3 года назад +1

    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 года назад +2

      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.

  • @piccolosan19
    @piccolosan19 3 года назад +2

    Piccolosan!!

  • @Akshaytanotra
    @Akshaytanotra 3 года назад +1

    What is the link to GitHub can't find in description

    • @GaryExplains
      @GaryExplains  3 года назад +1

      Try github.com/garyexplains which incidentally is the first result on Google if you search for "Gary Explains GitHub"

  • @youknowme2322
    @youknowme2322 3 года назад

    next: Gohan OS

  • @SkyRotionDan
    @SkyRotionDan 3 года назад +8

    i bet piccolo OS is made by Namekian 🤣🤣😂😂😂

    • @darkerm76
      @darkerm76 3 года назад +1

      But we can't understand their language 😂

  • @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 года назад +1

      Obviously that was a big typo, should be "CPU" not "program".

  • @sobertillnoon
    @sobertillnoon 3 года назад

    Should be named PiccolOS

  • @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" 😜

  • @rondamon4408
    @rondamon4408 3 года назад

    How do you use the debug pins? Do you b have a video for that?

    • @GaryExplains
      @GaryExplains  3 года назад +1

      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

  • @bbq1423
    @bbq1423 3 года назад

    Any git repo one could take a look at?

    • @GaryExplains
      @GaryExplains  3 года назад +1

      Just a readme in my GitHub at the moment: github.com/garyexplains/examples/tree/master/Raspberry%20Pi%20Pico/Piccolo_OS

  • @cornjulio4033
    @cornjulio4033 3 года назад

    This is definitely something I need, but don't want to understand.

  • @sahbibg9680
    @sahbibg9680 3 года назад

    2040 playing crisis in Piccolo OS

  • @poweruser64
    @poweruser64 3 года назад

    Nice title! Very clickable!

  • @renechawy
    @renechawy 3 года назад +2

    Request a RUclips video, #Pico with ARM assembly programming, with GitHub code, compile-linking with debugger.
    Like the C/C++ posted (5 ✨ 🌟)

  • @darkerm76
    @darkerm76 3 года назад +4

    So Where is the DragonBall?

  • @prabhatyadav8189
    @prabhatyadav8189 3 года назад

    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.

  • @user-kv2dv1rf4i
    @user-kv2dv1rf4i 3 года назад

    Don't ever say that word "let me explain " it's disgusting 😡😡😡😡😡😡😤😤