Quantcast
Channel: Intel® Software - Intel ISA Extensions
Viewing all articles
Browse latest Browse all 685

Problem when using RTM

$
0
0

Hello,

My name is George Mappouras and I am trying to make a simple program in order to evaluate the TSX in the new Haswell processors. However I came across a very strange problem that I can't find its cause and I was wondering if you could help me with it.

The idea is simple, I have 'x' accounts and 'n' threads. Each thread does 'k' amount of transactions between random accounts (I transfer a random amount from account1 to account2 ). I tried this program with RTM, spinlocks and mutex (fine grained locking). In the end I check my results by comparing them to a single threaded version of this program.

The problem is that in the case of the RTM (with or without fallback path) I noticed that sometimes the results don't match the single-threaded results.  I also noticed that this seems to happen only when I use hyperthreading. (The computer in which I test my program has 4 physical cores with hyperthreading, that means 8 threads max). I tried to debug my program and I suspect that the problem is in the way I use the RTM, as the lock-versions never seem to have this problem. So I focused at the RTM version with no fallback paths as it is more simple to be debugged.

The way I do the transaction using RTM is like this:

while (1)

{

                unsigned status = _xbegin();

                 if (status  == _XBEGIN_STARTED)

                {

                                //safe to make the transaction

                                mem[accnt1].account = mem[accnt1].account - size; //transactions

                                mem[accnt2].account = mem[accnt2].account + size;

                                _xend();

                                break;

                 }

  }

In addition, in some tests I did, I found out that when this problem shows up, the sum of the accounts at the end of the program doesn't match the sum of the initialized accounts. All the accounts at the start of the program are initialized with the same amount and as the accounts transfer money from one to another, the sum of the accounts should remain the same at the end of the program.

So it seems like a "race condition/conflict" was not detected. Am I using the RTM incorrect? How can I fix this problem?

You can find  a simplified version of the program I use that focuses on the RTM with no fallback path in the link bellow:

https://drive.google.com/#folders/0B6IURKnzk12ydUcyUkdUYnBZZ28

To compile the program you need to type: gcc tsx_evaluation.c util.c processor_map.c -pthread -o tsx_evaluation

I also include the results of some test cases that this problem showed up. I also have to mention that this problem shows up randomly and not always. However I only spotted it when using hyperthreading (more than 4 threads).

1)

Type=2 Nubmer of threads=8, Number of accounts=8, Transactions per thread=80000000

error at account 5, error at account 6,

total number of erros: 2

Correct values of accounts: 14090, 13887, 5078, -4194, 15042, -9530, -7250, -27043,

Final values of accounts: 14090, 13887, 5078, -4194, 15042, -9529, -7249, -27043,

2)

Type=2 Nubmer of threads=8, Number of accounts=8, Transactions per thread=80000000

error at account 1,

total number of erros: 1

Correct values of accounts: 14090, 13887, 5078, -4194, 15042, -9530, -7250, -27043,

Final values of accounts: 14090, 13886, 5078, -4194, 15042, -9530, -7250, -27043,

3)

Type=2 Nubmer of threads=5, Number of accounts=32, Transactions per thread=80000000

error at account 24,

total number of erros: 1

Correct values of accounts: 2604, -6267, -1540, 1546, 524, -2599, -8216, -11741, -1775, 5123, 16, 2248, 6963, -6540, -300, -13049, 7443, 5614, 2285, -6095, -991, 7504, 2022, -709, -2669, 2782, 6415, 6193, -249, 473, 2737, 568,

Final values of accounts: 2604, -6267, -1540, 1546, 524, -2599, -8216, -11741, -1775, 5123, 16, 2248, 6963, -6540, -300, -13049, 7443, 5614, 2285, -6095, -991, 7504, 2022, -709, -2670, 2782, 6415, 6193, -249, 473, 2737, 568,

 


Viewing all articles
Browse latest Browse all 685

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>