linux-kernel

How does Linux kernel migrate the process among multiple cores?

依然范特西╮ 提交于 2021-02-19 08:13:11
问题 Context: Process-1 is executing on core-0. Core-1 is idle. Now, process-1 uses sched_setaffinity() to change its CPU affinity as core-1. Question: Which kernel function(s) migrate the process-1 to execute on core-1? 回答1: Here is the call sequence starting from the sched_setaffinity system call entry point in the kernel: sys_sched_setaffinity. sched_setaffinity. __set_cpus_allowed_ptr. In the last function, there are two cases as shown in the code at line 1101: if (task_running(rq, p) || p-

How does Linux kernel migrate the process among multiple cores?

你说的曾经没有我的故事 提交于 2021-02-19 08:13:05
问题 Context: Process-1 is executing on core-0. Core-1 is idle. Now, process-1 uses sched_setaffinity() to change its CPU affinity as core-1. Question: Which kernel function(s) migrate the process-1 to execute on core-1? 回答1: Here is the call sequence starting from the sched_setaffinity system call entry point in the kernel: sys_sched_setaffinity. sched_setaffinity. __set_cpus_allowed_ptr. In the last function, there are two cases as shown in the code at line 1101: if (task_running(rq, p) || p-

How does linux kernel switch between user-mode and kernel-mode stack?

拜拜、爱过 提交于 2021-02-19 05:45:07
问题 How does linux kernel switch between user-mode and kernel-mode stack when a system call or an interrupt appears? I mean what is the exact mechanism - what happens to user-mode stack pointer and where does kernel-mode stack pointer come from? What is done by hardware and what must be done by software? 回答1: All of the words below are about x86. I will just describe entire syscall path, and this answer will contain requested information. First of all, you need to understand what is interrupt

How to find owner socket of sk_buff in Linux kernel?

时光毁灭记忆、已成空白 提交于 2021-02-19 04:41:49
问题 I'm trying to find the owner socket of an sk_buff instance, say, skb . My ultimate goal is to find a specific TCP option and somehow let the user space application to know. I plan to set a socket option when I find the TCP option and let the user space app to call getsockopt() . Therefore I need to know the ownership between sk_buff and sock . I find there is a field in sk_buff: struct sock *sk; However, when I try to retrieve this field at tcp_parse_options in tcp_input.c , I always get skb-

How to finding all runnable processes

两盒软妹~` 提交于 2021-02-19 04:14:04
问题 I'm learning about the scheduler and trying to print all runnable proceeses. So I have written a kernel module that uses the for_each_process macro to iterate over all processes, and prints the ones at "runnable" state. But this seems like a stupid (and inefficient) way of doing this. So I thought about getting a reference to all running queues and use their Red-Black-Tree to go over the runnable processes, but couldn't find a way to do this. I have found out that there is a list of sched

How to finding all runnable processes

[亡魂溺海] 提交于 2021-02-19 04:12:48
问题 I'm learning about the scheduler and trying to print all runnable proceeses. So I have written a kernel module that uses the for_each_process macro to iterate over all processes, and prints the ones at "runnable" state. But this seems like a stupid (and inefficient) way of doing this. So I thought about getting a reference to all running queues and use their Red-Black-Tree to go over the runnable processes, but couldn't find a way to do this. I have found out that there is a list of sched

How to finding all runnable processes

不羁岁月 提交于 2021-02-19 04:12:25
问题 I'm learning about the scheduler and trying to print all runnable proceeses. So I have written a kernel module that uses the for_each_process macro to iterate over all processes, and prints the ones at "runnable" state. But this seems like a stupid (and inefficient) way of doing this. So I thought about getting a reference to all running queues and use their Red-Black-Tree to go over the runnable processes, but couldn't find a way to do this. I have found out that there is a list of sched

How to finding all runnable processes

你离开我真会死。 提交于 2021-02-19 04:12:02
问题 I'm learning about the scheduler and trying to print all runnable proceeses. So I have written a kernel module that uses the for_each_process macro to iterate over all processes, and prints the ones at "runnable" state. But this seems like a stupid (and inefficient) way of doing this. So I thought about getting a reference to all running queues and use their Red-Black-Tree to go over the runnable processes, but couldn't find a way to do this. I have found out that there is a list of sched

How should I read Intel PCI uncore performance counters on Linux as non-root?

喜欢而已 提交于 2021-02-19 02:43:06
问题 I'd like to have a library that allows 'self profiling' of critical sections of Linux executables. In the same way that one can time a section using gettimeofday() or RDTSC I'd like to be able to count events such as branch misses and cache hits. There are a number of tools that do similar things (perf, PAPI, likwid) but I haven't found anything that matches what I'm looking for. Likwid comes closest, so I'm mostly looking at ways to modify it's existing Marker API. The per-core counters are

How does “get_user_pages” work (For linux driver)

落爺英雄遲暮 提交于 2021-02-18 22:37:28
问题 Working on a Linux PCI driver, now I'm trying to write codes for DMA using scatter/gather. For now, I've learned that to access to DMA datas directly from User space, we need to pin user space pages to kernel space. And to do this, we have get_user_pages , its full definition is like: int get_user_pages(struct task_struct * tsk, struct mm_struct * mm, unsigned long start, int nr_pages, int write, int force, struct page ** pages, struct vm_area_struct ** vmas); My first question is about the