The contexts the kernel is in while in kernel space












1















The following excerpt is from Linux Kernel Development(LKD) by Robert Love.




These contexts represent the breadth of the kernel’s activities. In
fact, in Linux, we can generalize that each processor is doing exactly
one of three things at any given moment:




  1. In user-space, executing user code in a process

  2. In kernel-space, in process context, executing on behalf of a specific process

  3. In kernel-space, in interrupt context, not associated with a process, handling an interrupt


This list is inclusive. Even corner cases fit into one of these three
activities: For exam- ple, when idle, it turns out that the kernel is
executing an idle process in process context in the kernel.




What I grasped from above is that when in Kernel-space, there are only two contexts(it's inclusive, according to Love), i.e., process context & interrupt context. To my understanding, the kernel enters process context when a process invokes a system call(e.g., read(), write(), etc.), while interrupt context happens when the kernel handles an interrupt.



But there are far more other functionalities in the kernel, for instance, there are kernel threads scheduled to do routine works(e.g., reclaiming memory), and even the scheduler itself is neither invoked by a system call nor by an interrupt.



So I wonder why the text says there are only two contexts in the kernel...?










share|improve this question


















  • 1





    even the scheduler itself is neither invoked by a system call nor by an interrupt - then when do you think is it invoked? IT's invoked on both, when a process does yield() and when an interrupt fires. kernel threads scheduled to do routine works(e.g., reclaiming memory) kernel handling is composed of top half and low half of work. The top is done in interrupts (register doing routine work), the low (do routing work) executes in low half.

    – Kamil Cuk
    Jan 20 at 7:08
















1















The following excerpt is from Linux Kernel Development(LKD) by Robert Love.




These contexts represent the breadth of the kernel’s activities. In
fact, in Linux, we can generalize that each processor is doing exactly
one of three things at any given moment:




  1. In user-space, executing user code in a process

  2. In kernel-space, in process context, executing on behalf of a specific process

  3. In kernel-space, in interrupt context, not associated with a process, handling an interrupt


This list is inclusive. Even corner cases fit into one of these three
activities: For exam- ple, when idle, it turns out that the kernel is
executing an idle process in process context in the kernel.




What I grasped from above is that when in Kernel-space, there are only two contexts(it's inclusive, according to Love), i.e., process context & interrupt context. To my understanding, the kernel enters process context when a process invokes a system call(e.g., read(), write(), etc.), while interrupt context happens when the kernel handles an interrupt.



But there are far more other functionalities in the kernel, for instance, there are kernel threads scheduled to do routine works(e.g., reclaiming memory), and even the scheduler itself is neither invoked by a system call nor by an interrupt.



So I wonder why the text says there are only two contexts in the kernel...?










share|improve this question


















  • 1





    even the scheduler itself is neither invoked by a system call nor by an interrupt - then when do you think is it invoked? IT's invoked on both, when a process does yield() and when an interrupt fires. kernel threads scheduled to do routine works(e.g., reclaiming memory) kernel handling is composed of top half and low half of work. The top is done in interrupts (register doing routine work), the low (do routing work) executes in low half.

    – Kamil Cuk
    Jan 20 at 7:08














1












1








1








The following excerpt is from Linux Kernel Development(LKD) by Robert Love.




These contexts represent the breadth of the kernel’s activities. In
fact, in Linux, we can generalize that each processor is doing exactly
one of three things at any given moment:




  1. In user-space, executing user code in a process

  2. In kernel-space, in process context, executing on behalf of a specific process

  3. In kernel-space, in interrupt context, not associated with a process, handling an interrupt


This list is inclusive. Even corner cases fit into one of these three
activities: For exam- ple, when idle, it turns out that the kernel is
executing an idle process in process context in the kernel.




What I grasped from above is that when in Kernel-space, there are only two contexts(it's inclusive, according to Love), i.e., process context & interrupt context. To my understanding, the kernel enters process context when a process invokes a system call(e.g., read(), write(), etc.), while interrupt context happens when the kernel handles an interrupt.



But there are far more other functionalities in the kernel, for instance, there are kernel threads scheduled to do routine works(e.g., reclaiming memory), and even the scheduler itself is neither invoked by a system call nor by an interrupt.



So I wonder why the text says there are only two contexts in the kernel...?










share|improve this question














The following excerpt is from Linux Kernel Development(LKD) by Robert Love.




These contexts represent the breadth of the kernel’s activities. In
fact, in Linux, we can generalize that each processor is doing exactly
one of three things at any given moment:




  1. In user-space, executing user code in a process

  2. In kernel-space, in process context, executing on behalf of a specific process

  3. In kernel-space, in interrupt context, not associated with a process, handling an interrupt


This list is inclusive. Even corner cases fit into one of these three
activities: For exam- ple, when idle, it turns out that the kernel is
executing an idle process in process context in the kernel.




What I grasped from above is that when in Kernel-space, there are only two contexts(it's inclusive, according to Love), i.e., process context & interrupt context. To my understanding, the kernel enters process context when a process invokes a system call(e.g., read(), write(), etc.), while interrupt context happens when the kernel handles an interrupt.



But there are far more other functionalities in the kernel, for instance, there are kernel threads scheduled to do routine works(e.g., reclaiming memory), and even the scheduler itself is neither invoked by a system call nor by an interrupt.



So I wonder why the text says there are only two contexts in the kernel...?







linux linux-kernel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 20 at 6:55









xczzhhxczzhh

281415




281415








  • 1





    even the scheduler itself is neither invoked by a system call nor by an interrupt - then when do you think is it invoked? IT's invoked on both, when a process does yield() and when an interrupt fires. kernel threads scheduled to do routine works(e.g., reclaiming memory) kernel handling is composed of top half and low half of work. The top is done in interrupts (register doing routine work), the low (do routing work) executes in low half.

    – Kamil Cuk
    Jan 20 at 7:08














  • 1





    even the scheduler itself is neither invoked by a system call nor by an interrupt - then when do you think is it invoked? IT's invoked on both, when a process does yield() and when an interrupt fires. kernel threads scheduled to do routine works(e.g., reclaiming memory) kernel handling is composed of top half and low half of work. The top is done in interrupts (register doing routine work), the low (do routing work) executes in low half.

    – Kamil Cuk
    Jan 20 at 7:08








1




1





even the scheduler itself is neither invoked by a system call nor by an interrupt - then when do you think is it invoked? IT's invoked on both, when a process does yield() and when an interrupt fires. kernel threads scheduled to do routine works(e.g., reclaiming memory) kernel handling is composed of top half and low half of work. The top is done in interrupts (register doing routine work), the low (do routing work) executes in low half.

– Kamil Cuk
Jan 20 at 7:08





even the scheduler itself is neither invoked by a system call nor by an interrupt - then when do you think is it invoked? IT's invoked on both, when a process does yield() and when an interrupt fires. kernel threads scheduled to do routine works(e.g., reclaiming memory) kernel handling is composed of top half and low half of work. The top is done in interrupts (register doing routine work), the low (do routing work) executes in low half.

– Kamil Cuk
Jan 20 at 7:08












1 Answer
1






active

oldest

votes


















1














The most important parts of a context are address space(or virtual memory) and cpu state(like register value, program counter etc.). From this aspect of view, there should be other two kind of contexts: kernel context and kernel-thread context.



Kernel itself runs in kernel space don't depend on tasks(including normal process and kernel threads). Its context is called idle context or swapper context.



Kernel threads also don't rely on any normal process context. They are scheduled like normal task, with different cpu state, but share the same address space. Actually, all tasks share the same kernel space part, which are same as the idle context's kernel part. That's why no need to change address space(or mm) when switching normal process to kernel thread or between kernel threads.



In fact, the interrupt context is exactly the same type with kernel context and kernel-threads context: they do not rely on any normal process context. Interrupt is totally asynchronous, so in its context there is no assumption of interrupted task's context. I think this is why Robert Love says there are only two kind of contexts: process context and other.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54274264%2fthe-contexts-the-kernel-is-in-while-in-kernel-space%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The most important parts of a context are address space(or virtual memory) and cpu state(like register value, program counter etc.). From this aspect of view, there should be other two kind of contexts: kernel context and kernel-thread context.



    Kernel itself runs in kernel space don't depend on tasks(including normal process and kernel threads). Its context is called idle context or swapper context.



    Kernel threads also don't rely on any normal process context. They are scheduled like normal task, with different cpu state, but share the same address space. Actually, all tasks share the same kernel space part, which are same as the idle context's kernel part. That's why no need to change address space(or mm) when switching normal process to kernel thread or between kernel threads.



    In fact, the interrupt context is exactly the same type with kernel context and kernel-threads context: they do not rely on any normal process context. Interrupt is totally asynchronous, so in its context there is no assumption of interrupted task's context. I think this is why Robert Love says there are only two kind of contexts: process context and other.






    share|improve this answer




























      1














      The most important parts of a context are address space(or virtual memory) and cpu state(like register value, program counter etc.). From this aspect of view, there should be other two kind of contexts: kernel context and kernel-thread context.



      Kernel itself runs in kernel space don't depend on tasks(including normal process and kernel threads). Its context is called idle context or swapper context.



      Kernel threads also don't rely on any normal process context. They are scheduled like normal task, with different cpu state, but share the same address space. Actually, all tasks share the same kernel space part, which are same as the idle context's kernel part. That's why no need to change address space(or mm) when switching normal process to kernel thread or between kernel threads.



      In fact, the interrupt context is exactly the same type with kernel context and kernel-threads context: they do not rely on any normal process context. Interrupt is totally asynchronous, so in its context there is no assumption of interrupted task's context. I think this is why Robert Love says there are only two kind of contexts: process context and other.






      share|improve this answer


























        1












        1








        1







        The most important parts of a context are address space(or virtual memory) and cpu state(like register value, program counter etc.). From this aspect of view, there should be other two kind of contexts: kernel context and kernel-thread context.



        Kernel itself runs in kernel space don't depend on tasks(including normal process and kernel threads). Its context is called idle context or swapper context.



        Kernel threads also don't rely on any normal process context. They are scheduled like normal task, with different cpu state, but share the same address space. Actually, all tasks share the same kernel space part, which are same as the idle context's kernel part. That's why no need to change address space(or mm) when switching normal process to kernel thread or between kernel threads.



        In fact, the interrupt context is exactly the same type with kernel context and kernel-threads context: they do not rely on any normal process context. Interrupt is totally asynchronous, so in its context there is no assumption of interrupted task's context. I think this is why Robert Love says there are only two kind of contexts: process context and other.






        share|improve this answer













        The most important parts of a context are address space(or virtual memory) and cpu state(like register value, program counter etc.). From this aspect of view, there should be other two kind of contexts: kernel context and kernel-thread context.



        Kernel itself runs in kernel space don't depend on tasks(including normal process and kernel threads). Its context is called idle context or swapper context.



        Kernel threads also don't rely on any normal process context. They are scheduled like normal task, with different cpu state, but share the same address space. Actually, all tasks share the same kernel space part, which are same as the idle context's kernel part. That's why no need to change address space(or mm) when switching normal process to kernel thread or between kernel threads.



        In fact, the interrupt context is exactly the same type with kernel context and kernel-threads context: they do not rely on any normal process context. Interrupt is totally asynchronous, so in its context there is no assumption of interrupted task's context. I think this is why Robert Love says there are only two kind of contexts: process context and other.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 20 at 10:56









        Chris TsuiChris Tsui

        374210




        374210
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54274264%2fthe-contexts-the-kernel-is-in-while-in-kernel-space%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Homophylophilia

            Updating UILabel text programmatically using a function

            Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage