real-time java threads insik shin real-time systems group university of pennsylvania
Post on 20-Dec-2015
216 views
TRANSCRIPT
Real-time Java Threads
Insik Shin
Real-time Systems GroupUniversity of Pennsylvania
KVM Threading System What kind of information for a thread?
data structures How to maintain such information? How to support multi-threading?
scheduling policy context switching mechanism
Additional features for supporting threads? timer, monitor
Thread Information pointer to ‘run’ method priority virtual machine execution stack virtual machine registers (ip, fp, sp) timer & monitor state (active | wait) thread queues: active, wait, timer, monitor
Thread Information in KVM pointer to ‘run’ method priority
virtual machine execution stack virtual machine registers (ip, fp, sp) timer & monitor state (active | wait) thread queues: active, wait, timer, monitor
Java-level thread information
implementation-level thread information
Data Structures in KVM Two separate structures
THREAD internal (VM-level) structure information for implementing threading system
JAVATHREAD information defined in Java class ‘Thread.java’
Advantages JAVATHREAD needs to be subclassed Implementation independent of the Java language
for portability & extension reasons
JAVATHREAD in KVM JAVATHREAD
COMMON_OBJECT_INFOlong priority current priority THREAD VMthread pointer to internal THREADINSTANCE target pointer to the object whose ‘run’
THREAD in KVM THREAD
THREAD nextAliveThread active thread queueTHREAD nextThread all thread queueJAVATHREAD javathread java-level thread informatinSTACK stack execution stackBYTE* ipStore program counterFRAME fpStore frame pointerCell* spStore execution stack pointer
MONITOR monitor thread monitor queueTHREAD nextAlarmThread thread timer queueLong wakeupTime[2] wakeup timeVoid (*wakeupCall)(THREAD) callback when timer expires state thread state
THREAD & JAVATHREAD in KVM THREAD & JAVATHREAD
JAVATHREAD javathread
THREAD VMthread
Thread Queues in KVM
nextThread
nextAliveThread
monitor
nextAlarmThread
Thread Queues in KVM
nextThread
nextAliveThread
monitor
nextAlarmThread
CurrentThread RunnableThreads
Thread Context Switching in KVM
IP, FP, SP
VM RegistersCurrentThread
1. store execution environment
Thread Context Switching in KVM
IP, FP, SP
VM Registers
1. store execution environment
CurrentThread
2. Pick a thread from ‘RunnableThreads’ queue
Thread Context Switching in KVM
IP, FP, SP
VM Registers
1. store execution environment
CurrentThread
2. Pick a thread from ‘RunnableThreads’ queue
3. Put the old thread into ‘RunnableThreads’ queue
Thread Context Switching in KVM
IP, FP, SP
VM Registers
1. store execution environment
CurrentThread
2. Pick a thread from ‘RunnableThreads’ queue
4. load execution environment
3. Put the old thread into ‘RunnableThreads’ queue
Thread Scheduling in KVM Scheduling policy
Round-robin with the following quantum: quantum = 500 * priority
Scheduler data structure THREAD CurrentThread THREAD RunnableThreads
Thread operations in KVM Constructors & deconstructors
BuildThread, DismantleThread Thread activation & deactivation
initThreadBehavior, startThread, stopThread, suspendThread, resumeThread, removeFirstRunnableThread
Multitasking operations switchThread storeExecutionEnvironment, loadExecutionEnvironment
Timer, Queue, Monitor operations
Java API & KVMThread.java public native void start();
KVM : nativeCore.c
Java_java_lang_Thread_start() {… startThread();…
}
KVM : thread.c
startThread() { …}
Real-time Thread Scheduling What kind of features to be added?
Real-time thread information Real-time (priority) scheduler Synchronization (monitor) Timer, Asynchrony
How to extend KVM for real-time threads?
Real-time Thread Information Scheduling parameters
priority, importance Release parameters
cost, deadline, overrunHandler, missHandler start, period, minInterarrival
Memory parameters maxMemoryArea, maxImmortal
Processing group parameters Scheduler
Data Structures in KVM Two separate structures
THREAD internal (VM-level) structure information for implementing threading system
JAVATHREAD information defined in Java class ‘Thread.java’
Advantages JAVATHREAD needs to be subclassed Implementation independent of the Java language
for portability & extension reasons
Real-time Thread Structure Two separate structures
THREAD internal (VM-level) structure information for implementing threading system
JAVATHREAD information defined in Java class ‘Thread.java’
RT_JAVATHREAD information defined in Java class ‘RealtimeThread.java’
Real-time Thread Structure RT_JAVATHREAD extends JAVATHREAD
JAVATHREADSchedulingParameter spReleaseParameter rpMemoryParameter mpProcessingGroupParameter pgpScheduler sch
COMMON_OBJECT_INFOlong priorityTHREAD VMthread INSTANCE target
THREAD in KVM
THREAD nextAliveThread active thread queueTHREAD nextThread all thread queueJAVATHREAD javathread java-level thread informatinSTACK stack execution stackBYTE* ipStore program counterFRAME fpStore frame pointerCell* spStore execution stack pointer
MONITOR monitor thread monitor queueTHREAD nextAlarmThread thread timer queueLong wakeupTime[2] wakeup timeVoid (*wakeupCall)(THREAD) callback when timer expires state thread state
THREAD in KVM
THREAD nextAliveThread active thread queueTHREAD nextThread all thread queueJAVATHREAD javathread java-level thread informatinSTACK stack execution stackBYTE* ipStore program counterFRAME fpStore frame pointerCell* spStore execution stack pointer
MONITOR monitor thread monitor queueTHREAD nextAlarmThread thread timer queueLong wakeupTime[2] wakeup timeVoid (*wakeupCall)(THREAD) callback when timer expires state thread state
bool_t realtime
Thread Structures for Real-time Java
realtime = false realtime = true
non-realtime thread realtime thread
Real-time Thread Supports We can use the same mechanisms as in
KVM for the followings: thread queue managements context switching
Real-time Thread Scheduler RTSJ suggests PriorityScheduler for RTJ Each RT thread can be associated with any
scheduler multiple schedulers at the same time Two-level scheduling
Two-level Scheduling
Meta-level scheduler
Priority scheduler
Round-robinscheduler
EDF scheduler
Thread Scheduling in KVM Scheduling policy
Round-robin with the following quantum: quantum = 500 * priority
Scheduler data structure THREAD CurrentThread THREAD RunnableThreads
Real-time Thread Scheduling Scheduling policy
Meta-level scheduling policy (priority) Scheduler data structure
SCHEDULER
THREAD CurrentThreadTHREAD RunnableThreads
Java API & KVMThread.java public native void start();
KVM : nativeCore.c
Java_java_lang_Thread_start() {… startThread();…
}
KVM : thread.c
startThread() { …}
Real-time Java API & KVMRealtimeThread.java public native void start();
KVM : nativeCore.c
Java_javax_rtgedition_RealtimeThread_start() {… startThread();…
}
KVM : thread.c
startThread() { …}