linux内核 in_device
时间: 2023-09-15 13:03:03 浏览: 67
Linux内核中的in_device(网络接口设备)是指用于网络通信的硬件接口。它是网络层和数据链路层之间的桥梁,负责处理网络数据包的接收和发送。
in_device结构体是内核中表示网络接口设备的数据结构。它包含了网络接口的各种属性和函数指针,用于处理接收和发送数据包的操作。
每个in_device结构体对应一块网络设备,如以太网卡、无线网卡等。内核通过in_device结构体来管理和控制不同的网络设备。
通过in_device结构体,内核可以获取网络设备的配置信息,如MAC地址、IP地址、子网掩码等。内核还可以通过in_device结构体中的函数指针,对网络设备进行操作,如启动/关闭接口、发送数据包等。
在网络通信中,in_device结构体起到了重要的作用。它负责接收网络数据包,并将其传递到内核中的网络协议栈进行处理。同时,它也负责将内核中的数据包发送到网络设备上进行传输。
总而言之,in_device是Linux内核中用于表示网络接口设备的数据结构。它是实现网络通信功能的核心之一,通过管理和控制网络设备,实现数据包的接收和发送。
相关问题
linux内核timer_interrupt()源码
以下是Linux内核4.19版本中timer_interrupt()函数的源码实现:
```
asmlinkage __visible void __weak timer_interrupt(struct pt_regs *regs)
{
struct cpu_data *cpu = get_cpu_ptr(smp_processor_id());
struct clock_event_device *evt = cpu->evtdev;
unsigned long next_jiffies = jiffies + 1;
if (unlikely(time_after_eq(next_jiffies, cpu->last_jiffies + TICK_NSEC))) {
/*
* Some of this is really subtle. If we're in the middle of a tick
* already, we don't want to update the tick count - that could
* confuse the heck out of anyone trying to do timing. So make sure
* we don't update the tick until after the tick period has
* expired.
*/
if (time_after(next_jiffies, cpu->last_jiffies + TICK_NSEC)) {
int clock_was_set = 0;
while (time_after_eq(next_jiffies, cpu->last_jiffies + TICK_NSEC)) {
cpu->last_jiffies += TICK_NSEC;
update_wall_time();
clock_was_set = tick_nohz_update_jiffies(&cpu->tick_dep_mask);
if (cpu_is_offline(smp_processor_id()))
return;
}
if (clock_was_set)
tick_program_event(evt, cpu->next_timer_interrupt);
}
/*
* We must make sure that the jiffies update is visible
* before we test time_after_eq().
*/
smp_wmb();
if (time_after_eq(next_jiffies, READ_ONCE(jiffies)))
__generic_touch_nmi_watchdog();
if (unlikely(in_nmi()))
return;
/*
* If we missed any timer interrupts, correct this now
* by advancing the local timer and updating wall time
* again.
*/
while (time_after_eq(next_jiffies, READ_ONCE(jiffies))) {
cpu->last_jiffies += TICK_NSEC;
update_wall_time();
tick_nohz_idle_enter();
}
}
evt->event_handler(evt);
}
```
timer_interrupt()函数是中断处理程序,用于处理定时器中断。该函数首先获取当前CPU的事件设备指针,然后计算出下一次中断的时间,如果下一次中断的时间已经到了,则更新 jiffies 值并调用事件处理函数。如果下一次中断的时间还没有到,则继续等待下一次中断。函数中还包含了一些调用其他函数的代码块,用于更新时间值、设置时钟事件等。
Linux 内核timer_interrupt()源码解析
timer_interrupt() 是 Linux 内核中的一个定时器中断处理函数,它主要用于处理内核中的各种定时器事件,包括时钟中断、定时器任务等。
源码如下:
```c
void __irqentry timer_interrupt(struct pt_regs *regs)
{
...
update_process_times(user_mode(regs));
profile_tick(CPU_PROFILING, user_mode(regs), regs);
if (user_mode(regs))
return;
irq_enter();
#ifdef CONFIG_NO_HZ_COMMON
/*
* The tick broadcast device is disabled after the first
* CPU goes offlined, see tick_nohz_enable.
*/
if (tick_nohz_tick_stopped())
goto out;
#endif
tick_check_idle(TICK_NMI_SAFE);
/*
* Tickless idle is in progress.
*/
if (idle_cpu(smp_processor_id())) {
watchdog_touch();
smp_idle_check();
goto out;
}
/*
* Check if we need to do anything at all:
*/
if (!tick_check_oneshot_broadcast(tick_nohz_full_cpu_idle())) {
if (tick_check_oneshot() &&
!tick_check_broadcast_expired() &&
!tick_broadcast_oneshot_active()) {
tick_program_event(tick_oneshot_broadcast, oneshot_timer.expires);
goto out;
}
if (tick_check_broadcast_spurious())
goto out;
if (tick_check_cpu_dead(cpu) || tick_check_new_device(cpu))
goto out;
tick_check_replacement(cpu);
}
/*
* Re-enable periodic tick if it is stopped and there are no
* oneshot or broadcast events pending:
*/
if (tick_check_periodic() &&
!tick_check_oneshot_active() &&
!tick_check_broadcast_active())
tick_program_event(tick_periodic, tick_next_period);
out:
irq_exit();
...
}
```
该函数的主要流程如下:
1. 调用 update_process_times() 和 profile_tick() 更新进程的时间信息和性能分析信息。
2. 判断是否是用户态,如果是则直接返回。
3. 调用 irq_enter() 进入中断上下文。
4. 检查 tickless idle 是否正在进行,如果是,则直接返回。
5. 检查是否正在进行 idle,如果是,则调用 watchdog_touch() 和 smp_idle_check(),并直接返回。
6. 检查是否需要进行任何操作。
7. 如果需要,检查是否需要启动一次性定时器事件。
8. 如果需要,检查是否需要启动广播定时器事件。
9. 如果需要,检查是否需要停止定时器,并重新启动。
10. 调用 irq_exit() 退出中断上下文。
总的来说,timer_interrupt() 函数主要用于检查和处理各种定时器事件,以保证内核的正常运行。这些事件包括一次性定时器、广播定时器、周期性定时器等。