aboutsummaryrefslogtreecommitdiff
path: root/src/include/ipxe/profile.h
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2010-04-19 20:16:01 +0100
committerMichael Brown <mcb30@ipxe.org>2010-04-19 23:43:39 +0100
commit8406115834d38bb743e01f35bfd36e835532415e (patch)
treeee1e3106e2cdc645d911ba5643f8414b21fc4c3e /src/include/ipxe/profile.h
parent2a36703af228bd10d50a31daec96072fe3a992a3 (diff)
downloadipxe-8406115834d38bb743e01f35bfd36e835532415e.zip
ipxe-8406115834d38bb743e01f35bfd36e835532415e.tar.gz
ipxe-8406115834d38bb743e01f35bfd36e835532415e.tar.bz2
[build] Rename gPXE to iPXE
Access to the gpxe.org and etherboot.org domains and associated resources has been revoked by the registrant of the domain. Work around this problem by renaming project from gPXE to iPXE, and updating URLs to match. Also update README, LOG and COPYRIGHTS to remove obsolete information. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/profile.h')
-rw-r--r--src/include/ipxe/profile.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/include/ipxe/profile.h b/src/include/ipxe/profile.h
new file mode 100644
index 0000000..60dd53a
--- /dev/null
+++ b/src/include/ipxe/profile.h
@@ -0,0 +1,80 @@
+#ifndef _IPXE_PROFILE_H
+#define _IPXE_PROFILE_H
+
+/** @file
+ *
+ * Profiling
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <stdint.h>
+
+/**
+ * A data structure for storing profiling information
+ */
+union profiler {
+ /** Timestamp (in CPU-specific "ticks") */
+ uint64_t timestamp;
+ /** Registers returned by rdtsc.
+ *
+ * This part should really be architecture-specific code.
+ */
+ struct {
+ uint32_t eax;
+ uint32_t edx;
+ } rdtsc;
+};
+
+/**
+ * Static per-object profiler, for use with simple_profile()
+ */
+static union profiler simple_profiler;
+
+/**
+ * Perform profiling
+ *
+ * @v profiler Profiler data structure
+ * @ret delta Elapsed ticks since last call to profile().
+ *
+ * Call profile() both before and after the code you wish to measure.
+ * The "after" call will return the measurement. For example:
+ *
+ * @code
+ *
+ * profile ( &profiler );
+ * ... do something here ...
+ * printf ( "It took %ld ticks to execute\n", profile ( &profiler ) );
+ *
+ * @endcode
+ */
+static inline __attribute__ (( always_inline )) unsigned long
+profile ( union profiler *profiler ) {
+ uint64_t last_timestamp = profiler->timestamp;
+
+ __asm__ __volatile__ ( "rdtsc" :
+ "=a" ( profiler->rdtsc.eax ),
+ "=d" ( profiler->rdtsc.edx ) );
+ return ( profiler->timestamp - last_timestamp );
+}
+
+/**
+ * Perform profiling
+ *
+ * @ret delta Elapsed ticks since last call to profile().
+ *
+ * When you only need one profiler, you can avoid the hassle of
+ * creating your own @c profiler data structure by using
+ * simple_profile() instead.
+ *
+ * simple_profile() is equivalent to profile(&simple_profiler), where
+ * @c simple_profiler is a @c profiler data structure that is static
+ * to each object which includes @c profile.h.
+ */
+static inline __attribute__ (( always_inline )) unsigned long
+simple_profile ( void ) {
+ return profile ( &simple_profiler );
+}
+
+#endif /* _IPXE_PROFILE_H */