[PATCH] D117370: [libcxx][SystemZ][z/OS] Added ceeedb.h for ceeedb_multithread and ceeedb_posix

Daniel McIntosh via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 14 16:52:45 PST 2022


DanielMcIntosh-IBM created this revision.
DanielMcIntosh-IBM added reviewers: ldionne, Mordante, Quuxplusone.
Herald added a subscriber: mgorny.
DanielMcIntosh-IBM requested review of this revision.
Herald added projects: libc++, LLVM.
Herald added subscribers: llvm-commits, libcxx-commits.
Herald added a reviewer: libc++.

On z/OS, the availability of several POSIX functions depends on the
environment at program start. As a result, we don't know at compile
time if mutexes and multithreading is supported.

The z/OS Language Environment provides a flag CEEEDB_POSIX to check
whether POSIX functions (and thus threading support) is enabled. It
also provides a flag CEEEDBMULTITHREAD which is set to true when more
than 1 thread is running, which we can use as an alternative in some
cases to get a little extra performance out of single-threaded
applications.

This is the 1st of 5 changes to add support for POSIX(OFF) on z/OS.
See D117366 <https://reviews.llvm.org/D117366> for more background, and D110349 <https://reviews.llvm.org/D110349> for discussion of an
alternative implementation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117370

Files:
  libcxx/src/CMakeLists.txt
  libcxx/src/include/ceeedb.h
  llvm/utils/gn/secondary/libcxx/include/BUILD.gn


Index: llvm/utils/gn/secondary/libcxx/include/BUILD.gn
===================================================================
--- llvm/utils/gn/secondary/libcxx/include/BUILD.gn
+++ llvm/utils/gn/secondary/libcxx/include/BUILD.gn
@@ -409,6 +409,7 @@
       "__string",
       "__support/android/locale_bionic.h",
       "__support/fuchsia/xlocale.h",
+      "__support/ibm/ceeedb.h",
       "__support/ibm/gettod_zos.h",
       "__support/ibm/limits.h",
       "__support/ibm/locale_mgmt_zos.h",
Index: libcxx/src/include/ceeedb.h
===================================================================
--- /dev/null
+++ libcxx/src/include/ceeedb.h
@@ -0,0 +1,55 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_IBM_CEEEDB_H
+#define _LIBCPP_SUPPORT_IBM_CEEEDB_H
+
+#ifndef __MVS__
+#  error This header should only be included on z/OS
+#endif
+
+#include <__config>
+#include <__gfunc.h>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+static inline unsigned char __libcpp_ceeedb_flags() {
+  // Offsets can be found in the z/OS Language Environment Vendor Interfaces book
+  // https://www-01.ibm.com/servers/resourcelink/svc00100.nsf/pages/zOSV2R4sa380688?OpenDocument
+#ifndef __64BIT__
+  enum { OFFSET_CEECAAEDB = 0x2f0 };
+  enum { OFFSET_CEEEDBFLAG1 = 0x08 };
+#else
+  enum { OFFSET_CEECAAEDB = 0x388 };
+  enum { OFFSET_CEEEDBFLAG1 = 0x100 };
+#endif
+
+  // See the zOS Language Environment Vendor Interfaces book for a description
+  // of the Common Anchor Area (CEECAA), the Enclave Data Block (CEECAAEDB),
+  // and the EDB flags (CEEEDBFLAG1).
+  const unsigned char* CEECAA = static_cast<const unsigned char*>(__gtca());
+  const unsigned char* CEECAAEDB =
+      *static_cast<const unsigned char**>(const_cast<void*>(static_cast<const void*>(CEECAA + OFFSET_CEECAAEDB)));
+  const unsigned char* CEEEDBFLAG1 = (CEECAAEDB + OFFSET_CEEEDBFLAG1);
+  return *CEEEDBFLAG1;
+}
+
+static inline bool __libcpp_ceeedb_multithread() {
+  const unsigned char CEEEDBMULTITHREAD = 0x02;
+  return __libcpp_ceeedb_flags() & CEEEDBMULTITHREAD;
+}
+
+static inline bool __libcpp_ceeedb_posix() {
+  const unsigned char CEEEDB_POSIX = 0x04;
+  return __libcpp_ceeedb_flags() & CEEEDB_POSIX;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_SUPPORT_IBM_CEEEDB_H
Index: libcxx/src/CMakeLists.txt
===================================================================
--- libcxx/src/CMakeLists.txt
+++ libcxx/src/CMakeLists.txt
@@ -112,6 +112,7 @@
     )
 elseif(ZOS)
   list(APPEND LIBCXX_SOURCES
+    include/ceeedb.h
     support/ibm/mbsnrtowcs.cpp
     support/ibm/wcsnrtombs.cpp
     support/ibm/xlocale_zos.cpp


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117370.400196.patch
Type: text/x-patch
Size: 2968 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220115/9ab8010c/attachment.bin>


More information about the llvm-commits mailing list