Handling Memory Ordering in Multithreaded Applications with Oracle Solaris Studio 12 Update 2: Part 2, Memory Barriers and Memory Fences

Similar documents
Handling Memory Ordering in Multithreaded Applications with Oracle Solaris Studio 12 Update 2: Part 1, Compiler Barriers

Installation Instructions: Oracle XML DB XFILES Demonstration. An Oracle White Paper: November 2011

Creating Custom Project Administrator Role to Review Project Performance and Analyze KPI Categories

Configuring Oracle Business Intelligence Enterprise Edition to Support Teradata Database Query Banding

Generate Invoice and Revenue for Labor Transactions Based on Rates Defined for Project and Task

An Oracle White Paper November Primavera Unifier Integration Overview: A Web Services Integration Approach

Correction Documents for Poland

JD Edwards EnterpriseOne Licensing

An Oracle White Paper December, 3 rd Oracle Metadata Management v New Features Overview

Using the Oracle Business Intelligence Publisher Memory Guard Features. August 2013

Tutorial on How to Publish an OCI Image Listing

Oracle Data Provider for.net Microsoft.NET Core and Entity Framework Core O R A C L E S T A T E M E N T O F D I R E C T I O N F E B R U A R Y

An Oracle White Paper September Security and the Oracle Database Cloud Service

Oracle CIoud Infrastructure Load Balancing Connectivity with Ravello O R A C L E W H I T E P A P E R M A R C H

Automatic Receipts Reversal Processing

Oracle DIVArchive Storage Plan Manager

Oracle Fusion Configurator

StorageTek ACSLS Manager Software Overview and Frequently Asked Questions

An Oracle White Paper July Oracle WebCenter Portal: Copying a Runtime-Created Skin to a Portlet Producer

Veritas NetBackup and Oracle Cloud Infrastructure Object Storage ORACLE HOW TO GUIDE FEBRUARY 2018

Loading User Update Requests Using HCM Data Loader

Oracle Cloud Applications. Oracle Transactional Business Intelligence BI Catalog Folder Management. Release 11+

Sun Fire X4170 M2 Server Frequently Asked Questions

Oracle Service Registry - Oracle Enterprise Gateway Integration Guide

Load Project Organizations Using HCM Data Loader O R A C L E P P M C L O U D S E R V I C E S S O L U T I O N O V E R V I E W A U G U S T 2018

Hard Partitioning with Oracle VM Server for SPARC O R A C L E W H I T E P A P E R J U L Y

An Oracle White Paper July Methods for Downgrading from Oracle Database 11g Release 2

An Oracle White Paper Oct Hard Partitioning With Oracle Solaris Zones

October Oracle Application Express Statement of Direction

An Oracle Technical Article March Certification with Oracle Linux 4

An Oracle White Paper October The New Oracle Enterprise Manager Database Control 11g Release 2 Now Managing Oracle Clusterware

April Understanding Federated Single Sign-On (SSO) Process

Oracle Learn Cloud. Taleo Release 16B.1. Release Content Document

Working with Time Zones in Oracle Business Intelligence Publisher ORACLE WHITE PAPER JULY 2014

Oracle Enterprise Performance Reporting Cloud. What s New in September 2016 Release (16.09)

An Oracle Technical Article August Certification with Oracle Linux 7

Subledger Accounting Reporting Journals Reports

Oracle Secure Backup. Getting Started. with Cloud Storage Devices O R A C L E W H I T E P A P E R F E B R U A R Y

Oracle Enterprise Data Quality New Features Overview

Oracle Utilities CC&B V2.3.1 and MDM V2.0.1 Integrations. Utility Reference Model Synchronize Master Data

An Oracle White Paper June StorageTek In-Drive Reclaim Accelerator for the StorageTek T10000B Tape Drive and StorageTek Virtual Storage Manager

Technical White Paper August Recovering from Catastrophic Failures Using Data Replicator Software for Data Replication

An Oracle Technical Article November Certification with Oracle Linux 7

WebCenter Portal Task Flow Customization in 12c O R A C L E W H I T E P A P E R J U N E

Integrating Oracle SuperCluster Engineered Systems with a Data Center s 1 GbE and 10 GbE Networks Using Oracle Switch ES1-24

E-BUSINESS SUITE APPLICATIONS R12 (R12.2.5) ORDER MANAGEMENT (OLTP) BENCHMARK - USING ORACLE11g

Achieving High Availability with Oracle Cloud Infrastructure Ravello Service O R A C L E W H I T E P A P E R J U N E

Oracle Virtual Directory 11g Oracle Enterprise Gateway Integration Guide

Oracle Service Cloud Agent Browser UI. November What s New

Oracle NoSQL Database For Time Series Data O R A C L E W H I T E P A P E R D E C E M B E R

ORACLE S PEOPLESOFT GENERAL LEDGER 9.2 (WITH COMBO EDITING) USING ORACLE DATABASE 11g FOR ORACLE SOLARIS (UNICODE) ON AN ORACLE S SPARC T7-2 Server

RAC Database on Oracle Ravello Cloud Service O R A C L E W H I T E P A P E R A U G U S T 2017

An Oracle Technical White Paper September Detecting and Resolving Oracle Solaris LUN Alignment Problems

An Oracle White Paper September, Oracle Real User Experience Insight Server Requirements

Oracle FLEXCUBE Direct Banking Release Corporate Cash Management User Manual. Part No. E

An Oracle White Paper October Deploying and Developing Oracle Application Express with Oracle Database 12c

Siebel CRM Applications on Oracle Ravello Cloud Service ORACLE WHITE PAPER AUGUST 2017

Oracle Database 10g Release 2 Database Vault - Restricting the DBA From Accessing Business Data

E-BUSINESS SUITE APPLICATIONS R12 (R12.2.5) HR (OLTP) BENCHMARK - USING ORACLE11g ON ORACLE S CLOUD INFRASTRUCTURE

An Oracle White Paper October Release Notes - V Oracle Utilities Application Framework

Product Release Notes

Benefits of an Exclusive Multimaster Deployment of Oracle Directory Server Enterprise Edition

Oracle Social Network

Oracle JD Edwards EnterpriseOne Object Usage Tracking Performance Characterization Using JD Edwards EnterpriseOne Object Usage Tracking

Pricing Cloud: Upgrading to R13 - Manual Price Adjustments from the R11/R12 Price Override Solution O R A C L E W H I T E P A P E R A P R I L

August 6, Oracle APEX Statement of Direction

Migrating VMs from VMware vsphere to Oracle Private Cloud Appliance O R A C L E W H I T E P A P E R O C T O B E R

Oracle FLEXCUBE Direct Banking Release Dashboard Widgets Transfer Payments User Manual. Part No. E

Overview. Implementing Fibre Channel SAN Boot with the Oracle ZFS Storage Appliance. January 2014 By Tom Hanvey; update by Peter Brouwer Version: 2.

Oracle Express CPQ for Salesforce.com

Oracle WebLogic Portal O R A C L E S T A T EM EN T O F D I R E C T IO N F E B R U A R Y 2016

An Oracle White Paper December Oracle Exadata Database Machine Warehouse Architectural Comparisons

See What's Coming in Oracle Taleo Business Edition Cloud Service

Deploy VPN IPSec Tunnels on Oracle Cloud Infrastructure. White Paper September 2017 Version 1.0

VISUAL APPLICATION CREATION AND PUBLISHING FOR ANYONE

Oracle Flash Storage System QoS Plus Operation and Best Practices ORACLE WHITE PAPER OCTOBER 2016

An Oracle White Paper October Minimizing Planned Downtime of SAP Systems with the Virtualization Technologies in Oracle Solaris 10

TABLE OF CONTENTS DOCUMENT HISTORY 3

Leverage the Oracle Data Integration Platform Inside Azure and Amazon Cloud

An Oracle White Paper June Exadata Hybrid Columnar Compression (EHCC)

Oracle Learn Cloud. What s New in Release 15B.1

Oracle Utilities Customer Care and Billing Release Utility Reference Model a Load Meter Reads

Oracle Fusion General Ledger Hierarchies: Recommendations and Best Practices. An Oracle White Paper April, 2012

Frequently Asked Questions Oracle Content Management Integration. An Oracle White Paper June 2007

Extreme Performance Platform for Real-Time Streaming Analytics

Oracle Data Masking and Subsetting

Deploying Custom Operating System Images on Oracle Cloud Infrastructure O R A C L E W H I T E P A P E R M A Y

Oracle JD Edwards EnterpriseOne Object Usage Tracking Performance Characterization Using JD Edwards EnterpriseOne Object Usage Tracking

An Oracle White Paper August Building Highly Scalable Web Applications with XStream

Technical Upgrade Guidance SEA->SIA migration

An Oracle White Paper March How to Define an Importer Returning Error Messages to the Oracle Web Applications Desktop Integrator Document

Oracle NoSQL Database Parent-Child Joins and Aggregation O R A C L E W H I T E P A P E R A P R I L,

PeopleSoft Fluid Navigation Standards

Advanced Global Intercompany Systems : Transaction Account Definition (TAD) In Release 12

Repairing the Broken State of Data Protection

Oracle Financial Consolidation and Close Cloud. What s New in the November Update (16.11)

An Oracle White Paper September Upgrade Methods for Upgrading to Oracle Database 11g Release 2

Differentiate Your Business with Oracle PartnerNetwork. Specialized. Recognized by Oracle. Preferred by Customers.

Data Capture Recommended Operating Environments

Oracle Forms Services Oracle Traffic Director Configuration

Transcription:

An Oracle White Paper September 2010 Handling Memory Ordering in Multithreaded Applications with Oracle Solaris Studio 12 Update 2: Part 2, Memory

Introduction... 1 What Is Memory Ordering?... 2 More About Memory Ordering... 2 Strong and Weak Memory Ordering... 3 SPARC and x86 Memory Ordering... 3 Intrinsic Support for Memory Barriers... 4 References... 5 Conclusion... 5

Introduction Oracle Solaris Studio 12 Update 2 introduces a new header file <mbarrier.h>. This header file provides a set of memory ordering intrinsics that are useful for enforcing memory ordering constraints in multithreaded applications. This article is part 2 of a two-part series. Part 1 discussed how compiler barriers can be used to stop the compiler from generating code that is incorrect due to reordered memory accesses. This part discusses how memory barriers or memory fences can be used to ensure that the processor does not reorder memory operations. 1

What Is Memory Ordering? Memory ordering is the order in which memory operations (loads and stores) are performed. There are two ways that memory ordering might be changed: The compiler might change memory ordering as a result of some compile-time optimizations. The processor might change memory ordering at run time. More About Memory Ordering Memory ordering controls the order in which memory operations in one thread become visible to other threads running on the system. In single-threaded applications and in most multithreaded code, the order in which operations are committed is not important. However, there are situations where it is important that memory operations are visible to other processors in the same order in which the original processor executed them. An example of when this is an issue is in the acquisition and release of mutex locks. Listing 1 shows a snippet of code in which a variable is modified and then a mutex lock is released. It is important that the store operation to the variable value is completed before the store operation to release the lock is issued. If these two stores are interchanged by the processor at run time, then other processors will see the lock released before they see the new value of the variable value protected by the lock. Consequently, another processor might immediately acquire the lock and receive the old contents of the variable value. Listing 1. Critical Section and Mutex Release... LOAD [&value], %o0 // Load value ADD %o0, 1, %o0 // Increment STORE %o0, [&value] // Store value STORE 0, [&lock] // Release lock To avoid this problem, we need to ensure that there is a memory barrier between the two store operations. This memory barrier ensures that hardware does not reorder the stores at run time. The modified code is shown in Listing 2. Listing 2. Critical Section with Memory Barrier and Mutex Release... LOAD [&value], %o0 // Load value ADD %o0, 1, %o0 // Increment STORE %o0, [&value] // Store value MEMORYBARRIER // Ensure that the stores remain ordered STORE 0, [&lock] // Release lock 2

Strong and Weak Memory Ordering Different processor types, different processor versions, and even one processor executing in different modes might have different policies towards enforcing memory ordering. SPARC and x86 processors implement what is known as strong memory ordering. With strong memory ordering, there are few situations in which it is necessary to explicitly include memory barriers. Other processors might implement weak memory ordering. For those processors, it is necessary to include memory barriers in most situations where the order in which memory operations become visible is critical for the correct functioning of the application. SPARC and x86 Memory Ordering SPARC processors implement what is known as total store ordering (TSO), which ensures that store memory operations are visible to the rest of the system in the order in which they occurred. x86 processors implement essentially the same memory ordering model. The UltraSPARC Architecture 2007 manual defines the TSO behavior as follows: "Loads are ordered with respect to earlier loads. Stores are ordered with respect to earlier loads and stores. Thus, loads can bypass earlier stores but cannot bypass earlier loads; stores cannot bypass earlier loads or stores." The following diagrams show these constraints. Figure 1 illustrates the situation for streams of loads or stores. Each load operation cannot pass either earlier or later load operations, and the stream of load operations is ordered. The same constraint is true for store operations. Figure 1. Ordering Constraints on Streams of Loads or Store Operations to Different Addresses 3

Figure 2 illustrates a more complex situation with mixed streams of load and store operations. In this situation, store operations can become visible after the execution of loads to different addresses that follow them in the instruction stream. Equivalently, later loads can be executed before the results of previous stores to different addresses become visible. Figure 2. Ordering Constraints on Mixed Streams of Load and Store Operations to Different Addresses The consequence of the implementation details on both SPARC and x86 processors is that the memory barrier shown in Listing 2 is not necessary. Although a memory barrier is not necessary for this particular code sequence, some other code sequences will require memory barriers to function correctly. For example, Dekker's Algorithm for mutual exclusion requires memory barriers to function correctly. In some situations, it might be useful to include the memory barrier so the code will also run when ported to processors that implement a weaker memory ordering model. Processors that do not need the instructions ignore them. Intrinsic Support for Memory Barriers SPARC processors use a membar instruction to provide a memory barrier, and x86 processors provide an mfence instruction. The particular variant of the instruction that is required depends on the situation in which the instruction is to be placed. Rather than expose this low level of detail to the user, the intrinsics defined in <mbarrier.h> provide a higher level of abstraction. 4

The available intrinsics are summarized in Table 1. TABLE 1. MEMORY BARRIER INTRINSICS PROVIDED BY <MBARRIER.H> INTRINSIC machine_r_barrier() machine_w_barrier() machine_rw_barrier() machine_acq_barrier() machine_rel_barrier() DESCRIPTION All previous loads must have completed before the next memory operation commences. All previous writes must have completed before the next memory operation commences. All previous memory operations must have completed before the next memory operation commences. With the acquire memory barrier intrinsic, all previous memory operations must have completed before any future read operations commence. With the release memory barrier intrinsic, all previous writes must have completed before any future memory operations commence. References Page 8 through 14 of Intel 64 and IA-32 Architectures Software Developer s Manual: http://www.intel.com/assets/pdf/manual/253668.pdf Page 93 of the UltraSPARC Architecture 2007 manual: http://opensparc-t2.sunsource.net/specs/ua2007-current-draft-hp-ext.pdf Conclusion This article, which is part 2 of a two-part series, described how memory barriers or memory fences can be used to ensure that a processor does not reorder memory operations. Part 1 of the series described how to use compiler barriers to stop the compiler from generating code that is incorrect due to reordered memory accesses. 5

Handling Memory Ordering in Multithreaded Applications with Oracle Solaris Studio 12 Update 2: Part 2, Memory Barriers and Memory Fences September 2010 Author: Darryl Gove Copyright 2010, Oracle and/or its affiliates. All rights reserved. This document is provided for information purposes only and the contents hereof are subject to change without notice. This document is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or implied in law, including implied warranties and conditions of merchantability or fitness for a particular purpose. We specifically disclaim any liability with respect to this document and no contractual obligations are formed either directly or indirectly by this document. This document may not be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without our prior written permission. Oracle Corporation World Headquarters 500 Oracle Parkway Redwood Shores, CA 94065 U.S.A. Worldwide Inquiries: Phone: +1.650.506.7000 Fax: +1.650.506.7200 oracle.com Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. AMD, Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro Devices. Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. UNIX is a registered trademark licensed through X/Open Company, Ltd. 0310