Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Closes #346, #363] Atomicpid, proc id type, state in procguard #401

Merged
8 commits merged into from
Feb 9, 2021

Conversation

anemoneflower
Copy link
Collaborator

주요 변경점입니다.

  • prod id type인 Pid를 만들었습니다.
  • ProcInfo에 있던 pidAtomicI32로 바꾸고 Proc으로 옮겼습니다.
  • Proc에서 unsafe하게 정의되어 있던 state()함수를 ProcGuard로 옮겼습니다.
    • ProcGuard없이 state에 접근하지 않습니다.

@@ -205,6 +205,8 @@ pub enum Procstate {
USED,
}

pub type Pid = i32;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PID가 더 좋을까요?

kernel-rs/src/proc.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@coolofficials coolofficials left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fn allocpid(&self) -> i32 {

의 return type도 Pid가 되어야 할 것 같습니다.

guard.deref_mut_info().pid = self.allocpid();

처럼 procinfo의 pid를 업데이트 해주기 때문에...

@coolofficials coolofficials self-requested a review February 5, 2021 07:30
Copy link
Collaborator

@coolofficials coolofficials left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

kernel-rs/src/proc.rs Outdated Show resolved Hide resolved
kernel-rs/src/proc.rs Show resolved Hide resolved
kernel-rs/src/proc.rs Outdated Show resolved Hide resolved
kernel-rs/src/proc.rs Outdated Show resolved Hide resolved
@@ -184,7 +184,7 @@ pub unsafe fn kerneltrap() {
// Give up the CPU if this is a timer interrupt.
if which_dev == 2 {
if let Some(proc) = kernel().current_proc() {
if unsafe { proc.state() } == Procstate::RUNNING {
if proc.lock().state() == Procstate::RUNNING {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 state에 접근할 때 lock을 걸지 않던 것은 xv6의 버그일까요? 아니면 lock을 걸 필요가 없는 이유가 있는 것일까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

procdumpkerneltrap을 제외하고는 다 lock을 걸고 state에 접근하는데, state를 읽고, proc의 값을 수정하는 작업이 lock을 걸고 있는 동안 진행됩니다.

kerneltrap()의 경우에는 yield에서 lock을 걸기 때문에 state를 읽을 때는 lock없이 읽은 것 같습니다. RUNNING상태를 바꾸는 곳이 yield이고, yield에서 sched가 실행되면 context switch가 일어나기 때문에 lock을 걸지 않은 것이 아닐까요?

다시 생각해보니

  1. 기존 코드처럼 unsafe하게 state를 읽거나
  2. proc_yieldProcGuard의 함수로 만드는 것이 좋을 것 같습니다.

@Medowhill

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제 생각에는 1을 선택하고 이 unsafe가 안전한 이유를 주석으로 설명하는 것이 좋은 것 같습니다. proc_yield는 현재 실행 중인 프로세스만 할 수 있는 일이니 지금처럼 CurrentProc의 메서드로 두는 것이 더 나아 보여서요.

Copy link
Collaborator Author

@anemoneflower anemoneflower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 반영했습니다 :)

  • pidProcInfo에 그대로 유지
  • dump를 unsafe하게 수정

kernel-rs/src/proc.rs Show resolved Hide resolved
@@ -184,7 +184,7 @@ pub unsafe fn kerneltrap() {
// Give up the CPU if this is a timer interrupt.
if which_dev == 2 {
if let Some(proc) = kernel().current_proc() {
if unsafe { proc.state() } == Procstate::RUNNING {
if proc.lock().state() == Procstate::RUNNING {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

procdumpkerneltrap을 제외하고는 다 lock을 걸고 state에 접근하는데, state를 읽고, proc의 값을 수정하는 작업이 lock을 걸고 있는 동안 진행됩니다.

kerneltrap()의 경우에는 yield에서 lock을 걸기 때문에 state를 읽을 때는 lock없이 읽은 것 같습니다. RUNNING상태를 바꾸는 곳이 yield이고, yield에서 sched가 실행되면 context switch가 일어나기 때문에 lock을 걸지 않은 것이 아닐까요?

다시 생각해보니

  1. 기존 코드처럼 unsafe하게 state를 읽거나
  2. proc_yieldProcGuard의 함수로 만드는 것이 좋을 것 같습니다.

@Medowhill

@@ -184,7 +184,7 @@ pub unsafe fn kerneltrap() {
// Give up the CPU if this is a timer interrupt.
if which_dev == 2 {
if let Some(proc) = kernel().current_proc() {
if unsafe { proc.state() } == Procstate::RUNNING {
if proc.lock().state() == Procstate::RUNNING {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제 생각에는 1을 선택하고 이 unsafe가 안전한 이유를 주석으로 설명하는 것이 좋은 것 같습니다. proc_yield는 현재 실행 중인 프로세스만 할 수 있는 일이니 지금처럼 CurrentProc의 메서드로 두는 것이 더 나아 보여서요.

Copy link
Collaborator Author

@anemoneflower anemoneflower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코멘트 반영했습니다. :)

  • kerneltrap() 에서 ProcInfo와 state에 접근해야 하기 때문에 관련된 field를 public으로 변경했습니다.

@Medowhill
Copy link
Collaborator

bors r+

@ghost
Copy link

ghost commented Feb 9, 2021

Build succeeded:

@ghost ghost merged commit 1c9ed84 into kaist-cp:riscv Feb 9, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pid, state should be methods of ProcGuard Process ID type 만들기
3 participants