-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
kernel-rs/src/proc.rs
Outdated
@@ -205,6 +205,8 @@ pub enum Procstate { | |||
USED, | |||
} | |||
|
|||
pub type Pid = i32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PID
가 더 좋을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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/trap.rs
Outdated
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기서 state
에 접근할 때 lock을 걸지 않던 것은 xv6의 버그일까요? 아니면 lock을 걸 필요가 없는 이유가 있는 것일까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
procdump
와 kerneltrap
을 제외하고는 다 lock을 걸고 state
에 접근하는데, state
를 읽고, proc
의 값을 수정하는 작업이 lock을 걸고 있는 동안 진행됩니다.
kerneltrap()
의 경우에는 yield
에서 lock을 걸기 때문에 state
를 읽을 때는 lock없이 읽은 것 같습니다. RUNNING
상태를 바꾸는 곳이 yield
이고, yield
에서 sched
가 실행되면 context switch가 일어나기 때문에 lock을 걸지 않은 것이 아닐까요?
다시 생각해보니
- 기존 코드처럼 unsafe하게
state
를 읽거나 proc_yield
를ProcGuard
의 함수로 만드는 것이 좋을 것 같습니다.
There was a problem hiding this comment.
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
의 메서드로 두는 것이 더 나아 보여서요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 반영했습니다 :)
pid
를ProcInfo
에 그대로 유지dump
를 unsafe하게 수정
kernel-rs/src/trap.rs
Outdated
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
procdump
와 kerneltrap
을 제외하고는 다 lock을 걸고 state
에 접근하는데, state
를 읽고, proc
의 값을 수정하는 작업이 lock을 걸고 있는 동안 진행됩니다.
kerneltrap()
의 경우에는 yield
에서 lock을 걸기 때문에 state
를 읽을 때는 lock없이 읽은 것 같습니다. RUNNING
상태를 바꾸는 곳이 yield
이고, yield
에서 sched
가 실행되면 context switch가 일어나기 때문에 lock을 걸지 않은 것이 아닐까요?
다시 생각해보니
- 기존 코드처럼 unsafe하게
state
를 읽거나 proc_yield
를ProcGuard
의 함수로 만드는 것이 좋을 것 같습니다.
kernel-rs/src/trap.rs
Outdated
@@ -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 { |
There was a problem hiding this comment.
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
의 메서드로 두는 것이 더 나아 보여서요.
d6e9b25
to
fc0685e
Compare
There was a problem hiding this 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으로 변경했습니다.
bors r+ |
Build succeeded: |
주요 변경점입니다.
Pid
를 만들었습니다.ProcInfo
에 있던pid
를AtomicI32
로 바꾸고Proc
으로 옮겼습니다.Proc
에서 unsafe하게 정의되어 있던state()
함수를ProcGuard
로 옮겼습니다.ProcGuard
없이state
에 접근하지 않습니다.