bigsys-gnu / mvcc-os

KhronOS, a scalable operating systems based on sv6 (MIT) with MV-RLU (multi-version concurrency control mechanism)
Other
1 stars 0 forks source link

MV-RLU Benchmark Bugs #51

Closed MadPlayer closed 2 years ago

MadPlayer commented 3 years ago

kbench 실행시 문제가 2가지 있습니다.

test thread 종료문제

stop이라는 공유 변수를 변경해도 종료되지 않는 문제가 있습니다.
gdb 실행시 mvrlu_try_lock을 지속적으로 실패하는 문제가 발견되었습니다.

qp_thread 종료문제

qp_thread는 mvrlu_finish 호출시에 종료하는데 test thread들이 실행중임에도 먼저 종료되는 문제가 발생했습니다. wait 함수의 비정상작동 혹은 부적절한 사용때문인 것으로 보입니다. 현재 wait에는 pid에 -1을 넘겨주고 있는데 이는 wait을 호출한 process의 자식들을 기다리게 합니다. 문제는 threadpin 함수로 생성한 process가 자식으로 등록되어 있는지의 여부입니다.

Process 문제 확인

scalefs에서는 여러 keyboard interrupt handling을 지원해 주고 있습니다.
kernel/console.cc에 이러한 정의들을 볼 수 있습니다.
제가 thread의 비정상 종료를 확인한 방법은 아래와 같습니다.

  1. make qemu로 scalefs를 실행
  2. kbench를 5초 정도로 여유롭게 실행 (kbench -d 5000)
  3. 실행 후 1초 정도 후에 키보드 Ctrl + p를 입력
    이 키입력은 현재 실행되고 있는 모든 Process들에 대한 정보를 출력합니다.
  4. 실행 후 5초 정도 지나면 kbench가 종료되지 않고 block됩니다. 이때 다시 키보드 Ctrl + p를 입력하면 test thread들은 실행 중이고 qp_thread만 죽은 것을 확인할 수 있습니다.

실제 실험 결과

Writing blocks ... done! (0 seconds)
xapic: Initializing LAPIC (CPU 1)
xapic: Initializing LAPIC (CPU 2)
xapic: Initializing LAPIC (CPU 3)
init complete at Tue Aug 17  8:05:18 2021
$ kbench -d 1 5000
kernel lavel benchmark start
-t #threads   : 4
-i Initial size : 32
-b Buckets      : 2
-d Duration     : 5000
-u Update rate  : 200
-r Range        : 64
-Set type     : hash-list
Run Kernel Level Benchmark
initialize 32 nodes...done
Main thread ID: 15
Creating 4 threads...
Thread created 0xffffff0016ffe600(c:1, s:2)

Thread created 0xffffff0016ffe200(c:2, s:2)
thread 18 Start
thread 19 Start
thread 17 Start

Thread created 0xffffff0017091a80(c:3, s:2)

Thread created 0xffffff0017091680(c:1, s:2)
 done!

10  init         sleep   0  22632989601
 ffffffffc010e220
 ffffffffc0133fce
 ffffffffc013c9f3
 ffffffffc01582ac
 ffffffffc0159723
 403ea1

14  sh           sleep   0  50972044468
 ffffffffc010e220
 ffffffffc0133fce
 ffffffffc013c9f3
 ffffffffc01582ac
 ffffffffc0159723
 40e874

15  kbench       sleep   0  51080225240
 ffffffffc010e220
 ffffffffc014c736
 ffffffffc014be98
 ffffffffc013c9f3
 ffffffffc01582ac
 ffffffffc0159723
 403e75

16  qp_thread    sleep   0  52655984649
 ffffffffc010e220
 ffffffffc018729f
 ffffffffc0185a43
 ffffffffc01345a7
 ffffffffc01597af

17  test_thread   run     1  51084182284

18  test_thread   run     2  51087610796

19  test_thread   run     3  51089471790

20  test_thread   runble  1  0
join 4 threads...
 done!

10  init         sleep   0  22632989601
 ffffffffc010e220
 ffffffffc0133fce
 ffffffffc013c9f3
 ffffffffc01582ac
 ffffffffc0159723
 403ea1

14  sh           sleep   0  50972044468
 ffffffffc010e220
 ffffffffc0133fce
 ffffffffc013c9f3
 ffffffffc01582ac
 ffffffffc0159723
 40e874

15  kbench       sleep   0  66928689829
 ffffffffc010e220
 ffffffffc01871c6
 ffffffffc0185f37
 ffffffffc014c796
 ffffffffc014be98
 ffffffffc013c9f3
 ffffffffc01582ac
 ffffffffc0159723
 403e75

17  test_thread   run     1  51084182284

18  test_thread   run     2  51087610796

19  test_thread   run     3  51089471790

20  test_thread   runble  1  0
QEMU: Terminated

여기서 추가적인 문제점을 확인할 수 있습니다.
test thread들 중 하나가 runnable 상태로 있는 것을 볼 수 있습니다.

위에서 실험한 코드는 https://github.com/MadPlayer/mvcc-os/tree/fix_port 에 있습니다.

MadPlayer commented 3 years ago

Test Thread 종료문제

mvrlu_try_lock을 무한히 반복하는 것은 아래의 코드를 제대로 구현하지 않았기 때문이었습니다.

int port_addr_in_log_region(void *addr__)
{
  unsigned long long addr = (unsigned long long)addr__;
  return addr >= KVMALLOC && addr < KVMALLOCEND;
}

Process 문제 확인

kernel에서 생성하는 process들은 따로 부모 자식 관계가 없이 생성되므로 wait을 사용할 수 없습니다. 단순히 오랜 시간을 기다리는 것으로 해결했습니다.

  stop = 1;
  cprintf("join %d threads...\n", nb_threads);

  sleep_usec(nsectime(), 4000); // wait for threads

  cprintf(" done!\n");