iPXE
Defines | 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.

Defines

#define PROFILE_COUNT   4096
 Number of sample iterations for profiling.

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.
static void librm_test_exec (void)
 Perform real mode transition self-tests.
 REQUIRING_SYMBOL (librm_test)
 REQUIRE_OBJECT (test)

Variables

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

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.


Define Documentation

#define PROFILE_COUNT   4096

Number of sample iterations for profiling.

Definition at line 44 of file librm_test.c.

Referenced by librm_test_exec().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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.

Referenced by librm_test_exec().

                                                                              {
        /* Do nothing */
}
static void librm_test_exec ( void  ) [static]

Perform real mode transition self-tests.

Definition at line 69 of file librm_test.c.

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

                                     {
        unsigned int i;
        unsigned long timestamp;
        uint32_t timestamp_lo;
        uint32_t timestamp_hi;
        uint32_t started;
        uint32_t stopped;
        uint32_t discard_d;

        /* Profile mode transitions.  We want to profile each
         * direction of the transition separately, so perform an RDTSC
         * while in real mode and tweak the profilers' start/stop
         * times appropriately.
         */
        for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
                profile_start ( &p2r_profiler );
                __asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" )
                                       : "=a" ( timestamp_lo ),
                                         "=d" ( timestamp_hi )
                                       : );
                timestamp = timestamp_lo;
                if ( sizeof ( timestamp ) > sizeof ( timestamp_lo ) )
                        timestamp |= ( ( ( uint64_t ) timestamp_hi ) << 32 );
                profile_start_at ( &r2p_profiler, timestamp );
                profile_stop ( &r2p_profiler );
                profile_stop_at ( &p2r_profiler, timestamp );
        }

        /* Profile complete real-mode call cycle */
        for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
                profile_start ( &real_call_profiler );
                __asm__ __volatile__ ( REAL_CODE ( "" ) : );
                profile_stop ( &real_call_profiler );
        }

        /* Profile complete virtual call cycle */
        for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
                __asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t"
                                                   "movl %k0, %k2\n\t"
                                                   VIRT_CALL ( librm_test_call )
                                                   "rdtsc\n\t" )
                                       : "=a" ( stopped ), "=d" ( discard_d ),
                                         "=R" ( started ) : );
                profile_start_at ( &virt_call_profiler, started );
                profile_stop_at ( &virt_call_profiler, stopped );
        }
}
REQUIRING_SYMBOL ( librm_test  )

Variable Documentation

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.

struct self_test librm_test __self_test
Initial value:
 {
        .name = "librm",
        .exec = librm_test_exec,
}

Real mode transition self-test.

Definition at line 118 of file librm_test.c.