feat: add lab-rv32i-freertos-static-task card

This commit is contained in:
user
2026-07-21 19:14:20 +02:00
commit 62efc0c91f
65 changed files with 33788 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
# K08 — DynamicTask, StaticTask, deletion and lifetime
## Position
- Series: FreeRTOS C++
- Lesson: L07, card K08
- Duration: 30 minutes
- Real dynamic `heap_4` plus caller TCB/stack in `.bss`
- Idle task itself and the verifier use static storage to isolate measurement
## Outcome
After 30 minutes the student can calculate stack words and bytes, prove dynamic
heap cost versus zero-delta static creation, classify TCB/stack addresses, and
explain why self-deletion and actual dynamic memory reclamation are separated by
idle-task cleanup.
## Lesson plan
| Time | Mode | Evidence |
| --- | --- | --- |
| 05 | units/storage | predict 256 words, bytes and locations |
| 510 | dynamic create | measure heap delta and classify TCB/stack |
| 1015 | static create | caller TCB/stack addresses; heap delta zero |
| 1520 | run/complete | identical result 500500; wrappers completed/null |
| 2025 | delete timing | heap still reduced immediately after self-delete |
| 2530 | idle cleanup | block verifier; recover exact dynamic delta/baseline |
## Canonical timeline
```text
baseline
-> xTaskCreate(dynamic): heap - dynamic_cost
-> xTaskCreateStatic(static): no heap change
-> both run and complete
-> both call vTaskDelete(nullptr)
-> verifier runs before idle: dynamic storage still pending cleanup
-> verifier blocks
-> idle calls termination cleanup:
dynamic TCB/stack -> vPortFree
static TCB/stack -> not freed (caller owned)
-> verifier wakes: heap == baseline
```
## Stable evidence
| Evidence | Required relation |
| --- | --- |
| dynamic cost | baseline - after_dynamic > 0 |
| static delta | after_static == after_dynamic |
| verifier delta | static verifier creation also leaves heap unchanged |
| dynamic addresses | TCB and stack base lie in `ucHeap` |
| static addresses | observed TCB/stack equal caller storage and lie outside heap |
| before idle | free equals post-create value, despite completed wrappers |
| after idle | free=baseline; recovered bytes=dynamic cost |
| units | 256 `StackType_t` words = 1024 B on RV32I |
## Main traps
1. `stack_depth` counts words, not bytes.
2. `vTaskDelete(nullptr)` removes the current task from scheduling but dynamic
memory reclamation is deferred to idle.
3. Static task deletion does not free caller storage; premature reuse is a
lifetime bug.
4. A wrapper handle becoming null is not proof that idle cleanup already ran.
5. Forced deletion does not run arbitrary C++ destructors on the victim stack.
## Acceptance
- host test proves both create APIs receive the same stable context and static
native handle equals caller TCB;
- ABI proves static worker storage is `.bss` and no vtable/init runtime exists;
- static create and verifier create have exactly zero heap delta;
- dynamic cost is recovered only after the verifier lets idle run;
- both results are 500500, states completed, handles null and final PASS is 1.
+344
View File
@@ -0,0 +1,344 @@
% Generated from json/card_source.json by tools/render_card.py.
% Do not edit manually; update the JSON and regenerate.
\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[polish]{babel}
\usepackage{csquotes}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage[a4paper,left=2.15cm,right=2.15cm,top=0.5cm,bottom=0.5cm,headheight=24mm,headsep=3mm,includehead]{geometry}
\usepackage{eso-pic}
\usepackage{marginnote}
\usepackage{array}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{pdflscape}
\usepackage{float}
\usepackage{silence}
\WarningFilter{soulutf8}{This package is obsolete}
\usepackage{pdfcomment}
\usepackage{enumitem}
\usepackage{needspace}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{microtype}
\usepackage[most]{tcolorbox}
\usepackage{qrcode}
\IfFileExists{references.bib}{%
\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}%
\addbibresource{references.bib}%
}{}
\hypersetup{hidelinks}
\IfFileExists{build-meta.tex}{%
\input{build-meta.tex}%
}{%
\newcommand{\BuildCommit}{lokalna}%
}
\newcommand{\DocumentAuthor}{M. Pabiszczak}
\newcommand{\DocumentYear}{2026}
\newcommand{\CardSeries}{freertos-cpp}
\newcommand{\CardNumber}{08}
\newcommand{\CardCount}{16}
\newcommand{\CardSlug}{static-task}
\newcommand{\CardVersion}{v00.01}
\newcommand{\DocumentUUID}{d9e45417-a37f-487c-813f-fc7a44d4b4f3}
\newcommand{\EmptyCheck}{\(\square\)}
\newcommand{\EscAnswerLines}[1][3]{\par\noindent\dotfill\par\noindent\dotfill\par\noindent\dotfill}
\newcommand{\EscWriteRow}[1][2.8em]{\rule{0pt}{#1}}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0.45em}
\setlength{\headheight}{24mm}
\setlength{\headsep}{3mm}
\setlength{\footskip}{8mm}
\setlength{\marginparwidth}{1.5cm}
\setlength{\marginparsep}{0.25cm}
\renewcommand{\arraystretch}{1.22}
% Margin separator lines disabled for layout trial.
\newcommand{\ESCPageResourceHeader}{%
\begingroup%
\setlength{\parskip}{0pt}%
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{0.35pt}%
\setlength{\arrayrulewidth}{0.35pt}%
\noindent\fbox{%
\begin{minipage}[c][23.5mm][c]{\dimexpr\textwidth-2\fboxrule\relax}%
\begin{minipage}[c][23mm][c]{\dimexpr\linewidth-24mm-0.35pt\relax}%
\setlength{\tabcolsep}{0pt}%
\renewcommand{\arraystretch}{0}%
\begin{tabularx}{\linewidth}{@{}p{\dimexpr0.50000000\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.15126050\linewidth-\arrayrulewidth\relax}|X@{}}%
\parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries TITLE}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{7.7}{7.9}\selectfont\ttfamily\bfseries DynamicTask, StaticTask, deletion and lifetime}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries VER.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.6}{6.8}\selectfont\ttfamily\bfseries v00.01}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries DATETIME}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries 2026-07-19T00:00:00+02:00}\hspace{0.45mm}}\par} \\%
\end{tabularx}%
\par\nointerlineskip%
\hrule height0.35pt%
\nointerlineskip%
\begin{tabularx}{\linewidth}{@{}p{\dimexpr0.50000000\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.25210084\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.14285714\linewidth-\arrayrulewidth\relax}|X@{}}%
\parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries PROJECT}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{7.7}{7.9}\selectfont\ttfamily\bfseries Freestanding C++ nad FreeRTOS}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries SERIES}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries FreeRTOS C++}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries CARD}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries 08/16}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries SHEET}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries \thepage/\pageref{LastPage}}\hspace{0.45mm}}\par} \\%
\end{tabularx}%
\par\nointerlineskip%
\hrule height0.35pt%
\nointerlineskip%
\begin{tabularx}{\linewidth}{@{}p{\dimexpr0.05882353\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.05042017\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.14705882\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.09243697\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.07563025\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.07563025\linewidth-\arrayrulewidth\relax}|X@{}}%
\parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries SUBJ.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries Inf.}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries PROG.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries CORE}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries SCOPE}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries LEVEL}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries POS.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hbox to\linewidth{\hspace{0.35mm}{\fontsize{3.4}{3.75}\selectfont\ttfamily\bfseries GITEA UUID}\hfill{\fontsize{3.4}{3.75}\selectfont\ttfamily d9e45417-a37f-487c-813f-fc7a44d4b4f3}\hspace{0.35mm}}\par\nointerlineskip\hbox to\linewidth{\hspace{0.35mm}{\fontsize{3.4}{3.75}\selectfont\ttfamily\bfseries CARD UUID} {\fontsize{3.4}{3.75}\selectfont\ttfamily d9e45417-a37f-487c-813f-fc7a44d4b4f3}\hfill{\fontsize{3.4}{3.75}\selectfont\ttfamily\bfseries AUTHOR M. Pabiszczak}\hspace{0.35mm}}} \\%
\end{tabularx}%
\par\nointerlineskip%
\hrule height0.35pt%
\nointerlineskip%
\begin{tabularx}{\linewidth}{@{}X@{}}%
\parbox[c][3.46276mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{4.5}{4.85}\selectfont\ttfamily\bfseries GITEA} {\fontsize{4.5}{4.85}\selectfont\ttfamily\href{https://zsl-gitea.mpabi.pl/edu-freertos-cpp/lab-rv32i-freertos-static-task}{\nolinkurl{https://zsl-gitea.mpabi.pl/edu-freertos-cpp/lab-rv32i-freertos-static-task}}}} \\%
\end{tabularx}%
\par\nointerlineskip%
\hrule height0.35pt%
\nointerlineskip%
\begin{tabularx}{\linewidth}{@{}X@{}}%
\parbox[c][3.46276mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{4.5}{4.85}\selectfont\ttfamily\bfseries HTML} {\fontsize{4.5}{4.85}\selectfont\ttfamily\href{}{\nolinkurl{}}}} \\%
\end{tabularx}%
\end{minipage}%
\vrule width0.35pt%
\begin{minipage}[c][23mm][c]{24mm}\centering%
{\tiny QR wyłączony}%
\end{minipage}%
\end{minipage}%
}%
\endgroup%
}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{\ESCPageResourceHeader}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\newcommand{\ESCMarginTag}[4]{%
\hspace*{#1}\textcolor{#2}{#3~#4}%
}
\newcommand{\ESCSectionBlockStart}{%
\Needspace{8\baselineskip}%
\par\vspace{0.35em}%
\noindent\textcolor{black!28}{\rule{\textwidth}{0.35pt}}%
\par\vspace{0.15em}%
}
\newcommand{\ESCSectionBlockEnd}{%
\par\vspace{0.25em}%
\noindent\textcolor{black!18}{\rule{\textwidth}{0.25pt}}%
\par\vspace{0.45em}%
}
\newcommand{\ESCTinyStepSeparator}{%
\par\vspace{0.10em}%
\noindent{\color{black!18}\leaders\hbox{\rule{0.60em}{0.22pt}\hspace{0.38em}}\hfill\kern0pt}%
\par\vspace{0.10em}%
}
\newtcolorbox{ESCTaskFrame}[1]{enhanced,breakable,arc=0pt,boxrule=0.35pt,colback=white,colframe=black,boxsep=0pt,left=1.4mm,right=1.4mm,top=0.8mm,bottom=0.8mm,colbacktitle=black!7,coltitle=black,title={\ttfamily\bfseries TASK\quad #1}}
\newtcolorbox{ESCBlockFrame}[1]{enhanced,breakable,arc=0pt,boxrule=0.35pt,colback=white,colframe=black!55,boxsep=0pt,left=1.0mm,right=1.0mm,top=0.6mm,bottom=0.6mm,colbacktitle=black!4,coltitle=black,title={\ttfamily\bfseries BLOCK\quad #1}}
\newtcolorbox{ESCStepFrame}[1]{enhanced,breakable,arc=0pt,boxrule=0.35pt,colback=white,colframe=black!28,boxsep=0pt,left=0.8mm,right=0.8mm,top=0.45mm,bottom=0.45mm,colbacktitle=black!2,coltitle=black,title={\ttfamily STEP\quad #1}}
\newtcolorbox{ESCConclusionFrame}{enhanced,breakable,arc=0pt,boxrule=0.45pt,colback=blue!2,colframe=blue!45!black,boxsep=0pt,left=1.2mm,right=1.2mm,top=0.7mm,bottom=0.7mm,colbacktitle=blue!7,coltitle=black,title={\ttfamily\bfseries WNIOSEK}}
\newcommand{\ESCLearningTreeWidget}{%
\reversemarginpar
\marginnote[%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\begin{minipage}[t]{\marginparwidth}%
\raggedright
{\bfseries\textcolor{black!65}{TECH}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\hspace*{0.28em}\textcolor{orange!85!black}{EK~LOCAL~DBG.TASK}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.02}{Mierzy heap delta i śledzi dynamiczne oraz statyczne adresy.}}\par%
\hspace*{0.54em}\textcolor{blue!70!black}{KW~LOCAL~DBG.TASK}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.02}{Dowodzi 1136 B kosztu, 0 B static delta, 256 słów równego 1024 B i exact reclaim.}}\par%
\end{minipage}%
}%
\end{minipage}%
]{}
\normalmarginpar
\marginnote{%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\hspace*{0.06cm}%
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
\raggedright
{\bfseries\textcolor{black!65}{OG}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\hspace*{0.28em}\textcolor{green!50!black}{EN~LOCAL~EN~RTOS.LIFE}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.02}{Analizuje completion, self-delete, idle cleanup i caller ownership.}}\par%
\hspace*{0.54em}\textcolor{blue!70!black}{KW~LOCAL~KW~RTOS.LIFE}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.02}{Wyjaśnia dwa momenty zakończenia i bezpieczny lifetime statycznego storage.}}\par%
\end{minipage}%
}%
\end{minipage}%
}
}
\begin{document}
\sloppy
\vspace{1.0em}
\noindent{\Large\bfseries Cel karty}\par
\vspace{0.35em}
Uczeń porównuje identyczne zachowanie taska tworzonego przez xTaskCreate i xTaskCreateStatic, przelicza stack words na bajty oraz mierzy moment odzyskania pamięci dynamicznej.
\vspace{0.8em}
\noindent\textcolor{black!25}{\rule{\textwidth}{0.35pt}}
\vspace{0.7em}
\noindent{\Large\bfseries Zakres karty}\par
\vspace{0.35em}
StaticTaskStorage pozostaje własnością callera. Self-delete kończy scheduling, lecz dynamiczny TCB i stack odzyskuje dopiero idle; wymuszone delete nie odwija ramek C++.
\vspace{0.8em}
\noindent\textcolor{black!25}{\rule{\textwidth}{0.35pt}}
\clearpage
\ESCSectionBlockStart
\section{Jednostki i dwa źródła storage}
\reversemarginpar
\marginnote[%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\begin{minipage}[t]{\marginparwidth}%
\raggedright
{\bfseries\textcolor{black!65}{TECH}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
]{}[-3.1em]
\normalmarginpar
\marginnote{%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\hspace*{0.06cm}%
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
\raggedright
{\bfseries\textcolor{black!65}{OG}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
}[-3.1em]
\begingroup
\scriptsize\ttfamily\color{black!60}\sloppy
\noindent drzewka: \pdftooltip[width=\textwidth]{D1}{K08.WE01.TECH.LOCAL.DBG.TASK.02 | WE 01: Storage taska i cleanup. Porównanie dynamicznej i\textCR statycznej polityki storage taska oraz pełnej osi życia delete. | EK LOCAL DBG.TASK.02:\textCR Mierzy heap delta i śledzi dynamiczne oraz statyczne adresy. | KW LOCAL DBG.TASK.02: Dowodzi\textCR 1136 B kosztu, 0 B static delta, 256 słów równego 1024 B i exact reclaim.}\par
\vspace{0.10em}%
\noindent K1: Przelicz 256 StackType\_t words na 1024 B.\quad D1\par
\ESCTinyStepSeparator
\noindent K2: Sklasyfikuj dynamiczne adresy w ucHeap i statyczne w .bss.\quad D1\par
\par\vspace{0.18em}%
\endgroup
Oblicz stack bytes, a potem porównaj kernel-allocated TCB/stack z osobnym StaticTaskStorage w .bss.
\ESCSectionBlockEnd
\ESCSectionBlockStart
\section{Dynamiczny koszt kontra static delta}
\reversemarginpar
\marginnote[%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\begin{minipage}[t]{\marginparwidth}%
\raggedright
{\bfseries\textcolor{black!65}{TECH}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
]{}[-3.1em]
\normalmarginpar
\marginnote{%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\hspace*{0.06cm}%
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
\raggedright
{\bfseries\textcolor{black!65}{OG}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
}[-3.1em]
\begingroup
\scriptsize\ttfamily\color{black!60}\sloppy
\noindent drzewka: \pdftooltip[width=\textwidth]{D1}{K08.WE01.TECH.LOCAL.DBG.TASK.02 | WE 01: Storage taska i cleanup. Porównanie dynamicznej i\textCR statycznej polityki storage taska oraz pełnej osi życia delete. | EK LOCAL DBG.TASK.02:\textCR Mierzy heap delta i śledzi dynamiczne oraz statyczne adresy. | KW LOCAL DBG.TASK.02: Dowodzi\textCR 1136 B kosztu, 0 B static delta, 256 słów równego 1024 B i exact reclaim.}\par
\vspace{0.10em}%
\noindent K1: Wyznacz dynamic cost 1136 B i static delta 0 B.\quad D1\par
\ESCTinyStepSeparator
\noindent K2: Potwierdź identyczny wynik workerów 500500.\quad D1\par
\par\vspace{0.18em}%
\endgroup
Zmierz baseline, create dynamic i create static. Wyjaśnij TCB oraz narzut heap_4 ponad 1024 B stacka.
\ESCSectionBlockEnd
\ESCSectionBlockStart
\section{Self-delete i cleanup przez idle}
\reversemarginpar
\marginnote[%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\begin{minipage}[t]{\marginparwidth}%
\raggedright
{\bfseries\textcolor{black!65}{TECH}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
]{}[-3.1em]
\normalmarginpar
\marginnote{%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\hspace*{0.06cm}%
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
\raggedright
{\bfseries\textcolor{black!65}{OG}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
}[-3.1em]
\begingroup
\scriptsize\ttfamily\color{black!60}\sloppy
\noindent drzewka: \pdftooltip[width=\textwidth]{D1}{K08.WE01.OG.LOCAL.RTOS.LIFE.02 | WE 01: Storage taska i cleanup. Porównanie dynamicznej i\textCR statycznej polityki storage taska oraz pełnej osi życia delete. | EN LOCAL RTOS.LIFE.02:\textCR Analizuje completion, self-delete, idle cleanup i caller ownership. | KW LOCAL RTOS.LIFE.02:\textCR Wyjaśnia dwa momenty zakończenia i bezpieczny lifetime statycznego storage.}\par
\vspace{0.10em}%
\noindent K1: Rozdziel completion/null handle od memory reclaim.\quad D1\par
\ESCTinyStepSeparator
\noindent K2: Uzasadnij caller ownership i granicę destruktorów C++.\quad D1\par
\par\vspace{0.18em}%
\endgroup
Porównaj free przed idle z baseline, pozwól idle wykonać cleanup i potwierdź exact recovery dynamicznego kosztu.
\ESCSectionBlockEnd
\end{document}
+225
View File
@@ -0,0 +1,225 @@
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[polish]{babel}
\usepackage[a4paper,margin=1.55cm]{geometry}
\usepackage{array,tabularx,booktabs,amsmath,amssymb,xcolor,listings,hyperref,fancyhdr,lastpage,enumitem}
\definecolor{accent}{HTML}{16324A}\definecolor{accentlight}{HTML}{EEF3F7}\definecolor{rulegray}{HTML}{D7DEE5}
\hypersetup{colorlinks=true,linkcolor=accent,urlcolor=blue}
\IfFileExists{build-meta.tex}{\input{build-meta.tex}}{\newcommand{\BuildCommit}{local}}
\newcommand{\PublisherDomain}{mpabi}
\newcommand{\CardArea}{inf}
\newcommand{\CardSeries}{freertos-cpp}
\newcommand{\CardNumber}{08}
\newcommand{\CardCount}{16}
\newcommand{\CardSlug}{static-task}
\newcommand{\CardVersion}{v00.01}
\newcommand{\DocumentUUID}{d9e45417-a37f-487c-813f-fc7a44d4b4f3}
\newcommand{\blank}[1]{\rule{#1}{.2pt}}
\lstset{language=C++,basicstyle=\ttfamily\scriptsize,columns=fullflexible,keepspaces=true,frame=single,breaklines=true,showstringspaces=false,numbers=none,backgroundcolor=\color{accentlight},rulecolor=\color{rulegray}}
\pagestyle{fancy}\fancyhf{}
\lhead{\textbf{K08 · FreeRTOS C++ · storage taska}}\rhead{\small L07 · dynamic/static i delete}
\lfoot{\scriptsize commit \BuildCommit}\cfoot{\scriptsize \thepage/\pageref{LastPage}}\rfoot{\scriptsize V11.3.0 / \CardVersion}
\setlength{\headheight}{14pt}\setlength{\footskip}{19pt}
\setlist[itemize]{nosep,leftmargin=1.45em}\setlist[enumerate]{nosep,leftmargin=1.65em}
\begin{document}\sloppy
\begin{center}
{\LARGE\bfseries \texttt{DynamicTask}, \texttt{StaticTask} i lifetime}\par
\vspace{.25em}{\large delete logiczny teraz, reclaim dynamiczny przez idle}\par
\end{center}
\noindent\begin{tabularx}{\textwidth}{@{}p{1.65cm}Xp{1.55cm}X@{}}
\toprule
Karta & K08 / \CardCount & Czas & 30 minut \\
Platforma & Hazard3 / RV32I & Język & freestanding C++17 \\
Stack & 256 słów & Polityki & heap kontra caller storage \\
Wersja & \CardVersion & UUID karty & \texttt{d9e45417-...} \\
\bottomrule
\end{tabularx}
\section*{To samo zachowanie, dwa źródła TCB i stacka}
\begin{center}
\texttt{xTaskCreate -> TCB + stack from heap\_4}\\[.4em]
\texttt{xTaskCreateStatic -> caller StaticTask\_t + StackType\_t[]}
\end{center}
Oba workery liczą 1..1000 i kończą wynikiem 500500. Różni je miejsce,
właściciel oraz moment odzyskania pamięci.
\noindent\fcolorbox{accent}{accentlight}{\begin{minipage}{.94\textwidth}
\textbf{Kontrakt K08.} Null handle i stan completed oznaczają zakończenie
wrappera, lecz nie dowodzą jeszcze zwolnienia dynamicznego TCB/stacka. To robi
idle. Statyczne bufory nigdy nie stają się własnością kernela.
\end{minipage}}
\section*{Plan 30 minut}
\noindent\begin{tabularx}{\textwidth}{@{}p{1.35cm}p{3.1cm}X@{}}
\toprule
Czas & Tryb & Dowód \\
\midrule
0--5 & jednostki & 256 słów, liczba bajtów i lokalizacje \\
5--10 & dynamic & heap delta, TCB i stack w ucHeap \\
10--15 & static & caller TCB/stack w .bss, heap delta 0 \\
15--20 & wykonanie & oba wyniki 500500, completed/null \\
20--25 & delete & dynamic heap nadal zmniejszony przed idle \\
25--30 & cleanup & verifier blokuje; idle odzyskuje dokładny delta \\
\bottomrule
\end{tabularx}
\section*{Predykcja}
256 słów RV32I $\times$ \blank{1cm} B/słowo = \blank{2cm} B. Czy
\texttt{vTaskDelete(nullptr)} samo natychmiast wywoła dwa free dynamicznego
taska? \blank{3cm}
\newpage
\section{Słowa, bajty i właściciel storage}
\noindent\begin{tabularx}{\textwidth}{@{}p{4.1cm}p{5.0cm}X@{}}
\toprule
Właściwość & DynamicTask & StaticTask \\
\midrule
API & \texttt{xTaskCreate} & \texttt{xTaskCreateStatic} \\
TCB & przydziela kernel z heapu & caller przekazuje \texttt{StaticTask\_t} \\
stack & kernel: depth w słowach & caller: \texttt{StackType\_t[N]} \\
heap delta przy create & \blank{3cm} & \blank{3cm} \\
adres TCB & \blank{3cm} & \blank{3cm} \\
adres stack base & \blank{3cm} & \blank{3cm} \\
właściciel po delete & idle odzyskuje dynamiczny & caller nadal posiada statyczny \\
\bottomrule
\end{tabularx}
\section*{Oblicz przed kompilacją}
\begin{align*}
\text{stack bytes} &= \text{stack words}\times\texttt{sizeof(StackType\_t)}\\
&=256\times\blank{1cm}=\blank{2cm}\ \text{B}
\end{align*}
Dynamiczny koszt będzie większy od samych stack bytes, bo obejmuje także TCB
oraz narzut bloków allocatora. Predykcja kosztu: \blank{3cm} B. Pomiar:
\blank{3cm} B. Różnica: \blank{3cm} B.
\section{Caller-supplied storage musi naprawdę być osobne}
\begin{lstlisting}
StaticTaskStorage<256> worker_storage; // .bss
StaticWorker worker{worker_storage};
xTaskCreateStatic(entry, "static", 256, &worker, priority,
worker_storage.stack, &worker_storage.tcb);
\end{lstlisting}
W ELF symbol \texttt{g\_static\_worker\_storage} ma typ sekcji
\blank{2cm}. Odczyty muszą spełnić:
\begin{center}
\texttt{observed TCB == \&worker\_storage.tcb}\\
\texttt{observed stack base == worker\_storage.stack}
\end{center}
\section*{Dlaczego storage jest oddzielone od handle?}
Handle może zostać wyzerowany po completion. Bufor statyczny nadal istnieje i
ma własny czas życia. Nie wolno go jednak ponownie użyć, dopóki usunięcie taska
nie jest ustalone; sam „request stop” nie wystarcza.
\newpage
\section{Oś czasu delete i idle cleanup}
\begin{center}
\texttt{baseline}\\
$\downarrow$ \texttt{xTaskCreate(dynamic): free -= cost}\\
$\downarrow$ \texttt{xTaskCreateStatic(static): delta 0}\\
$\downarrow$ \texttt{workers run -> completed -> handle=null -> self-delete}\\
$\downarrow$ \texttt{verifier runs before idle: dynamic cost still absent}\\
$\downarrow$ \texttt{verifier vTaskDelay(2): idle cleans termination list}\\
$\downarrow$ \texttt{verifier wakes: free == baseline}
\end{center}
\noindent\begin{tabularx}{\textwidth}{@{}p{5.7cm}p{4cm}X@{}}
\toprule
Pomiar & Predykcja & Odczyt \\
\midrule
baseline free & \blank{3cm} & \blank{3cm} \\
free po dynamic start & mniejsze & \blank{3cm} \\
free po static start & bez zmiany & \blank{3cm} \\
free po static verifier create & bez zmiany & \blank{3cm} \\
free przed idle cleanup & nadal zmniejszone & \blank{3cm} \\
free po idle cleanup & baseline & \blank{3cm} \\
recovered by idle & dynamic cost & \blank{3cm} \\
\bottomrule
\end{tabularx}
\section*{Co robi idle?}
Self-delete nie może zwolnić własnego stosu, gdy kod nadal na nim wykonuje
instrukcje. Kernel odkłada dynamiczny TCB na listę terminacji. Idle działa już
na innym stosie i może bezpiecznie wywołać cleanup/free. Dla statycznego taska
rozpoznaje caller-owned storage i go nie zwalnia.
\section*{Dwa różne zdania o zakończeniu}
\begin{enumerate}
\item \textbf{Logiczne}: task nie jest schedulowany, wrapper ma completed/null.
\item \textbf{Pamięciowe}: idle odzyskał dynamiczny TCB/stack; current free
wróciło o dokładny koszt.
\end{enumerate}
Czy verifier o priorytecie 1 może sprawdzić reclaim bez blokowania się?
\blank{3cm}. Dlaczego? \blank{11cm}\\[1em]\blank{16cm}
\section*{Granica destruktorów aplikacyjnych}
Wymuszone usunięcie innego taska nie odwija automatycznie jego ramek C++.
Workery K08 kończą member body normalnie, a dopiero trampoline self-delete.
\newpage
\section{Hazard3/GDB i zaliczenie}
\begin{lstlisting}[language=bash]
make check
riscv64-unknown-elf-gdb build/task01_static_task/prog.elf
b task_storage_debug_checkpoint
\end{lstlisting}
\begin{lstlisting}
p g_heap_baseline
p g_heap_after_dynamic_start
p g_heap_after_static_start
p g_heap_before_idle_cleanup
p g_heap_after_idle_cleanup
p/x g_dynamic_tcb
p/x g_dynamic_stack_low
p/x g_static_tcb
p/x g_static_tcb_storage
p/x g_static_stack_low
p/x g_static_stack_storage
p g_static_stack_words
p g_static_stack_bytes
p g_task_storage_pass
\end{lstlisting}
\noindent\begin{tabularx}{\textwidth}{@{}p{1cm}p{4.1cm}X@{}}
\toprule
STOP & Stan & Dowód \\
\midrule
1 & baseline & current free zapisane \\
2 & dynamic created & heap spada; handle/TCB i stack w ucHeap \\
3--4 & static created & caller addresses; heap bez zmiany \\
5--8 & workers & oba wyniki 500500; completion/self-delete \\
9 & before idle & handles null, lecz dynamic cost nadal zajęty \\
10 & after idle & odzyskany dokładny cost; free=baseline \\
11 & final & static storage zachowane; pass=1 \\
\bottomrule
\end{tabularx}
\section*{Zaliczenie}
\begin{itemize}
\item $\square$ przeliczam 256 słów na 1024 B;
\item $\square$ pokazuję dodatni dynamic cost i zerowy static delta;
\item $\square$ klasyfikuję dynamic addresses w heapie i static w .bss;
\item $\square$ rozróżniam completion/null od idle memory reclaim;
\item $\square$ pokazuję before-idle, after-idle i exact recovered cost;
\item $\square$ nie przypisuję kernelowi własności static storage.
\end{itemize}
\section*{Wyjście}
Dlaczego self-delete nie może od razu zwolnić własnego stacka?\\[.5em]
\blank{16cm}\\[1em]
Kiedy wolno ponownie użyć statycznego TCB/stacka?\\[.5em]
\blank{16cm}
\vfill
\noindent\textbf{Następna karta K09:} statyczna fasada schedulera,
\texttt{this\_task}, critical section i guard zawieszenia z poprawnym restore.
\end{document}