Slide Show Title

Download Report

Transcript Slide Show Title

Using POSIX to Maximize Code
Portability in Embedded Systems
Peter van der Veen
QNX Software Systems
POSIX®
/pahz-icks/

POSIX, pronounced pahz-icks as in positive, not poh-six, or
other variations

POSIX is a registered trademark of the IEEE
►
Licensed through certification

An acronym for Portable Operating System Interface

POSIX is a family of standards developed by the Portable
Applications Standards Committee (PASC) of the IEEE
Computer Society
All content copyright QNX Software Systems.
2
What Is POSIX?


It’s about portability
►
Both programmers and application source code
►
Portability of the OS kernel itself and/or application binary code are
not objectives
POSIX is a set of books specifying APIs
►
It is neither a piece of code
►
Nor an operating system
►
It is a rich, proven API
All content copyright QNX Software Systems.
3
What Is an API?

Application Program Interface
 Written contract between system developers and application
developers
 It is not a piece of code, it is a piece of paper defining what the
two sets of developers are guaranteed to receive and are in
turn responsible for providing
All content copyright QNX Software Systems.
4
The Need for Standard APIs
Standardized functionality

Standardized “square” peg in
the round hole
► “Bits where change is not
interesting”
► Where the benefits of
commonality outweigh the
value of differences
► Where we can achieve
economies of scale, including
interoperability
Private product specific functionality
All content copyright QNX Software Systems.
5
Scalable API Portability
POSIX APIs
support
portability
across a
range of
devices
All content copyright QNX Software Systems.
6
POSIX 1003.1, 2004 Edition

Approved December 6, 2001

2004 edition incorporates two Technical Corrigenda

Developed by the Austin Group (see later)

Supersedes all the major POSIX standards except 1003.13 (realtime
profiles) and 1003.5 (Ada bindings)

A combined system interfaces (including all realtime POSIX) and
utilities specification as a single 4000 page standard

The core of DoD’s mandated Joint Technical Architecture (JTA) OS
Services, replacing 1003.1-1996 and its amendments

Technically identical to the Base specifications of the Single UNIX
Specification and ISO 9945
All content copyright QNX Software Systems.
7
Definitions
Commands
Rationale
System Interfaces
The Common Base
Specifications
IEEE Std. 1003.1,
ISO/IEC 9945
The Open Group Base
Specifications Issue 6
The Core of the Single UNIX
Specification v3
All content copyright QNX Software Systems.
8
The Austin Group

The Austin Group combines the formal standards process of
the IEEE and ISO, with the industry standards of The Open
Group and the community at large

Electronic participation

Participation in the group is free
(www.opengroup.org/austin)

The final standard in HTML is available for free download
from the World Wide Web (www.unix.org/version3)
All content copyright QNX Software Systems.
9
POSIX 1003.13-2003

Approved December 10, 2003

A set of POSIX realtime profiles

Supersedes POSIX.13-1998 updated to address
►
1003.1-2001 (which includes all of realtime POSIX)
►
Profiles of all 1003.5-series standards (Ada bindings to POSIX)
►
Field experience with 1003.13-1998
►
Input from the Linux, realtime and/or embedded Linux, and
traditional RTOS communities
All content copyright QNX Software Systems.
10
POSIX 1003.13 Profiles
POSIX-RT
Profile 54
POSIX-RT
Profile 53
Profile 54: 1003.1-2003 Base Multiprocess, Threads, File System
Units of Functionality
Units of Functionality
Units of Functionality
Units of Functionality
-
POSIX-RT
Profile 52
Profile 53:
Multi-process, Threads; File System
Profile 52:
Single Process, Threads, File System
POSIX-RT
Profile 51
Profile 51:
Single Process, Threads; No File System
Portable Operating System Interface
IEEE Standard POSIX 1003.13
Allows Portability of Applications
All content copyright QNX Software Systems.
11
POSIX 1003.13

POSIX 1003.13 is a subprofile standard of 1003.1-2001
►
It allows diverse realtime operating systems “clothed” with a
runtime library to comply
►
This standardizes the application-to-RTOS API, allowing
considerable application code portability between different RTOS
offerings, which portability had not been possible in the past
►
RTOS+wrapper offerings can be compared and competed directly
►
There are currently four profiles
All content copyright QNX Software Systems.
12
Using POSIX in Embedded
Systems
Today’s Environment

Typical company has multiple product lines
and limited interoperability

Vendors are locked into a single OS solution or

Applications need to be recoded or ported to deploy on
different product lines
►
Takes time, adds costs
►
Increases delays to product deployment
Application
Application
Application
Product Line A
OS 1
Product Line B
OS 2
Product Line C
OS 3
Recoding
All content copyright QNX Software Systems.
14
Standards & Portability

Standard APIs preserve software investments

Portability lowers time, cost, and risk associated
with integrating new technology across product lines

Common standard maximizes application base for
development environments

Developers familiar with standard become productive
more quickly
All content copyright QNX Software Systems.
15
POSIX Compliance
OS Comparison
POSIX Feature Matrix
PSE 51
PSE 52
PSE 53
PSE 54
POSIX
1003.1-2001
1003.1-90 Processes
-
-



1003.1-90 Pipes
-
-



1003.1-90 Files & Directories
-

-


1003.1-90 Users & Groups
-
-
-


1003.1b-93 Memory Protection
-
-



1003.1b-93 Hi Res. Clocks &
Timers





1003.1b-93 Realtime Signals





1003.1b-93 Semaphores





1003.1b-93 Shared Memory





1003.1b-93 IPC Message
Passing





Feature
Check for Advanced Realtime
All content copyright QNX Software Systems.
17
POSIX Feature Matrix
PSE 51
PSE 52
PSE 53
PSE 54
POSIX
1003.1-2001
1003.1c-95 Threads





1003.1c-95 Thread
Safe Functions





1003.1c-95 Thread
Attribute Stack Address





1003.1c-95 Thread
Attribute Stack Size





1003.1c-95 Thread
Process Shared
-
-



1003.1c-95 Thread
Priority Scheduling





1003.1c-95 Thread
Priority Inheritance





1003.1c-95 Thread
Priority Protection





POSIX2_SW_DEV
-
-
-


Feature
All content copyright QNX Software Systems.
18
POSIX Profiles – OS Compliance
POSIX Standard
QNX Neutrino
Linux
RTOS x
Specification Base
1003.1-2001
1003.1-1996*
PSE 51/PSE 52
Realtime (.1b)



Realtime Threads (.1c)


-
1003.1d-1999 Additional
Realtime

-
-

-
-
Configure,
GCC, perl, …
Configure,
GCC, perl, …
-
(Sporadic server scheduling,
execution timers, …)
1003.1j-200x Advanced
Realtime
(Barriers, spin-locks, …)
Best practices
(development)
* Newer versions of Linux kernel moving toward conformance with 2001 specification.
All content copyright QNX Software Systems.
19
Linux-POSIX (Base) Portability

Application portability between Linux and POSIX Base (2003)
can be easily accomplished
►

Both Linux and new POSIX specification share large POSIX feature
set
Linux developers can retain programming model
and existing APIs while porting applications to
POSIX, including embedded systems
Bottom line:

Porting applications between Linux and POSIX Base
implementations is relatively simple

Standard POSIX APIs are key
All content copyright QNX Software Systems.
20
POSIX Summary

Standard interface increases software portability for all
embedded systems

Some markets, such as military, moving toward using
POSIX as their base specification

OS compliance/conformance a matter of degree

►
Many RTOS offerings conform to PSE 51 or PSE 52, against the
1003.1-1996 specification
►
QNX Neutrino provides compliance with 1003.1-2004
►
Linux moving toward 2001.3-2004 with latest versions
Migration of legacy RTOS code to POSIX RTOS
increases software portability
All content copyright QNX Software Systems.
21
Examples
Migration, portability in the presence of unspecified
behavior, etc.
Unspecified/Implementation
Specific Behavior

Task at-hand requires knowledge of unspecified behavior or
of implementation-defined behavior
►
For best performance
► To enable feature that is difficult to achieve with mandated
interfaces

Codify
►
Best practices
► Information about different implementations

Conditional compilation
►
Appropriate macro definitions
► Appropriate configuration
 E.g. Autoconf
 May include “discovery”
All content copyright QNX Software Systems.
23
Application Porting Example –
Lynx Text Browser
Untar the source:
Go to the source directory.
Make a host directory:
Go to the host directory.
tar xz lynx2.8.4.tar.gz
cd lynx2-8-4
mkdir x86-pc-nto-qnx
cd x86-pc-nto-qnx
Make.
../configure
make
Install the browser:
make install
Configure the source:
Install.
All content copyright QNX Software Systems.
24
Unspecified Behavior – Directory
Scanning (disk usage – du)
while (entry = readdir(dirp)) {
struct stat stat;
char path[PATH_MAX+1];
strcpy(path, pathname);
strcat(path, entry->d_name);
stat(path, &stat);
if (S_ISDIR(stat.st_mode))
usage += du(path);
#ifdef HAVE_SYMLINKS
/* May be determined by Autoconf! */
else if (S_ISLNK) {
lstat(path, &stat);
if (S_ISDIR(stat.st_mode)) {
char linkpath[PATH_MAX+1];
int chars;
if ((chars = readlink(path, linkpath, PATH_MAX)) > 0) {
linkpath[chars] = '\0';
usage += du(linkpath);
}
}
#endif
}
}
All content copyright QNX Software Systems.
25
Summary

POSIX is a scalable standard with many different levels of
compliance and many optional feature sets

Program by contract

►
Define a profile(s) that matches your needs and stick to it
►
Select vendor implementations that match your profile
Follow best practices whenever possible
►
Avoid unspecified or undefined behavior
►
Code conditionally to abstract over differences
All content copyright QNX Software Systems.
26
Thank You!

Learn more about POSIX Certification:
http://posixcertified.ieee.org

Download the QNX white paper “Using POSIX in Embedded
Systems: http://www.qnx.com/info/posix_whitepaper

Get your free 30-day evaluation copy of QNX Momentics
development suite v6.3: http://www.qnx.com/products/eval/
Questions?
All content copyright QNX Software Systems.
27