Operating Systems Principles

Slides:



Advertisements
Ähnliche Präsentationen
E-Solutions mySchoeller.com for Felix Schoeller Imaging
Advertisements

Themenportal Europäische Geschichte / Web portal European History
Service Discovery in Home Environments
H - A - M - L - E - IC T Teachers Acting Patterns while Teaching with New Media in the Subjects German, Mathematics and Computer Science Prof. S. Blömeke,
DNS-Resolver-Mechanismus
Kapitel 9: Graphdurchlauf
R. Zankl – Ch. Oelschlegel – M. Schüler – M. Karg – H. Obermayer R. Gottanka – F. Rösch – P. Keidler – A. Spangler th Expert Meeting Business.
Herzlich Willkommen zum Informations-Forum: SAP Interoperabilität
The difference between kein and nicht.
Multi electron atoms Atoms with Z>1 contain >1 electron. This changes the atomic structure considerably because in addition to the electron-nucleus interaction,
Embedded & Real-time Operating Systems
Fakultät für informatik informatik 12 technische universität dortmund Optimizations Peter Marwedel TU Dortmund Informatik 12 Germany 2009/01/17 Graphics:
Fakultät für informatik informatik 12 technische universität dortmund Mapping of Applications to Platforms Peter Marwedel TU Dortmund, Informatik 12 Germany.
Fakultät für informatik informatik 12 technische universität dortmund Universität Dortmund Middleware Peter Marwedel TU Dortmund, Informatik 12 Germany.
Fakultät für informatik informatik 12 technische universität dortmund Specifications Peter Marwedel TU Dortmund, Informatik 12 Graphics: © Alexandra Nolte,
Peter Marwedel TU Dortmund, Informatik 12
Fakultät für informatik informatik 12 technische universität dortmund Hardware/Software Partitioning Peter Marwedel Informatik 12 TU Dortmund Germany Chapter.
Regional Support in the context of LCG/EGEE
1 Named Pipes alias FIFO Haben einen Eintrag im Dateisystem und sind somit durch Zugriffsrechte identifizierbar Ermöglichen die Kommunikation zwischen.
Wozu die Autokorrelationsfunktion?
Hier wird Wissen Wirklichkeit Computer Architecture – Part 10 – page 1 of 31 – Prof. Dr. Uwe Brinkschulte, Prof. Dr. Klaus Waldschmidt Part 10 Thread and.
Operating Systems Principles
Thomas Herrmann Software - Ergonomie bei interaktiven Medien Step 6: Ein/ Ausgabe Instrumente (Device-based controls) Trackball. Joystick.
Munz – IT/TG - Lörrach. Goals of this intensive lecture To learn: To learn: –What does it means programming in Java ? –What is JAVA good/bad for ? –Which.
CCNA Exploration Network Fundamentals
Comparative Adjectives. The term comparison of adjectives is used when two or more persons or things have the same quality (height, size, color, any characteristic)
Die Hausaufgaben: Machen Sie Ü. 7 auf S. 29
Adjektive Endungen von Frau Templeton.
Laurie Clarcq The purpose of language, used in communication, is to create a picture in the mind and/or the heart of another.
Institut AIFB, Universität Karlsruhe (TH) Forschungsuniversität gegründet 1825 Towards Automatic Composition of Processes based on Semantic.
Montag, den Hausaufgabe für Dienstag den Keine Hausaufgabe!!! Film: 8:00 oder 9:30 Guten Tag!
Sanjay Patil Standards Architect – SAP AG April 2008
| DC-IAP/SVC3 | © Bosch Rexroth Pneumatics GmbH This document, as well as the data, specifications and other information set forth in.
BAS5SE | Fachhochschule Hagenberg | Daniel Khan | S SPR5 MVC Plugin Development SPR6P.
3rd Review, Vienna, 16th of April 1999 SIT-MOON ESPRIT Project Nr Siemens AG Österreich Robotiker Technische Universität Wien Politecnico di Milano.
The free XML Editor for Windows COOKTOP Semistrukturierte Daten 1 Vortrag Semistrukturierte Daten 1 COOKTOP The free XML-Editor for Windows
Übungsaufgabe, Permissions, ACLs
3/28/2017 8:11 PM Visual Studio Tools für Office { Rapid Application Development für Office } Jens Häupel Platform Strategy Manager Microsoft Deutschland.
Department of Computer Science Homepage HTML Preprocessor Perl Database Revision Control System © 1998, Leonhard Jaschke, Institut für Wissenschaftliches.
Algorithm Engineering Parallele Algorithmen Stefan Edelkamp.
Algorithm Engineering Parallele Algorithmen Stefan Edelkamp.
Real Time Operating System
Fusszeilentext – bitte in (Ansicht – Master – Folienmaster, 1. Folie oben) individuell ändern! Danach wieder zurück in Normalansicht gehen! 1 OTR Shearography.
Fach: Informatik Thema: Maschinendatenerfassung Klasse: 2AHWILJahrgang: 2013/2014 Höhere Technische Bundes-Lehr-und Versuchsanstalt St.Pölten Fachbereich.
Kölner Karneval By Logan Mack
Staatsballett Berlin Ein Verbesserungskonzept für den Social- Media Auftritt Your picture here.
Ein Projekt des Technischen Jugendfreizeit- und Bildungsvereins (tjfbv) e.V. kommunizieren.de Blended Learning for people with disabilities.
Perspektiven – “Perspectives” – Herr Wallace
Travelling Salesman Problem (TSP)
Nouns. What is a noun O A noun is the name of a person, O place, O animal O or thing.
Design Patterns Ein Muster (pattern) ist eine Idee, die sich in einem praktischen Kontext als nützlich erwiesen hat und dies auch in anderen sein wird.
External Labels – The rules For all external labels the following rules apply (external labels are all labels which are not inside of a shape) - all labels.
Negation is when you dont have or dont do something.
Adjectiv Endungen Lite: Adjective following articles and pre-ceeding nouns. Colors and Clothes.
Wind Energy in Germany 2004 Ralf Christmann, BMU Joachim Kutscher, PTJ
AVL-Trees (according to Adelson-Velskii & Landis, 1962) In normal search trees, the complexity of find, insert and delete operations in search.
KIT – die Kooperation von Forschungszentrum Karlsruhe GmbH und Universität Karlsruhe (TH) Vorlesung Knowledge Discovery - Institut AIFB Tempus fugit Towards.
Ambient Intelligence WS 10/11
Separable Verbs Turn to page R22 in your German One Book R22 is in the back of the book There are examples at the top of the page.
1 Intern | ST-IN/PRM-EU | | © Robert Bosch GmbH Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung,
Launch ON Global.vi System ID object name classname Services to suscribe Observer Control Ref vi-path Service name Step 1 : Objects register to the Global.vi´s,
1 Stevens Direct Scaling Methods and the Uniqueness Problem: Empirical Evaluation of an Axiom fundamental to Interval Scale Level.
Selectivity in the German Mobility Panel Tobias Kuhnimhof Institute for Transport Studies, University of Karlsruhe Paris, May 20th, 2005.
Technische Universität München 1 CADUI' June FUNDP Namur G B I The FUSE-System: an Integrated User Interface Design Environment Frank Lonczewski.
TUM in CrossGrid Role and Contribution Fakultät für Informatik der Technischen Universität München Informatik X: Rechnertechnik und Rechnerorganisation.
Instrumente und Unterhaltung End of Unit Assessment.
Adjective Declension in German
Alois Schütte Advanced System Programming 2 Interprozeßkommunikation  2.1 JVM Ablaufumgebung  2.2 Java Native Interface (JNI)  Verwendung von.
Netzwerk - Programmierung
CSL211 Computer Architecture
 Präsentation transkript:

Operating Systems Principles Lab 3 – User Level Threads

Drittes Praktikum 2 Wochen Zeit zum Lösen der Aufgaben In dieser Woche Aufgabenstellung auf der SAR Website Abgabe über GOYA Abgabefrist: 10.06.2013 In dieser Woche Erläutern der Aufgabenstellung Nächste Woche Zeit zur Bearbeitung Nächste Veranstaltung 10./11.06.2013

Lab 3 explained User Level Thread Library Unterbrechung nicht an beliebiger Stelle: nicht-präemptiv Threads geben die CPU freiwillig auf oder warten auf das Eintreffen eines Ereignisses Threads und Scheduler teilen sich einen Prozess typedef void (*ult_func)(); extern int ult_spawn(ult_func f); extern void ult_yield(); extern void ult_exit(int status); extern int ult_waitpid(int tid, int *status); extern int ult_read(int fd, void *buf, int count); extern void ult_init(ult_func f);

Lab 3 explained Erzeugen eines Threads: ult_spawn /* type of function executed by thread */ typedef void (*ult_func)(); /* spawn a new thread, return its ID */ extern int ult_spawn(ult_func f); Erzeugen eines Threads: ult_spawn Eintrittspunkt f mit Prototyp ult_func Erzeugen der internen Strukturen: TCB, etc. Einordnen in die Run-Queue An dieser Stelle kein Scheduling Rückgabe der Thread-ID

Lab 3 explained Freiwillige Aufgabe des Prozessors /* yield the CPU to another thread */ extern void ult_yield(); Freiwillige Aufgabe des Prozessors Aktivieren des Schedulers Auswahl eines anderen, lauffähigen Threads Aktivieren des ausgewählten Threads

Lab 3 explained Beenden eines User-Threads /* current thread exits */ extern void ult_exit(int status); Beenden eines User-Threads Der aufrufende Thread wird zum Zombie Speichern des Exit-Status Exit-Status kann mit ult_waitpid abgefragt werden

Lab 3 explained Warten auf Threads /* thread waits for termination of another thread */ /* returns 0 for success, -1 for failure */ /* exit-status of terminated thread is obtained */ extern int ult_waitpid(int tid, int *status); Warten auf Threads Warten auf Beendigung des Threads mit ID tid Rufender Thread wird erst nach der Beendigung fortgesetzt Liefert den Exit-Status zurück Ist der Thread schon beendet, dann kehrt der Aufruf sofort zurück Andernfalls muss der Scheduler regelmäßig überprüfen, ob der Thread beendet wurde

Lab 3 explained Lesen aus Dateien /* read from file, block the thread if no data available */ extern int ult_read(int fd, void *buf, int count); Lesen aus Dateien Wrapper-Funktion für die Funktion read der Unix-API Problem: read ist ein Systemruf und kann im Kernel blockieren Damit blockiert der Prozess und alle User-Threads Lösung: Vorheriges Überprüfen, ob ausreichend Daten vorhanden sind Wenn nicht, blockiert der rufende Thread und gibt die CPU an einen Anderen ab Scheduler muss wieder regelmäßig überprüfen, ob der rufende Thread fortgesetzt werden kann Realisierung: Non-blocking IO

Lab 3 explained Initialisieren der Thread-Bibliothek /* start scheduling and spawn a thread running function f */ extern void ult_init(ult_func f); Initialisieren der Thread-Bibliothek Muss als erste Funktion der Bibliothek vor allen anderen gerufen werden Anlegen der Datenstrukturen für Scheduler und Thread-Verwaltung Erzeugen eines initialen Threads Warten auf Beendigung des initialen Threads

ULT Example void threadA() {…} void threadB() {…} void myInit() {…} int  main() {     printf("starting myInit\n"); fflush(stdout);     ult_init(myInit);     exit(0); }

ULT Example void myInit() { int cpid[2], i, status;     cpid[0] = ult_spawn(threadA);     cpid[1] = ult_spawn(threadB);     for (i = 0; i < 2; i++) {         if (ult_waitpid(cpid[i], &status) == -1) {             ult_exit(-1);         }     }     ult_exit(0); }

Lab 3 explained Test-Programm Thread A kopiert aus /dev/random nach /dev/null Führt diverse Statistiken mit Anzahl an bereits kopierten Bytes Zeit seit Start des Threads Durchsatz … Thread B stellt eine Shell bereit Auslesen der Statistiken des Threads A (Kommando stats) Beenden des Programms (Kommando exit)

/* type of function executed by thread */ typedef void (*ult_func)(); /* spawn a new thread, return its ID */ extern int ult_spawn(ult_func f); /* yield the CPU to another thread */ extern void ult_yield(); /* current thread exits */ extern void ult_exit(int status); /* thread waits for termination of another thread */ /* returns 0 for success, -1 for failure */ /* exit-status of terminated thread is obtained */ extern int ult_waitpid(int tid, int *status); /* read from file, block the thread if no data available */ extern int ult_read(int fd, void *buf, int count); /* start scheduling and spawn a thread running function f */ extern void ult_init(ult_func f);

Processes vs. Threads Process Threads Independent memory space Protected access to other resources Large context Heavy weight: (expensive to create and switch between) Threads Shared memory space with other threads Shared resources (i.e. unprotected) Small context Light weight: (efficient to create and switch between)

OS Support for Processes / Threads MSDOS Embedded OS UNIX Solaris, Windows NT

Allocation of Process State Thread Control Block contains a register image, thread priority and thread state information

Thread State/Control Information Thread Control Block (TCB) Each thread has its own execution state A thread has a small amount of local data Local stack All threads share the global address space of their process Data written by one thread is seen by all others What problems are caused by threads sharing local data?? Thread Queues Separate queues for running, waiting, zombie, etc.

Big Picture

Big Picture

Big Picture

User Level Threads (ULT) User Threads Processor

User Level Threads (ULTs) ULTs are implemented in an application library Creation, termination, and communication Scheduling and context switching The kernel is not aware of the threads The kernel only schedules the process Thread library divides time amongst threads

Advantages of ULTs Switching between threads is fast Requires a mode switch not a process switch Thread library can run on any platform Portable, ULTs are implemented in software Application specific scheduling Each process can use a different scheduling policy (I.e. round robin vs. FIFO)

Disadvantages of ULTs A blocking system call in one thread will block all threads The OS does not know that there is more than one thread of execution A multi-threaded application cannot take advantage of multi-processing No system level priority Priority of threads is based on the priority of the process

Kernel Level Threads (KLTs) User Threads Kernel Threads Processor

Kernel Level Threads All thread management is done by kernel No thread library Each user thread is mapped to a thread in kernel space Kernel maintains context information for the process and the threads Switching between threads requires the kernel Scheduling on a thread basis

Advantages/Disadvantages of KLTs Multiple threads can be scheduled on multiple processors Blocking of one thread does not block others Kernel routines can be multithreaded Disadvantages Thread switching must be done by kernel More overhead switching between threads

Combined ULT and KLTs User Threads Kernel Threads Processors

Combined ULT/KLT Approaches Combines the advantages of both approaches Thread creation done in user space Most scheduling and communication done in user space KLTs run in parallel and do not block other KLTs User can adjust the number of KLTs Mapping between UL/KL threads can be: 1 to 1 (same as kernel threads alone) M to N (some user threads share)

Slow System Calls Ones that can “block” forever i.e., a read from a pipe, terminal, or network device Write when … Open blocks Modem answers phone Network device FIFO for writing when no other process open for reading Reads/writes with mandatory record locks on files

Non-blocking I/O Calling open with the flag O_NONBLOCK sets nonblocking attribute for the file_descriptor returned fd = open(path, 0644 | O_CREAT | O_NONBLOCK); For a file_descriptor that is already open we can use fcntl to set it to nonblocking #include <fcntl.h> void set_fl(int fd, int flags) /* flags are file status flags to turn on */ { int val; if ((val = fcntl(fd, F_GETFL, 0)) < 0) err_sys("fcntl F_GETFL error"); val |= flags; /* turn on flags */ if (fcntl(fd, F_SETFL, val) < 0) err_sys("fcntl F_SETFL error"); }

Non-Blocking write #include <errno.h> #include <fcntl.h> char buf[500000]; int main(void) { int ntowrite, nwrite; char *ptr; ntowrite = read(STDIN_FILENO, buf, sizeof(buf)); fprintf(stderr, "read %d bytes\n", ntowrite); set_fl(STDOUT_FILENO, O_NONBLOCK); ptr = buf; while (ntowrite > 0) { errno = 0; nwrite = write(STDOUT_FILENO, ptr, ntowrite); printf("nwrite = %d, errno = %d\n", nwrite, errno); if (nwrite > 0) { ptr += nwrite; ntowrite -= nwrite; } clr_fl(STDOUT_FILENO, O_NONBLOCK); /* clear nonblocking */ exit(0);

Non-Blocking write

Non-local Jumps (1) void signalHandler( int arg ) {…} int main() {          stack_t stack;         stack.ss_flags = 0;          stack.ss_size = STACK;          stack.ss_sp = malloc(STACK);          sigaltstack( &stack, 0 );          struct sigaction sa;          sa.sa_handler = &signalHandler;          sa.sa_flags = SA_ONSTACK;          sigemptyset( &sa.sa_mask );          sigaction( SIGUSR1, &sa, 0 );          raise( SIGUSR1 ); ...          free( stack.ss_sp );          return 0; }

Non-local Jumps (1) jmp_buf child, parent; void threadFunction() { if ( setjmp( child ) ) {          longjmp( parent, 1 );     } longjmp( parent, 1 ); } void signalHandler( int arg ) {     if ( setjmp( child ) ){      threadFunction();     } } int main() { ...          raise( SIGUSR1 );          if ( setjmp( parent ) )          {              if ( setjmp( parent ) == 0 ) longjmp( child, 1 );          }          else longjmp( child, 1 );          return 0; } child child parent

Misc Useful functions: fnctl select open close setjmp longjmp The Single UNIX Specification, http://www.opengroup.org/onlinepubs/009695399/

Lab 2 - Besprechung Gesucht: eine einfache Shell Bereitstellen einer Kommandozeile und Ausführen eines Programms mit Kommandozeilenparametern Aktuelles Verzeichnis relativ zum Einstiegspunkt als Prompt Ausführen eines Programms im Hintergrund mit Rückgabe der PID Wechseln des Arbeitsverzeichnisses Warten auf Prozesse. Warten auf eine Teilmenge der aktuell ausgeführten Hintergrundprozesse pid1 ... pidN Das "wait" soll mit Ctrl+C unterbrechbar sein Bei Terminierung: möglichst viel Informationen über den Endzustand des Prozesses ausgeben Grund des Terminierens, Rückgabewert, …