内核线程绑定CPU
来源:互联网 发布:信息碎片化定义知乎 编辑:程序博客网 时间:2024/05/02 15:14
内核线程绑定到CPU上执行测试代码:
From 12f206e044f467919180aa26148eaacd82964ece Mon Sep 17 00:00:00 2001From: Chen Jun <675816156@qq.com>Date: Thu, 7 Dec 2017 08:24:52 -0800Subject: [PATCH] bind kthread on cpu Test--- arch/arm64/Kconfig | 2 +- fs/proc/uptime.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-)diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfigindex 6df1e6e..ecbb44b 100644--- a/arch/arm64/Kconfig+++ b/arch/arm64/Kconfig@@ -580,7 +580,7 @@ config NR_CPUS int "Maximum number of CPUs (2-4096)" range 2 4096 # These have to remain sorted largest to smallest- default "64"+ default "8" config HOTPLUG_CPU bool "Support for hot-pluggable CPUs"diff --git a/fs/proc/uptime.c b/fs/proc/uptime.cindex 33de567..c237260 100644--- a/fs/proc/uptime.c+++ b/fs/proc/uptime.c@@ -6,6 +6,54 @@ #include <linux/time.h> #include <linux/kernel_stat.h> #include <linux/cputime.h>+#include <linux/kthread.h>+#include <linux/delay.h>++static DECLARE_COMPLETION(thread_done);+static atomic_long_t count = ATOMIC64_INIT(0);++static int thread_func(void *arg)+{+ int cpu;+ long long val;++ cpu = *(int *)arg;+ pr_err("%s start on cpu%d\n", __func__, cpu);++ msleep(10000);+ pr_err("%s end on cpu%d\n", __func__, cpu);++ if ((val = atomic64_inc_return(&count)) >= NR_CPUS) {+ pr_err("%s %d end atomic %lld\n", __func__, cpu, val);+ complete(&thread_done);+ }++ return 0;+}++static void self_test(void)+{+ int cpu, ret;+ struct task_struct *kthread[8] = {0};++ init_completion(&thread_done);+ memset(&count, 0, sizeof(count));++ for_each_online_cpu(cpu) {+ kthread[cpu] = kthread_create_on_cpu(thread_func, &cpu, cpu, "cjthread/%d");+ if (IS_ERR(kthread[cpu])) {+ pr_err("fail to kthread_create_on_cpu\n");+ return ;+ }+ }++ for_each_online_cpu(cpu) {+ ret = wake_up_process(kthread[cpu]);+ pr_err("wake_up_process %d ret %d\n", cpu, ret);+ }+ wait_for_completion(&thread_done);+ pr_err("%s %d completed\n", __func__, __LINE__);+} static int uptime_proc_show(struct seq_file *m, void *v) {@@ -16,6 +64,7 @@ static int uptime_proc_show(struct seq_file *m, void *v) u32 rem; int i;+ self_test(); idletime = 0; for_each_possible_cpu(i) idletime += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE];-- 2.7.4
阅读全文
0 0
- 内核线程绑定CPU
- 线程绑定CPU核
- 线程cpu绑定技术
- 线程绑定CPU
- 为线程绑定CPU
- 线程绑定CPU核
- 线程绑定CPU核
- 线程绑定CPU核
- 线程绑定CPU核
- 线程绑定CPU核
- 线程绑定CPU核
- 线程绑定CPU核
- 线程与内核绑定
- 进程线程与cpu绑定
- 【进程线程绑定CPU】总结
- 【历程线程绑定CPU】总结
- 线程与cpu进行绑定
- 线程绑定CPU核-sched_setaffinity
- 种草莓 HNUST 1714(求正方形边长 DP)
- C++多线程下子类"部分析构"问题
- 171206 逆向-JarvisOJ(病毒数据分析)(1)
- cpp中类和struct的区别
- Struts 2的struts.xml中配置json类型
- 内核线程绑定CPU
- bzoj 3781: 小B的询问(莫队)
- 使用log4j记录日志
- Untitled
- 循环队列
- L-System分形
- Linux系统编程——Linux系统调用
- 从iOS开发走向Java开发
- 王一三学习笔记 | 什么是J2EE