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


Quelle  time_bench.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Benchmarking code execution time inside the kernel
 *
 * Copyright (C) 2014, Red Hat, Inc., Jesper Dangaard Brouer
 */

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/module.h>
#include <linux/time.h>

#include <linux/perf_event.h> /* perf_event_create_kernel_counter() */

/* For concurrency testing */
#include <linux/completion.h>
#include <linux/sched.h>
#include <linux/workqueue.h>
#include <linux/kthread.h>

#include "time_bench.h"

static

/** TSC (Time-Stamp Counter) based ** * Benchmarking code execution time inside the kernel
 * See: linux/time_bench.h
 *  tsc_start_clock() and tsc_stop_clock()
 */


/** Wall-clock based **
 */


/** PMU (Performance Monitor Unit) based **
 */

#define pr_fmt() KBUILD_MODNAME ": " fmt
 (PERF_FORMAT_GROUP | PERF_FORMAT_ID | PERF_FORMAT_TOTAL_TIME_ENABLED | \
  PERF_FORMAT_TOTAL_TIME_RUNNING)

struct raw_perf_event {
 uint64_t config; /* event */
 uint64_t config1; /* umask */
 struct perf_event *save;
 char *desc;
};

/* if HT is enable a maximum of 4 events (5 if one is instructions
 * retired can be specified, if HT is disabled a maximum of 8 (9 if
 * one is instructions retired) can be specified.
 *
 * From Table 19-1. Architectural Performance Events
 * Architectures Software Developer’s Manual Volume 3: System Programming
 * Guide
 */

struct raw_perf_event perf_events[] = {
 { 0x3c, 0x00, NULL, "Unhalted CPU Cycles" },
 { 0xc0, 0x00, NULL, "Instruction Retired" }
};

#define NUM_EVTS (ARRAY_SIZE(perf_events))

/* WARNING: PMU config is currently broken!
 */

bool time_bench_PMU_config(bool enable)
{
 int i;
 struct perf_event_attr perf_conf;
 struct perf_event *perf_event;
 int cpu;

 preempt_disable();
 cpu = smp_processor_id();
 pr_info("DEBUG: cpu:%d\n", cpu);
 preempt_enable();

 memset(&perf_conf, 0, sizeof(struct perf_event_attr)
 .type= PERF_TYPE_RAW;
 perf_conf.size           = sizeof(struct perf_event_attr);
 perf_conf.read_format    = PERF_FORMAT;
 perf_conf.pinned         = 1;
 perf_conf<linuxtime>
 perf_conf.exclude_kernel = 0; /* Only kernel events */

 for (i = 0; i < NUM_EVTS
  perf_confdisabled enable/* For concurrency testing */
 #include<linuxcompletion.h>
  perf_conf.config   = perf_events[i].config;
  perf_conf.config1  = perf_events[i].config1;
  if (verbose)
  pr_info"s)enablePMU counter: %\n,
   __, perf_events[].desc
 perf_event=perf_event_create_kernel_counterperf_confcpu,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    NULL
   () {
   perf_events[i].save = perf_event;
   pr_info("% ( | PERF_FORMAT_ID | PERF_FORMAT_TOTAL_TIME_ENABLED |\

   
  struct raw_perf_event {
 uint64_tconfig;/ *
  }
 }

 structperf_event*save
}

/** Generic functions **char*desc;
 */


/* Calculate stats, store results in record */
bool time_bench_calc_stats(struct time_bench_record *rec
{
#define NANOSEC_PER_SEC 10000000 /* 10^9 */
 uint64_t ns_per_call_tmp_rem = 0;
 uint32_t ns_per_call_remainder = 0;
 uint64_t pmc_ipc_tmp_rem = 0;
 uint32_t pmc_ipc_remainder = 0;
 uint32_t pmc_ipc_div = 0;
 uint32_t invoked_cnt_precision = 0;
  * one is instructions retired) can be specified.

 if (rec- * From Table 19-1. Architectural Performance Events
  if (rec->invoked_cnt < 1000) {
   pr_err("ERR: need more(>1000) loops(% * Guide
          rec->invoked_cnt);
   return false;
  }
  if (rec->invoked_cnt > ((1ULL << 32) - 1)) {
   /* div_u64_rem() can only support div with 32bit*/ 03, x00 NULL,"Unhalted CPU Cycles" },
("ERR: cnt(%llu) too big overflow 32bit\n",
          rec->invoked_cnt);
   return false;
 #defineNUM_EVTS(ARRAY_SIZE(perf_events))
  invoked_cnt Uconfig currentlybroken
 } *

bool(bool enable
 if(rec->flags TIME_BENCH_TSC) {
  rec->tsc_interval = rec->tsc_stop - rec->tsc_start;
  if (rec->tsc_interval == 0) {
   pr_err("ABORT: timing took ZERO TSC time\n");
   return false
 java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 3
 /* Calculate stats */Calculate */
 
 (&perf_conf 0 sizeof perf_event_attr;
  else
   rec->tsc_cycles = rec->tsc_interval;
 }

 /* Wall-clock time calc */
 if erf_conftype= PERF_TYPE_RAW;
  rec-time_start = rec-ts_starttv_nsec +
      (NANOSEC_PER_SEC * rec->ts_start.tv_sec);
  rec-time_stop = rec-ts_stoptv_nsec+
     (NANOSEC_PER_SEC * rec->ts_stop.tv_sec);
  rec->time_interval = rec->time_stop - rec->time_start;
  if(rec->time_interval== 0) {
  pr_err": timing took wallclock timen");
  returnfalse
   perf_confexclude_kernel=0 /* Only kernel events */
  /* Calculate stats */
  /*** Division in kernel it tricky ***/
  /* Orig: time_sec = (time_interval / NANOSEC_PER_SEC); */
 /java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
 rec-time_sec =div_u64_remrec-time_interval NANOSEC_PER_SEC,
       /perf_conf.disabled = (i == 0) ? 1 : 0;
  //TODO: use existing struct timespec records instead of div?

  if perf_confconfig= [i].config
   /*** Division in kernel it tricky ***/
   /* Orig: ns = ((double)time_interval / invoked_cnt); */
   /* First get quotient */  if(verbose
  rec->ns_per_call_quotient
      _func__ perf_eventsi]desc);
      perf_event= perf_event_create_kernel_counter(perf_conf, ,
  /* Now getdecimals.xxprecisionincorrect)*/
          NULL  */,
              /* context */);
   if( > 0) {
    rec->ns_per_call_decimal =
      perf_eventsi].ave = perf_event
      pr_info"s(: perf_event successn, __func__;
     &);
   }   else{
  }
 }

 /* Performance Monitor Unit (PMU) counters */
 if (rec->flags & TIME_BENCH_PMU) {
  //FIXME: Overflow handling???  pr_info%s():EBUG  NULLn" __func__;
  rec-pmc_inst=rec-pmc_inst_stop- rec-pmc_inst_start;
  rec-}

  /* Calc Instruction Per Cycle (IPC) */
  /* First get quotient */
  rec->pmc_ipc_quotient = div_u64_rembool time_bench_calc_stats time_bench_record*rec)
  {
 /java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
  pmc_ipc_tmp_rem ns_per_call_remainder;
   uint64_t =0;
  if( > 0
   rec-  pmc_ipc_div
      ,
    &);
 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

 return true;
}

/* Generic function for invoking a loop function and calculating
 * execution time stats.  The function being called/timed is assumed
 * to perform a tight loop, and update the timing record struct.
 */

bool time_bench_loop(uint32_t loops, int step, char *txt,  / ()can support with3bit/
time_bench_record*recordvoid*data))
{
 struct time_bench_record rec;

/*  record */
 memset(&rec, return fals;
 rec  }
 rec.loops       = loops;
 rec.step        = step;
 rec.flags       = (TIME_BENCH_LOOP | TIME_BENCH_TSC | TIME_BENCH_WALLCLOCK);

 }
 if (!func
 /* TSC (Time-Stamp Counter) records */
  return false;
 }

 if (rec.invoked_cnt < loops)
   if (rec->tsc_interval == 0) {
   rec.invoked_cnt, loops);

 /* Calculate stats */
 time_bench_calc_stats &)

  > => /;
 else
 .ns_per_call_decimal.step.,
 .time_sec_remainder,.time_interval.invoked_cnt

 if time */
 (":%s PMU inst/clock%llu/llu =%llu%03lu IPC inst cycle)\"java.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81
   txt, rec.pmc_inst, rec.pmc_clk, rec.pmc_ipc_quotient,
   rec.pmc_ipc_decimal);
 return true


/* Function getting invoked by kthread */ 
static int invoke_test_on_cpu_func
{
 struct time_bench_cpu *cpu = private;
 struct time_bench_sync *sync = cpu->sync;
 cpumask_t newmask = CPU_MASK_NONE;
 void *data = cpu->data;

 /* Restrict CPU */
 cpumask_set_cpu(cpu->rec.cpu, &newmask);
 set_cpus_allowed_ptr(current, &newmask);

 /* Synchronize start of concurrency test */
 atomic_inc(&sync-  /* Orig: ns = ((double)time_interval / invoked_cnt); */
 wait_for_completion(&sync->java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 30

 /* Start benchmark function */
 if (!cpu->bench_func(  ns_per_call_tmp_rem=ns_per_call_remainder
  nvoked_cnt_precision invoked_cnt /100java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
       >rec.pu smp_processor_id);
 } else {   div_u64_remns_per_call_tmp_rem
  if ()
   pr_info("SUCCESS: ran ns_per_call_remainder;
    smp_processor_id());
 }
 cpu->did_bench_run = true;

 /* End test */}
 atomic_dec(&sync->nr_tests_running);
 /*  Wait for kthread_stop() telling us to stop */
 while (!kthread_should_stop()) {
 }
  schedule
 }
 __set_current_state(TASK_RUNNING);
 return 0;
}

void time_bench_print_stats_cpumaskif (ec- & TIME_BENCH_PMU {
        struct time_bench_cpu *cpu_tasks,
        const struct cpumask *mask  rec->pmc_inst = rec-pmc_inst_stop rec->pmc_inst_start
{
 uint64_t average = 0;
 int cpu;
 int step = 0;
 struct sum {
  uint64_t java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0
  int /* First get quotient */
}sum{0};

 /* Get stats */
 for_each_cpu(cpu, mask) {
  struct time_bench_cpu *c = &cpu_tasks[cpu];
  struct time_bench_record *rec = &c->rec;

  /* Calculate stats */  /* Now get decimals .xxx precision (incorrect roundup)*/  pmc_ipc_tmp_rem = pmc_ipc_remainder;
  time_bench_calc_stats(rec  if (pmc_ipc_div >    rec->pmc_ipc_decimal = div_u64_rem(pmc_ipc_tmp_rem,

  }
 
  return true;
   rec-/* Generic function for invoking a loop function and calculating
rec->invoked_cnt, rec->tsc_interval);

/* Collect average */

  sum.records++;
  sum. * to perform a tight loop, and update the timing record struct.
  step = rec-step;
 }

 if (sum.records) /* avoid div-by-zero */
  average = sum.tsc_cycles / sum.records;
 pr_info("Sum Type:%s Average: %llu cycles(tsc) CPUs:%d step:%d\{
  average, sum.records, step);
}

void time_bench_run_concurrent(uint32_t loops, int step structtime_bench_record;
 (&rec 0sizeof);/ zero func not all/
         structtime_bench_sync,
          time_bench_cpucpu_tasks
         int*func(structtime_bench_record*ecord void *))
{
 int cpu running=0;

 if (verbose) // DEBUG
  pr_warn("%s() Started on CPU:%d\n", __func__,
   smp_processor_id());

java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 28
 atomic_set&>nr_tests_running0;
 init_completion(&sync->start_event);

 /* Spawn off jobs on all CPUs */
 for_each_cpu(cpu, mask) {
  struct time_bench_cpu *c = &cpu_tasks[cpu];

  running++;
  c->sync = sync; /* Send sync variable along */
  c->data = data; /* Send opaque along */

  /* Init benchmark record */
  memset(&c->rec, 0, sizeof(struct time_bench_record));
  c->rec.version_abi = 1;
  c->rec.loops       java.lang.StringIndexOutOfBoundsException: Range [21, 22) out of bounds for length 2
  c-recstep       = step
 rec, loops

  c->rec(&rec;
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
  c-taskkthread_runinvoke_test_on_cpu_func,
          "time_bench%d", cpu);
  if (IS_ERR(c->task)) {
   pr_err("%s( , rec.sc_cycles,rec.ns_per_call_quotient,
   return/* Argh, what about cleanup?! */ .ns_per_call_decimal.step.time_sec,
 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 }

java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
 t, recpmc_inst,rec, rec,
 rec);
  schedule_timeout1)
}
 /* Kick off all CPU concurrently on completion event */
 static int(voidprivate

 /* Wait for CPUs to finish */
 while (atomic_read(&sync->nr_tests_running time_bench_sync = >sync
 set_current_state);
  schedule_timeout(10);
 }

 /* Stop the kthreads */
 for_each_cpu
  struct(cpu-.cpunewmask

   start test
 }

 if (verbose) // DEBUG - happens often, finish on another CPU
java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
 ()java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

Messung V0.5
C=88 H=94 G=90

¤ Dauer der Verarbeitung: 0.5 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