/* Unavailable exceptions to test in HTM */ #define FP_UNA_EXCEPTION 0 #define VEC_UNA_EXCEPTION 1 #define VSX_UNA_EXCEPTION 2
#define NUM_EXCEPTIONS 3 #define err_at_line(status, errnum, format, ...) \
error_at_line(status, errnum, __FILE__, __LINE__, format ##__VA_ARGS__)
#define pr_warn(code, format, ...) err_at_line(0, code, format, ##__VA_ARGS__) #define pr_err(code, format, ...) err_at_line(1, code, format, ##__VA_ARGS__)
struct Flags { int touch_fp; int touch_vec; int result; int exception;
} flags;
bool expecting_failure(void)
{ if (flags.touch_fp && flags.exception == FP_UNA_EXCEPTION) returnfalse;
if (flags.touch_vec && flags.exception == VEC_UNA_EXCEPTION) returnfalse;
/* *Checkifwewereexpectingafailureanditdidnotoccurbychecking *CR0statejustafterweleavethetransaction.Eitherwaywecheckif *vs0orvs32gotcorrupted.
*/ if (expecting_failure() && !is_failure(cr_)) {
printf("\n\tExpecting the transaction to fail, %s", "but it didn't\n\t");
flags.result++;
}
/* Check if we were not expecting a failure and a it occurred. */ if (!expecting_failure() && is_failure(cr_) &&
!failure_is_reschedule()) {
printf("\n\tUnexpected transaction failure 0x%02lx\n\t",
failure_code()); return (void *) -1;
}
/* 0x4 is a success and 0xa is a fail. See comment in is_failure(). */ if (DEBUG)
printf("CR0: 0x%1lx ", cr_ >> 28);
/* Check FP (vs0) for the expected value. */ if (high_vs0 != 0x5555555555555555 || low_vs0 != 0xFFFFFFFFFFFFFFFF) {
printf("FP corrupted!");
printf(" high = %#16" PRIx64 " low = %#16" PRIx64 " ",
high_vs0, low_vs0);
flags.result++;
} else
printf("FP ok ");
/* Check VEC (vs32) for the expected value. */ if (high_vs32 != 0x5555555555555555 || low_vs32 != 0xFFFFFFFFFFFFFFFF) {
printf("VEC corrupted!");
printf(" high = %#16" PRIx64 " low = %#16" PRIx64,
high_vs32, low_vs32);
flags.result++;
} else
printf("VEC ok");
putchar('\n');
return NULL;
}
/* Thread to force context switch */ void *tm_una_pong(void *not_used)
{ /* Wait thread get its name "pong". */ if (DEBUG)
sleep(1);
/* Classed as an interactive-like thread. */ while (1)
sched_yield();
}
/* Function that creates a thread and launches the "ping" task. */ void test_fp_vec(int fp, int vec, pthread_attr_t *attr)
{ int retries = 2; void *ret_value;
pthread_t t0;
flags.touch_fp = fp;
flags.touch_vec = vec;
/* *Withoutluckit'spossiblethatthetransactionisabortednotdueto *theunavailableexceptioncaughtinthemiddleasweexpectbutalso, *forinstance,duetoacontextswitchorduetoaKVMreschedule(if *it'srunningonaVM).Thuswetryafewtimesbeforegivingup, *checkingifthefailurecauseistheoneweexpect.
*/ do { int rc;
/* Bind to CPU 0, as specified in 'attr'. */
rc = pthread_create(&t0, attr, tm_una_ping, (void *) &flags); if (rc)
pr_err(rc, "pthread_create()");
rc = pthread_setname_np(t0, "tm_una_ping"); if (rc)
pr_warn(rc, "pthread_setname_np");
rc = pthread_join(t0, &ret_value); if (rc)
pr_err(rc, "pthread_join");
retries--;
} while (ret_value != NULL && retries);
if (!retries) {
flags.result = 1; if (DEBUG)
printf("All transactions failed unexpectedly\n");
/* Set CPU 0 mask into the pthread attribute. */
rc = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset); if (rc)
pr_err(rc, "pthread_attr_setaffinity_np()");
rc = pthread_create(&t1, &attr /* Bind to CPU 0 */, tm_una_pong, NULL); if (rc)
pr_err(rc, "pthread_create()");
/* Name it for systemtap convenience */
rc = pthread_setname_np(t1, "tm_una_pong"); if (rc)
pr_warn(rc, "pthread_create()");
flags.result = 0;
for (exception = 0; exception < NUM_EXCEPTIONS; exception++) {
printf("Checking if FP/VEC registers are sane after");
if (exception == FP_UNA_EXCEPTION)
printf(" a FP unavailable exception...\n");
elseif (exception == VEC_UNA_EXCEPTION)
printf(" a VEC unavailable exception...\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.