What is a spinlock? //Source Dive// 002

What is a spinlock? //Source Dive// 002

Low Byte Productions

1 год назад

47,204 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@andreabisio
@andreabisio - 02.10.2023 23:01

I adore source dives!

Ответить
@john999
@john999 - 03.10.2023 21:07

Great work. Please continue.
I am reminded of my computer science lecture at the university. But here it is more condensed and directly explained on a live example. I like that. Not too theoretical.

Ответить
@FredBakker
@FredBakker - 03.10.2023 21:39

What happens with incoming interrupts while they are disabled? Are they lost forever, or queued somewhere to be processed after interrupts are enabled again?

Ответить
@nerdx00
@nerdx00 - 04.10.2023 07:41

Sorry if this should be obvious but I don't really understand how `started` is shared between cores here with them each having their own stack at this point? I probably don't understand all the implications of `volatile static` but I thought the value would live on the stack.

Ответить
@StephenKelly-q4f
@StephenKelly-q4f - 04.10.2023 19:19

I don't understand the condition on cpuid() ==0. Is main() invoked once for each core??

Ответить
@myhobbies5965
@myhobbies5965 - 04.10.2023 21:16

What a excellent way of teaching low level.

Ответить
@ilyasabi8920
@ilyasabi8920 - 10.10.2023 03:35

Excellent work, can you explain things like memory barriers instruction fences? It kinda seems like more efficient way of doing for things include parallelism, concurrency (in general we try to get compiler to out our way when talking about locks but this let's compiler to understand our intent more clearly so maybe more efficient?). There are many good explanation in web but your videos are more entertaining and more people might learn about. 👍

Ответить
@fraserwilliams5223
@fraserwilliams5223 - 10.10.2023 12:45

Such a cool series!

Ответить
@stephanfrank696
@stephanfrank696 - 11.10.2023 01:05

Hello, maybe someone can answer my question: How can mycpu()->noff ever be more than 1? What am I missing here? Great series though :)

Ответить
@idlewise
@idlewise - 11.10.2023 22:46

Took me a while to realise that this was the next video after "How does an OS boot? //Source Dive// 001", because I was looking for "How does an OS boot? //Source Dive// 002"

Ответить
@Otakutaru
@Otakutaru - 12.10.2023 00:21

Would you consider using some drawing program to illustrate what you're talking about? there are some points where the CS background needed goes way up and you go into a 5 minute tangent. Visuals could help alleviate that

Ответить
@ZeroPlayerGame
@ZeroPlayerGame - 14.10.2023 22:50

Thought I'd weigh in - the historical reason for C names being short isnt just lack of storage, it's because one of the popular early compilers (I forget which, maybe indeed K&R one) only compared the first 8 bytes of names to determine what's what, so your first 8 bytes had to count.

Ответить
@meerkatpowergaming9412
@meerkatpowergaming9412 - 15.10.2023 07:17

I am trying to understand this, but I can't find the clint.

Ответить
@leandrormor
@leandrormor - 15.10.2023 22:38

thanks for sharing, I'm following the series :) I'm crazy to learn more about virtual memory, I believe I just know it in high level, tlb,mmu, pages,frames.... but I'm anxious to see it implemented!

Ответить
@supergamerfr
@supergamerfr - 17.10.2023 21:29

Amazing work well done really rare 👏👏👏

Ответить
@markuswerner1166
@markuswerner1166 - 18.10.2023 09:10

Great Video. I enjoy watching it. Keep going, please.

Ответить
@iamdriy
@iamdriy - 20.10.2023 05:55

This is really cool! At work I deal with an RTOS and have access to the source and it's cool seeing the similarities in the steps many operating systems take to boot.

Ответить
@WeekendStudy-xo6lq
@WeekendStudy-xo6lq - 21.10.2023 17:06

That is eye opening 👌😉. And greetings from attacked israel. May the CLINT be with us and the good guys prevail! 🫡

Ответить
@ivopfaffen
@ivopfaffen - 22.10.2023 18:31

this is so cool!
i'm currently taking an OS class where we work with xv6, and your videos have been really helpful :)
right now we're implementing MLFQ scheduling, and watching this series is helping a ton in understanding how everything works.
greetings from Argentina!

Ответить
@thisismissem
@thisismissem - 24.10.2023 05:00

Why do we run a function, then acquire a lock and wait, blocking that CPU instead of saying "hey, I'd like this resource, and when it's available I want to run this code" essentially making locks non-blocking

Ответить
@cjxordi
@cjxordi - 27.10.2023 06:44

While I watched, I had some thoughts (I don't know a lot about that low level stuff), I saw before locking mutex it disables interrupts (I'm not sure if it disables it for that particular core that tries to acquire mutex or for whole CPU). But why we cannot process interrupt in another core that doesn't wait for mutex to be released, and if the interrupt belongs (data or code) to core that waits, "reschedule" it again after the mutex is released. It might be stupid, but Im curios if that would be possible.

Ответить
@adrianlazar1454
@adrianlazar1454 - 30.10.2023 13:48

Amazing work! It's a pleasure to watch your deep dives. Can't even tell when the time flies by!

Ответить
@terrym2007
@terrym2007 - 03.11.2023 07:27

Great Work....thanks

Ответить
@cya3mdirl158
@cya3mdirl158 - 03.11.2023 23:43

So advanced topics. Wow. But what for beginners? Tannenbaun book about OS?
You are PRO BRO

Ответить
@flyme2themoon578
@flyme2themoon578 - 05.11.2023 21:43

Love your content. This is great work!

Ответить
@CosmicRaccoon
@CosmicRaccoon - 10.11.2023 10:32

These videos are great, love the content, thank you very much! ✨

Ответить
@thealliedhacker
@thealliedhacker - 12.11.2023 23:01

The description for push_off isn't really correct, when you're talking about having "multiple locks" on the same CPU.

We've already seen that locks aren't re-entrant, as calling acquire twice before release gets a panic.
But the code IS allowing push_off calls to be re-entrant, meaning we can have a push_off followed by another push_off , then two pop_off calls.
If we did this, only one set of push_off/pop_off calls could ever be from acquire/release (since acquire isn't re-entrant)... if acquire was the only caller, none of that logic would be necessary.

In other words, push_off/pop_off has a bunch of logic and structures to make it re-entrant, but they're not related to locking.
All mentions of "another lock" in the description of these functions are instead referring to "another (non-locking related) push_off caller".

Ответить
@voiceoftreason1760
@voiceoftreason1760 - 12.11.2023 23:04

Request: "how does riscv handle the situation where a hardware interrupt comes in while some atomic operation is executing, and interrupts are temporarily turned off?"
###
assistant: When a hardware interrupt occurs while an atomic operation is executing and interrupts are temporarily turned off, RISC-V handles the situation by ensuring that the atomic operation completes before servicing the interrupt.

RISC-V processors have a mechanism called "interrupt disable" that allows the software to temporarily disable interrupts. When interrupts are disabled, the processor will not respond to any interrupt requests until they are re-enabled.

During an atomic operation, interrupts are typically disabled to ensure that the operation is executed atomically, without any interruption. If a hardware interrupt occurs while interrupts are disabled, the interrupt request is still registered by the processor, but it is not serviced immediately.

Once the atomic operation completes and interrupts are re-enabled, the processor will check if any interrupt requests were registered during the disabled interrupt state. If there are pending interrupts, the processor will handle them in the order they were received, following the interrupt priority scheme defined by the system.

In summary, RISC-V ensures that interrupts are not serviced immediately when they occur during an atomic operation with interrupts disabled. Instead, the interrupts are queued and serviced once the atomic operation completes and interrupts are re-enabled.


>>> so there is a kind of interrupt queue for this? Can it overflow? what would happen in that case if it did?
Yes, RISC-V processors typically have an interrupt queue to handle pending interrupts. This queue can store multiple interrupt requests that occurred while interrupts were disabled.

The size of the interrupt queue is implementation-dependent and can vary between different RISC-V processors. In some cases, the interrupt queue may have a fixed size, while in others it may be dynamically allocated.

If the interrupt queue becomes full and a new interrupt request arrives, it can lead to an overflow condition. The behavior in such a case depends on the specific implementation of the RISC-V processor.

In some implementations, when the interrupt queue overflows, the oldest pending interrupt may be dropped or discarded to make space for the new interrupt. This means that the dropped interrupt will not be serviced until the next occurrence of that interrupt.

Other implementations may have mechanisms to handle overflow conditions more gracefully. For example, they may provide additional storage or buffers to accommodate a larger number of pending interrupts, or they may prioritize certain types of interrupts over others.

It's important to note that the behavior in case of an interrupt queue overflow is implementation-specific and may vary between different RISC-V processors. System designers and software developers need to consider the interrupt handling capabilities and limitations of the specific RISC-V processor they are working with to ensure proper interrupt management and avoid potential issues caused by overflow conditions.

Ответить
@arctitan7076
@arctitan7076 - 16.11.2023 00:08

Thanks so much!

Ответить
@weicco
@weicco - 18.11.2023 10:26

I was writing cpu scheduler to one OS back in days. I gave up because I had that mental problem back then that if I couldn't come up with perfect solution, I refused to do it 😂 I was struggling how to write perfect priorized list and ended up with all kinds of schedulers where I tried to keep of statistics of triggered tasks to alter their priorities on fly and so on. It just went over my head.

Ответить
@sup5282
@sup5282 - 25.11.2023 22:49

Probably I understood 10 percent of material cause I have low skill but it was really interesting. Main insight is that see into source of OS is not so terrifying)

Ответить
@lars-magnusskog3983
@lars-magnusskog3983 - 12.12.2023 05:35

Brilliantly explained. Thanks a million for this.

Ответить
@jonasbachmann2650
@jonasbachmann2650 - 28.12.2023 18:54

couldnt a context switch happen between intr_get() and intr_off()? or would that be okay anyways?

Ответить
@thalesfm
@thalesfm - 29.12.2023 20:05

Regarding the cryptic naming conventions of older software, it's worth noting that the original ANSI C standard specifies that for external identifiers only the first 6 characters are considered "significant." So if a program had two identifiers with the same 6-character prefix (but which were otherwise different) the compiler's behavior was undefined(!). In practice this means compilers were free to ignore longer identifiers, so programmers were pretty much forced to come up with really short names for functions/variables. I think it's unfortunate that the convention seems to have stuck with C developers, but it's understandable why programmers did that sort of thing back in the day.

Ответить
@saianoop9515
@saianoop9515 - 02.01.2024 02:57

You mentioned that the names are shortened to reduce memory usage of code. however, if we add comments, wouldn't that be a net increase in storage required? Are the comments added recently to help people and weren't part of the original codebase? Or, ig the comment is a one time trade off cost for a variable used like 100 times.

Ответить
@paulurbanus3598
@paulurbanus3598 - 03.01.2024 09:02

Excellent explanation of the fence instruction, to keep the compiler and the CPU from reordering operations. As an EE and software hack, I've seen reference to the fence instruction. Your explanation makes it's usage (and why it's named 'fence') clear.

Ответить
@ВиталийМихальчук-л4ь
@ВиталийМихальчук-л4ь - 31.01.2024 17:26

What a great work, thanks for such dense but yet conceivable and understandable video!

Ответить
@ryantaylor6470
@ryantaylor6470 - 03.02.2024 21:35

Great video! Really easy to follow

Ответить
@MichaelGrnbk
@MichaelGrnbk - 19.03.2024 00:54

Really good educational presentation - thanks for providing an overview to order of and why things are done. I did embedded RTOS system programming some years ago and I do have a good understanding on how things work - but nice to get a refresh on the general architecture and functionality of the various components - and some of it I never touched - so nice to get further info :)

Ответить
@typedeaf
@typedeaf - 23.03.2024 06:38

Ответить
@OmprakashOmYadav
@OmprakashOmYadav - 28.03.2024 01:34

Thank you.

Ответить
@furkanonder-ut4mz
@furkanonder-ut4mz - 27.05.2024 00:46

Good stuff mate!

Ответить
@salilphadnis4147
@salilphadnis4147 - 03.06.2024 16:08

Can't thank you enough for this series. This is incredibly useful.

Ответить
@Chabdi111
@Chabdi111 - 17.06.2024 15:13

Awsome work, i hope u do more videos that i can learn fron :)

Ответить
@avinashverma3973
@avinashverma3973 - 17.06.2024 21:38

awesome video

Ответить
@MauricioMartinez0707
@MauricioMartinez0707 - 14.09.2024 07:17

are spin locks the only thing that can turn off interrupts? if not, then I see some issues with the implementation of push_off and pop_off (in regards to intena)

Ответить