Sunteți pe pagina 1din 36

Case Study: MAC OS

Topics and Members:


Tanuj: Thread Management
Pranjal: Process Management
Anshul: Scheduling
Kartiki: Memory Management
Shruti: I/o Management
Pranay: Concurrency
Process Management
Process management is the process by which
operating systems manage processes, threads,
enable processes to share information, protect
process resources and allocate system
resources to processes that request them in a
safe manner
PROCESS MANAGER

The Process Manager provides a cooperative


multitasking environment
• Getting information about other processes
• Launching other application
• Termination an application
The Mac has it’s own Task Manager but it
goes by another name: Activity Monitor.
Activity Monitor functions in a very similar
way to how Task Manager does in Windows,
letting you easily view, manage, and end
tasks, applications, and any active processes
that are running in Mac OS X. If you’re
unfamiliar with Activity Monitor or task
management on the Mac in general, don’t
worry, because despite it’s immense power
and control, it’s not complicated to use.
PROCESS LIFE CYCLE

• Process is partially created


• Process is runnable
• Process is awaiting event
• Process is stopped (by signal or parent
process)
• Process is partially terminated (waiting for
parent process to collect status)
LIVE PROCESS MANAGEMENT

• With UNIX having many tasks running


simultaneously, through the years developers
have incorporated several command-line tools
that allow for live process management.
These include "top", "kill", "ps", "df", and
"vm_stats“.
THREAD MANAGEMENT
THREADS IN MAC
● Each process is made of one or more threads.
● Each thread represents single path of execution
through the application code.
● Every application starts with a single thread, which
runs the application main function.
● Each thread has its own execution stack and is
scheduled for runtime separately by the kernel.
● All threads in a single application share the same
virtual memory space and have the same access
rights as the process itself.
THREAD COSTS
Items Approximate cost Notes

Kernel Approximately 1 KB This memory is used to store the thread data structures and
data attributes, much of which is allocated as wired memory and
structure therefore cannot be paged to disk.
s

Stack 512 KB (secondary The minimum allowed stack size for secondary threads is 16 KB
space threads) and the stack size must be a multiple of 4 KB. The space for this
memory is set aside in your process space at thread creation time,
8 MB (OS X main thread) but the actual pages associated with that memory are not created
1 MB (iOS main thread) until they are needed.

Creation Approximately 90 This value reflects the time between the initial call to create the
time microseconds thread and the time at which the thread’s entry point routine began
executing. The figures were determined by analyzing the mean
and median values generated during thread creation on an Intel-
based iMac with a 2 GHz Core Duo processor and 1 GB of RAM
running OS X v10.5.
CREATING A THREAD
Creating low-level threads is relatively simple. In all
cases, you must have a function or method to act as
your thread’s main entry point and you must use one
of the available thread routines to start your thread.
The following sections show the basic creation
process for the more commonly used thread
technologies.
METHODS OF CREATING THREADS:
● Using NSThread
● Usinf Posix Thread
SCHEDULING
SCHEDULING
• CPU scheduling is a process which allows one
process to use the CPU while the execution of
another process is on hold(in waiting state).
• The aim of scheduling is to make the system
efficient, fast and user friendly.
• Criterias for best scheduling algorithms:
– CPU utilization
– Throughput
– Turn around time
– Waiting time
– Load average
– Response time
• Mac OS uses cooperative scheduling for
threads
– Controls multiple cooperative threads
– Provides preemptive scheduling for
multiprocessing tasks.
• The kernel schedules multiprocessing tasks
using a preemptive scheduling algorithm.
• Currently, Mac OS supports time-sharing and
fixed-priority scheduling.
• Mac OS supports the multilevel feedback queue
scheduling and round-robin (RR) scheduling
algorithm.

1. Round Robin(RR) Scheduling:


• It is the preemptive process scheduling
algorithm.
• Each process is provided a fix time to execute, it
is called a quantum.
• Context switching is used to save states of
preempted processes.
2. Multilevel Feedback-Queue Scheduling:
● A process can move between the various queues.
● Multilevel-feedback-queue scheduler defined by
the following parameters:
○ Number of queues
○ Scheduling algorithms for each queue
○ Method used to determine when to upgrade a
process
○ Method used to determine when to demote a
process
○ Method used to determine which queue a
process will enter when that process needs
service
EXAMPLE FOR MULTILEVEL FEEDBACK
QUEUE

Three queues:
• Q0 – RR with time
quantum 8 milliseconds
•Q1 – RR time quantum
16 milliseconds
•Q2 – FCFS
MEMORY MANAGEMENT
MEMORY MANAGEMENT

• Mac OS includes a fully-integrated virtual


memory system that you cannot turn off.
• It is always on, providing up to 4 gigabytes of
addressable space per 32-bit process and
approximately 18 exabytes of addressable
space for 64-bit processes.
MEMORY MANAGEMENT

• When the Macintosh Operating System starts up,


it divides the available RAM into two broad
sections.
• These include system partition and application
partition.
• System Partition-It reserves for itself a zone or
partition of memory known as the system
partition.
MEMORY MANAGEMENT
• System partition consists of:
1. The System Heap
2. The System Global Variables.
• The system heap- for exclusive use by the
Operating System.
• variables -to maintain different kinds of
information about the operating environment.
MEMORY MANAGEMENT
• Application Partition-When an application is
launched, the Operating System assigns it a
section of memory known as its application
partition.
• Application partition is divided into three
major parts:
1. The application stack.
2. The application heap.
3. The application global variables and A5
world.
I/O MANAGEMENT
• The I/O is a collection of system frameworks,
libraries, tools, and other resources for creating
device drivers in OS X.
• It is based on an object-oriented programming
model implemented in a restricted form of C++
that omits features unsuitable for use within a
multithreaded kernel.
• By modelling the hardware connected to an OS X
system and abstracting
• OS X is largely the product of two strains of
operating-system technology: Mac OS 9 (and its
predecessors) and BSD
Why current OS I/O model
was redesigned?
• First, neither the Mac OS 9 driver model nor the
FreeBSD driver model offers a set of features rich
enough to meet the needs of OS X.
• The OS X kernel handles
• memory protection,
• preemptive multitasking,
• multiprocessing, and other features not present in
previous versions of Mac OS.
• Although FreeBSD is capable of handling these
features, it does not offer other features expected in
a modern operating system such as:
• automatic configuration
• driver stacking
• power management
• dynamic loading of devices.
• Although FreeBSD is capable of handling these
features, it does not offer other features expected in
a modern operating system such as:
• automatic configuration
• driver stacking
• power management
• dynamic loading of devices.
• The I/O Kit’s designers settled on an object-oriented
programming model that abstracted the kernel capabilities
and hardware of an OS X system and provided a view of this
abstraction to the upper layers of the operating system.
• This abstraction implements behaviour common to all
types of device drivers .
• Eg:
Consider virtual memory. In Mac OS 9, virtual
memory is not a fundamental part of the operating
system; it is an option. Because of this, a developer
must always take virtual memory into account when
creating a driver, and this raises certain
complications. In contrast, virtual memory is an
inherent capability of OS X and cannot be turned off.
Because virtual memory is a fundamental and
assumed capability, knowledge of it is incorporated
into system software and driver writers do not have
to take it into account.
• The I/O Kit provides a model of system hardware in
an object-oriented framework. Each type of service
or device is represented by a C++ class; each
discrete service or device is represented by an
instance (object) of that class.
• There are three major conceptual elements of the
I/O Kit architecture:
• Families
• Drivers
• Nubs
• Families
• A family defines a collection of high-level abstractions
common to all devices of a particular category that
takes the form of C code and C++ classes.
• Drivers
• A driver is an I/O Kit object that manages a specific
device or bus, presenting a more abstract view of that
device to other parts of the system.
• Nubs
• A nub is an I/O Kit object that represents a point of
connection for a driver. It represents a controllable
entity such as a disk or a bus.
Concurrency Programming
in MAC OS
What is concurrency ?
Concurrency is the notion of multiple things happening at the
same time. With the proliferation of multicore CPUs and the
realization that the number of cores in each processor will
only increase, software developers need new ways to take
advantage of them. Although operating systems like Mac OS X
and iOS are capable of running multiple programs in parallel,
most of those programs run in the background and perform
tasks that require little continuous processor time. It is the
current foreground application that both captures the user’s
attention and keeps the computer busy. If an application has a
lot of work to do but keeps only a fraction of the available
cores occupied, those extra processing resources are wasted.
In the past, introducing concurrency to an
application required the creation of one or more
additional threads. Unfortunately, writing
threaded code is challenging. Threads are a low-
level tool that must be managed manually
Both Mac OS X and iOS adopt a more
asynchronous approach to the execution of
concurrent tasks than is traditionally found in
thread-based systems and applications. Rather
than creating threads directly, applications need
only define specific tasks and then let the system
perform them. By letting the system manage the
threads, applications gain a level of scalability
not possible with raw threads. Application
developers also gain a simpler and more efficient
programming model.
Before going further one should know these
terms
• The term thread is used to refer to a separate
path of execution for code. The underlying
implementation for threads in Mac OS X is based
on the POSIX threads API.

• The term process is used to refer to a running


executable, which can encompass multiple
threads.

• The term task is used to refer to the abstract


concept of work that needs to be performed.
Why one needs
concurrency in an OS?
In the early days of computing, the maximum amount
of work that a computer could perform was
determined by the clock speed of the CPU. But as
technology advanced and processor designs became
more compact, heat and other physical constraints
started to limit the maximum clock speeds of
processors. And so, chip manufacturers looked for
other ways to increase the total performance of their
chips. The solution they settled on was increasing the
number of processor cores on each chip. By increasing
the number of cores, a single chip could execute more
instructions per second without increasing the CPU
speed or changing the chip size or thermal
characteristics. The only problem was how to take
advantage of the extra cores.
Instead of relying on threads, Mac OS X and iOS take
an asynchronous design approach to solving the
concurrency problem. Asynchronous functions have
been present in operating systems for many years and
are often used to initiate tasks that might take a long
time.
But now, Mac OS X and iOS provide technologies to
allow you to perform any task asynchronously without
having to manage the threads yourself
The GCD
approach
One of the technologies for starting tasks
asynchronously is Grand Central Dispatch (GCD). This
technology takes the thread management code you
would normally write in your own applications and
movesthat code down to the system level. All you
have to do is define the tasks you want to execute
and add them to an appropriate dispatch queue.
GCD takes care of creating the needed threads and
of scheduling your tasks to run on those threads.
Because the thread management is now part of the
system, GCD provides a holistic approach to task
management and execution, providing better
efficiency than traditional threads.

S-ar putea să vă placă și