Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Practical Session 6 Multitasking vs. multithreading Threads Concurrency vs. Parallelism Java Threads Thread confinement Object/Class Immutability.
Threads, SMP, and Microkernels
Process management Information maintained by OS for process management  process context  process control block OS virtualization of CPU for each process.
Tutorial 4 Scheduling. Why do we need scheduling? To manage processes according to requirements of a system, like: –User responsiveness or –Throughput.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Ade Azurat, Advanced Programming 2004 (Based on LYS Stefanus’s slides) Advanced Programming 2004, Based on LYS Stefanus’s slides Slide 2.1 Multithreading.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Multithreading The objectives of this chapter are:
Programming R-T Abstractions TSW November 2009 Anders P. Ravn Aalborg University.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
The Implementation of Dynamic Priority Assignment on CVM Threading System Insik Shin Real-time Systems Group University of Pennsylvania.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Clocks & Asynchronous Events. Overview Clocks  API  Implementation Asynchronous Events  API  Single Threaded Model  Multi-Threaded Model  Code Walkthrough.
Multithreading.
Intro to Java The Java Virtual Machine. What is the JVM  a software emulation of a hypothetical computing machine that runs Java bytecodes (Java compiler.
COP 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Advanced Operating Systems CIS 720 Lecture 1. Instructor Dr. Gurdip Singh – 234 Nichols Hall –
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Fast Multi-Threading on Shared Memory Multi-Processors Joseph Cordina B.Sc. Computer Science and Physics Year IV.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Chapter 1 Process and Thread. 1.2 process The address space of a program – Text – Code – Stack – Heap A set of registers – PC – SP Other resources – Files.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Dr. R R DOCSIT, Dr BAMU. Basic Java : Multi Threading 2 Objectives of This Session State what is Multithreading. Describe the life cycle of Thread.
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
Operating Systems Scheduling. Bursts of CPU usage alternate with periods of waiting for I/O. (a) A CPU-bound process. (b) An I/O-bound process. Scheduling.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
1 Introduction to Threads Computers can perform many tasks concurrently – download a file, print a file, receive , etc. Sequential languages such.
Java Thread and Memory Model
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Department of Computer Science and Software Engineering
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Parallel Processing (CS526) Spring 2012(Week 8).  Shared Memory Architecture  Shared Memory Programming & PLs  Java Threads  Preparing the Environment.
Programming Languages and Paradigms Activation Records in Java.
Thread Scheduling and Dispatching Maung Aung Han Marc E. Loy Jihua Zhong CIS 642: Seminar in Real-time Systems Instructor: Professor Insup Lee.
Lecture 20 Threads Richard Gesick. Threads Makes use of multiple processors/cores if available Share memory within the program (as opposed to processes.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
1 Lecture 6 “Nachos” n nachos overview n directory structure n nachos emulated machine n nachos OS n nachos scheduler n nachos threads.
Multithreading The objectives of this chapter are: To understand the purpose of multithreading To describe Java's multithreading mechanism.
CIS NET Applications1 Chapter 8 – Multithreading and Concurrency Management.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Multithreading The objectives of this chapter are:
OPERATING SYSTEM CONCEPT AND PRACTISE
Processes and threads.
Process concept.
Introduction to the CVM and the Timesys RI
Java Multithreading.
Threads and Scheduling
Lecture Topics: 11/1 Processes Process Management
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
G53SRP: Real Time Threads in RTSJ (part I)
Lecture 7 Processes and Threads.
Nachos Threads and Concurrency
Threads & multithreading
Multithreading.
PROCESS MANAGEMENT Information maintained by OS for process management
Lecture Topics: 11/1 General Operating System Concepts Processes
Lecture 4- Threads, SMP, and Microkernels
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Threads and Concurrency
- When you approach operating system concepts there might be several confusing terms that may look similar but in fact refer to different concepts:  multiprogramming, multiprocessing, multitasking,
Multithreading in java.
Multithreading The objectives of this chapter are:
Presentation transcript:

Real-time Java Threads Insik Shin Real-time Systems Group University 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_INFO long priority current priority THREAD VMthread pointer to internal THREAD INSTANCE target pointer to the object whose ‘run’

THREAD in KVM  THREAD THREAD nextAliveThread active thread queue THREAD nextThread all thread queue JAVATHREAD javathread java-level thread informatin STACK stack execution stack BYTE* ipStore program counter FRAME fpStore frame pointer Cell* spStore execution stack pointer MONITOR monitor thread monitor queue THREAD nextAlarmThread thread timer queue Long wakeupTime[2] wakeup time Void (*wakeupCall)(THREAD) callback when timer expires state thread state

THREAD & JAVATHREAD in KVM  THREAD & JAVATHREAD JAVATHREAD javathreadTHREAD 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 Registers CurrentThread 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 & KVM Thread.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 JAVATHREAD SchedulingParameter sp ReleaseParameter rp MemoryParameter mp ProcessingGroupParameter pgp Scheduler sch COMMON_OBJECT_INFO long priority THREAD VMthread INSTANCE target

THREAD in KVM THREAD nextAliveThread active thread queue THREAD nextThread all thread queue JAVATHREAD javathread java-level thread informatin STACK stack execution stack BYTE* ipStore program counter FRAME fpStore frame pointer Cell* spStore execution stack pointer MONITOR monitor thread monitor queue THREAD nextAlarmThread thread timer queue Long wakeupTime[2] wakeup time Void (*wakeupCall)(THREAD) callback when timer expires state thread state

THREAD in KVM THREAD nextAliveThread active thread queue THREAD nextThread all thread queue JAVATHREAD javathread java-level thread informatin STACK stack execution stack BYTE* ipStore program counter FRAME fpStore frame pointer Cell* spStore execution stack pointer MONITOR monitor thread monitor queue THREAD nextAlarmThread thread timer queue Long wakeupTime[2] wakeup time Void (*wakeupCall)(THREAD) callback when timer expires state thread state bool_t realtime

Thread Structures for Real-time Java realtime = falserealtime = 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-robin scheduler 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 CurrentThread THREAD RunnableThreads

Java API & KVM Thread.java public native void start(); KVM : nativeCore.c Java_java_lang_Thread_start() { … startThread(); … } KVM : thread.c startThread() { … }

Real-time Java API & KVM RealtimeThread.java public native void start(); KVM : nativeCore.c Java_javax_rtgedition_RealtimeThread_start() { … startThread(); … } KVM : thread.c startThread() { … }