Test "make sure to context-switch to idle thread when therad's status is PS_EXITED" on arm64
Change-Id: I757d529e49655e9010022f10414e4d6c9eb4c059 Refs: #1029
This commit is contained in:
committed by
Masamichi Takagi
parent
01b2a1d213
commit
0ee446923a
16
test/mng_mod/issues/1029/arm64/Makefile
Normal file
16
test/mng_mod/issues/1029/arm64/Makefile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Makefile COPYRIGHT FUJITSU LIMITED 2018
|
||||||
|
CC=gcc
|
||||||
|
TARGET=sched_test go_test
|
||||||
|
all:: $(TARGET)
|
||||||
|
|
||||||
|
sched_test: sched_test.c
|
||||||
|
$(CC) -o $@ $<
|
||||||
|
|
||||||
|
go_test: go_test.c
|
||||||
|
$(CC) -o $@ $<
|
||||||
|
|
||||||
|
test:: $(TARGET)
|
||||||
|
./run.sh
|
||||||
|
|
||||||
|
clean::
|
||||||
|
rm -f $(TARGET)
|
||||||
85
test/mng_mod/issues/1029/arm64/README
Normal file
85
test/mng_mod/issues/1029/arm64/README
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/* README COPYRIGHT FUJITSU LIMITED 2018 */
|
||||||
|
|
||||||
|
McKernel プロセスへ直接送信されたシグナルによるfutex の中断機能
|
||||||
|
テストセットREADME
|
||||||
|
|
||||||
|
(1) テストの実行方法
|
||||||
|
以下の手順でテストを実行する
|
||||||
|
1. $HOME/.mck_test_configを用意する
|
||||||
|
当該ファイルは、McKernelをビルドした際に生成されるmck_test_config.sample ファイルを
|
||||||
|
$HOMEにコピーし、適宜編集する
|
||||||
|
mcreboot.shのオプションには-Oを付与すること
|
||||||
|
2. run.sh内のSTRESSBINにストレステストセットのパスを設定する
|
||||||
|
3. patch/1029.patchを適用し、ビルドしたMcKernelを用意する
|
||||||
|
4. make test を実行する
|
||||||
|
|
||||||
|
(2) テスト項目詳細
|
||||||
|
1. ストレステストを用いた確認
|
||||||
|
ISSUE01: futex_wait()で待っているプロセスをKILLシグナルで終了させても問題がないこと。
|
||||||
|
→ 全てSUCCESS で、McKernel上にプロセスとスレッドの残留が無ければOK
|
||||||
|
|
||||||
|
2. 基本動作確認
|
||||||
|
schedule()実行時のコンテキストスイッチ前thread(prev)と、
|
||||||
|
runqに積まれている実行待ちthreadの状態の以下の組み合わせで、
|
||||||
|
schedule()が想定どおりの動作をすることを確認する。
|
||||||
|
|
||||||
|
◆prevがidleのケース
|
||||||
|
CT_001: runqが空
|
||||||
|
⇒ コンテキストスイッチを行わない
|
||||||
|
|
||||||
|
CT_002: runqに実行待ちのthreadが存在し、且つ、そのthreadが1度も実行状態になっていない
|
||||||
|
⇒ 非idleのthreadにスイッチする
|
||||||
|
|
||||||
|
CT_003: runqに実行待ちのthreadが存在し、且つ、そのthreadが実行状態になったことがある
|
||||||
|
⇒ 非idleのthreadにスイッチする
|
||||||
|
|
||||||
|
◆schedule時点で当該CPUのCPU_FLAGS_NEED_MIGRATEが活性化しているケース
|
||||||
|
CT_004: runqが空
|
||||||
|
⇒ idleにスイッチする
|
||||||
|
|
||||||
|
CT_005: runqに実行待ちのthreadが存在し、且つ、そのthreadが1度も実行状態になっていない
|
||||||
|
⇒ idleにスイッチする
|
||||||
|
|
||||||
|
CT_006: runqに実行待ちのthreadが存在し、且つ、そのthreadが実行状態になったことがある
|
||||||
|
⇒ idleにスイッチする
|
||||||
|
|
||||||
|
◆prevがidle以外で、statusがPS_EXITED以外:
|
||||||
|
CT_007: runqが空
|
||||||
|
⇒ idleにスイッチする
|
||||||
|
|
||||||
|
CT_008: runqに実行待ちのthreadが存在し、且つ、そのthreadが1度も実行状態になっていない
|
||||||
|
⇒ 非idleのthreadにスイッチする
|
||||||
|
|
||||||
|
CT_009: runqに実行待ちのthreadが存在し、且つ、そのthreadが実行状態になったことがある
|
||||||
|
⇒ 非idleのthreadにスイッチする
|
||||||
|
|
||||||
|
◆prevがidle以外で、statusがPS_EXITED:
|
||||||
|
CT_010: runqが空
|
||||||
|
⇒ idleにスイッチする
|
||||||
|
|
||||||
|
CT_011: runqに実行待ちのthreadが存在し、且つ、そのthreadが1度も実行状態になっていない
|
||||||
|
⇒ idleにスイッチする
|
||||||
|
|
||||||
|
CT_012: runqに実行待ちのthreadが存在し、且つ、そのthreadが実行状態になったことがある
|
||||||
|
⇒ idleにスイッチする
|
||||||
|
|
||||||
|
(3) 実行結果ログ
|
||||||
|
result.logファイル内に実行時のログを記載する。
|
||||||
|
|
||||||
|
実行に利用したIHK/McKernelは、IA版における下記の版数相当の
|
||||||
|
arm64版移植IHK/McKernelである。
|
||||||
|
|
||||||
|
IHK
|
||||||
|
commit d6fcbee8cb91f9ec4b49f97c918e696ac0335aaf
|
||||||
|
Author: Shiratori, Takehiro <fj0300es@aa.jp.fujitsu.com>
|
||||||
|
Date: Tue Oct 16 16:25:33 2018 +0900
|
||||||
|
|
||||||
|
McKernel
|
||||||
|
commit 6f9fef2b13447c74c36d15cf5ebd186f8395ccca
|
||||||
|
Author: Ken Sato <ken.sato.ty@hitachi-solutions.com>
|
||||||
|
Date: Tue Sep 25 10:05:41 2018 +0900
|
||||||
|
|
||||||
|
(4) 備考
|
||||||
|
特になし。
|
||||||
|
|
||||||
|
以上。
|
||||||
41
test/mng_mod/issues/1029/arm64/go_test.c
Normal file
41
test/mng_mod/issues/1029/arm64/go_test.c
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define DEF_LOOPS 10
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
pid_t pid[256];
|
||||||
|
int result, i, j;
|
||||||
|
int loops = DEF_LOOPS;
|
||||||
|
char *_argv[3];
|
||||||
|
|
||||||
|
if (argc > 1) {
|
||||||
|
loops = atoi(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < loops && (pid[i] = fork()) > 0; i++);
|
||||||
|
|
||||||
|
if (i == loops) { // parent
|
||||||
|
for (i = 0; i < loops; i++) {
|
||||||
|
printf("go_test parent pid=%d\n", getpid());
|
||||||
|
waitpid(pid[i], NULL, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pid[i] == 0) {
|
||||||
|
printf("go_test child pid=%d\n", getpid());
|
||||||
|
_argv[0] = "./sched_test";
|
||||||
|
_argv[1] = "4";
|
||||||
|
_argv[2] = NULL;
|
||||||
|
execve(_argv[0], _argv, NULL);
|
||||||
|
|
||||||
|
perror("execve");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
perror("Error fork()");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
165
test/mng_mod/issues/1029/arm64/patch/1029.patch
Normal file
165
test/mng_mod/issues/1029/arm64/patch/1029.patch
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
diff --git a/kernel/include/process.h b/kernel/include/process.h
|
||||||
|
index 2007abf..45232f0 100644
|
||||||
|
--- a/kernel/include/process.h
|
||||||
|
+++ b/kernel/include/process.h
|
||||||
|
@@ -723,6 +723,9 @@ struct thread {
|
||||||
|
// for performance counter
|
||||||
|
unsigned long pmc_alloc_map;
|
||||||
|
unsigned long extra_reg_alloc_map;
|
||||||
|
+
|
||||||
|
+// TestCode for #1029
|
||||||
|
+int started;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define VM_RANGE_CACHE_SIZE 4
|
||||||
|
diff --git a/kernel/process.c b/kernel/process.c
|
||||||
|
index 83a94fa..79fa37b 100644
|
||||||
|
--- a/kernel/process.c
|
||||||
|
+++ b/kernel/process.c
|
||||||
|
@@ -3255,12 +3255,16 @@ out_schedule:
|
||||||
|
schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
+// TestCode for #1029
|
||||||
|
+int cases[13] = {0};
|
||||||
|
void schedule(void)
|
||||||
|
{
|
||||||
|
struct cpu_local_var *v;
|
||||||
|
struct thread *next, *prev, *thread, *tmp = NULL;
|
||||||
|
int switch_ctx = 0;
|
||||||
|
struct thread *last;
|
||||||
|
+// TestCode for #1029
|
||||||
|
+int runq_cnt = 0, case_num = 0, not_started = 0;
|
||||||
|
|
||||||
|
if (cpu_local_var(no_preempt)) {
|
||||||
|
kprintf("%s: WARNING can't schedule() while no preemption, cnt: %d\n",
|
||||||
|
@@ -3289,6 +3293,70 @@ void schedule(void)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+// TestCode for #1029
|
||||||
|
+// flag for thread is started or not
|
||||||
|
+if (prev) {
|
||||||
|
+ prev->started = 1;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+// check runq
|
||||||
|
+runq_cnt = 0;
|
||||||
|
+not_started = 0;
|
||||||
|
+list_for_each_entry_safe(thread, tmp, &(v->runq), sched_list) {
|
||||||
|
+ if (thread->tid == prev->tid) {
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /* Skip not-schedulable */
|
||||||
|
+ if (thread->status == PS_RUNNING ||
|
||||||
|
+ (thread->status == PS_INTERRUPTIBLE && hassigpending(thread))) {
|
||||||
|
+ } else {
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ runq_cnt++;
|
||||||
|
+ if (!thread->started) {
|
||||||
|
+ not_started = 1;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+// test cases
|
||||||
|
+if (!prev) {
|
||||||
|
+ case_num = 0;
|
||||||
|
+} else if (prev == &cpu_local_var(idle)) { // prev is idle
|
||||||
|
+ if (runq_cnt == 0) { // runq is empty
|
||||||
|
+ case_num = 1;
|
||||||
|
+ } else if (not_started) { // runq has other NOT_started thread
|
||||||
|
+ case_num = 2;
|
||||||
|
+ } else { // runq has other started thread
|
||||||
|
+ case_num = 3;
|
||||||
|
+ }
|
||||||
|
+} else if (v->flags & CPU_FLAG_NEED_MIGRATE) { // prev is NEED_MIGRATE
|
||||||
|
+ if (runq_cnt == 0) { // runq is empty
|
||||||
|
+ case_num = 4;
|
||||||
|
+ } else if (not_started) { // runq has other NOT_started thread
|
||||||
|
+ case_num = 5;
|
||||||
|
+ } else { // runq has other started thread
|
||||||
|
+ case_num = 6;
|
||||||
|
+ }
|
||||||
|
+} else if (prev->status != PS_EXITED) { // prev is NOT EXITED
|
||||||
|
+ if (runq_cnt == 0) { // runq is empty
|
||||||
|
+ case_num = 7;
|
||||||
|
+ } else if (not_started) { // runq has other NOT_started thread
|
||||||
|
+ case_num = 8;
|
||||||
|
+ } else { // runq has other started thread
|
||||||
|
+ case_num = 9;
|
||||||
|
+ }
|
||||||
|
+} else { // prev is NOT EXITED
|
||||||
|
+ if (runq_cnt == 0) { // runq is empty
|
||||||
|
+ case_num = 10;
|
||||||
|
+ } else if (not_started) { // runq has other NOT_started thread
|
||||||
|
+ case_num = 11;
|
||||||
|
+ } else { // runq has other started thread
|
||||||
|
+ case_num = 12;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
/* Switch to idle() when prev is PS_EXITED since it always reaches release_thread()
|
||||||
|
because it always resumes from just after ihk_mc_switch_context() call. See #1029 */
|
||||||
|
if (v->flags & CPU_FLAG_NEED_MIGRATE ||
|
||||||
|
@@ -3324,6 +3392,58 @@ void schedule(void)
|
||||||
|
|
||||||
|
set_timer(1);
|
||||||
|
|
||||||
|
+// TestCode for #1029
|
||||||
|
+switch (case_num) {
|
||||||
|
+case 0:
|
||||||
|
+ break;
|
||||||
|
+case 1:
|
||||||
|
+ if (!cases[case_num]) {
|
||||||
|
+ if (!switch_ctx) {
|
||||||
|
+ kprintf("[OK] CT_%03d not_switch\n", case_num);
|
||||||
|
+ } else {
|
||||||
|
+ kprintf("[NG] CT_%03d %d -> %d\n", case_num, prev->tid, next->tid);
|
||||||
|
+ }
|
||||||
|
+ cases[case_num] = 1;
|
||||||
|
+ }
|
||||||
|
+ break;
|
||||||
|
+case 4:
|
||||||
|
+case 5:
|
||||||
|
+case 6:
|
||||||
|
+case 7:
|
||||||
|
+case 10:
|
||||||
|
+case 11:
|
||||||
|
+case 12:
|
||||||
|
+ // switch to idle
|
||||||
|
+ if (!cases[case_num]) {
|
||||||
|
+ if (next == &cpu_local_var(idle)) {
|
||||||
|
+ kprintf("[OK] CT_%03d %d => %d\n", case_num,
|
||||||
|
+ prev ? prev->tid : 0, next ? next->tid : 0);
|
||||||
|
+ } else {
|
||||||
|
+ kprintf("[NG] CT_%03d %d => %d\n", case_num, prev->tid, next->tid);
|
||||||
|
+ }
|
||||||
|
+ cases[case_num] = 1;
|
||||||
|
+ }
|
||||||
|
+ break;
|
||||||
|
+case 2:
|
||||||
|
+case 3:
|
||||||
|
+case 8:
|
||||||
|
+case 9:
|
||||||
|
+ // switch to NOT idle
|
||||||
|
+ if (!cases[case_num]) {
|
||||||
|
+ if (next != &cpu_local_var(idle)) {
|
||||||
|
+ kprintf("[OK] CT_%03d %d => %d\n", case_num,
|
||||||
|
+ prev ? prev->tid : 0, next ? next->tid : 0);
|
||||||
|
+ } else {
|
||||||
|
+ kprintf("[NG] CT_%03d\n", case_num);
|
||||||
|
+ }
|
||||||
|
+ cases[case_num] = 1;
|
||||||
|
+ }
|
||||||
|
+ break;
|
||||||
|
+
|
||||||
|
+default:
|
||||||
|
+ kprintf("unexpected case_num\n");
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
if (switch_ctx) {
|
||||||
|
dkprintf("schedule: %d => %d \n",
|
||||||
|
prev ? prev->tid : 0, next ? next->tid : 0);
|
||||||
46
test/mng_mod/issues/1029/arm64/result.log
Normal file
46
test/mng_mod/issues/1029/arm64/result.log
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
gcc -o sched_test sched_test.c
|
||||||
|
gcc -o go_test go_test.c
|
||||||
|
./run.sh
|
||||||
|
mcstop+release.sh ... done
|
||||||
|
mcreboot.sh -c 4-15 -m 4G@0,4G@1,4G@2,4G@3 -O ... done
|
||||||
|
SUCCESS kmsg
|
||||||
|
SUCCESS clear_kmsg
|
||||||
|
timeout -s 9 60 /opt/ppos//bin/mcexec /opt/stress_test/src/killit -np 16 -nosignal /opt/stress_test/src/signalonfutex 1> /tmp/dtest.log 2>&1
|
||||||
|
SUCCESS mcexec
|
||||||
|
SUCCESS mcexec /opt/stress_test/src/killit -np 16 -nosignal /opt/stress_test/src/signalonfutex
|
||||||
|
SUCCESS kmsg
|
||||||
|
mck-mcexec.sh: WARNING: kmsg isn't empty
|
||||||
|
=== kmsg begins ====
|
||||||
|
[ 0]: [OK] CT_002 0 => 2514
|
||||||
|
[ 1]: [OK] CT_007 2529 => 1
|
||||||
|
[ 7]: [OK] CT_010 2603 => 7
|
||||||
|
[ 1]: [OK] CT_003 1 => 2529
|
||||||
|
[ 0]: [OK] CT_008 2514 => 2758
|
||||||
|
[ 1]: [OK] CT_009 2785 => 2700
|
||||||
|
[ 1]: [OK] CT_012 2831 => 1
|
||||||
|
[ 0]: fileobj_free(ffff800042231040 ffff8003c42cdb00): free failed. -32
|
||||||
|
[ 0]: fileobj_free(ffff8000422d0020 ffff8003c42cda80): free failed. -32
|
||||||
|
|
||||||
|
=== kmsg ends ====
|
||||||
|
SUCCESS ioctl 40000000 1
|
||||||
|
SUCCESS kmsg
|
||||||
|
SUCCESS 0 processes found
|
||||||
|
SUCCESS ioctl 40000000 2
|
||||||
|
SUCCESS kmsg
|
||||||
|
SUCCESS 0 threads found
|
||||||
|
SUCCESS mcexec not found
|
||||||
|
ISSUE01: OK
|
||||||
|
mcstop+release.sh ... done
|
||||||
|
mcreboot.sh -c 4-15 -m 4G@0,4G@1,4G@2,4G@3 -O ... done
|
||||||
|
[OK] CT_001 not_switch
|
||||||
|
[OK] CT_002 0 => 3216
|
||||||
|
[OK] CT_003 1 => 3231
|
||||||
|
[OK] CT_004 3245 => 2
|
||||||
|
[OK] CT_005 3530 => 1
|
||||||
|
[OK] CT_006 3361 => 1
|
||||||
|
[OK] CT_007 3216 => 0
|
||||||
|
[OK] CT_008 3231 => 3331
|
||||||
|
[OK] CT_009 3231 => 3245
|
||||||
|
[OK] CT_010 3440 => 1
|
||||||
|
[OK] CT_011 3362 => 1
|
||||||
|
[OK] CT_012 3361 => 1
|
||||||
22
test/mng_mod/issues/1029/arm64/run.sh
Executable file
22
test/mng_mod/issues/1029/arm64/run.sh
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
## run.sh COPYRIGHT FUJITSU LIMITED 2018 ##
|
||||||
|
|
||||||
|
USELTP=0
|
||||||
|
USEOSTEST=0
|
||||||
|
|
||||||
|
. ../../../../common.sh
|
||||||
|
|
||||||
|
STRESSBIN=
|
||||||
|
|
||||||
|
${STRESSBIN}/mck-mcexec.sh ${STRESSBIN}/killit -np 16 -nosignal ${STRESSBIN}/signalonfutex
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
echo "ISSUE01: OK"
|
||||||
|
else
|
||||||
|
echo "ISSUE01: NG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mcstop
|
||||||
|
mcreboot
|
||||||
|
|
||||||
|
${MCEXEC} ./go_test 10 > /dev/null
|
||||||
|
${IHKOSCTL} 0 kmsg | grep CT_ | cut -f 2 -d ":" | sort
|
||||||
75
test/mng_mod/issues/1029/arm64/sched_test.c
Normal file
75
test/mng_mod/issues/1029/arm64/sched_test.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sched.h>
|
||||||
|
|
||||||
|
#define DEF_LOOPS 10
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
pid_t pid[256];
|
||||||
|
cpu_set_t cpu_set;
|
||||||
|
int result, i, j;
|
||||||
|
int loops = DEF_LOOPS;
|
||||||
|
|
||||||
|
if (argc > 1) {
|
||||||
|
loops = atoi(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
CPU_ZERO(&cpu_set);
|
||||||
|
CPU_SET(1, &cpu_set);
|
||||||
|
|
||||||
|
result = sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set);
|
||||||
|
|
||||||
|
if (result != 0) {
|
||||||
|
perror("Error sched_setaffinity()");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < loops && (pid[i] = fork()) > 0; i++);
|
||||||
|
|
||||||
|
if (i == loops) { // parent
|
||||||
|
for (i = 0; i < loops; i++) {
|
||||||
|
printf("sched_test parent pid=%d\n", getpid());
|
||||||
|
waitpid(pid[i], NULL, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pid[i] == 0) {
|
||||||
|
printf("sched_test child pid=%d\n", getpid());
|
||||||
|
cpu_set_t child_set;
|
||||||
|
|
||||||
|
CPU_ZERO(&child_set);
|
||||||
|
CPU_SET(2, &child_set);
|
||||||
|
result = sched_setaffinity(0, sizeof(cpu_set_t), &child_set);
|
||||||
|
if (result != 0) {
|
||||||
|
perror("Error sched_setaffinity() on child");
|
||||||
|
}
|
||||||
|
|
||||||
|
result = sched_yield();
|
||||||
|
if (result != 0) {
|
||||||
|
perror("Error sched_yield()");
|
||||||
|
}
|
||||||
|
|
||||||
|
CPU_ZERO(&child_set);
|
||||||
|
CPU_SET(1, &child_set);
|
||||||
|
result = sched_setaffinity(0, sizeof(cpu_set_t), &child_set);
|
||||||
|
if (result != 0) {
|
||||||
|
perror("Error sched_setaffinity() on child");
|
||||||
|
}
|
||||||
|
|
||||||
|
result = sched_yield();
|
||||||
|
if (result != 0) {
|
||||||
|
perror("Error sched_yield()");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("child[%d] is done.\n", i);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
perror("Error fork()");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
printf("parent is done.\n");
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user