Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

32
Procesi in niti pri Windows NT

Transcript of Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Page 1: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Procesi in niti pri Windows NT

Page 2: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Procesi in niti

Page 3: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Primeri sistemskih niti

Page 4: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

4 konteksti izvajanja kode

Page 5: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Procesi in niti

• The process has a virtual memory address space, information (such as a base priority), and an affinity for one or more processors.

• Threads are the unit of execution scheduled by the kernel’s dispatcher.

• Each thread has its own state, including a priority, processor affinity, and accounting information.

• A thread can be one of six states: ready, standby, running, waiting, transition, and terminated.

Page 6: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

ProcesOpisniki virtualnega naslovnega prostora

.

.

.

Handle 1

Handle 2

Handle 3

Tabela ročic do objektov

Thread x

File y

Sekcija z

Objekti, z dovoljenim dostopom

...

Dostopni žeton

Page 7: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

• Virtual address space (including program global storage, heap storage, threads’ stacks)

processes cannot corrupt each other’s address space by mistake

• Working set (physical memory “owned” by the process)• Access token (includes security identifiers)• Handle table for Win32 kernel objects• These are common to all threads in the process, but separate

and protected between processes

Vsak proces ima svoje lastno…

Page 8: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Vsaka nit ima svoj …

• Stack (automatic storage, call frames, etc.)• Instance of a top-level function• Scheduling state (Wait, Ready, Running, etc.) and priority• Current access mode (user mode or kernel mode)• Saved CPU state if it isn’t Running• Access token (optional -- overrides process’s if present)

Page 9: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Kernel — razvrščanje

• The dispatcher uses a 32-level priority scheme to determine the order of thread execution. Priorities are divided into two classes.– The real-time class contains threads with priorities

ranging from 16 to 31.– The variable class contains threads having priorities

from 0 to 15.• Characteristics of XP’s priority strategy.

– Trends to give very good response times to interactive threads that are using the mouse and windows.

– Enables I/O-bound threads to keep the I/O devices busy.

– Complete-bound threads soak up the spare CPU cycles in the background.

Page 10: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Kernel — razvrščanje (nadaljevanje.)

• Scheduling can occur when a thread enters the ready or wait state, when a thread terminates, or when an application changes a thread’s priority or processor affinity.

• Real-time threads are given preferential access to the CPU; but XP does not guarantee that a real-time thread will start to execute within any particular time limit. (This is known as soft realtime.)

Page 11: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Programmer Interface — Process Management

• Process is started via the CreateProcess routine which loads any dynamic link libraries that are used by the process, and creates a primary thread.

• Additional threads can be created by the CreateThread function.

• Every dynamic link library or executable file that is loaded into the address space of a process is identified by an instance handle.

Page 12: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Process Management (Cont.)

• Scheduling in Win32 utilizes four priority classes:- IDLE_PRIORITY_CLASS (priority level 4)- NORMAL_PRIORITY_CLASS (level8 — typical for most

processes- HIGH_PRIORITY_CLASS (level 13)- REALTIME_PRIORITY_CLASS (level 24)

• To provide performance levels needed for interactive programs, XP has a special scheduling rule for processes in the NORMAL_PRIORITY_CLASS.– XP distinguishes between the foreground process that is

currently selected on the screen, and the background processes that are not currently selected.

– When a process moves into the foreground, XP increases the scheduling quantum by some factor, typically 3.

Page 13: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Process Management (Cont.)

• The kernel dynamically adjusts the priority of a thread depending on whether it is I/O-bound or CPU-bound.

• To synchronize the concurrent access to shared objects by threads, the kernel provides synchronization objects, such as semaphores and mutexes.– In addition, threads can synchronize by using the WaitForSingleObject or WaitForMultipleObjects functions.

– Another method of synchronization in the Win32 API is the critical section.

Page 14: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Process Management (Cont.)

• A fiber is user-mode code that gets scheduled according to a user-defined scheduling algorithm.– Only one fiber at a time is permitted to execute, even

on multiprocessor hardware.– XP includes fibers to facilitate the porting of legacy

UNIX applications that are written for a fiber execution model.

Page 15: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Processes and Threads (1)

Basic concepts used for CPU and resource management

Page 16: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Processes and Threads (2)

Relationship between jobs, processes, threads, and fibers

Page 17: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Razvrščanje pri Windows 2000

• • Windows 2000 schedules at the thread granularity.• • Priority-driven, preemptive scheduling system• – The highest-priority runnable thread always runs.• – Time-sliced, round-robin within a priority level.• • Windows 2000 uses 32 priority levels• – System level (0), Variable levels (1-15), Real-time levels (16-31)• • From Win32 point of view• – Processes are given a priority class upon creation:• » Idle, Below Normal, Normal, Above Normal, High, Real-time• » Changeable by Task Manager.• – The individual threads have a relative priority within the class:• » Idle, Lowest, Below-Normal, Normal, Above Normal, Highest,• Time-Critical

Page 18: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Prioritete jedra pri Windows 2000

Page 19: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Scheduling (1)

Mapping of Win32 priorities to Windows 2000 priorities

Page 20: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Scheduling (2)

Windows 2000 supports 32 priorities for threads

Page 21: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

An example of priority inversion

Scheduling (3)

Page 22: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Job, Process, Thread & Fiber Mgmt. API Calls

Some of Win32 calls for managing processes, threads and fibers

Page 23: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

CPE je zasedena – zakaj le?

Page 24: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Kateri proces teče?

Page 25: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Process explorer (Sysinternals)Process treeIf left justified, parent has exitedDisappears if you sort by any columnBring back with View->Show Process TreeAdditional details in process listIcon and description (from .EXE)User Name shows domain nameHighlight Own, Services ProcessesDifferences highightingGreen: new, Red: goneView->Update speed->Paused

Page 26: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

32 bitni virtualni naslovni prostor (x86)

Page 27: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Proces in uporaba pomnilnika: “delovna množica”

Page 28: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Zamenjava delovne množice

Page 29: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Podatki o pomnilniku za proces

Page 30: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Souporabljen pomnilnik

Page 31: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Vpogled v delovne množice

Page 32: Procesi in niti pri Windows NT. Procesi in niti Primeri sistemskih niti.

Življenje servisa