#ifdef CONFIG_SMP { int i; p->has_cpu = 0; p->processor = current->processor; /* ?? should we just memset this ?? */ for(i = 0; i < smp_num_cpus; i++) p->per_cpu_utime[i] = p->per_cpu_stime[i] = 0; spin_lock_init(&p->sigmask_lock); }
时间: 2024-03-11 22:46:32 浏览: 13
继续上面的代码,如果内核配置中启用了 SMP(对称多处理),则为新进程初始化 has_cpu 和 processor 成员变量。然后使用循环将新进程的 per_cpu_utime 和 per_cpu_stime 数组都初始化为 0。这两个数组用于跟踪进程在每个 CPU 上的用户和系统时间。最后初始化新进程的 sigmask_lock 成员变量,用于保护新进程的信号屏蔽字。
相关问题
/* Real-Time classes' related field in a runqueue: */ struct rt_rq { struct rt_prio_array active; unsigned int rt_nr_running; unsigned int rr_nr_running; #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED struct { int curr; /* highest queued rt task prio */ #ifdef CONFIG_SMP int next; /* next highest */ #endif } highest_prio; #endif #ifdef CONFIG_SMP unsigned int rt_nr_migratory; unsigned int rt_nr_total; int overloaded; struct plist_head pushable_tasks; #endif /* CONFIG_SMP */ int rt_queued; int rt_throttled; u64 rt_time; u64 rt_runtime; /* Nests inside the rq lock: */ raw_spinlock_t rt_runtime_lock; #ifdef CONFIG_RT_GROUP_SCHED unsigned int rt_nr_boosted; struct rq *rq; struct task_group *tg; #endif };
这是 Linux 内核中实时调度器相关的代码,定义了一个名为 `rt_rq` 的结构体类型,表示实时进程在运行队列中的相关信息。该结构体包含了以下字段:
- `active`:实时进程在运行队列中的优先级数组;
- `rt_nr_running`:当前实时进程的数量;
- `rr_nr_running`:当前时间片轮转进程的数量;
- `highest_prio`:最高实时进程的优先级;
- `rt_nr_migratory`:正在迁移的实时进程数量;
- `rt_nr_total`:实时进程总数;
- `overloaded`:是否超载;
- `pushable_tasks`:可移动的任务列表;
- `rt_queued`:正在排队的实时进程数量;
- `rt_throttled`:正在被限制的实时进程数量;
- `rt_time`:实时进程的运行时间;
- `rt_runtime`:实时进程的运行总时间;
- `rt_runtime_lock`:实时进程的运行时间锁;
- `rt_nr_boosted`:已提升优先级的实时进程数量;
- `rq`:实时进程所在的运行队列;
- `tg`:实时进程所在的任务组。
#ifndef DISABLE_LIBSSH if (session->ssh_chan != NULL) { /* we are getting data from libssh's channel */ status = ssh_channel_poll_timeout(session->ssh_chan, timeout, 0); if (status > 0) { revents = POLLIN; } } else #endif #ifdef ENABLE_TLS if (session->tls != NULL) { /* we are getting data from TLS session using OpenSSL */ fds.fd = SSL_get_fd(session->tls); fds.events = POLLIN; fds.revents = 0; status = poll(&fds, 1, timeout); revents = (unsigned long int) fds.revents; } else #endif
这段代码是一个网络库的代码,主要是用于从网络通道中读取数据。其中,该代码使用了条件编译,根据是否定义了DISABLE_LIBSSH和ENABLE_TLS宏来选择不同的代码路径。当DISABLE_LIBSSH宏被定义时,该代码段会从libssh的channel中获取数据;当ENABLE_TLS宏被定义时,该代码段会从OpenSSL的TLS session中获取数据。poll函数会等待timeout时间,直到有数据可读或者等待超时返回。如果有数据可读,则将revents设置为POLLIN表示有数据可读。