Bladeren bron

[profile] Provide methods for profiling individual stages of operations

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 jaren geleden
bovenliggende
commit
a0da06c306
2 gewijzigde bestanden met toevoegingen van 41 en 11 verwijderingen
  1. 6
    4
      src/arch/i386/transitions/librm_test.c
  2. 35
    7
      src/include/ipxe/profile.h

+ 6
- 4
src/arch/i386/transitions/librm_test.c Bestand weergeven

@@ -51,7 +51,8 @@ static struct profiler r2p_profiler __profiler = { .name = "r2p" };
51 51
  */
52 52
 static void librm_test_exec ( void ) {
53 53
 	unsigned int i;
54
-	unsigned long p2r_elapsed;
54
+	unsigned long timestamp;
55
+	unsigned int discard_d;
55 56
 
56 57
 	/* Profile mode transitions.  We want to profile each
57 58
 	 * direction of the transition separately, so perform an RDTSC
@@ -61,10 +62,11 @@ static void librm_test_exec ( void ) {
61 62
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
62 63
 		profile_start ( &p2r_profiler );
63 64
 		__asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" )
64
-				       : "=A" ( r2p_profiler.started ) : );
65
+				       : "=a" ( timestamp ), "=d" ( discard_d )
66
+				       : );
67
+		profile_start_at ( &r2p_profiler, timestamp );
65 68
 		profile_stop ( &r2p_profiler );
66
-		p2r_elapsed = ( r2p_profiler.started - p2r_profiler.started );
67
-		profile_update ( &p2r_profiler, p2r_elapsed );
69
+		profile_stop_at ( &p2r_profiler, timestamp );
68 70
 	}
69 71
 }
70 72
 

+ 35
- 7
src/include/ipxe/profile.h Bestand weergeven

@@ -9,7 +9,6 @@
9 9
 
10 10
 FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12
-#include <stdint.h>
13 12
 #include <bits/profile.h>
14 13
 #include <ipxe/tables.h>
15 14
 
@@ -26,7 +25,9 @@ struct profiler {
26 25
 	/** Name */
27 26
 	const char *name;
28 27
 	/** Start timestamp */
29
-	uint64_t started;
28
+	unsigned long started;
29
+	/** Stop timestamp */
30
+	unsigned long stopped;
30 31
 	/** Number of samples */
31 32
 	unsigned int count;
32 33
 	/** Mean sample value (scaled) */
@@ -62,6 +63,20 @@ extern unsigned long profile_mean ( struct profiler *profiler );
62 63
 extern unsigned long profile_variance ( struct profiler *profiler );
63 64
 extern unsigned long profile_stddev ( struct profiler *profiler );
64 65
 
66
+/**
67
+ * Start profiling
68
+ *
69
+ * @v profiler		Profiler
70
+ * @v started		Start timestamp
71
+ */
72
+static inline __attribute__ (( always_inline )) void
73
+profile_start_at ( struct profiler *profiler, unsigned long started ) {
74
+
75
+	/* If profiling is active then record start timestamp */
76
+	if ( PROFILING )
77
+		profiler->started = started;
78
+}
79
+
65 80
 /**
66 81
  * Start profiling
67 82
  *
@@ -72,23 +87,36 @@ profile_start ( struct profiler *profiler ) {
72 87
 
73 88
 	/* If profiling is active then record start timestamp */
74 89
 	if ( PROFILING )
75
-		profiler->started = profile_timestamp();
90
+		profile_start_at ( profiler, profile_timestamp() );
76 91
 }
77 92
 
78 93
 /**
79 94
  * Record profiling result
80 95
  *
81 96
  * @v profiler		Profiler
97
+ * @v stopped		Stop timestamp
82 98
  */
83 99
 static inline __attribute__ (( always_inline )) void
84
-profile_stop ( struct profiler *profiler ) {
85
-	uint64_t ended;
100
+profile_stop_at ( struct profiler *profiler, unsigned long stopped ) {
86 101
 
87 102
 	/* If profiling is active then record end timestamp and update stats */
88 103
 	if ( PROFILING ) {
89
-		ended = profile_timestamp();
90
-		profile_update ( profiler, ( ended - profiler->started ) );
104
+		profiler->stopped = stopped;
105
+		profile_update ( profiler, ( stopped - profiler->started ) );
91 106
 	}
92 107
 }
93 108
 
109
+/**
110
+ * Record profiling result
111
+ *
112
+ * @v profiler		Profiler
113
+ */
114
+static inline __attribute__ (( always_inline )) void
115
+profile_stop ( struct profiler *profiler ) {
116
+
117
+	/* If profiling is active then record end timestamp and update stats */
118
+	if ( PROFILING )
119
+		profile_stop_at ( profiler, profile_timestamp() );
120
+}
121
+
94 122
 #endif /* _IPXE_PROFILE_H */

Laden…
Annuleren
Opslaan