summaryrefslogtreecommitdiffstats
path: root/src/include/ipxe/fault.h
diff options
context:
space:
mode:
authorMichael Brown2015-07-22 03:56:49 +0200
committerMichael Brown2015-07-22 22:17:47 +0200
commitd0325b1da64c8ff611cd4c3151e266dd2685c462 (patch)
treeaa8daf27408752e2c88cba632fe8443682922b50 /src/include/ipxe/fault.h
parent[tcp] Ensure FIN is actually sent if connection is closed while idle (diff)
downloadipxe-d0325b1da64c8ff611cd4c3151e266dd2685c462.tar.gz
ipxe-d0325b1da64c8ff611cd4c3151e266dd2685c462.tar.xz
ipxe-d0325b1da64c8ff611cd4c3151e266dd2685c462.zip
[fault] Generalise NETDEV_DISCARD_RATE fault injection mechanism
Provide a generic inject_fault() function that can be used to inject random faults with configurable probabilities. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/fault.h')
-rw-r--r--src/include/ipxe/fault.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/include/ipxe/fault.h b/src/include/ipxe/fault.h
new file mode 100644
index 000000000..32aa06484
--- /dev/null
+++ b/src/include/ipxe/fault.h
@@ -0,0 +1,32 @@
+#ifndef _IPXE_FAULT_H
+#define _IPXE_FAULT_H
+
+/** @file
+ *
+ * Fault injection
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <config/fault.h>
+
+extern int inject_fault_nonzero ( unsigned int rate );
+
+/**
+ * Inject fault with a specified probability
+ *
+ * @v rate Reciprocal of fault probability (zero for no faults)
+ * @ret rc Return status code
+ */
+static inline __attribute__ (( always_inline )) int
+inject_fault ( unsigned int rate ) {
+
+ /* Force dead code elimination in non-fault-injecting builds */
+ if ( rate == 0 )
+ return 0;
+
+ return inject_fault_nonzero ( rate );
+}
+
+#endif /* _IPXE_FAULT_H */