Przeglądaj źródła

[librm] Add a profiling self-test for measuring mode transition times

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 lat temu
rodzic
commit
bd640bc364
1 zmienionych plików z 77 dodań i 0 usunięć
  1. 77
    0
      src/arch/i386/transitions/librm_test.c

+ 77
- 0
src/arch/i386/transitions/librm_test.c Wyświetl plik

@@ -0,0 +1,77 @@
1
+/*
2
+ * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ */
19
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+/** @file
23
+ *
24
+ * Real mode transition self-tests
25
+ *
26
+ * This file allows for easy measurement of the time taken to perform
27
+ * real mode transitions, which may have a substantial overhead when
28
+ * running under a hypervisor.
29
+ *
30
+ */
31
+
32
+/* Forcibly enable assertions */
33
+#undef NDEBUG
34
+
35
+#include <ipxe/test.h>
36
+#include <ipxe/profile.h>
37
+#include <realmode.h>
38
+
39
+/** Number of sample iterations for profiling */
40
+#define PROFILE_COUNT 4096
41
+
42
+/** Protected-to-real mode transition profiler */
43
+static struct profiler p2r_profiler __profiler = { .name = "p2r" };
44
+
45
+/** Real-to-protected mode transition profiler */
46
+static struct profiler r2p_profiler __profiler = { .name = "r2p" };
47
+
48
+/**
49
+ * Perform real mode transition self-tests
50
+ *
51
+ */
52
+static void librm_test_exec ( void ) {
53
+	unsigned int i;
54
+	unsigned long p2r_elapsed;
55
+
56
+	/* Profile mode transitions.  We want to profile each
57
+	 * direction of the transition separately, so perform an RDTSC
58
+	 * while in real mode and tweak the profilers' start/stop
59
+	 * times appropriately.
60
+	 */
61
+	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
62
+		profile_start ( &p2r_profiler );
63
+		__asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" )
64
+				       : "=A" ( r2p_profiler.started ) : );
65
+		profile_stop ( &r2p_profiler );
66
+		p2r_elapsed = ( r2p_profiler.started - p2r_profiler.started );
67
+		profile_update ( &p2r_profiler, p2r_elapsed );
68
+	}
69
+}
70
+
71
+/** Real mode transition self-test */
72
+struct self_test librm_test __self_test = {
73
+	.name = "librm",
74
+	.exec = librm_test_exec,
75
+};
76
+
77
+REQUIRE_OBJECT ( test );

Ładowanie…
Anuluj
Zapisz