Changeset 13f066d for libcfa/src


Ignore:
Timestamp:
Mar 4, 2023, 1:35:31 PM (15 months ago)
Author:
caparson <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
231e1ae
Parents:
1e38178 (diff), a8667ab (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
libcfa/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel/cluster.cfa

    r1e38178 r13f066d  
    6969}
    7070
    71 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    72         // No forward declaration needed
    73         #define __kernel_rseq_register rseq_register_current_thread
    74         #define __kernel_rseq_unregister rseq_unregister_current_thread
    75 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    76         static void __kernel_raw_rseq_register  (void);
    77         static void __kernel_raw_rseq_unregister(void);
    78 
    79         #define __kernel_rseq_register __kernel_raw_rseq_register
    80         #define __kernel_rseq_unregister __kernel_raw_rseq_unregister
    81 #else
    82         // No forward declaration needed
    83         // No initialization needed
    84         static inline void noop(void) {}
    85 
    86         #define __kernel_rseq_register noop
    87         #define __kernel_rseq_unregister noop
    88 #endif
    89 
    9071//=======================================================================
    9172// Cluster wide reader-writer lock
     
    11091// Lock-Free registering/unregistering of threads
    11192unsigned register_proc_id( void ) with(__scheduler_lock.lock) {
    112         __kernel_rseq_register();
    113 
    11493        bool * handle = (bool *)&kernelTLS().sched_lock;
    11594
     
    161140
    162141        __atomic_store_n(cell, 0p, __ATOMIC_RELEASE);
    163 
    164         __kernel_rseq_unregister();
    165142}
    166143
     
    504481        /* paranoid */ verify( mock_head(this)    == this.l.prev );
    505482}
    506 
    507 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    508         // No definition needed
    509 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    510 
    511         #if defined( __x86_64 ) || defined( __i386 )
    512                 #define RSEQ_SIG        0x53053053
    513         #elif defined( __ARM_ARCH )
    514                 #ifdef __ARMEB__
    515                 #define RSEQ_SIG    0xf3def5e7      /* udf    #24035    ; 0x5de3 (ARMv6+) */
    516                 #else
    517                 #define RSEQ_SIG    0xe7f5def3      /* udf    #24035    ; 0x5de3 */
    518                 #endif
    519         #endif
    520 
    521         extern void __disable_interrupts_hard();
    522         extern void __enable_interrupts_hard();
    523 
    524         static void __kernel_raw_rseq_register  (void) {
    525                 /* paranoid */ verify( __cfaabi_rseq.cpu_id == RSEQ_CPU_ID_UNINITIALIZED );
    526 
    527                 // int ret = syscall(__NR_rseq, &__cfaabi_rseq, sizeof(struct rseq), 0, (sigset_t *)0p, _NSIG / 8);
    528                 int ret = syscall(__NR_rseq, &__cfaabi_rseq, sizeof(struct rseq), 0, RSEQ_SIG);
    529                 if(ret != 0) {
    530                         int e = errno;
    531                         switch(e) {
    532                         case EINVAL: abort("KERNEL ERROR: rseq register invalid argument");
    533                         case ENOSYS: abort("KERNEL ERROR: rseq register no supported");
    534                         case EFAULT: abort("KERNEL ERROR: rseq register with invalid argument");
    535                         case EBUSY : abort("KERNEL ERROR: rseq register already registered");
    536                         case EPERM : abort("KERNEL ERROR: rseq register sig  argument  on unregistration does not match the signature received on registration");
    537                         default: abort("KERNEL ERROR: rseq register unexpected return %d", e);
    538                         }
    539                 }
    540         }
    541 
    542         static void __kernel_raw_rseq_unregister(void) {
    543                 /* paranoid */ verify( __cfaabi_rseq.cpu_id >= 0 );
    544 
    545                 // int ret = syscall(__NR_rseq, &__cfaabi_rseq, sizeof(struct rseq), RSEQ_FLAG_UNREGISTER, (sigset_t *)0p, _NSIG / 8);
    546                 int ret = syscall(__NR_rseq, &__cfaabi_rseq, sizeof(struct rseq), RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
    547                 if(ret != 0) {
    548                         int e = errno;
    549                         switch(e) {
    550                         case EINVAL: abort("KERNEL ERROR: rseq unregister invalid argument");
    551                         case ENOSYS: abort("KERNEL ERROR: rseq unregister no supported");
    552                         case EFAULT: abort("KERNEL ERROR: rseq unregister with invalid argument");
    553                         case EBUSY : abort("KERNEL ERROR: rseq unregister already registered");
    554                         case EPERM : abort("KERNEL ERROR: rseq unregister sig  argument  on unregistration does not match the signature received on registration");
    555                         default: abort("KERNEL ERROR: rseq unregisteunexpected return %d", e);
    556                         }
    557                 }
    558         }
    559 #else
    560         // No definition needed
    561 #endif
  • libcfa/src/concurrency/kernel/private.hfa

    r1e38178 r13f066d  
    1010// Created On       : Mon Feb 13 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 12 08:21:33 2020
    13 // Update Count     : 9
     12// Last Modified On : Thu Mar  2 16:04:46 2023
     13// Update Count     : 11
    1414//
    1515
     
    2929
    3030extern "C" {
    31 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    32         #include <rseq/rseq.h>
    33 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    34         #include <linux/rseq.h>
    35 #else
    36         #ifndef _GNU_SOURCE
    37         #error kernel/private requires gnu_source
    38         #endif
    3931        #include <sched.h>
    40 #endif
    4132}
    4233
     
    110101// Hardware
    111102
    112 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    113         // No data needed
    114 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    115         extern "Cforall" {
    116                 extern __attribute__((aligned(64))) __thread volatile struct rseq __cfaabi_rseq;
    117         }
    118 #else
    119         // No data needed
    120 #endif
    121 
    122103static inline int __kernel_getcpu() {
    123104        /* paranoid */ verify( ! __preemption_enabled() );
    124 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    125         return rseq_current_cpu();
    126 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    127         int r = __cfaabi_rseq.cpu_id;
    128         /* paranoid */ verify( r >= 0 );
    129         return r;
    130 #else
    131105        return sched_getcpu();
    132 #endif
    133106}
    134107
  • libcfa/src/concurrency/kernel/startup.cfa

    r1e38178 r13f066d  
    147147__scheduler_RWLock_t __scheduler_lock @= { 0 };
    148148
    149 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    150         // No data needed
    151 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    152         extern "Cforall" {
    153                 __attribute__((aligned(64))) __thread volatile struct rseq __cfaabi_rseq @= {
    154                         .cpu_id : RSEQ_CPU_ID_UNINITIALIZED,
    155                 };
    156         }
    157 #else
    158         // No data needed
    159 #endif
    160 
    161149//-----------------------------------------------------------------------------
    162150// Struct to steal stack
  • libcfa/src/containers/array.hfa

    r1e38178 r13f066d  
    99
    1010
    11 //
    12 // Single-dim array sruct (with explicit packing and atom)
    13 //
    14 
     11//
     12// The `array` macro is the public interface.
     13// It computes the type of a dense (trivially strided) array.
     14// All user-declared objects are dense arrays.
     15//
     16// The `arpk` (ARray with PacKing info explicit) type is, generally, a slice with _any_ striding.
     17// This type is meant for internal use.
     18// CFA programmers should not instantiate it directly, nor access its field.
     19// CFA programmers should call ?[?] on it.
     20// Yet user-given `array(stuff)` expands to `arpk(stuff')`.
     21// The comments here explain the resulting internals.
     22//
     23// Just as a plain-C "multidimesional" array is really array-of-array-of-...,
     24// so does arpk generally show up as arpk-of-arpk-of...
     25//
     26// In the example of `array(float, 3, 4, 5) a;`,
     27// `typeof(a)` is an `arpk` instantiation.
     28// These comments explain _its_ arguments, i.e. those of the topmost `arpk` level.
     29//
     30// [N]    : the number of elements in `a`; 3 in the example
     31// S      : carries the stride size (distance in bytes between &myA[0] and &myA[1]), in sizeof(S);
     32//          same as Timmed when striding is trivial, same as Timmed in the example
     33// Timmed : (T-immediate) the inner type; conceptually, `typeof(a)` is "arpk of Timmed";
     34//          array(float, 4, 5) in the example
     35// Tbase  : (T-base) the deepest element type that is not arpk; float in the example
     36//
    1537forall( [N], S & | sized(S), Timmed &, Tbase & ) {
     38
     39    //
     40    // Single-dim array sruct (with explicit packing and atom)
     41    //
    1642    struct arpk {
    1743        S strides[N];
  • libcfa/src/interpose.cfa

    r1e38178 r13f066d  
    1010// Created On       : Wed Mar 29 16:10:31 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb 24 15:31:03 2023
    13 // Update Count     : 185
     12// Last Modified On : Thu Mar  2 13:56:26 2023
     13// Update Count     : 191
    1414//
    1515
     
    5353
    5454static generic_fptr_t interpose_symbol( const char symbol[], const char version[] ) {
    55         static void * library;
    56         static void * pthread_library;
    57 
     55        void * library;
     56        #if defined( RTLD_NEXT )
     57        library = RTLD_NEXT;
     58        #else
     59        library = dlopen( "libc.so.6", RTLD_LAZY );
    5860        if ( ! library ) {
    59                 library = dlopen( "libc.so.6", RTLD_LAZY );
    6061                const char * error = dlerror();
    6162                if ( error ) {
     
    6364                } // if
    6465        } // if
    65         if ( ! pthread_library ) {
    66                 pthread_library = dlopen( "libpthread.so", RTLD_LAZY );
    67                 const char * error = dlerror();
    68                 if ( error ) {
    69                         abort( "interpose_symbol : failed to open libpthread, %s\n", error );
    70                 } // if
    71         } // if
     66        #endif
    7267
    7368        return do_interpose_symbol(library, symbol, version);
     
    108103
    109104                if(__cfathreadabi_interpose_startup) __cfathreadabi_interpose_startup( do_interpose_symbol );
     105
     106                // SKULLDUGGERY: In Ubuntu 22.04, someone augmented signal.h to allow SIGSTKSZ to be "sysconf(_SC_SIGSTKSZ)" in
     107                // sigstksz.h, as well as 8192 in sigstack.h. HOWEVER, they forgot to provide a mechanism to tell signal.h to
     108                // use sigstack.h rather than sigstksz.h. (I'm not happy.) By undefining _GNU_SOURCE before signal.h and
     109                // redefining it afterwards, you can get 8192, but then nothing works correctly inside of signal.h without
     110                // _GNU_SOURCE defined.  So what is needed is a way to get signal.h to use sigstack.h WITH _GNU_SOURCE defined.
     111                // Basically something is wrong with features.h and its use in signal.h.
     112
     113                #undef SIGSTKSZ
     114                #define SIGSTKSZ 8192
    110115
    111116                // As a precaution (and necessity), errors that result in termination are delivered on a separate stack because
  • libcfa/src/interpose_thread.cfa

    r1e38178 r13f066d  
    3939        const char version[]
    4040) libcfa_public {
    41         static void * library;
     41        void * library;
     42        #if defined( RTLD_NEXT )
     43        library = RTLD_NEXT;
     44        #else
     45        // missing RTLD_NEXT => must hard-code library name, assuming libstdc++
     46        library = dlopen( "libthread_db.so", RTLD_LAZY );
    4247        if ( ! library ) {
    43                 library = dlopen( "libpthread.so", RTLD_LAZY );
    4448                const char * error = dlerror();
    4549                if ( error ) {
     
    4751                }
    4852        } // if
     53        #endif // RTLD_NEXT
    4954
    5055        return do_interpose_symbol(library, symbol, version);
Note: See TracChangeset for help on using the changeset viewer.