ASELSANMicrokernel
S334 · SOURCE-BOUND GATE EVIDENCE

S334 · Yield-now production writer guard integration

production acquire → S247 guard modülü → Operations-bound focused test Bu sayfa yalnız S334 kapısına aittir; komşu kapıların kaynakları bu kabulün içine katılmaz.

S334Production writer guardOperations id exactsource SHA exacttest target exact

operation: g8l-s334-yield-now-writer-guard-integration-partial

production · S247 guard · focused test · Operations · 4 exact excerpt

sequence-bound=true · implementation-bound=true
01 · Test edilen uygulama/model kodu

Kapının yürüttüğü gerçek kaynak

tam Rust öğesiL5915–L6069
kernel/src/task/scheduler.rs::yield_now

/// Cooperative veya preemptive yield.
///
/// IRQ'lar tüm queue mutasyonu + context_switch süresi boyunca maskelidir
/// (re-entrant scheduler'ı engeller). `IrqGuard` task'in stack'inde durur;
/// context_switch geri döndüğünde aynı task tekrar buraya ulaştığında drop
/// edilir → DAIF restore.
///
/// Eğer current task `Dead` durumdaysa kuyruğa geri konmaz. Ancak çalışan
/// kernel stack'i bu task'e ait olduğu için burada drop da edilmez: task tek
/// yuvalı `retired_task` alanına taşınır ve başka bir stack üzerindeki sonraki
/// `yield_now` girişinde reaper tarafından düşürülür.
pub unsafe fn yield_now() {
    crate::irq_lock!();

    #[cfg(all(target_arch = "aarch64", target_os = "none", feature = "board-rpi5"))]
    let s334_writer_access = crate::g8l_target_dispatch_scheduler_owner_scheduler_mutation_production_migration_lifecycle_s334_yield_now_writer_guard_integration::acquire_s334_production_scheduler_writer_access()
        .unwrap_or_else(|error| panic!("S334 yield-now writer guard failed closed: {:?}", error));
    let sched = &mut *core::ptr::addr_of_mut!(SCHEDULER);

    // This call is reached only after any earlier context switch has returned
    // into the currently executing task. It must stay before current_task is
    // taken so the task owning this stack can never be reaped here.
    sched.reap_retired_task();

    let Some(mut current) = sched.current_task.take() else {
        return;
    };

    let is_dead = current.state == TaskState::Dead;
    let old_asid = current.asid;

    // Dead task için ekstra temizlik ve log (user task'ler için önemli)
    if is_dead {
        let is_user_task = current.is_user;
        let task_name = current.name.clone();
        let task_id = current.id;

        current.user_sp = 0;
        current.saved_user_elr = 0;
        current.saved_user_spsr = 0;
        current.saved_user_gprs = [0; 31];

        if is_user_task {
            crate::kprintln!(
                "[M4.3-DEBUG] >>> Retiring DEAD USER TASK: '{}' (id={}) — user_sp cleared, frame zeroed",
                task_name, task_id
            );
        } else {
            crate::kprintln!(
                "[M4.3-DEBUG] Retiring DEAD KERNEL TASK: '{}' (id={})",
                task_name,
                task_id
            );
        }

        // There is no safe stack to switch to. Keep the dead task as current
        // and return to task_exit's WFI fallback without reclaiming anything.
        // If a task becomes ready later, a subsequent yield can retire it.
        if sched.ready_queue.is_empty() {
            crate::kprintln!(
                "[K1-LIFECYCLE] no ready task; retaining dead task #{} on its current stack",
                current.id
            );
            sched.current_task = Some(current);
            return;
        }
    }

    // Eski task'in context'ini sakla — Dead olsa bile context_switch oraya
    // SAVE yapmak zorunda (ret-address vs.). Sadece queue'ya geri koymuyoruz.
    let mut dead_to_retire = None;
    let old_ctx_ptr: *mut TaskContext = if is_dead {
        // Dead task'in context'i kullanılmayacak ama SAVE için bir hedef
        // gerek. Static bir scratch yer ayır.
        static mut DEAD_SCRATCH: TaskContext = TaskContext {
            x19: 0,
            x20: 0,
            x21: 0,
            x22: 0,
            x23: 0,
            x24: 0,
            x25: 0,
            x26: 0,
            x27: 0,
            x28: 0,
            x29: 0,
            x30: 0,
            sp: 0,
            fp: FpState {
                q: [[0; 2]; 32],
                fpsr: 0,
                fpcr: 0,
            },
        };
        dead_to_retire = Some(current);
        core::ptr::addr_of_mut!(DEAD_SCRATCH)
    } else {
        // Vruntime güncelle (CFS benzeri)
        let delta = (current.default_time_slice - current.time_slice) as u64;
        sched.update_vruntime(&mut current, delta.max(1));

        let ptr = &mut current.context as *mut TaskContext;

        // Geri kuyruğa koy
        current.state = TaskState::Ready;
        if current.time_slice == 0 {
            current.time_slice = current.default_time_slice;
        }
        sched.ready_queue.push(PriorityTask::new(current));
        ptr
    };

    if let Some(prio_next) = sched.ready_queue.pop() {
        let mut next = prio_next.task;
        next.state = TaskState::Running;
        let next_name = next.name.clone();
        let next_is_user = next.is_user;
        let new_ctx = &mut next.context as *mut TaskContext;
        let slice = next.default_time_slice;

        crate::kprintln!(
            "[M4.3-DEBUG] context_switch: {} → {} (next_is_user={})",
            if is_dead { "DEAD" } else { "old" },
            next_name,
            next_is_user
        );

        // M8.2 — Scheduler entegrasyonu: Bir sonraki task'e geçmeden önce
        // doğru AddressSpace'i (TTBR0) aktif hale getiriyoruz.
        #[cfg(all(target_arch = "aarch64", target_os = "none", feature = "board-rpi5"))]
        let prepare_task_for_context_switch = |next_task: &Task| unsafe {
            prepare_task_for_context_switch_from_s334_snapshot(next_task, old_asid);
        };
        prepare_task_for_context_switch(&next);

        sched.current_task = Some(next);
        sched.ticks_until_preempt = slice;

        if let Some(dead) = dead_to_retire.take() {
            assert!(
                sched.retired_task.is_none(),
                "deferred reaper slot must be empty before retiring current task"
            );
            sched.retired_task = Some(dead);
        }

        #[cfg(all(target_arch = "aarch64", target_os = "none", feature = "board-rpi5"))]
        drop(s334_writer_access);
        context_switch(old_ctx_ptr, new_ctx);
    }
    // A live task is requeued above, and the dead/no-ready case returned
    // before reaching this point; therefore the queue cannot be empty here.
    debug_assert!(dead_to_retire.is_none());
}
snippet sha256: 1690788853b5file sha256: 838dd474448c
02 · Ortak exclusion üyeliği

S247 production writer guard

tam Rust öğesiL151–L165
kernel/src/g8l_target_dispatch_scheduler_owner_scheduler_mutation_production_migration_lifecycle_s334_yield_now_writer_guard_integration.rs::acquire_s334_production_scheduler_writer_access

/// Acquire from the exact static gate used by routed readers and prior
/// writers. The legacy global scheduler remains a CPU0-only boundary.
#[cfg(all(target_arch = "aarch64", target_os = "none", feature = "board-rpi5"))]
pub fn acquire_s334_production_scheduler_writer_access(
) -> Result<G8lS334ProductionSchedulerWriterAccess, G8lS247WholeSchedulerAccessError> {
    let caller_cpu =
        crate::percpu::try_current_cpu_id().ok_or(G8lS247WholeSchedulerAccessError::InvalidCpu)?;
    if caller_cpu != crate::g8l_runtime_contract::CPU0 {
        return Err(G8lS247WholeSchedulerAccessError::InvalidCpu);
    }
    let access = crate::g8l_target_dispatch_scheduler_owner_scheduler_mutation_production_migration_lifecycle_s246_whole_scheduler_read_access_guard::S247_PRODUCTION_WHOLE_SCHEDULER_ACCESS_GATE
        .try_acquire_exclusive_for_valid_cpu(caller_cpu)?;
    Ok(G8lS334ProductionSchedulerWriterAccess { _access: access })
}
snippet sha256: 8ed4f2d2302dfile sha256: 667ca156e377
03 · Doğrulayan test kodu

Operations komutuna bağlı focused test

tam Rust öğesiL201–L218
simulation/tests/g8l_target_dispatch_scheduler_owner_scheduler_mutation_production_migration_lifecycle_s334_yield_now_writer_guard_integration.rs::target_function_contains_one_scheduler_writer_and_one_s334_guard

#[test]
fn target_function_contains_one_scheduler_writer_and_one_s334_guard() {
    let target = yield_now_boundary();
    assert_eq!(target.matches("addr_of_mut!(SCHEDULER)").count(), 1);
    assert_eq!(
        target
            .matches("acquire_s334_production_scheduler_writer_access()")
            .count(),
        1
    );
    assert_eq!(
        target
            .matches("context_switch(old_ctx_ptr, new_ctx)")
            .count(),
        1
    );
}
snippet sha256: 5677d0c6b179file sha256: 96dece7b3df2
04 · Kapı kimlik kaydı

Operations sıra, kimlik ve başlık bağı

tam Operations kaydıL14317–L14370
website/src/lib/operations.ts::g8l-s334-yield-now-writer-guard-integration-partial
  {
    id: "g8l-s334-yield-now-writer-guard-integration-partial",
    date: "2026-08-27",
    sequence: 334,
    status: "passed",
    umbrella_status: "partial",
    title: "S334 · Yield-now production writer guard integration",
    summary:
      "S334, yield_now içindeki tek mutable SCHEDULER yolunu IRQ-masked CPU0 sınırında S333 ve 44 production reader'ın kullandığı aynı S247 state word'e bağlar. Writer üyeliği reaper, current-task take, dead/live requeue, owned old-ASID snapshot ile adres-uzayı hazırlığı, next-task yayımı ve deferred retirement'ı kapsar; askıda kalan continuation global writer'ı tutmasın diye context_switch öncesinde düşer. Guarded writer 7/69, açık writer 62 ve provider authority 0'dır.",
    evidence: [
      "Focused yield-now writer-integration kapısı iki bağımsız koşuda 26/26 PASS: 141 B / SHA-256 21a41d2628ef64ed51b5ee88b70062b4fe124b2e9017f7bd8f6c854bc4295452.",
      "Aynı S247 state word üzerinde CPU0-only writer membership, non-CPU0 pre-commit rejection, reader→writer ve writer→reader exclusion, exact-once commit/error release ve S333→S334 token monotonluğu doğrulandı.",
      "Production kaynak sırası IRQ guard → acquire_s334 writer → tek mutable alias → retired reaper → current take/owned old-ASID snapshot → dead/live requeue → snapshot-only TTBR0/TLBI hazırlığı → current/tick/retired publication → writer drop → context_switch olarak kilitlendi.",
      "Snapshot-only hazırlık helper'ı SCHEDULER pointer'ı veya S257/S265 reader acquire içermez; böylece writer altında nested reader self-deadlock'ı üretilmez. Exact tarihsel prepare_task_for_context_switch(&next) kaynak token'ı ve S296 yield semantiği korunur.",
      "QEMU, RPi4, RPi5 ve RPi5+SMP AArch64 compile profilleri exit 0 verdi; warning header'ları 293/391/1130/1130, zero-warning iddiası yoktur.",
      "Operations komut haritasından türetilen S238–S334 matrisi iki bağımsız koşuda 98 grup / 1443/1443 PASS; süre-normalize çıktılar 12809 B / SHA-256 97a0903505eb2e6d7ef107eafa9d77e2ca47bebcc67e83676179e6afd0d94573 ile byte-eşittir.",
      "Exact yedi tarihsel G8h assertion adı dışlanıp kayıtlı --test-threads=1 kabulü kullanıldığında tam workspace iki koşuda 296 sonuç grubu / 3266 PASS / 0 fail / 7 filtered verdi; süre-normalize sonuç özetleri 28297 B / SHA-256 d7b6548b444667902fbe72735045024a0727e76e28d06a7504933072051d0770 ile byte-eşittir. Filtresiz seri audit yalnız frozen S96 exceptions.S identity kapısında RED kaldığı için global workspace GREEN iddia edilmez.",
      "make verify-qemu iki bağımsız PASS verdi: strict ELF W^X 31/31 ve aynı 1551 B / SHA-256 527ef12c2bc56140e14e13be445f78c8e38872febc9849afcfacd499238ff966 smoke özeti korundu. Bu ortak regresyon board-rpi5-only S334 yield_now writer invocation kanıtı değildir.",
      "Yerel website 514/514 test ile PASS; lint, boş çıktılı TypeScript kontrolü ve 23/23 static route ayrıca geçti. S334 kaydı yereldir ve deployment yapılmadı.",
      "S245 request ve S244 admission dokunulmadan kalır; production provider authority=0, whole-scheduler exclusion=false ve toplam 62 production writer açık kalır.",
      "Fiziksel/device işlem yapılmadı: physical/device operations=0 ve RUNBOOK_EXECUTED_IN_S334=NO.",
    ],
    commands: [
      "cargo test --quiet -p aselsan_microkernel_simulation --test g8l_target_dispatch_scheduler_owner_scheduler_mutation_production_migration_lifecycle_s334_yield_now_writer_guard_integration -- --test-threads=1",
      "cargo check -p aselsan_kernel --target aarch64-unknown-none --no-default-features --features board-rpi5",
      "cargo check -p aselsan_kernel --target aarch64-unknown-none --no-default-features --features board-rpi5,smp",
      "cargo test --workspace --quiet -- --test-threads=1 [seven exact historical --skip filters]",
    ],
    terminalSessions: [
      {
        id: "g8l-s334-yield-now-writer-guard-integration",
        title: "G8l S334 yield-now writer guard integration",
        commandLines: [
          "cargo test --quiet -p aselsan_microkernel_simulation --test g8l_target_dispatch_scheduler_owner_scheduler_mutation_production_migration_lifecycle_s334_yield_now_writer_guard_integration -- --test-threads=1",
        ],
        outputLines: [
          "test result: ok; S334 focused 1 group / 26 passed; 0 failed",
          "shared S247 gate: 44 guarded readers + 7/69 guarded writers; 62 writers open",
          "owned old-ASID snapshot avoids nested reader; writer drops before context_switch",
        ],
        exitCode: 0,
        outputMode: "complete",
      },
    ],
    terminalSessionsNote:
      "S334 yedinci production writer'ın kaynak entegrasyonudur; supported RPi5 yield_now invocation'ı veya context-switch runtime gözlemi yapılmadığı için cihaz ve global exclusion kanıtı oluşmadı.",
    limitations: [
      "62 production writer aynı shared gate dışında kaldığı için whole-scheduler exclusion ve provider authority açık kalır.",
      "Writer context_switch öncesinde bilinçli olarak düşer; snapshot-only address-space hazırlığının supported-board runtime invocation'ı gözlenmemiştir.",
      "Default-parallel PTY determinism S331'den açık taşınır; kayıtlı seri kabul matrisi kullanılır.",
      "Transient-contention liveness/soak, Generic SMP ve fiziksel RPi kabulü açık kalır.",
      "Yerel web doğrulaması deployment değildir; canlı site bu değişiklikle güncellenmemiştir.",
    ],
  },
snippet sha256: 53d6f83b1d93file sha256: 9726dbf00f84
Focused test komutu
cargo test -p aselsan_microkernel_simulation --test g8l_target_dispatch_scheduler_owner_scheduler_mutation_production_migration_lifecycle_s334_yield_now_writer_guard_integration -- --test-threads=1
proof: docs/M8.1-RPi5-G8l-S334-Yield-Now-Writer-Guard-Integration-Proof.md
Registry schema v5 · generator website/scripts/generate-code-gates.mjs · Tam SHA-256: 3050638b71a684d8f8f947a8a6faa237a17fa8db5dc0db04fb207b668b462af9