iPXE
Macros | Functions | Variables
librm_test.c File Reference

Real mode transition self-tests. More...

#include <ipxe/test.h>
#include <ipxe/profile.h>
#include <realmode.h>

Go to the source code of this file.

Macros

#define PROFILE_COUNT   4096
 Number of sample iterations for profiling. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static __asmcall void librm_test_call (struct i386_all_regs *ix86 __unused)
 Dummy function for profiling tests. More...
 
static void librm_test_exec (void)
 Perform real mode transition self-tests. More...
 
 REQUIRING_SYMBOL (librm_test)
 
 REQUIRE_OBJECT (test)
 

Variables

static struct profiler p2r_profiler __profiler = { .name = "p2r" }
 Protected-to-real mode transition profiler. More...
 
struct self_test librm_test __self_test
 Real mode transition self-test. More...
 

Detailed Description

Real mode transition self-tests.

This file allows for easy measurement of the time taken to perform real mode transitions, which may have a substantial overhead when running under a hypervisor.

Definition in file librm_test.c.

Macro Definition Documentation

◆ PROFILE_COUNT

#define PROFILE_COUNT   4096

Number of sample iterations for profiling.

Definition at line 44 of file librm_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ librm_test_call()

static __asmcall void librm_test_call ( struct i386_all_regs *ix86  __unused)
static

Dummy function for profiling tests.

Definition at line 61 of file librm_test.c.

61  {
62  /* Do nothing */
63 }

Referenced by librm_test_exec().

◆ librm_test_exec()

static void librm_test_exec ( void  )
static

Perform real mode transition self-tests.

Definition at line 69 of file librm_test.c.

69  {
70  unsigned int i;
71  unsigned long timestamp;
72  uint32_t timestamp_lo;
73  uint32_t timestamp_hi;
76  uint32_t discard_d;
77 
78  /* Profile mode transitions. We want to profile each
79  * direction of the transition separately, so perform an RDTSC
80  * while in real mode and tweak the profilers' start/stop
81  * times appropriately.
82  */
83  for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
84  profile_start ( &p2r_profiler );
85  __asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" )
86  : "=a" ( timestamp_lo ),
87  "=d" ( timestamp_hi )
88  : );
89  timestamp = timestamp_lo;
90  if ( sizeof ( timestamp ) > sizeof ( timestamp_lo ) )
91  timestamp |= ( ( ( uint64_t ) timestamp_hi ) << 32 );
92  profile_start_at ( &r2p_profiler, timestamp );
93  profile_stop ( &r2p_profiler );
94  profile_stop_at ( &p2r_profiler, timestamp );
95  }
96 
97  /* Profile complete real-mode call cycle */
98  for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
99  profile_start ( &real_call_profiler );
100  __asm__ __volatile__ ( REAL_CODE ( "" ) : );
101  profile_stop ( &real_call_profiler );
102  }
103 
104  /* Profile complete virtual call cycle */
105  for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
106  __asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t"
107  "movl %k0, %k2\n\t"
109  "rdtsc\n\t" )
110  : "=a" ( stopped ), "=d" ( discard_d ),
111  "=R" ( started ) : );
112  profile_start_at ( &virt_call_profiler, started );
113  profile_stop_at ( &virt_call_profiler, stopped );
114  }
115 }
#define VIRT_CALL(function)
Call C function from real-mode code.
Definition: librm.h:78
unsigned long long uint64_t
Definition: stdint.h:13
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
static __asmcall void librm_test_call(struct i386_all_regs *ix86 __unused)
Dummy function for profiling tests.
Definition: librm_test.c:61
static void profile_stop_at(struct profiler *profiler, unsigned long stopped)
Stop profiling.
Definition: profile.h:143
static int started
"startup() has been called" flag
Definition: init.c:37
__be64 timestamp
Definition: CIB_PRM.h:38
#define PROFILE_COUNT
Number of sample iterations for profiling.
Definition: librm_test.c:44
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
unsigned int uint32_t
Definition: stdint.h:12
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
static void profile_start_at(struct profiler *profiler, unsigned long started)
Start profiling.
Definition: profile.h:129
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
unsigned long stopped
Stop timestamp.
Definition: profile.h:32

References __asm__(), __volatile__(), librm_test_call(), PROFILE_COUNT, profile_start(), profile_start_at(), profile_stop(), profile_stop_at(), REAL_CODE, started, profiler::stopped, timestamp, and VIRT_CALL.

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( librm_test  )

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( test  )

Variable Documentation

◆ __profiler

struct profiler virt_call_profiler __profiler = { .name = "p2r" }
static

Protected-to-real mode transition profiler.

Virtual call profiler.

Real-mode call profiler.

Real-to-protected mode transition profiler.

Definition at line 47 of file librm_test.c.

◆ __self_test

struct self_test librm_test __self_test
Initial value:
= {
.name = "librm",
.exec = librm_test_exec,
}
static void librm_test_exec(void)
Perform real mode transition self-tests.
Definition: librm_test.c:69

Real mode transition self-test.

Definition at line 118 of file librm_test.c.