Improving Program Performance Function Visibility in z/TPF C++ Load Modules October 2, 2015 10/2/20151American Express Public.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Chapter 10 Linking and Loading. Separate assembly creates “.mob” files.
Key-word Driven Automation Framework Shiva Kumar Soumya Dalvi May 25, 2007.
Linking & Loading CS-502 Operating Systems
Chapter 3 Loaders and Linkers
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
Linkers and Loaders 1 Linkers & Loaders – A Programmers Perspective.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
 2005 Pearson Education, Inc. All rights reserved Introduction.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
VBA Modules, Functions, Variables, and Constants
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
FunctionsFunctions Systems Programming. Systems Programming: Functions 2 Functions   Simple Function Example   Function Prototype and Declaration.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Guide To UNIX Using Linux Third Edition
C++ fundamentals.
FunctionsFunctions Systems Programming Concepts. Functions   Simple Function Example   Function Prototype and Declaration   Math Library Functions.
OBJECT MODULE FORMATS. The object module format we have employed as an educational device is called OMF (relocatable object format). It’s one of the earliest.
Database System Development Lifecycle © Pearson Education Limited 1995, 2005.
Overview of the Database Development Process
Programming Languages and Paradigms Object-Oriented Programming.
Implementation Yaodong Bi. Introduction to Implementation Purposes of Implementation – Plan the system integrations required in each iteration – Distribute.
chap13 Chapter 13 Programming in the Large.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
More C++ Classes Systems Programming. C++ Classes  Preprocessor Wrapper  Time Class Case Study –Two versions (old and new)  Class Scope and Assessing.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
Chapter 6: User-Defined Functions
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
Chapter 13 : Symbol Management in Linking
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
CSc 453 Linking and Loading
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Chapter Goals Describe the application development process and the role of methodologies, models, and tools Compare and contrast programming language generations.
Chapter 10 Application Development
Lecture 3 Translation.
Appendix 1 - Packages Jim Fawcett copyright (c)
Linking & Loading.
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
Software Development with uMPS
CS-3013 Operating Systems C-term 2008
Introduction to C Programming Language
Scope (visibility) scope in C is simple:
Introduction to Classes and Objects
Computer Organization and Design Assembly & Compilation
The Assembly Language Level
Linking & Loading CS-502 Operating Systems
1-6 Midterm Review.
Linking & Loading CS-502 Operating Systems
Compiler vs linker The compiler translates one .c file into a .o file
Program Assembly.
The Three Attributes of an Identifier
Presentation transcript:

Improving Program Performance Function Visibility in z/TPF C++ Load Modules October 2, /2/20151American Express Public

10/2/20152 Improving Program Performance: Function Visibility Introduction The TPF operating system, the platform on which the Credit Authorization System (CAS) resides was updated in March 2010 to the most recent version of the IBM supported operating called z/TPF. This was an AIU required project that will enable future scalability, performance, and enhanced functionality to meet business growth and complexity. To mitigate the risk of migration to the new operating system, the new system was installed without taking advantage of any new capabilities offered by the upgrade, even those capabilities which would provide performance improvements. The z/TPF Post-Migration project is tasked to evaluate and implement some of the new capabilities of the new operating system and to use them to provide performance, quality, or maintainability improvements to the TPF platform and the mission critical CAS application. One requirement is to explore and implement C++ Shared Object (CSO) Function visibility to optimize program performance, which will be the focus of this presentation. American Express Public

10/2/20153 Improving Program Performance: Glossary VisibilityThe scope of a function exposed the application system. Global VisibilityFunctions with Global Visibility are callable from any function defined to the system. Local VisibilityFunctions with Local Visibility are callable only from within the Load Module or Shared Object in which they are defined. Static functionsStatic functions are only callable from within the object in which they are defined. Load ModuleA TPF Program Load Unit (see Shared Object) ObjectThe resulting output file from a C++ compiled source file. Shared ObjectSame as a Load Module, the output of 1 or more link edited object files in to a single Load Module. All z/TPF Load Modules are Shared Objects. Procedure Linkage Table (PLT)Contains the addresses of referenced functions outside of the calling shared object Global Offset Table (GOT)Holds absolute addresses in private data, enabling sharing of program text across multiple processes GCCGNU Compiler Collection. The C++ compiler used to create z/TPF C++ Shared Objects. Glossary American Express Public

10/2/20154 Improving Program Performance: Function Visibility What is Visibility? Visibility describes the scope in which a function is exposed to the application system. A function can be classified (in terms of visibility) as:  Global – Function can be called from any function in any load module.  Local – Function can only be called from any function within the load module in which it is defined.  Static – Function can only be called from any function within the object in which it is defined. Descriptions and example call diagrams of each type of function are presented on the following slides. American Express Public

10/2/20155 Improving Program Performance: Function Visibility Global Visibility Functions with Global Visibility may be called from any Load Module in the system. In TPF 4.1 they were called exported functions. Functions with Global Visibility are designed to perform a service that can be shared across many Load Modules. Software development time is saved as functions can be ‘reused’ as needed and if successfully implemented do not require detailed testing if imported into a load module. The concept of build / test once, re-use many times applies to functions with Global Visibility. Example of Global Function Call: Green Arrows represent valid function calls Red Arrows represent invalid function calls American Express Public

10/2/20156 Improving Program Performance: Function Visibility Local Visibility Functions with Local Visibility may be called from any object within the load module in which they are defined. Functions with Local Visibility perform a service that is shared across more than 1 object file of a single Load Module. The difference is a Local function is not callable outside of the Load Module in which it is defined. Functions with Local Visibility provide a common service that is “local” to the load module in which it is defined.. Example of Local Function Call: Green Arrows represent valid function calls Red Arrows represent invalid function calls American Express Public

10/2/20157 Improving Program Performance: Function Visibility Static Visibility Functions with Static Visibility may be called only from within the object file in which they are defined. Static functions provide the fastest call linkage between functions as they may only be called from within the object file in which they are defined. For static functions, the compiler will include the absolute address of the start of the function at the program location of a call to a static function. One use of static functions is to provide program structure / modularity to program design and implementation. Example of Static Function Call: Green Arrows represent valid function calls Red Arrows represent invalid function calls American Express Public

10/2/20158 Improving Program Performance: Visibility in TPF 4.1 TPF 4.1 Visibility and the OS/390 C/C++ Compiler Functions defined in Dynamic Link Libraries (DLLs) are made public or “visible” to programs outside of the module in which they are defined by:  Coding the name of the function within the parenthesis of a #pragma export () pre-processor directive.  The OS/390 C++ preprocessor would create an external reference entry to the export file of the load module.  Any load module that needs to call the exported function would need to include DS entry in its build script file to resolve the external reference, allowing for a complete build of the load module. In Dynamic Load Modules (DLMs), the only function with Global Visibility is the external entry point function, all others have Local Visibility. American Express Public

10/2/20159 Improving Program Performance: Visibility in z/TPF z/TPF Visibility and the GCC C/C++ Compiler In z/TPF all Load Modules are Shared Objects, and by default, the GCC constructs ALL functions with Global Visibility. The compiler and linker must be instructed to hide functions that do not require Global Visibility. This is accomplished using 1 of the following methods. Single Entry Point Shared Object: This is the z/TPF equivalent to a DLM. The program entry point is identified in the load module’s make file using the APP_ENTRY := ENTRYNAME entry. To insure only the entry point is visible, the APP_EXPORT := ENTRY line is coded in the makefile. Including this entry will inform the GCC to build all functions with Local Visibility, except for the specified entry point function. Functions can be specified with Static Visibility using the method described below (provided it meets the requirements for static visibility). Multiple Entry Point Shared Object Functions with Local Visibility: This is equivalent to a non-static Local function that is NOT called from outside of the shared object in which it is defined. This type of function is only called from within the Load Module that contains the object. To “hide’ these types of functions from outside of the load module, the code the GCC attribute __attribute__((visibility("hidden"))). Using this method, the function is visible only from within the load module in which it is defined. Single or Multiple Entry Point Shared Object Functions with Static Visibility: Functions that are called only from within the object in which they are defined should be declared as static functions. This type of function provides the most efficient type of linkage, thus resulting in the most optimal function call performance. American Express Public

10/2/ Improving Program Performance: Design Considerations Program Design Considerations The decision of what type of visibility that should be applied to a function is dependent upon the use of the function in the application system. The following process flow is provided to assist with program design American Express Public

10/2/ Improving Program Performance: Programming Examples Functions with Global Visibility As stated, the GCC and Linker will build all functions with Global Visibility unless instructed to do otherwise. So there is no special attributes or declarations required for a function to have Global Visibility. However, functions should only have Global Visibility when they are callable from outside of the Load Module in which they are defined. This type of function is useful for library functions that serve a role that can be shared by many load modules in the application or enterprise. A WWCAS Example would be the Date Conversion functions made visible from Load Module DZ71 void myGlobalFunction(void); void myGlobalFunction(void) { printf(“My global function/n”); return; } void myGlobalFunction(void); void myGlobalFunction(void) { printf(“My global function/n”); return; } Function with Global Visibility Program Example American Express Public

10/2/ Improving Program Performance: Function Visibility Global Visibility: Function Call Linkage 1.The calling function, branches to the Procedure Linkage Table (PLT) entry of the called function. If this is the first call to the called function, the PLT contains the address to a PAT Stub entry of the load module that contains the called function. The PLT entry code branches to aforementioned address. 2.The PAT Stub Entry points to the PLT of the load module that contains the called function. Using the Symbol Table Offset entry of the called function, a branch to the first entry of the called modules PLT is taken. 3.The first entry of the PLT branches to the dynamic linkage routine which obtains the address of the called function is obtained from the PLT, which is returned to the called module and updated in the calling module’s PLT entry for the called function. 4.A branch to the function address is taken, executing the function. 5.Subsequent calls to the function by this Shared Object branch directly to the called function’s address. Opportunity Functions declared as Global functions, when only used as Local functions or static functions result in wasted space for the symbol tables, PLT entries. Execution time for Global Functions is longer due to the need to locate the function addresses in memory. Therefore only functions that require Global scope should be built as Global Functions. This statement does not in any way discourage the design and use of Global Functions. Appropriate use of Global functions can reduce software development and maintenance costs. American Express Public

10/2/ Improving Program Performance: Programming Examples Functions with Local Visibility To instruct the GCC and Linker to build functions with Local Visibility, use of the GCC visibility (“hidden”) attribute is required to be placed before the function prototype. Use of this attribute instructs the GCC to not build an external symbol table entry for the function making it callable from any function defined in the load module in which the local function is defined. Functions should have Local Visibility when they are callable from outside of the object file in which they are defined, but not outside of the load module in which they are defined. This type of function would provide a common service callable by one or more functions defined in multiple object files. __attribute__((visibility("hidden"))) void myHiddenFunction(void); void myHiddenFunction(void) { printf(“My hidden function/n”) return; } __attribute__((visibility("hidden"))) void myHiddenFunction(void); void myHiddenFunction(void) { printf(“My hidden function/n”) return; } Function with Local Visibility Program Example American Express Public

10/2/ Improving Program Performance: Function Visibility Local Visibility: Function Call Linkage 1.The Program Linkage Editor, supplies the address of the called function outside of the calling function’s object. 2.The calling function, branches to the address of the called function. Opportunity Local functions provide the performance benefit of avoiding the dynamic linkage to locate the address of the called function built as a Global Function. Locally called Global functions have the address of the function supplied by the Linkage Editor at build time. If a Global Function is only called locally, consider changing the scope of the called function to Local or static, to obtain the performance benefits. American Express Public

10/2/ Improving Program Performance: Programming Examples Static Functions To instruct the GCC and Linker to build static function, the function prototype and header must include the keyword static before the function return type. Use of the static keyword instructs the GCC to insert the address of the start of the function in the function call branch instruction. Since a static function is only to be called from within the object in which it is defined, it is the most efficient type of function call as the function address is known at compile time and can be included in the branch address of the calling function static void myStaticFunction(void); static void myHiddenFunction(void) { printf(“My static function/n”) return; } static void myStaticFunction(void); static void myHiddenFunction(void) { printf(“My static function/n”) return; } Function with Local Visibility Program Example American Express Public

10/2/ Improving Program Performance: Function Visibility Static Visibility: Function Call Linkage Since the address of a static Function is known at compile time, the address of the function is supplied by the compiler and the function is called directly. Opportunity If a Global or Local Function is only called from within the object in which it is defined, consider changing the scope of the called function to static, to obtain the performance benefits. American Express Public

10/2/ Improving Program Performance: Questions American Express Public

10/2/ Improving Program Performance: References References Useful information provided here for individual research and education. Visibility Presentation from the Orlando 2008 TUG Presentation by IBM on Program Optimization using Visibility zSeries ELF Application Binary Interface Supplement Very technical document on Extended Linkage Format and function call linkage How to Write Shared Libraries Ulrich Drepper Red Hat Inc. Another very technical document on library development and Visibility Dynamic Linking and Loading, Web Article on Run Time Linking Optimizing Performance using Visibility White Paper upon which this presentation is based. American Express Public