<p dir="ltr"><br>
On Mar 25, 2015 6:33 AM, &quot;Sreejith M M&quot; &lt;<a href="mailto:sreejith.mm@gmail.com">sreejith.mm@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Jan 28, 2015 at 9:56 PM, Sreejith M M &lt;<a href="mailto:sreejith.mm@gmail.com">sreejith.mm@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi,<br>
&gt;&gt;<br>
&gt;&gt; I was trying to understand the difference in scheduling between<br>
&gt;&gt; processes and threads(belong to same process).<br>
&gt;&gt;<br>
&gt;&gt; I was thinking that, when kernel has to switch to a task which belong<br>
&gt;&gt; to the same process, it does not have to clear / replace page global<br>
&gt;&gt; directories and other memory related information.<br>
&gt;&gt;<br>
&gt;&gt; But in switch_mm function some code is put under CONFIG_SMP function.<br>
&gt;&gt; What is its signigicance? Code is<br>
&gt;&gt; below(<a href="http://lxr.free-electrons.com/source/arch/x86/include/asm/mmu_context.h#L37">http://lxr.free-electrons.com/source/arch/x86/include/asm/mmu_context.h#L37</a>)<br>
&gt;&gt; .<br>
&gt;&gt; What I infer is that the code is doing flush tlb, reload page table<br>
&gt;&gt; directories etc in multiprocessor mode(obviously)  but I believe this<br>
&gt;&gt; code may never be executed .<br>
&gt;&gt;<br>
&gt;&gt; Can anyone help to understand what this part of the function supposed to do?<br>
&gt;&gt;<br>
&gt;&gt;  60 #ifdef CONFIG_SMP<br>
&gt;&gt;  61           else {<br>
&gt;&gt;  62                 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);<br>
&gt;&gt;  63                 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);<br>
&gt;&gt;  64<br>
&gt;&gt;  65                 if (!cpumask_test_cpu(cpu, mm_cpumask(next))) {<br>
&gt;&gt;  66                         /*<br>
&gt;&gt;  67                          * On established mms, the mm_cpumask is<br>
&gt;&gt; only changed<br>
&gt;&gt;  68                          * from irq context, from<br>
&gt;&gt; ptep_clear_flush() while in<br>
&gt;&gt;  69                          * lazy tlb mode, and here. Irqs are blocked during<br>
&gt;&gt;  70                          * schedule, protecting us from<br>
&gt;&gt; simultaneous changes.<br>
&gt;&gt;  71                          */<br>
&gt;&gt;  72                         cpumask_set_cpu(cpu, mm_cpumask(next));<br>
&gt;&gt;  73                         /*<br>
&gt;&gt;  74                          * We were in lazy tlb mode and leave_mm disabled<br>
&gt;&gt;  75                          * tlb flush IPI delivery. We must reload CR3<br>
&gt;&gt;  76                          * to make sure to use no freed page tables.<br>
&gt;&gt;  77                          */<br>
&gt;&gt;  78                         load_cr3(next-&gt;pgd);<br>
&gt;&gt;  79                         trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH,<br>
&gt;&gt; TLB_FLUSH_ALL);<br>
&gt;&gt;  80                         load_LDT_nolock(&amp;next-&gt;context);<br>
&gt;&gt;  81                 }<br>
&gt;&gt;  82         }<br>
&gt;&gt;  83 #endif<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; Regards,<br>
&gt;&gt; Sreejith<br>
&gt;<br>
&gt;<br>
&gt; Hi ,<br>
&gt;<br>
&gt; can someone please give me any answers for this?<br>
&gt;<br>
&gt; -- <br>
&gt; Regards,<br>
&gt; Sreejith<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Kernelnewbies mailing list<br>
&gt; <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
&gt; <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
&gt;</p>
<p dir="ltr">This code is handling context switch from a kernel thread back to user mode thread so TLB entries are invalid translation for user mode thread and do not correspond to user process pgd. It is Master kernel page table translation as a result of kernel thread execution.</p>
<p dir="ltr">-Rajat</p>