Code Monkey home page Code Monkey logo

tsx-tools's Introduction

tsx-tools

Useful TSX related tools

TSX (Intel Transactional Synchronization Extension) is a hardware transactional memory extension in recent 4th generation Core Intel CPUs codenamed Haswell. For more information see http://en.wikipedia.org/wiki/Transactional_Synchronization_Extensions and http://www.intel.com/software/tsx

This package provides some tools and libraries for TSX development.

Compilation notes

You may need to update your compiler's copy of cpuid.h depending on the version. In general, it should be sufficient to simply copy the file from a newer source distribution.

For example, on Mac OS X with LLVM version 4.2 (check with cc --version), you should replace /usr/lib/clang/4.2/include/cpuid.h with the one available at https://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/cpuid.h?view=co

has-tsx

Check if the current CPU supports TSX.

    % make
    % ./has-tsx
    RTM: Yes
    HLE: Yes

Emulated headers for HLE and RTM intrinsics

Headers to emulate the gcc 4.8+ and the Microsoft HLE/RTM intrinsics on older gcc compatible compilers. Plus a special header to expose the control flow of abort handlers directly using "asm goto".

rtm.h

    #include "rtm.h"        /* For gcc 4.8 use immintrin.h and -mrtm */
    ..
    if (_xbegin() == _XBEGIN_STARTED) {
            /* read lock */
            /* transaction */
            _xend();
    } else 
            /* fallback to read lock */

hle-emulation.h

Note HLE is deprecated. Please use RTM.

hle-ms.h

Provide Microsoft C compatible HLE intrinsics for gcc.

Note HLE is deprecated. Please use RTM.

rtm-goto.h

An experimential RTM intrinsics implementation that directly exposes the control flow of the abort handler. This allows to save a few instructions and may be clearer. Requires a compiler with "asm goto" support (gcc 4.7+ or some earlier RedHat gcc versions)

#include "rtm-goto.h"

XBEGIN(abort_handler);
/* Transaction */
XEND();	
return;

/* Transaction aborts come here */
unsigned status;
XFAIL_STATUS(abort_handler, status);
/* Examine status to determine abort cause */
/* Fallback path */

tsx-cpuid.h

Utility functions to check if the current CPU supports HLE or RTM from a program.

#include "tsx-cpuid.h"

init:
	if (cpu_has_rtm())
		have_rtm = 1;

lock code:
	if (have_rtm && _xbegin() == _XBEGIN_STARTED) {
		/* RTM code */
		_xend();
	} else { 
		/* fallback */
	}

ignore-xend.so

When running with the RTM enabled glibc unlocking and unlocked lock causes a general protection fault. Normal glibc ignores those. This LD_PRELOAD catches these faults and allows the buggy programs to run. May also be useful with older RTM based lock libraries.

LD_PRELOAD=/path/to/ignore-xend.so program

remove-hle.py

Remove HLE prefixes from a binary. Useful for verifying that a problem happens without HLE too. First run without -p and verify the patch sites, then use with -p binary to patch.

Warning: this can destroy a binary since there can be false positives. Always run on a backup copy.

tsx-assert.h

Normal assert does not work in TSX transaction. The assert output is an IO operation, which causes an abort so the assert gets discarded (unless it happens again when re-executed non transactionally)

This can be a curse or a blessing, but there are some situations where it is inconvenient.

tsx-assert.h provides a TSX aware assert. It only works with RTM, not with HLE. It commits the transaction before executing the assert.

#include "tsx-assert.h"

/* in transaction */
tsx_assert(condition);

Link the program with the tsx-assert.o object file

gcc ... tsx-assert.o

Based on a idea from Torvald Riegel.

glibc-tune

glibc tune allows to change the lock elision parameters in the currently running glibc.

This can be useful to experiment with elision enabled/disabled, force enable elision on glibc builds that were not built with --enable-lock-elision=yes, or tune retry parameters to improve performance on larger systems.

locks

tsxlocks is a simple library of reference TSX lock elision locks.

tsx-tools's People

Contributors

adferguson avatar andikleen avatar mfernan2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tsx-tools's Issues

Re-enable HTM

As you know, the recent hardware bug forced Intel to temporarily turn off RTM feature on a recent release of processor series. Some references show that by configuring the model specific registers (MSR), we can re-enable it, so do you have more detailed approaches about it?

Thanks & regards

Missing definitions for spin_init_hle and spin_init_rtm

The following functions are defined in the header but they are not defined.

extern void spin_init_hle(int *);
extern void spin_init_rtm(int *);

I know, from the implementation of lock/unlock, that they should be initialized with 1.

Just a question : TSx for only 4th Gen Intel CPUs?

I see in the TSX Tools description saying, TSX is for 4th Gen Intel CPUs. Does this feature not works for recent 11 Gen CPUs or after 4th Gen CPUs? Or do we have details somewhere like the recent CPUs comes with this feature, which we can refer?

Thanks in advance..!

_xbegin() API from "rtm.h" always returning 0

My CPU supports RTM and HLE(ran the first test in the README).

I have following gcc version:

gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0

Now, when I run the sample code, i.e.

int status = _xbegin();
if (status == _XBEGIN_STARTED)

I am always getting value of 'status' as 0 while _XBEGIN_STARTED is returning -1.

Could you let me know what should be done to resolve issue?

Also, tried to run HLE by importing the said header file 'hle-emulation.h'. But its giving the error:

try.c:(.text+0x12): undefined reference to __hle_acquire_test_and_set' try.c:(.text+0x35): undefined reference to __hle_release_clear'
collect2: error: ld returned 1 exit status

How to resolve this as well?

missing tsx-assert.h

Hello andikleen,

It seems miss tsx-assert.h in the branch master. Could you please add it up? I could not make successfully.

How to understand the example usage of hle

For the example provided in the readme,

    #include "hle-emulation.h"
    #include "immintrin.h"  /* for _mm_pause() */

    static volatile int lock;

    /* Take elided lock */
    while (__hle_acquire_test_and_set(&lock) == 1) {
            while (lock == 0)
                    _mm_pause();
    }
    ...
    /* Release elided lock */
    __hle_release_clear(&lock);

why shall we check (lock == 0) when we fail to acquire the lock? Isn't it the case that a set lock should be something non-zero?

make command error

Hi Team,

I get below error when i run make command..
make error
This repo do not have proper setup guide and required softwares to run this code. Can you pls update that as well?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.