Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  tm-tmspr.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright 2015, Michael Neuling, IBM Corp.
 *
 * Original: Michael Neuling 3/4/2014
 * Modified: Rashmica Gupta 8/12/2015
 *
 * Check if any of the Transaction Memory SPRs get corrupted.
 * - TFIAR  - stores address of location of transaction failure
 * - TFHAR  - stores address of software failure handler (if transaction
 *   fails)
 * - TEXASR - lots of info about the transacion(s)
 *
 * (1) create more threads than cpus
 * (2) in each thread:
 *  (a) set TFIAR and TFHAR a unique value
 *  (b) loop for awhile, continually checking to see if
 *  either register has been corrupted.
 *
 * (3) Loop:
 *  (a) begin transaction
 *     (b) abort transaction
 * (c) check TEXASR to see if FS has been corrupted
 */


#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>

#include "utils.h"
#include "tm.h"

int num_loops = 1000000;
int passed = 1;

void tfiar_tfhar(void *in)
{
 unsigned long tfhar, tfhar_rd, tfiar, tfiar_rd;
 int i;

 /* TFIAR: Last bit has to be high so userspace can read register */
 tfiar = ((unsigned long)in) + 1;
 tfiar += 2;
 mtspr(SPRN_TFIAR, tfiar);

 /* TFHAR: Last two bits are reserved */
 tfhar = ((unsigned long)in);
 tfhar &= ~0x3UL;
 tfhar += 4;
 mtspr(SPRN_TFHAR, tfhar);

 for (i = 0; i < num_loops; i++) {
  tfhar_rd = mfspr(SPRN_TFHAR);
  tfiar_rd = mfspr(SPRN_TFIAR);
  if ( (tfhar != tfhar_rd) || (tfiar != tfiar_rd) ) {
   passed = 0;
   return;
  }
 }
 return;
}

void texasr(void *in)
{
 unsigned long i;
 uint64_t result = 0;

 for (i = 0; i < num_loops; i++) {
  asm __volatile__(
   "tbegin.;"
   "beq 3f ;"
   "tabort. 0 ;"
   "tend.;"

   /* Abort handler */
   "3: ;"
   ::: "memory");

                /* Check the TEXASR */
                result = mfspr(SPRN_TEXASR);
  if ((result & TEXASR_FS) == 0) {
   passed = 0;
   return;
  }
 }
 return;
}

int test_tmspr()
{
 pthread_t *thread;
 int     thread_num;
 unsigned long i;

 SKIP_IF(!have_htm());
 SKIP_IF(htm_is_synthetic());

 /* To cause some context switching */
 thread_num = 10 * sysconf(_SC_NPROCESSORS_ONLN);

 thread = malloc(thread_num * sizeof(pthread_t));
 if (thread == NULL)
  return EXIT_FAILURE;

 /* Test TFIAR and TFHAR */
 for (i = 0; i < thread_num; i += 2) {
  if (pthread_create(&thread[i], NULL, (void *)tfiar_tfhar,
       (void *)i))
   return EXIT_FAILURE;
 }
 /* Test TEXASR */
 for (i = 1; i < thread_num; i += 2) {
  if (pthread_create(&thread[i], NULL, (void *)texasr, (void *)i))
   return EXIT_FAILURE;
 }

 for (i = 0; i < thread_num; i++) {
  if (pthread_join(thread[i], NULL) != 0)
   return EXIT_FAILURE;
 }

 free(thread);

 if (passed)
  return 0;
 else
  return 1;
}

int main(int argc, char *argv[])
{
 if (argc > 1) {
  if (strcmp(argv[1], "-h") == 0) {
   printf("Syntax:\t []\n");
   return 0;
  } else {
   num_loops = atoi(argv[1]);
  }
 }
 return test_harness(test_tmspr, "tm_tmspr");
}

Messung V0.5
C=93 H=99 G=95

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge