Add gate_patch/patches/gate_v0_1.patch
This commit is contained in:
commit
b945b46c3c
1 changed files with 171 additions and 0 deletions
171
gate_patch/patches/gate_v0_1.patch
Normal file
171
gate_patch/patches/gate_v0_1.patch
Normal file
|
|
@ -0,0 +1,171 @@
|
||||||
|
/*
|
||||||
|
* KI-GENERIERTER EXPERIMENTELLER KERNEL-PATCH – NUR DEMONSTRATIONS- UND
|
||||||
|
* LERNZWECKE
|
||||||
|
*
|
||||||
|
* Generiert von OpenAI im Rahmen eines Experiments auf https://donau2space.de
|
||||||
|
* Experiment-Key: gate_v0_1_patch
|
||||||
|
*
|
||||||
|
* WICHTIG:
|
||||||
|
* - Dieser Patch wurde in keiner Weise auf echten Systemen getestet
|
||||||
|
* - Es besteht erhebliche Absturz-, Datenverlust- und Sicherheitsgefahr
|
||||||
|
* - KEINESFALL auf produktiven oder wichtigen Systemen anwenden!
|
||||||
|
* - Nur für Forschung, Lernzwecke und Diskussion gedacht
|
||||||
|
* - Möglicherweise verursacht der Patch Kernel-Panics, Dateisystem-Korruption
|
||||||
|
* oder andere schwerwiegende Probleme
|
||||||
|
*/
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/drivers/mika/gate_eval.c
|
||||||
|
@@
|
||||||
|
+#include <linux/export.h>
|
||||||
|
+#include <linux/kernel.h>
|
||||||
|
+#include <linux/limits.h>
|
||||||
|
+#include <linux/printk.h>
|
||||||
|
+#include <linux/types.h>
|
||||||
|
+
|
||||||
|
+#define GATE_V0_1_MAX_SAMPLES 6
|
||||||
|
+#define GATE_V0_1_DEFAULT_K 5
|
||||||
|
+#define GATE_V0_1_WARN_MARGIN_DEFAULT 4
|
||||||
|
+
|
||||||
|
+enum gate_decision_state {
|
||||||
|
+ GATE_DECISION_PASS = 0,
|
||||||
|
+ GATE_DECISION_WARN,
|
||||||
|
+ GATE_DECISION_FAIL,
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+struct gate_evaluation_data {
|
||||||
|
+ u32 mischfenster_p95[GATE_V0_1_MAX_SAMPLES];
|
||||||
|
+ u8 sample_count;
|
||||||
|
+ u8 required_k;
|
||||||
|
+ u32 fail_threshold;
|
||||||
|
+ u32 warn_margin_limit;
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+struct decision_result {
|
||||||
|
+ enum gate_decision_state decision;
|
||||||
|
+ s32 margin;
|
||||||
|
+ bool flaky_flag;
|
||||||
|
+ u8 subset_flip_count;
|
||||||
|
+ u8 used_k;
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+static u8 gate_resolve_k(const struct gate_evaluation_data *data, u8 n)
|
||||||
|
+{
|
||||||
|
+ if (!n)
|
||||||
|
+ return 0;
|
||||||
|
+
|
||||||
|
+ if (data->required_k && data->required_k <= n)
|
||||||
|
+ return data->required_k;
|
||||||
|
+
|
||||||
|
+ return min_t(u8, GATE_V0_1_DEFAULT_K, n);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static u8 gate_count_fail_samples(const struct gate_evaluation_data *data,
|
||||||
|
+ u8 n)
|
||||||
|
+{
|
||||||
|
+ u8 i, fails = 0;
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < n; i++) {
|
||||||
|
+ if (data->mischfenster_p95[i] >= data->fail_threshold)
|
||||||
|
+ fails++;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return fails;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static s32 gate_margin_to_threshold(const struct gate_evaluation_data *data,
|
||||||
|
+ u8 n)
|
||||||
|
+{
|
||||||
|
+ u8 i;
|
||||||
|
+ s32 tightest = INT_MAX;
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < n; i++) {
|
||||||
|
+ s32 delta = (s32)data->fail_threshold -
|
||||||
|
+ (s32)data->mischfenster_p95[i];
|
||||||
|
+
|
||||||
|
+ if (delta < tightest)
|
||||||
|
+ tightest = delta;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return tightest == INT_MAX ? 0 : tightest;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static u8 gate_subset_flip_count(const struct gate_evaluation_data *data,
|
||||||
|
+ u8 n, u8 k, u8 fail_count)
|
||||||
|
+{
|
||||||
|
+ u8 i, flips = 0;
|
||||||
|
+ bool base_fail = fail_count >= k;
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < n; i++) {
|
||||||
|
+ bool sample_fail = data->mischfenster_p95[i] >=
|
||||||
|
+ data->fail_threshold;
|
||||||
|
+ u8 subset_fail = fail_count - sample_fail;
|
||||||
|
+ bool subset_state = subset_fail >= k;
|
||||||
|
+
|
||||||
|
+ if (subset_state != base_fail)
|
||||||
|
+ flips++;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return flips;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+struct decision_result evaluate_gate(const struct gate_evaluation_data *data)
|
||||||
|
+{
|
||||||
|
+ struct decision_result result = {
|
||||||
|
+ .decision = GATE_DECISION_WARN,
|
||||||
|
+ .margin = INT_MAX,
|
||||||
|
+ .flaky_flag = true,
|
||||||
|
+ .subset_flip_count = 0,
|
||||||
|
+ .used_k = 0,
|
||||||
|
+ };
|
||||||
|
+ u8 n, k, fail_count;
|
||||||
|
+ s32 margin;
|
||||||
|
+ u32 warn_margin;
|
||||||
|
+ bool hard_fail;
|
||||||
|
+
|
||||||
|
+ if (WARN_ONCE(!data, "gate_v0_1: NULL data\n"))
|
||||||
|
+ return result;
|
||||||
|
+
|
||||||
|
+ n = clamp_t(u8, data->sample_count, 0, GATE_V0_1_MAX_SAMPLES);
|
||||||
|
+ if (!n) {
|
||||||
|
+ pr_warn_once("gate_v0_1: no samples, defaulting to WARN\n");
|
||||||
|
+ return result;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (!data->fail_threshold) {
|
||||||
|
+ pr_warn_once("gate_v0_1: fail threshold missing\n");
|
||||||
|
+ return result;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ k = gate_resolve_k(data, n);
|
||||||
|
+ if (!k) {
|
||||||
|
+ pr_warn_once("gate_v0_1: invalid k-of-n parameters\n");
|
||||||
|
+ return result;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ result.used_k = k;
|
||||||
|
+
|
||||||
|
+ fail_count = gate_count_fail_samples(data, n);
|
||||||
|
+ margin = gate_margin_to_threshold(data, n);
|
||||||
|
+ result.margin = margin;
|
||||||
|
+
|
||||||
|
+ hard_fail = fail_count >= k;
|
||||||
|
+ result.decision = hard_fail ? GATE_DECISION_FAIL : GATE_DECISION_PASS;
|
||||||
|
+
|
||||||
|
+ result.subset_flip_count =
|
||||||
|
+ gate_subset_flip_count(data, n, k, fail_count);
|
||||||
|
+ result.flaky_flag = result.subset_flip_count;
|
||||||
|
+
|
||||||
|
+ warn_margin = data->warn_margin_limit ?
|
||||||
|
+ data->warn_margin_limit :
|
||||||
|
+ GATE_V0_1_WARN_MARGIN_DEFAULT;
|
||||||
|
+
|
||||||
|
+ if (result.decision == GATE_DECISION_FAIL &&
|
||||||
|
+ margin >= -(s32)warn_margin)
|
||||||
|
+ result.decision = GATE_DECISION_WARN;
|
||||||
|
+
|
||||||
|
+ if (result.decision == GATE_DECISION_PASS && result.flaky_flag)
|
||||||
|
+ result.decision = GATE_DECISION_WARN;
|
||||||
|
+
|
||||||
|
+ return result;
|
||||||
|
+}
|
||||||
|
+EXPORT_SYMBOL_GPL(evaluate_gate);
|
||||||
Loading…
Reference in a new issue