Processors
Intel® Processors, Tools, and Utilities
14514 Discussions

Intel- TSX: why My rtm is acting weird?

Alam__Shariful
New Contributor I
1,076 Views

I have the following code using Intel-rtm,

rtmCheck.c:

 

#include <stdio.h>
#include <stdlib.h>
#include <immintrin.h>

int test_otherfunction(int a, int b){
    int c=0;
    for (int i=0; i<1000;i++){
        c=c+a+b;
        //printf("%d\n",c);
    }


    for (int i=0; i<1000000000;i++){
        c=c+a+b;
        //printf("%d\n",c);
    }
    // RTM did Succeeded, but after some tires

    for (int i=0; i<1000000000;i++){
        c=c+a+b;
        //printf("%d\n",c);
    }
    for (int i=0; i<1000000000;i++){
        c=c+a+b;
        //printf("%d\n",c);
    }


    return 1;
}

int main(int argc, char *argv[])
{
    int result=-1;
    unsigned status;
    while(result!=1){
        if ((status = _xbegin()) == _XBEGIN_STARTED) {
            if(test_otherfunction(1,2))
                result=1;
                _xend();
        }else{
            printf("rtmCheck: Transaction failed\n");
            printf("status is %ld\n", status);
	    printf("Trying again ...\n");
            //break;
        }
        
    }
    printf("rtmCheck : Result is %d\n", result);

    return 0;
}

 

 If I compile with the following Makefile1, It always failed. I guess that is expected. And I'm okay with it.

Makefile1

CC=gcc
CFLAGS= -mrtm

rtmCheck: rtmCheck.o
        $(CC) $(CFLAGS) -o rtmCheck rtmCheck.o

clean: 
        rm -f *.o rtmCheck

Output:

$./rtmCheck
rtmCheck: Transaction failed status is 0 Trying again ... rtmCheck: Transaction failed status is 0 Trying again ... rtmCheck: Transaction failed status is 0 Trying again ... ........... ...........

But I have another Makefile2. If I compile my code with this(Makefile2) this works every time. just not understanding why?

Makefile2:

CC  := gcc
CFLAGS  :=  -mrtm -Wall -g -MD -O2 -I ../
LDFLAGS := -ltest 

tests_files := rtmCheck

all: $(tests_files)

rtmCheck: rtmCheck.o ../libtest/libtest.a
        $(CC) $(CFLAGS) -static $(<) -L../libtest/ $(LDFLAGS) -o $(@)

clean:
        rm -f *.o test *.d $(tests_files)

-include *.d

OutPut:

$./rtmCheck 
rtmCheck : Result is 1

Above Make file use some static library. But I'm not using anything from the library. Can someone please tell me why this is happening?

0 Kudos
6 Replies
Alam__Shariful
New Contributor I
1,071 Views

It was the  -O2 flag on the Makefile2. Removing -O2  flag yield the same result. 

Thanks

0 Kudos
Alberto_Sykes
Employee
1,055 Views

Alam__Shariful, Thank you for posting in the Intel® Communities Support.


In order for us to be able to provide the most accurate assistance on this matter, we just wanted to confirm a few details about your system:

what is the model of the Intel® Processor you are using?

Where is the Intel® Processor installed, what is the model of the motherboard?

Could you please provide a description of the Intel® TSX issue and RTM?

Are you a software/hardware developer?

Are you working on a project?

What is the project about?


Any questions, please let me know.


Regards,

Albert R.


Intel Customer Support Technician

A Contingent Worker at Intel


0 Kudos
Alberto_Sykes
Employee
1,034 Views

Hello Alam__Shariful, I just wanted to check if you saw the information posted previously and if you need further assistance on this matter?


Regards,

Albert R.


Intel Customer Support Technician

A Contingent Worker at Intel


0 Kudos
Alam__Shariful
New Contributor I
1,030 Views

Hi Mr. Albert,

I did not reply to your previous post because as I mentioned in my first reply that I was able to find the reason behind that weird rtm behavior. My rtm was acting weird because of the compilers -o2 optimization flag. It appears that with that optimization flag compiler was solving the value of C without running the code inside rtm. Hence, rtm was always successful regardless the size of the code block.  Changing the type of variable C from int to volatile actually do the trick. So, now the rtm is running as expected.

0 Kudos
Alberto_Sykes
Employee
1,021 Views

Hi Alam__Shariful, Thank you very much for letting us know those details.

 

No problem at all, perfect, excellent, we are glad to hear that now the RTM is running as expected. 

I can see in our database that you submitted another thread about the same matter where basically I asked you the same questions as in here, so I will close this thread and I will continue providing assistance on the new one, if you have further questions, please post them on your new thread:

https://community.intel.com/t5/forums/forumtopicpage/board-id/processors/message-id/47970#M47970

 

Regards,

Albert R.

 

Intel Customer Support Technician

A Contingent Worker at Intel

 

0 Kudos
Alam__Shariful
New Contributor I
1,018 Views

Hi Alberto_R_Intel1,

Sure. Appreciate your help. 

 

Regards,

Shariful

0 Kudos
Reply